Beispiel #1
0
        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);
        }