public Result <GroupUserViewModel> GetGroupUserViewModel(string groupId) { _logger.LogInformation($"Getting Group. GroupId {groupId}"); SelectSpecification <GroupEntity, GroupUserViewModel> selectSpecification = new SelectSpecification <GroupEntity, GroupUserViewModel>(); selectSpecification.AddFilter(x => x.Id == groupId); selectSpecification.AddSelect(x => new GroupUserViewModel( x.Id, x.Name)); GroupUserViewModel groupUserViewModel = _groupStore.Get(selectSpecification); if (groupUserViewModel == null) { _logger.LogError($"No Group. GroupId {groupId}"); return(Result.Fail <GroupUserViewModel>("no_group", "No Group")); } groupUserViewModel.CanAssigneGroupRoles = _groupUserStore.CanAssigneGroupRoles(); groupUserViewModel.CanMangeGroupRoles = _groupUserStore.CanManageGroupRoles(); groupUserViewModel.CanChangeOwnRole = _groupUserStore.CanChangeOwnRole(); return(Result.Ok(groupUserViewModel)); }
public Result ChangeRole(long groupUserId, string roleId, string userId) { _logger.LogInformation($"Changing GroupUser role. GroupUserId {groupUserId}, roleId {roleId}"); Result roleValidResult = RoleIsValid(roleId); if (roleValidResult.Failure) { return(Result.Fail(roleValidResult.Errors)); } List <RoleListData> canAssigneGroupRoles = _groupUserStore.CanAssigneGroupRoles(); if (!canAssigneGroupRoles.Any(x => x.Id == roleId)) { _logger.LogError($"User does not have permission to assign role. RoleId {roleId}"); return(Result.Fail("no_permission", "No Permission")); } Result <GroupUserEntity> getGroupUserResult = _groupUserStore.Get(groupUserId); if (getGroupUserResult.Failure) { return(Result.Fail(getGroupUserResult.Errors)); } GroupUserEntity groupUser = getGroupUserResult.Value; List <RoleListData> canManageGroupRoles = _groupUserStore.CanManageGroupRoles(); if (!canManageGroupRoles.Any(x => x.Id != groupUser.RoleId)) { _logger.LogError($"User does not have permission to manage role. GroupUserId {groupUserId} RoleId {roleId}"); return(Result.Fail("no_permission", "No Permission")); } if (!_groupUserStore.CanChangeOwnRole()) { if (groupUser.UserId == userId) { _logger.LogError($"User can not change his own role"); return(Result.Fail("user_can_not_change_his_own_role", "User can not change his own role")); } } groupUser.UpdateRole(roleId); bool updateResult = _groupUserRepository.Update(groupUser); if (!updateResult) { _logger.LogError($"Failed to change group user role. GroupUserId {groupUserId}, roleId {roleId}"); return(Result.Fail("failed_to_cahnge_group_user_role", "Failed to change GroupUser role")); } return(Result.Ok()); }
private async Task <Result> ChangeRoleAsync(long groupUserId, string roleId, string userId) { _logger.LogInformation($"Changing GroupUser role. GroupUserId {groupUserId}, roleId {roleId}"); Result roleValidResult = await RoleIsValid(roleId); if (roleValidResult.Failure) { return(Result.Fail(roleValidResult)); } List <RoleListData> canAssigneGroupRoles = _groupUserStore.CanAssigneGroupRoles(); if (!canAssigneGroupRoles.Any(x => x.Id == roleId)) { _logger.LogError($"User does not have permission to assign role. RoleId {roleId}"); return(Result.Fail(NO_PERMISSION)); } Core.Models.Result.Result <GroupUserEntity> getGroupUserResult = _groupUserStore.Get(groupUserId); if (getGroupUserResult.Failure) { return(getGroupUserResult.ToNewResult()); } GroupUserEntity groupUser = getGroupUserResult.Value; List <RoleListData> canManageGroupRoles = _groupUserStore.CanManageGroupRoles(); if (!canManageGroupRoles.Any(x => x.Id != groupUser.RoleId)) { _logger.LogError($"User does not have permission to manage role. GroupUserId {groupUserId} RoleId {roleId}"); return(Result.Fail(NO_PERMISSION)); } if (!_groupUserStore.CanChangeOwnRole()) { if (groupUser.UserId == userId) { _logger.LogError($"User can not change his own role"); return(Result.Fail(USER_CAN_NOT_CHANGE_HIS_OWN_ROLE)); } } groupUser.UpdateRole(roleId); bool updateResult = await _groupUserDAO.Update(groupUser); if (!updateResult) { _logger.LogError($"Failed to change group user role. GroupUserId {groupUserId}, roleId {roleId}"); return(Result.Fail(FAILED_TO_CAHNGE_GROUP_USER_ROLE)); } return(Result.Ok()); }
public async Task <Result <GroupAdminUserIndexViewModel> > GetIndexViewModel(string groupId) { List <RoleListData> canAssigneRoles = await _groupUserStore.CanAssigneRoles(); List <RoleListData> canManageRoles = await _groupUserStore.CanManageRoles(); bool canChangeOwnRole = _groupUserStore.CanChangeOwnRole(); GroupAdminUserIndexViewModel viewModel = new GroupAdminUserIndexViewModel( groupId: groupId, canMangeGroupRoles: canManageRoles, canAssigneGroupRoles: canAssigneRoles, canChangeOwnRole: canChangeOwnRole); return(Result.Ok(viewModel)); }