public IActionResult Delete([FromQuery] string name) { if (!_currentUser.HasRole(Permission.UserAccountAdmin)) { return(Forbidden()); } _logger.LogInformation("Removing user group: {0}", name); // determine whether specified user group is related to a system group or not. Deleting one of system group is not allowed if (EnumInfo.GetList <SystemUserGroup>().Any(systemUserGroup => systemUserGroup.Name.ToUpper() == name.ToUpper())) { return(Error("Removing a system user group is not permitted")); } Maybe <AppGroup> userGroup = _groupRepo.FindByName(name); if (userGroup.HasNoValue) { return(Error($"No matching user group found: {name}")); } // remove user groups and their aggregates _groupRepo.Delete(userGroup.Value.Id); return(Ok("User group removed")); }
public IActionResult GetNotAssignedPermissions([FromQuery] int id) { if (!_currentUser.HasRole(Permission.UserAccountAdmin)) { return(Forbidden()); } _logger.LogInformation("Retrieving not assigned permissions list for user group: {0}", id); Maybe <AppGroup> userGroup = _groupRepo.GetById(id); if (userGroup.HasNoValue) { return(Error($"No matching user group found: {id}")); } List <AppPermission> permissions = _permissionRepo.GetList().ToList(); List <int> assignedPermissions = userGroup.Value.GroupPermissions.Select(d => d.PermissionId).ToList(); var result = permissions .Where(p => !assignedPermissions.Any(d => d == p.Id)) // exclude already assigned permissions to specified group .Join(EnumInfo.GetList <Permission>().ToList(), p => p.Name, all => all.Name, (p, all) => new { p, all }) .Select(d => new PermissionDTO { Id = d.p.Id, Name = d.p.Name, Description = d.p.Description, Group = d.all.Group, Active = true }); return(Ok(result, contextReadonly: true)); }
public IActionResult GetList() { if (!_currentUser.HasRole(Permission.UserAccountAdmin)) { return(Forbidden()); } _logger.LogInformation("Retrieving system modules permission list"); List <EnumDescription> permissions = EnumInfo.GetList <Permission>().ToList(); List <AppPermission> activePermissions = _permissionRepo.GetList().ToList(); var result = permissions.GroupJoin( activePermissions, all => all.Name, active => active.Name, (all, active) => new { all, active = (Maybe <AppPermission>)active.FirstOrDefault() }) .Select(d => new PermissionDTO { Id = d.active.HasValue ? d.active.Unwrap(p => p.Id) : default(int?), Name = d.all.Name, Description = d.all.Description, Group = d.all.Group, Active = d.active.HasValue }); return(Ok(result, contextReadonly: true)); }