public static bool CanChangeRoleOfMember(this AppUserRole caller, AppUserRole oldRole, AppUserRole newRole) { if (caller.IsNone() || oldRole.IsNone() || newRole.IsNone()) { return(false); } if (!HasPermissionsToChangeRoleOfMember(caller)) { return(false); } if (oldRole == newRole) { return(false); } if (oldRole.IsOwner() || newRole.IsOwner()) { return(false); } if ((oldRole.IsScrumMaster() || newRole.IsScrumMaster()) && !caller.IsOwner()) { return(false); } return(true); }
public async Task ChangeUserRoleAsync(string senderUserId, int projectId, string userId, AppUserRoleDto newRoleDto) { AppUserRole senderRole = await GetRoleIfMember(senderUserId, projectId); if (!senderRole.HasPermissionsToChangeRoleOfMember()) { throw new ForbiddenResponseException("You haven't permissions to change roles of members in this project"); } AppUserRole currRole = await _puRepo.GetRoleOfMember(userId, projectId); AppUserRole newRole = _mapper.Map <AppUserRoleDto, AppUserRole>(newRoleDto); if (!senderRole.CanChangeRoleOfMember(currRole, newRole)) { throw new ForbiddenResponseException($"You cannot change role from {currRole.Name} to {newRole.Name}."); } if (newRole.IsScrumMaster() && await _puRepo.DoesExistScrumMasterInProjectAsync(projectId)) { throw new ForbiddenResponseException("Only one Scrum Master can be on project"); } ProjectUser pu = new ProjectUser() { ProjectId = projectId, UserId = userId, UserRoleId = newRole.Id }; await _puRepo.UpdateRecordAsync(pu); }
public static bool HasPermissionsToChangeRoleOfMember(this AppUserRole role) { if (role.IsOwner() || role.IsScrumMaster()) { return(true); } else { return(false); } }
/// <summary> /// Defines user roles which can change sprint state. /// </summary> /// <param name="sprintBl">Extends sprint business logic class.</param> /// <param name="role">Role of user in project.</param> /// <returns>Boolean value which points to possibility to change sprint state.</returns> public static bool CanChangeSprint(this SprintBl sprintBl, AppUserRole role) { if (role.IsScrumMaster() || role.IsOwner()) { return(true); } else { return(false); } }
public static bool IsPartOfTeam(this AppUserRole role) { if (role.IsOwner() || role.IsScrumMaster() || role.IsDeveloper()) { return(true); } else { return(false); } }
public static bool IsScrumMasterOrOwner(this AppUserRole role) { if (role.IsOwner() || role.IsScrumMaster()) { return(true); } else { return(false); } }
/// <summary> /// Defines user roles which can view project data. /// </summary> /// <param name="projectBl">Extends project business logic class.</param> /// <param name="role">Role of user in project.</param> /// <returns>Boolean value which points to possibility to view project data.</returns> public static bool CanAccessProject(this ProjectBl projectBl, AppUserRole role) { if (role.IsScrumMaster() || role.IsOwner() || role.IsDeveloper() || role.IsObserver()) { return(true); } else { return(false); } }
public async Task AddMemberAsync(string senderUserId, int projectId, string userId, AppUserRoleDto roleDto) { AppUserRole senderRole = await GetRoleIfMember(senderUserId, projectId); if (!senderRole.CanAddNewMember()) { throw new ForbiddenResponseException("You haven't permissions to add members to this project"); } if (!await _userRepo.ExistsWithId(userId)) { throw new NotFoundResponseException("Cannot find user to add into project."); } if (!((await _puRepo.GetRoleOfMember(userId, projectId)).IsNone())) { throw new BadRequestResponseException("This user already exists in project."); } AppUserRole role = _mapper.Map <AppUserRoleDto, AppUserRole>(roleDto); if (role.IsNone()) { throw new BadRequestResponseException("Given role is bad."); } if (role.IsOwner()) { throw new BadRequestResponseException("Cannot add Owner to project."); } if (role.IsScrumMaster() && await _puRepo.DoesExistScrumMasterInProjectAsync(projectId)) { throw new BadRequestResponseException("Scrum Master already exists in project."); } var pu = new ProjectUser() { ProjectId = projectId, UserId = userId, UserRoleId = role.Id }; await _puRepo.CreateRecordAsync(pu); }
public static bool CanSetAssignedUser(this AppUserRole role) { return(role.IsOwner() || role.IsScrumMaster()); }