11using System . Data . Entity ;
2- using System . Data . Entity . Validation ;
32using JoinRpg . Data . Interfaces ;
43using JoinRpg . Data . Write . Interfaces ;
54using JoinRpg . DataModel ;
@@ -24,7 +23,7 @@ public async Task<PlotFolderIdentification> CreatePlotFolder(ProjectIdentificati
2423 }
2524
2625 var project = await UnitOfWork . GetDbSet < Project > ( ) . FindAsync ( projectId . Value ) ;
27- _ = project . RequestMasterAccess ( CurrentUserId , acl => acl . CanManagePlots ) ;
26+ _ = project . RequestMasterAccess ( CurrentUserId , acl => acl . CanManagePlots ) . EnsureProjectActive ( ) ;
2827 var startTimeUtc = DateTime . UtcNow ;
2928 var plotFolder = new PlotFolder
3029 {
@@ -64,7 +63,7 @@ public async Task EditPlotFolder(int projectId, int plotFolderId, string plotFol
6463 {
6564 var folder = await LoadProjectSubEntityAsync < PlotFolder > ( projectId , plotFolderId ) ;
6665
67- _ = folder . RequestMasterAccess ( CurrentUserId , acl => acl . CanManagePlots ) ;
66+ _ = folder . RequestMasterAccess ( CurrentUserId , acl => acl . CanManagePlots ) . EnsureProjectActive ( ) ;
6867
6968 folder . TodoField = todoField ;
7069 folder . IsActive = true ; //Restore if deleted
@@ -81,7 +80,7 @@ public async Task<PlotVersionIdentification> CreatePlotElement(PlotFolderIdentif
8180 {
8281 var folder = await LoadProjectSubEntityAsync < PlotFolder > ( plotFolderId ) ;
8382
84- _ = folder . RequestMasterAccess ( CurrentUserId ) ;
83+ _ = folder . RequestMasterAccess ( CurrentUserId ) . EnsureProjectActive ( ) ;
8584
8685 var now = DateTime . UtcNow ;
8786 var characterGroups = await ProjectRepository . LoadGroups ( targetGroups ) ;
@@ -123,18 +122,15 @@ public async Task<PlotVersionIdentification> CreatePlotElement(PlotFolderIdentif
123122 public async Task DeleteFolder ( int projectId , int plotFolderId )
124123 {
125124 var folder = await LoadProjectSubEntityAsync < PlotFolder > ( projectId , plotFolderId ) ;
126- if ( ! folder . HasMasterAccess ( CurrentUserId , acl => acl . CanManagePlots ) )
127- {
128- throw new DbEntityValidationException ( ) ;
129- }
130- var now = DateTime . UtcNow ;
125+ _ = folder . RequestMasterAccess ( CurrentUserId , Permission . CanManagePlots ) . EnsureProjectActive ( ) ;
126+
131127 _ = SmartDelete ( folder ) ;
132128 foreach ( var element in folder . Elements )
133129 {
134130 element . IsActive = false ;
135- element . ModifiedDateTime = now ;
131+ element . ModifiedDateTime = Now ;
136132 }
137- folder . ModifiedDateTime = now ;
133+ folder . ModifiedDateTime = Now ;
138134 await UnitOfWork . SaveChangesAsync ( ) ;
139135 }
140136
@@ -150,14 +146,14 @@ public async Task DeleteElement(PlotElementIdentification plotElementId)
150146 private async Task < PlotElement > LoadElement ( PlotElementIdentification plotElementId )
151147 {
152148 var folder = await LoadProjectSubEntityAsync < PlotFolder > ( plotElementId . PlotFolderId ) ;
153- _ = folder . RequestMasterAccess ( CurrentUserId ) ;
149+ _ = folder . RequestMasterAccess ( CurrentUserId ) . EnsureProjectActive ( ) ;
154150 return folder . Elements . Single ( e => e . PlotElementId == plotElementId . PlotElementId ) ;
155151 }
156152
157153 private async Task < PlotElement > LoadElementForManage ( PlotElementIdentification plotElementId )
158154 {
159155 var folder = await LoadProjectSubEntityAsync < PlotFolder > ( plotElementId . PlotFolderId ) ;
160- _ = folder . RequestMasterAccess ( CurrentUserId , Permission . CanManagePlots ) ;
156+ _ = folder . RequestMasterAccess ( CurrentUserId , Permission . CanManagePlots ) . EnsureProjectActive ( ) ;
161157 return folder . Elements . Single ( e => e . PlotElementId == plotElementId . PlotElementId ) ;
162158 }
163159
@@ -228,7 +224,7 @@ public async Task EditPlotElementText(PlotElementIdentification plotelementid, s
228224 public async Task MoveElement ( int projectId , int plotElementId , int parentCharacterId , int direction )
229225 {
230226 var character = await LoadProjectSubEntityAsync < Character > ( projectId , parentCharacterId ) ;
231- _ = character . RequestMasterAccess ( CurrentUserId , acl => acl . CanEditRoles ) ;
227+ _ = character . RequestMasterAccess ( CurrentUserId , acl => acl . CanEditRoles ) . EnsureProjectActive ( ) ;
232228
233229 var plots = await PlotRepository . GetPlotsForCharacter ( character ) ;
234230
@@ -314,6 +310,8 @@ public async Task UnPublishElement(PlotElementIdentification plotElementId)
314310 public async Task ReorderPlots ( PlotFolderIdentification plotFolderId , PlotFolderIdentification ? afterPlotFolderId )
315311 {
316312 var targetFolder = await LoadProjectSubEntityAsync < PlotFolder > ( plotFolderId ) ;
313+ _ = targetFolder . RequestMasterAccess ( CurrentUserId , Permission . CanManagePlots ) . EnsureProjectActive ( ) ;
314+
317315 var afterFolder = afterPlotFolderId is not null ? await LoadProjectSubEntityAsync < PlotFolder > ( afterPlotFolderId ) : null ;
318316
319317 targetFolder . Project . Details . PlotFoldersOrdering
@@ -326,6 +324,8 @@ public async Task ReorderPlotElements(PlotElementIdentification plotElementId, P
326324 {
327325 var targetFolder = await LoadProjectSubEntityAsync < PlotFolder > ( plotElementId . PlotFolderId ) ;
328326
327+ _ = targetFolder . RequestMasterAccess ( CurrentUserId , Permission . CanManagePlots ) . EnsureProjectActive ( ) ;
328+
329329 targetFolder . ElementsOrdering = DomainMoveHelper . MoveAfter ( plotElementId ,
330330 afterPlotElementId ,
331331 targetFolder . ElementsOrdering ,
@@ -337,8 +337,11 @@ public async Task ReorderPlotElements(PlotElementIdentification plotElementId, P
337337
338338 public async Task ReorderPlotByChar ( CharacterIdentification characterId , PlotElementIdentification targetId , PlotElementIdentification ? afterId )
339339 {
340+
340341 var character = await CharactersRepository . GetCharacterAsync ( characterId ) ;
341342
343+ _ = character . RequestMasterAccess ( CurrentUserId , Permission . CanManagePlots ) . EnsureProjectActive ( ) ;
344+
342345 var plotTarget = ToTarget ( character ) ;
343346
344347 var plots = await PlotRepository . GetPlotsBySpecification ( new PlotSpecification ( plotTarget , PlotVersionFilter . PublishedVersion , PlotElementType . RegularPlot ) ) ;
0 commit comments