public async Task <object> Post(AssignRoles request) { if (!Request.IsInProcessRequest()) { await RequiredRoleAttribute.AssertRequiredRoleAsync(Request, RoleNames.Admin); } if (string.IsNullOrEmpty(request.UserName)) { throw new ArgumentNullException(nameof(request.UserName)); } var userAuth = await AuthRepositoryAsync.GetUserAuthByUserNameAsync(request.UserName).ConfigAwait(); if (userAuth == null) { throw HttpError.NotFound(request.UserName); } await AuthRepositoryAsync.AssignRolesAsync(userAuth, request.Roles, request.Permissions).ConfigAwait(); return(new AssignRolesResponse { AllRoles = (await AuthRepositoryAsync.GetRolesAsync(userAuth).ConfigAwait()).ToList(), AllPermissions = (await AuthRepositoryAsync.GetPermissionsAsync(userAuth).ConfigAwait()).ToList(), }); }
public object Post(AssignRoles request) { if (!Request.IsInProcessRequest()) { RequiredRoleAttribute.AssertRequiredRoles(Request, RoleNames.Admin); } if (string.IsNullOrEmpty(request.UserName)) { throw new ArgumentNullException(nameof(request.UserName)); } var userAuth = AuthRepository.GetUserAuthByUserName(request.UserName); if (userAuth == null) { throw HttpError.NotFound(request.UserName); } AuthRepository.AssignRoles(userAuth, request.Roles, request.Permissions); return(new AssignRolesResponse { AllRoles = AuthRepository.GetRoles(userAuth).ToList(), AllPermissions = AuthRepository.GetPermissions(userAuth).ToList(), }); }
public object Post(AssignRoles request) { request.UserName.ThrowIfNullOrEmpty(); var userAuth = UserAuthRepo.GetUserAuthByUserName(request.UserName); if (userAuth == null) throw HttpError.NotFound(request.UserName); if (!request.Roles.IsEmpty()) { foreach (var missingRole in request.Roles.Where(x => !userAuth.Roles.Contains(x))) { userAuth.Roles.Add(missingRole); } } if (!request.Permissions.IsEmpty()) { foreach (var missingPermission in request.Permissions.Where(x => !userAuth.Permissions.Contains(x))) { userAuth.Permissions.Add(missingPermission); } } UserAuthRepo.SaveUserAuth(userAuth); return new AssignRolesResponse { AllRoles = userAuth.Roles, AllPermissions = userAuth.Permissions, }; }
public object Post(AssignRoles request) { RequiredRoleAttribute.AssertRequiredRoles(Request, RoleNames.Admin); request.UserName.ThrowIfNullOrEmpty(); var authRepo = HostContext.AppHost.GetAuthRepository(base.Request); using (authRepo as IDisposable) { var userAuth = authRepo.GetUserAuthByUserName(request.UserName); if (userAuth == null) { throw HttpError.NotFound(request.UserName); } authRepo.AssignRoles(userAuth, request.Roles, request.Permissions); return(new AssignRolesResponse { AllRoles = authRepo.GetRoles(userAuth).ToList(), AllPermissions = authRepo.GetPermissions(userAuth).ToList(), }); } }
public object Post(AssignRoles request) { request.UserName.ThrowIfNullOrEmpty(); var userAuth = UserAuthRepo.GetUserAuthByUserName(request.UserName); if (userAuth == null) { throw HttpError.NotFound(request.UserName); } UserAuthRepo.AssignRoles(userAuth, request.Roles, request.Permissions); return(new AssignRolesResponse { AllRoles = UserAuthRepo.GetRoles(userAuth).ToList(), AllPermissions = UserAuthRepo.GetPermissions(userAuth).ToList(), }); }