Skip to content

Commit

Permalink
School/application folder changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paullocknimble committed Jun 7, 2024
1 parent 801aafa commit 1bdfbbb
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class AcademyConversionProject
public int Id { get; set; }
public int? Urn { get; set; }
public int? FormAMatProjectId { get; set; }
public Guid? SharePointId { get; set; }
public Guid? SchoolSharePointId { get; set; }
public Guid? ApplicationSharePointId { get; set; }
public bool? IsFormAMat { get; set; }
public DateTime CreatedOn { get; set; }
public string SchoolName { get; set; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dfe.PrepareConversions.Configuration
{
public class SharePointOptions
{
public bool Enabled { get; set; }
public string Url { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@page "/project-documents/{id:int}"
@using Dfe.PrepareConversions.Data.Models
@using Dfe.PrepareConversions.Services.Helpers
@model Dfe.PrepareConversions.Pages.ProjectDocuments.IndexModel
@{
ViewData["Title"] = "Project documents";
Expand All @@ -15,25 +14,9 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form asp-page-handler="GetFile" method="get">


<partial name="Shared/_FilesPartial" model='new FilesViewModel {
Urn = Model.Project.SchoolURN,
EntityId = Model.Project.SharePointId.Value,
ApplicationReference = Model.Project.ApplicationReferenceNumber,
FilePrefixSection = FileUploadConstants.ResolutionConsentfilePrefixFieldName,
SectionName = "Resolution Consent",
FileNames = Model.ResolutionConsentFileNames
}' />
</form>
<partial name="Shared/_FilesPartial" model='new FilesViewModel {
Urn = Model.Project.SchoolURN,
EntityId = Model.Project.SharePointId.Value,
ApplicationReference = Model.Project.ApplicationReferenceNumber,
FilePrefixSection = FileUploadConstants.DioceseFilePrefixFieldName,
SectionName = "Diocese",
FileNames = Model.DioceseFileNames
}' />

Application level documents folder <a href="@Model.ApplicationLevelDocumentsFolder" target="_blank">here</a><br />
School level documents folder <a href="@Model.SchoolLevelDocumentsFolder" target="_blank">here</a>
</div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Dfe.PrepareConversions.Data.Services;
using Dfe.PrepareConversions.Models;
using Dfe.PrepareConversions.Services;
using Dfe.PrepareConversions.Services.Helpers;
using Dfe.PrepareConversions.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
Expand All @@ -12,63 +11,38 @@
using System.Net.Http;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using static System.Net.WebRequestMethods;

namespace Dfe.PrepareConversions.Pages.ProjectDocuments;

public class IndexModel : BaseAcademyConversionProjectPageModel
{
private readonly IFileService _fileService;
private readonly IConfiguration _configuration;

public string ReturnPage { get; set; }
public string ReturnId { get; set; }

public IndexModel(IAcademyConversionProjectRepository repository, IFileService fileService) : base(repository)
public IndexModel(IAcademyConversionProjectRepository repository, IConfiguration configuration) : base(repository)
{
_fileService = fileService;
_configuration = configuration;
}

[BindProperty]
public List<string> DioceseFileNames { get; set; }
public string ApplicationLevelDocumentsFolder { get; set; }
[BindProperty]
public List<string> ResolutionConsentFileNames { get; private set; }
public string SchoolLevelDocumentsFolder { get; private set; }

public override async Task<IActionResult> OnGetAsync(int id)
{
await base.OnGetAsync(id);
var rootSharePointFolder = _configuration["Sharepoint:Url"];

DioceseFileNames = await _fileService.GetFiles(FileUploadConstants.TopLevelSchoolFolderName, Project.SharePointId.ToString(), Project.ApplicationReferenceNumber, FileUploadConstants.DioceseFilePrefixFieldName);
//TempDataHelper.StoreSerialisedValue($"{EntityId}-dioceseFiles", TempData, DioceseFileNames);
//FoundationConsentFileNames = await _fileUploadService.GetFiles(FileUploadConstants.TopLevelSchoolFolderName, EntityId.ToString(), ApplicationReference, FileUploadConstants.FoundationConsentFilePrefixFieldName);
//https://educationgovuk.sharepoint.com/sites/sip-dev/sip_application/Forms/AllItems.aspx?id=%2Fsites%2Fsip%2Ddev%2Fsip%5Fapplication%2FA2B%5F0027%5F63B137B6D21DEB11A813000D3A38AA47

ResolutionConsentFileNames = await _fileService.GetFiles(FileUploadConstants.TopLevelSchoolFolderName, Project.SharePointId.ToString(), Project.ApplicationReferenceNumber, FileUploadConstants.ResolutionConsentfilePrefixFieldName);
ApplicationLevelDocumentsFolder = $"{rootSharePointFolder}sip_application/{Project.ApplicationReferenceNumber}_{Project.ApplicationSharePointId.Value.ToString("N").ToUpper()}";
SchoolLevelDocumentsFolder = $"{rootSharePointFolder}sip_applyingschools/{Project.ApplicationReferenceNumber}_{Project.SchoolSharePointId.Value.ToString("N").ToUpper()}";

return Page();
}

public async Task<HttpResponseMessage> GetFile(string entityName, string recordId, string recordName, string fieldName, string fileName)
{
//if (String.IsNullOrEmpty(id))
// return Request.CreateResponse(HttpStatusCode.BadRequest);

var file = await _fileService.DownloadFile(entityName, recordId, recordName, fieldName, fileName);

HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

response.Content = new StreamContent(GenerateStreamFromString(file));
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = fileName;
//response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

return response;
}

public static Stream GenerateStreamFromString(string s)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 3 additions & 8 deletions Dfe.PrepareConversions/Dfe.PrepareConversions/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Dfe.PrepareConversions.Routing;
using Dfe.PrepareConversions.Security;
using Dfe.PrepareConversions.Services;
using Dfe.PrepareConversions.Services.Helpers;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -150,14 +149,10 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<IGraphUserService, GraphUserService>();
services.AddScoped<IDfeHttpClientFactory, DfeHttpClientFactory>();
services.AddScoped<ICorrelationContext, CorrelationContext>();
services.AddSingleton<IAadAuthorisationHelper, AadAuthorisationHelper>();

services.Configure<SharePointApiOptions>(Configuration.GetSection("Sharepoint"));
var sharepointOptions = Configuration.GetSection("Sharepoint").Get<SharePointApiOptions>();
services.AddHttpClient<IFileService, FileService>(client =>
{
client.BaseAddress = new Uri(sharepointOptions.ApiUrl);
});
services.Configure<SharePointOptions>(Configuration.GetSection("Sharepoint"));
var sharepointOptions = Configuration.GetSection("Sharepoint").Get<SharePointOptions>();

Links.InializeProjectDocumentsEnabled(sharepointOptions.Enabled);

// Initialize the TransfersUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public ProjectViewModel(AcademyConversionProject project)
{
Id = project.Id.ToString();
FormAMatProjectId = project.FormAMatProjectId;
SharePointId = project.SharePointId;
ApplicationSharePointId = project.ApplicationSharePointId;
SchoolSharePointId = project.SchoolSharePointId;
IsFormAMat = project.IsFormAMat.HasValue && project.IsFormAMat.Value;
ProjectStatus = ProjectListHelper.MapProjectStatus(project.ProjectStatus).Value;
ProjectStatusColour = ProjectListHelper.MapProjectStatus(project.ProjectStatus).Colour;
Expand Down Expand Up @@ -131,7 +132,8 @@ public ProjectViewModel(AcademyConversionProject project)

public string Id { get; }
public int? FormAMatProjectId { get; }
public Guid? SharePointId { get; }
public Guid? SchoolSharePointId { get; }
public Guid? ApplicationSharePointId { get; }
public string ProjectStatus { get; }
public string ProjectStatusColour { get; }
public string ApplicationReferenceNumber { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
"MaintenanceMode": false,
"Sharepoint": {
"Enabled": false,
"ApiUrl": "",
"ClientId": "",
"Secret": "",
"Authority": ""
"Url": ""
}
}

0 comments on commit 1bdfbbb

Please sign in to comment.