Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ManageRoles permission. #18927

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override void Define(IPermissionDefinitionContext context)
usersPermission.AddChild(IdentityPermissions.Users.Update, L("Permission:Edit"));
usersPermission.AddChild(IdentityPermissions.Users.Delete, L("Permission:Delete"));
usersPermission.AddChild(IdentityPermissions.Users.ManagePermissions, L("Permission:ChangePermissions"));
usersPermission.AddChild(IdentityPermissions.Users.ManageRoles, L("Permission:ManageRoles"));

identityGroup
.AddPermission(IdentityPermissions.UserLookup.Default, L("Permission:UserLookup"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class Users
public const string Update = Default + ".Update";
public const string Delete = Default + ".Delete";
public const string ManagePermissions = Default + ".ManagePermissions";
public const string ManageRoles = Update + ".ManageRoles";
}

public static class UserLookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;

Expand All @@ -16,17 +17,19 @@ public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppSe
protected IIdentityUserRepository UserRepository { get; }
protected IIdentityRoleRepository RoleRepository { get; }
protected IOptions<IdentityOptions> IdentityOptions { get; }

protected IPermissionChecker PermissionChecker { get; }
public IdentityUserAppService(
IdentityUserManager userManager,
IIdentityUserRepository userRepository,
IIdentityRoleRepository roleRepository,
IOptions<IdentityOptions> identityOptions)
IOptions<IdentityOptions> identityOptions,
IPermissionChecker permissionChecker)
{
UserManager = userManager;
UserRepository = userRepository;
RoleRepository = roleRepository;
IdentityOptions = identityOptions;
PermissionChecker = permissionChecker;
}

//TODO: [Authorize(IdentityPermissions.Users.Default)] should go the IdentityUserAppService class.
Expand Down Expand Up @@ -169,6 +172,7 @@ protected virtual async Task UpdateUserByInput(IdentityUser user, IdentityUserCr
(await UserManager.SetEmailAsync(user, input.Email)).CheckErrors();
}


