Commit fb047242 authored by hasan khaddour's avatar hasan khaddour

fix roles / gather the role in a one place

parent 48a31497
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSManagement.Domain.Identity.Constants
{
/// <summary>
/// Provide a role nmaes
/// </summary>
/// this classs provide a contant role names
/// gathering the roles source in a one place make change roles easier
///
public static class RolesNames
{
public const string ADMIN = "Admin";
public const string PROJECTS_PLANNER = "Projects-Planner";
public const string CUSTOMERS_PLANNER = "Customer-Planner";
public const string EMPLOYEE = "Employee";
public const string SCIENTIFIC_DEPUTY = "Scientific-Deputy";
}
}
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PSManagement.Domain.Employees.Entities; using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Identity.Constants;
using PSManagement.Domain.Identity.Entities; using PSManagement.Domain.Identity.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -42,10 +43,12 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext ...@@ -42,10 +43,12 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext
{ {
builder.Entity<Role>().HasData( builder.Entity<Role>().HasData(
new Role {Id=1, Name = "Admin" }, new Role {Id=1, Name = RolesNames.ADMIN },
new Role {Id = 2, Name = "Employee" }, new Role {Id = 2, Name = RolesNames.EMPLOYEE},
new Role {Id = 4, Name = "Scientific-Deputy" }, new Role {Id = 4, Name = RolesNames.PROJECTS_PLANNER },
new Role { Id = 5, Name = "Planner" } new Role { Id = 5, Name =RolesNames.SCIENTIFIC_DEPUTY},
new Role { Id = 6, Name = RolesNames.CUSTOMERS_PLANNER }
); );
......
...@@ -19,10 +19,12 @@ using PSManagement.Application.Customers.UseCases.Queries.GetCustomer; ...@@ -19,10 +19,12 @@ using PSManagement.Application.Customers.UseCases.Queries.GetCustomer;
using Ardalis.Result; using Ardalis.Result;
using PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo; using PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo;
using PSManagement.Presentation.Controllers.ApiBase; using PSManagement.Presentation.Controllers.ApiBase;
using PSManagement.Domain.Identity.Constants;
namespace PSManagement.Presentation.Controllers.Customers namespace PSManagement.Presentation.Controllers.Customers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[Authorize] [Authorize]
public class CustomersController : APIController public class CustomersController : APIController
{ {
...@@ -55,7 +57,10 @@ namespace PSManagement.Presentation.Controllers.Customers ...@@ -55,7 +57,10 @@ namespace PSManagement.Presentation.Controllers.Customers
return HandleResult(_mapper.Map<Result<CustomerResponse>>(result)); return HandleResult(_mapper.Map<Result<CustomerResponse>>(result));
} }
[HttpPost] [HttpPost]
[Authorize(Roles=RolesNames.CUSTOMERS_PLANNER)]
public async Task<IActionResult> Post(CreateCustomerRequest request) public async Task<IActionResult> Post(CreateCustomerRequest request)
{ {
var command = _mapper.Map<CreateCustomerCommand>(request); var command = _mapper.Map<CreateCustomerCommand>(request);
...@@ -81,6 +86,7 @@ namespace PSManagement.Presentation.Controllers.Customers ...@@ -81,6 +86,7 @@ namespace PSManagement.Presentation.Controllers.Customers
} }
[Authorize(Roles = RolesNames.CUSTOMERS_PLANNER)]
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id) public async Task<IActionResult> Delete(int id)
{ {
...@@ -92,6 +98,7 @@ namespace PSManagement.Presentation.Controllers.Customers ...@@ -92,6 +98,7 @@ namespace PSManagement.Presentation.Controllers.Customers
} }
[Authorize(Roles = RolesNames.CUSTOMERS_PLANNER)]
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<IActionResult> Put(int id, UpdateCustomerRequest request) public async Task<IActionResult> Put(int id, UpdateCustomerRequest request)
{ {
...@@ -108,7 +115,9 @@ namespace PSManagement.Presentation.Controllers.Customers ...@@ -108,7 +115,9 @@ namespace PSManagement.Presentation.Controllers.Customers
} }
[HttpPost("AddContactInfo")] [HttpPost("AddContactInfo")]
[Authorize(Roles = RolesNames.CUSTOMERS_PLANNER)]
public async Task<IActionResult> PostContactInfo(AddContactInfoRequest request) public async Task<IActionResult> PostContactInfo(AddContactInfoRequest request)
{ {
var command = _mapper.Map<AddContactInfoCommand>(request); var command = _mapper.Map<AddContactInfoCommand>(request);
...@@ -120,6 +129,7 @@ namespace PSManagement.Presentation.Controllers.Customers ...@@ -120,6 +129,7 @@ namespace PSManagement.Presentation.Controllers.Customers
[HttpPost("RemoveContactInfo")] [HttpPost("RemoveContactInfo")]
[Authorize(Roles = RolesNames.CUSTOMERS_PLANNER)]
public async Task<IActionResult> DeleteContactInfo(RemoveContactInfoRequest request) public async Task<IActionResult> DeleteContactInfo(RemoveContactInfoRequest request)
{ {
var command = _mapper.Map<RemoveContactInfoCommand>(request); var command = _mapper.Map<RemoveContactInfoCommand>(request);
......
...@@ -28,6 +28,8 @@ using PSManagement.Application.Projects.UseCases.Queries.GetParticipationChangeH ...@@ -28,6 +28,8 @@ using PSManagement.Application.Projects.UseCases.Queries.GetParticipationChangeH
using PSManagement.Application.Projects.UseCases.Queries.GetCompletionContribution; using PSManagement.Application.Projects.UseCases.Queries.GetCompletionContribution;
using PSManagement.Application.Projects.UseCases.Commands.RemoveAttachment; using PSManagement.Application.Projects.UseCases.Commands.RemoveAttachment;
using PSManagement.Application.Projects.UseCases.Queries.GetProjectCompletion; using PSManagement.Application.Projects.UseCases.Queries.GetProjectCompletion;
using PSManagement.Domain.Identity.Constants;
using Microsoft.AspNetCore.Authorization;
namespace PSManagement.Presentation.Controllers.Projects namespace PSManagement.Presentation.Controllers.Projects
{ {
...@@ -280,6 +282,7 @@ namespace PSManagement.Presentation.Controllers.Projects ...@@ -280,6 +282,7 @@ namespace PSManagement.Presentation.Controllers.Projects
#region Propose #region Propose
[HttpPost] [HttpPost]
[Authorize(Roles = RolesNames.SCIENTIFIC_DEPUTY)]
public async Task<IActionResult> Post([FromBody] CreateProjectRequest request) public async Task<IActionResult> Post([FromBody] CreateProjectRequest request)
{ {
var command = _mapper.Map<CreateProjectCommand>(request); var command = _mapper.Map<CreateProjectCommand>(request);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PSManagement.Application.Contracts.Authorization; using PSManagement.Application.Contracts.Authorization;
using PSManagement.Domain.Identity.Constants;
using PSManagement.Presentation.Controllers.ApiBase; using PSManagement.Presentation.Controllers.ApiBase;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -11,6 +12,7 @@ using System.Threading.Tasks; ...@@ -11,6 +12,7 @@ using System.Threading.Tasks;
namespace PSManagement.Presentation.Controllers.Roles namespace PSManagement.Presentation.Controllers.Roles
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[Authorize(Roles = RolesNames.ADMIN)]
public class RolesController : APIController public class RolesController : APIController
{ {
private readonly IRoleService _roleService; private readonly IRoleService _roleService;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PSManagement.Application.Contracts.Authorization; using PSManagement.Application.Contracts.Authorization;
using PSManagement.Domain.Identity.Constants;
using PSManagement.Presentation.Controllers.ApiBase; using PSManagement.Presentation.Controllers.ApiBase;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -11,6 +12,7 @@ using System.Threading.Tasks; ...@@ -11,6 +12,7 @@ using System.Threading.Tasks;
namespace PSManagement.Presentation.Controllers.Roles namespace PSManagement.Presentation.Controllers.Roles
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[Authorize(Roles = RolesNames.ADMIN)]
public class UserRolesController : APIController public class UserRolesController : APIController
{ {
private readonly IUserRoleService _userRoleService; private readonly IUserRoleService _userRoleService;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment