-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from sancsoft/344-project-activities-and-rost…
…er-allow-pms-to-edit 344 project activities and roster allow pms to edit
- Loading branch information
Showing
11 changed files
with
264 additions
and
24 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/angular/hq/src/app/models/projects/delete-project-activity-v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface DeleteProjectActivityV1Request { | ||
projectId: string; | ||
id: string; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/dotnet/HQ.Server/Authorization/ProjectsAuthorizationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using HQ.Server.Data; | ||
using HQ.Server.Data.Models; | ||
|
||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Authorization.Infrastructure; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace HQ.Server.Authorization; | ||
|
||
public class ProjectsAuthorizationHandler : AuthorizationHandler<OperationAuthorizationRequirement, Project> | ||
{ | ||
private readonly HQDbContext _context; | ||
|
||
public ProjectsAuthorizationHandler(HQDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, OperationAuthorizationRequirement requirement, Project resource) | ||
{ | ||
var staffId = context.User.GetStaffId(); | ||
var isStaff = context.User.IsInRole("staff"); | ||
var isExecutive = context.User.IsInRole("executive"); | ||
var isAdmin = context.User.IsInRole("administrator"); | ||
|
||
if (isExecutive || isAdmin) | ||
{ | ||
context.Succeed(requirement); | ||
return; | ||
} | ||
|
||
if (!isStaff) | ||
{ | ||
return; | ||
} | ||
|
||
if (!staffId.HasValue) | ||
{ | ||
return; | ||
} | ||
|
||
if (staffId.Value != resource.ProjectManagerId) | ||
{ | ||
return; | ||
} | ||
|
||
var staff = await _context.Staff.FindAsync(staffId.Value); | ||
if (staff == null) | ||
{ | ||
return; | ||
} | ||
if (requirement.Name == nameof(ProjectsOperation.AddProjectMember)) | ||
{ | ||
context.Succeed(requirement); | ||
return; | ||
} | ||
switch (requirement.Name) | ||
{ | ||
case nameof(ProjectsOperation.AddProjectMember): | ||
if (staffId.Value == resource.ProjectManagerId) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
|
||
break; | ||
case nameof(ProjectsOperation.DeleteProjectActivity): | ||
if (staffId.Value == resource.ProjectManagerId) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
|
||
break; | ||
case nameof(ProjectsOperation.UpsertProjectActivity): | ||
if (staffId.Value == resource.ProjectManagerId) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
|
||
break; | ||
case nameof(ProjectsOperation.RemoveProjectMember): | ||
if (staffId.Value == resource.ProjectManagerId) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
|
||
break; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Authorization.Infrastructure; | ||
|
||
namespace HQ.Server.Authorization; | ||
|
||
public class ProjectsOperation | ||
{ | ||
public static OperationAuthorizationRequirement RemoveProjectMember = new OperationAuthorizationRequirement { Name = nameof(RemoveProjectMember) }; | ||
public static OperationAuthorizationRequirement AddProjectMember = new OperationAuthorizationRequirement { Name = nameof(AddProjectMember) }; | ||
public static OperationAuthorizationRequirement DeleteProjectActivity = new OperationAuthorizationRequirement { Name = nameof(DeleteProjectActivity) }; | ||
public static OperationAuthorizationRequirement UpsertProjectActivity = new OperationAuthorizationRequirement { Name = nameof(UpsertProjectActivity) }; | ||
|
||
} |
Oops, something went wrong.