if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase))
{
(await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors();
Expand All @@ -183,7 +187,7 @@ protected virtual async Task UpdateUserByInput(IdentityUser user, IdentityUserCr
user.Surname = input.Surname;
(await UserManager.UpdateAsync(user)).CheckErrors();
user.SetIsActive(input.IsActive);
if (input.RoleNames != null)
if (input.RoleNames != null && await PermissionChecker.IsGrantedAsync(IdentityPermissions.Users.ManageRoles))
{
(await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@
<Tabs @bind-SelectedTab="@EditModalSelectedTab">
<Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab>
<Tab Name="Roles">@L["Roles"]</Tab>
@if (EditUserRoles != null && EditUserRoles.Any())
{
<Tab Name="Roles">@L["Roles"]</Tab>
}
</Items>
<Content>
<TabPanel Name="UserInformations">
Expand Down Expand Up @@ -258,18 +261,21 @@
</Field>
<ExtensionProperties TEntityType="IdentityUserUpdateDto" TResourceType="IdentityResource" Entity="@EditingEntity" LH="@LH" ModalType="ExtensionPropertyModalType.EditModal" />
</TabPanel>
<TabPanel Name="Roles">
@if (EditUserRoles != null)
{
@foreach (var role in EditUserRoles)
@if (EditUserRoles != null && EditUserRoles.Any())
{
<TabPanel Name="Roles">
@if (EditUserRoles != null)
{
<Field>
<input type="hidden" @bind-value="@role.Name" />
<Check TValue="bool" @bind-Checked="@role.IsAssigned">@role.Name</Check>
</Field>
@foreach (var role in EditUserRoles)
{
<Field>
<input type="hidden" @bind-value="@role.Name" />
<Check TValue="bool" @bind-Checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
}
}
</TabPanel>
</TabPanel>
}
</Content>
</Tabs>
</Validations>
Expand All @@ -286,4 +292,4 @@
@if (HasManagePermissionsPermission)
{
<PermissionManagementModal @ref="PermissionManagementModal" />
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions;
using Volo.Abp.AspNetCore.Components.Web.Extensibility.TableColumns;
using Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Identity.Localization;
using Volo.Abp.ObjectExtending;
using Volo.Abp.PermissionManagement.Blazor.Components;
Expand Down Expand Up @@ -43,6 +45,9 @@ public partial class UserManagement
private TextRole _passwordTextRole = TextRole.Password;
public bool IsEditCurrentUser { get; set; }

[Inject]
protected IPermissionChecker PermissionChecker { get; set; }

public UserManagement()
{
ObjectMapperContext = typeof(AbpIdentityBlazorModule);
Expand Down Expand Up @@ -121,15 +126,19 @@ protected override async Task OpenEditModalAsync(IdentityUserDto entity)
{
EditModalSelectedTab = DefaultSelectedTab;
IsEditCurrentUser = entity.Id == CurrentUser.Id;
var userRoleNames = (await AppService.GetRolesAsync(entity.Id)).Items.Select(r => r.Name).ToList();

EditUserRoles = Roles.Select(x => new AssignedRoleViewModel
if (await PermissionChecker.IsGrantedAsync(IdentityPermissions.Users.ManageRoles))
{
Name = x.Name,
IsAssigned = userRoleNames.Contains(x.Name)
}).ToArray();
var userRoleNames = (await AppService.GetRolesAsync(entity.Id)).Items.Select(r => r.Name).ToList();

EditUserRoles = Roles.Select(x => new AssignedRoleViewModel
{
Name = x.Name,
IsAssigned = userRoleNames.Contains(x.Name)
}).ToArray();

ChangePasswordTextRole(TextRole.Password);
ChangePasswordTextRole(TextRole.Password);
}
await base.OpenEditModalAsync(entity);
}
catch (Exception ex)
Expand All @@ -141,8 +150,10 @@ protected override async Task OpenEditModalAsync(IdentityUserDto entity)
protected override Task OnUpdatingEntityAsync()
{
// apply roles before saving
EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray();

if (EditUserRoles != null)
{
EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray();
}
return base.OnUpdatingEntityAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "تحرير",
"Permission:Delete": "حذف",
"Permission:ChangePermissions": "تغيير الأذونات",
"Permission:ManageRoles": "إدارة الأدوار",
"Permission:UserManagement": "إدارة المستخدم",
"Permission:UserLookup": "بحث المستخدم",
"DisplayName:Abp.Identity.Password.RequiredLength": "الطول المطلوب",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "وقت انتهاء القفل",
"FailedAccessCount": "فشل عدد الوصول"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Upravit",
"Permission:Delete": "Smazat",
"Permission:ChangePermissions": "Změnit oprávnění",
"Permission:ManageRoles": "Správa rolí",
"Permission:UserManagement": "Správa uživatelů",
"Permission:UserLookup": "Vyhledání uživatele",
"DisplayName:Abp.Identity.Password.RequiredLength": "Požadovaná délka",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Čas konce uzamčení",
"FailedAccessCount": "Počet neúspěšných přístupů"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Bearbeiten",
"Permission:Delete": "Löschen",
"Permission:ChangePermissions": "Berechtigungen ändern",
"Permission:ManageRoles": "Rollen verwalten",
"Permission:UserManagement": "Benutzerverwaltung",
"Permission:UserLookup": "Benutzersuche",
"DisplayName:Abp.Identity.Password.RequiredLength": "Erforderliche Länge",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Endzeit der Sperrung",
"FailedAccessCount": "Anzahl der fehlgeschlagenen Zugriffe"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"Permission:Edit": "Επεξεργασία",
"Permission:Delete": "Διαγραφή",
"Permission:ChangePermissions": "Αλλαγές στα δικαιώματα",
"Permission:ManageRoles": "Διαχείριση ρόλων",
"Permission:UserManagement": "Διαχείριση χρηστών",
"Permission:UserLookup": "Αναζήτηση χρήστη",
"DisplayName:Abp.Identity.Password.RequiredLength": "Απαιτούμενο μήκος",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"Permission:Edit": "Edit",
"Permission:Delete": "Delete",
"Permission:ChangePermissions": "Change permissions",
"Permission:ManageRoles": "Manage roles",
"Permission:UserManagement": "User management",
"Permission:UserLookup": "User lookup",
"Feature:IdentityGroup": "Identity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Edit",
"Permission:Delete": "Delete",
"Permission:ChangePermissions": "Change permissions",
"Permission:ManageRoles": "Manage roles",
"Permission:UserManagement": "User management",
"Permission:UserLookup": "User lookup",
"DisplayName:Abp.Identity.Password.RequiredLength": "Required length",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Editar",
"Permission:Delete": "Borrar",
"Permission:ChangePermissions": "Cambiar permisos",
"Permission:ManageRoles": "Gestionar roles",
"Permission:UserManagement": "Gestión de usuarios",
"Permission:UserLookup": "Busqueda de usuario",
"DisplayName:Abp.Identity.Password.RequiredLength": "Longitud requerida",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Hora de finalización del bloqueo",
"FailedAccessCount": "Recuento de acceso fallido"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"Permission:Edit": "ویرایش",
"Permission:Delete": "حذف",
"Permission:ChangePermissions": "تغییر مجوزها",
"Permission:ManageRoles": "مدیریت نقشها و وظایف",
"Permission:UserManagement": "مدیریت کاربر",
"Permission:UserLookup": "جستجوی کاربر",
"DisplayName:Abp.Identity.Password.RequiredLength": "طول مورد نیاز",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Muokkaus",
"Permission:Delete": "Poisto",
"Permission:ChangePermissions": "Muuta käyttöoikeuksia",
"Permission:ManageRoles": "Hallitse rooleja",
"Permission:UserManagement": "Käyttäjien hallinta",
"Permission:UserLookup": "Käyttäjähaku",
"DisplayName:Abp.Identity.Password.RequiredLength": "Vaadittu pituus",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Lukituksen päättymisaika",
"FailedAccessCount": "Epäonnistuneet käyttöoikeudet"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Modifier",
"Permission:Delete": "Supprimer",
"Permission:ChangePermissions": "Modifier les autorisations",
"Permission:ManageRoles": "Gérer les rôles",
"Permission:UserManagement": "Gestion des utilisateurs",
"Permission:UserLookup": "Recherche utilisateur",
"DisplayName:Abp.Identity.Password.RequiredLength": "Longueur requise",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Heure de fin du verrouillage",
"FailedAccessCount": "Nombre d&#39;accès ayant échoué"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "संपादित करें",
"Permission:Delete": "हटाएं",
"Permission:ChangePermissions": "अनुमतियाँ बदलें",
"Permission:ManageRoles": "भूमिकाएँ प्रबंधित करें",
"Permission:UserManagement": "उपयोगकर्ता प्रबंधन",
"Permission:UserLookup": "उपयोगकर्ता की खोज",
"DisplayName:Abp.Identity.Password.RequiredLength": "आवश्यक लंबाई",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "तालाबंदी समाप्ति समय",
"FailedAccessCount": "विफल पहुंच गणना"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Uredi",
"Permission:Delete": "Izbrisati",
"Permission:ChangePermissions": "Promjena dopuštenja",
"Permission:ManageRoles": "Upravljanje ulogama",
"Permission:UserManagement": "Upravljanje korisnicima",
"Permission:UserLookup": "Traženje korisnika",
"DisplayName:Abp.Identity.Password.RequiredLength": "Potrebna dužina",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Vrijeme završetka zaključavanja",
"FailedAccessCount": "Broj neuspjelih pristupa"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Szerkesztés",
"Permission:Delete": "Törlés",
"Permission:ChangePermissions": "Engedélyek módosítása",
"Permission:ManageRoles": "Szerepkörök kezelése",
"Permission:UserManagement": "Felhasználókezelés",
"Permission:UserLookup": "Felhaszáló keresés",
"DisplayName:Abp.Identity.Password.RequiredLength": "Szükséges hossz",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "A zárolás befejezési ideje",
"FailedAccessCount": "Sikertelen hozzáférések száma"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Breyta",
"Permission:Delete": "Eyða",
"Permission:ChangePermissions": "Breyta heimildum",
"Permission:ManageRoles": "Hlutverka umsjón",
"Permission:UserManagement": "Notanda umsjón",
"Permission:UserLookup": "Leita að notanda",
"DisplayName:Abp.Identity.Password.RequiredLength": "Nauðsynleg lengdh",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Lokatími lokunar",
"FailedAccessCount": "Misheppnuð fjöldi aðgangs"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Modifica",
"Permission:Delete": "Elimina",
"Permission:ChangePermissions": "Modifica le autorizzazioni",
"Permission:ManageRoles": "Gestione ruoli",
"Permission:UserManagement": "Gestione utenti",
"Permission:UserLookup": "Ricerca utente",
"DisplayName:Abp.Identity.Password.RequiredLength": "Lunghezza richiesta",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Ora di fine del blocco",
"FailedAccessCount": "Conteggio accessi non riusciti"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"Permission:Edit": "Verander",
"Permission:Delete": "Verwijder",
"Permission:ChangePermissions": "Wijzig de rechten",
"Permission:ManageRoles": "Beheer rollen",
"Permission:UserManagement": "Gebruikersbeheer",
"Permission:UserLookup": "Gebruiker opzoeken",
"DisplayName:Abp.Identity.Password.RequiredLength": "Vereiste lengte",
Expand Down Expand Up @@ -127,4 +128,4 @@
"LockoutEndTime": "Eindtijd uitsluiting",
"FailedAccessCount": "Aantal mislukte toegangen"
}
}
}
Loading
Loading