diff --git a/.version b/.version index cbe80f6..75a498f 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.3.6.5 \ No newline at end of file +0.4.6.6 \ No newline at end of file diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj index f0da5a6..cd844fb 100644 --- a/Brizco.Api/Brizco.Api.csproj +++ b/Brizco.Api/Brizco.Api.csproj @@ -6,8 +6,8 @@ enable Linux ..\docker-compose.dcproj - 0.3.6.5 - 0.3.6.5 + 0.4.6.6 + 0.4.6.6 diff --git a/Brizco.Api/Controllers/RoleController.cs b/Brizco.Api/Controllers/RoleController.cs index d021ef8..35aae30 100644 --- a/Brizco.Api/Controllers/RoleController.cs +++ b/Brizco.Api/Controllers/RoleController.cs @@ -15,17 +15,17 @@ public class RoleController : ICarterModule group.MapGet("/permission", GetPermissions) .WithDisplayName("Permissions") - .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageRoles)) + .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageRoles, ApplicationPermission.ViewRoles)) .HasApiVersion(1.0); group.MapGet("", GetAllAsync) .WithDisplayName("GetAllRoles") - .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageRoles)) + .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageRoles , ApplicationPermission.ViewRoles)) .HasApiVersion(1.0); group.MapGet("{id}", GetAsync) .WithDisplayName("GetOneRole") - .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageRoles)) + .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageRoles, ApplicationPermission.ViewRoles)) .HasApiVersion(1.0); //group.MapPost("", Post) diff --git a/Brizco.Api/Controllers/UserController.cs b/Brizco.Api/Controllers/UserController.cs index 131a980..788ca80 100644 --- a/Brizco.Api/Controllers/UserController.cs +++ b/Brizco.Api/Controllers/UserController.cs @@ -27,7 +27,6 @@ public class UserController : ICarterModule group.MapPost("/role/change/{roleId}", ChangeUserRoleAsync) .WithDisplayName("GetUserProfile") - .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageUsers)) .HasApiVersion(1.0); group.MapPost("", Post) diff --git a/Brizco.Common/Models/Claims/ApplicationClaims.cs b/Brizco.Common/Models/Claims/ApplicationClaims.cs index 9a021c9..537cca5 100644 --- a/Brizco.Common/Models/Claims/ApplicationClaims.cs +++ b/Brizco.Common/Models/Claims/ApplicationClaims.cs @@ -176,6 +176,13 @@ public static class ApplicationClaims Title = "مشاهده گزارشات", Detail = "دسترسی به مشاهده گزارشات" }; + public static ClaimDto ViewRoles { get; } = new ClaimDto + { + Type = CustomClaimType.Permission, + Value = ApplicationPermission.ViewRoles, + Title = "مشاهده نقش ها", + Detail = "دسترسی به مشاهده نقش ها" + }; public static ClaimDto ManageUsers { get; } = new ClaimDto { Type = CustomClaimType.Permission, @@ -201,9 +208,10 @@ public static class ApplicationClaims ManageShiftPlans, ViewShifts, ManageShifts, + ViewRoles, ManageUsers, - ViewUsers + ViewUsers, ViewComplexes, ManageComplexes, @@ -233,6 +241,9 @@ public static class ApplicationClaims ViewUsers.GetClaim, ManageUsers.GetClaim, + + ViewRoles.GetClaim, + ViewTasks.GetClaim, ManageTasks.GetClaim, @@ -245,6 +256,7 @@ public static class ApplicationClaims ManageActivities.GetClaim, ViewActivities.GetClaim, + ChangeActivityStatus.GetClaim, ManageRoutines.GetClaim, ViewRoutines.GetClaim, @@ -267,10 +279,13 @@ public static class ApplicationClaims ManageActivities.GetClaim, ViewActivities.GetClaim, + ChangeActivityStatus.GetClaim, ViewUsers.GetClaim, ManageUsers.GetClaim, + ViewRoles.GetClaim, + ViewTasks.GetClaim, ManageTasks.GetClaim, @@ -295,6 +310,8 @@ public static class ApplicationClaims public static List ViewerOwnerClaims = new List { + ManageReports.GetClaim, + ViewStaffs.GetClaim, ViewActivities.GetClaim, diff --git a/Brizco.Common/Models/Claims/ApplicationPermission.cs b/Brizco.Common/Models/Claims/ApplicationPermission.cs index 9d7d939..3991d51 100644 --- a/Brizco.Common/Models/Claims/ApplicationPermission.cs +++ b/Brizco.Common/Models/Claims/ApplicationPermission.cs @@ -3,6 +3,7 @@ public static class ApplicationPermission { public const string ManageReports = nameof(ManageReports); public const string ManageRoles = nameof(ManageRoles); + public const string ViewRoles = nameof(ViewRoles); public const string ManageUsers = nameof(ManageUsers); public const string ViewUsers = nameof(ViewUsers); diff --git a/Brizco.Core/Brizco.Core.csproj b/Brizco.Core/Brizco.Core.csproj index cf1d8fa..6d3ae84 100644 --- a/Brizco.Core/Brizco.Core.csproj +++ b/Brizco.Core/Brizco.Core.csproj @@ -36,6 +36,7 @@ + @@ -47,6 +48,7 @@ + @@ -54,6 +56,7 @@ + diff --git a/Brizco.Core/EntityServices/ComplexService.cs b/Brizco.Core/EntityServices/ComplexService.cs index 1941bcc..30cbe16 100644 --- a/Brizco.Core/EntityServices/ComplexService.cs +++ b/Brizco.Core/EntityServices/ComplexService.cs @@ -50,7 +50,7 @@ public class ComplexService : IComplexService if (!createViewerResult.Succeeded) throw new AppException(string.Join('|', createViewerResult.Errors)); - foreach (var claim in ApplicationClaims.ManagerClaims) + foreach (var claim in ApplicationClaims.ViewerOwnerClaims) await _roleManager.AddClaimAsync(viewOwnerRole, claim); var superVisorRole = new ApplicationRole diff --git a/Brizco.Core/EntityServices/UserService.cs b/Brizco.Core/EntityServices/UserService.cs index 1c46ac6..18166fe 100644 --- a/Brizco.Core/EntityServices/UserService.cs +++ b/Brizco.Core/EntityServices/UserService.cs @@ -1,9 +1,4 @@ -using System.Security.Claims; -using Brizco.Domain.CommandQueries.Queries; -using Brizco.Domain.Mappers; -using Mapster; - -namespace Brizco.Core.EntityServices; +namespace Brizco.Core.EntityServices; public class UserService : IUserService { @@ -37,6 +32,8 @@ public class UserService : IUserService var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) throw new AppException("User NotFound", ApiResultStatusCode.NotFound); + if (user.SignUpStatus < SignUpStatus.ComplexCreated) + throw new UnauthorizedAccessException("SignUp is not completed"); var response = new ProfileResponseDto(); @@ -87,7 +84,21 @@ public class UserService : IUserService if (!Guid.TryParse(_currentUserService.UserId, out var userId)) throw new AppException("Wrong Token", ApiResultStatusCode.UnAuthorized); + + if (!Guid.TryParse(_currentUserService.ComplexId, out var complexId)) + throw new AppException("Wrong Token", ApiResultStatusCode.UnAuthorized); + AccessToken jwt; + + + var complexUser = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(mcu => mcu.UserId == userId && mcu.ComplexId == complexId) + .Select(ComplexUserMapper.ProjectToSDto) + .FirstOrDefaultAsync(cancellationToken); + if (complexUser == null) + throw new AppException("User role is wrong", ApiResultStatusCode.BadRequest); + var complexUserRole = await _repositoryWrapper.SetRepository() .TableNoTracking .Where(c => c.Id == roleId) @@ -97,17 +108,9 @@ public class UserService : IUserService if (complexUserRole == null) throw new AppException("Role not found", ApiResultStatusCode.NotFound); - var complexUser = await _repositoryWrapper.SetRepository() - .TableNoTracking - .Where(mcu => mcu.Id == complexUserRole.ComplexUserId) - .Select(ComplexUserMapper.ProjectToSDto) - .FirstOrDefaultAsync(cancellationToken); - var user = await _userManager.FindByIdAsync(userId.ToString()); if (user == null) throw new AppException("User not found", ApiResultStatusCode.NotFound); - if (complexUser?.UserId != user.Id) - throw new AppException("User role is wrong", ApiResultStatusCode.BadRequest); user.SelectedComplexUserRoleId = complexUserRole.Id; await _userManager.UpdateAsync(user); diff --git a/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs b/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs index 57aba33..336d597 100644 --- a/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs +++ b/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs @@ -9,6 +9,7 @@ public class ShiftPlanSDto : BaseDto public int UndoneActivitiesCount { get; set; } public int DoneActivitiesCount { get; set; } public int TotalActivitiesCount { get; set; } + public int StaffCount { get; set; } public int CompletePercent { get; internal set; } public string CompleteDescription { get; internal set; } = string.Empty; public Guid ShiftId { get; set; } diff --git a/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs b/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs index 6d4aef7..af88c99 100644 --- a/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs +++ b/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs @@ -61,9 +61,22 @@ public class GetShiftPlansQueryHandler : IRequestHandler(); + shift.Days.OrderBy(d=>d).ToList().ForEach(d => + { + if(d==DayOfWeek.Saturday) + shiftDays.Insert(0,d); + else{ + shiftDays.Add(d);} + }); + shift.Days = shiftDays; + } return shifts; } diff --git a/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs b/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs index 234037f..e19c0e8 100644 --- a/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs +++ b/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs @@ -112,6 +112,13 @@ public class GetShiftPlansQueryHandler : IRequestHandler() + .TableNoTracking + .CountAsync(spu => spu.ShiftPlanId == shiftPlan.Id, cancellationToken); + } + return shiftPlans; } } \ No newline at end of file