Permissions not detected
As the host admin, I am creating a new tenant. Upon creation of the tenant, I manually create an admin user for this tenant and a new admin role for this admin user, and assign the following permissions to this role:
IdentityPermissions.Roles.DefaultIdentityPermissions.Roles.CreateIdentityPermissions.Roles.UpdateIdentityPermissions.Roles.DeleteIdentityPermissions.Roles.ManagePermissions
using
await _permissionManager.SetForRoleAsync(tenantAdminRoleName, permission, true)
Role creation is done as follows:
var tenantAdminRole = new IdentityRole(
GuidGenerator.Create(),
tenantAdminRoleName,
tenantId
)
{
IsDefault = false,
IsPublic = true
};
(await _roleManager.CreateAsync(tenantAdminRole)).CheckErrors();
(await _userManager.AddToRoleAsync(tenantAdmin, tenantAdminRoleName)).CheckErrors();
In the database I can verify that the user and role are created correctly with the relevant tenant ID, and the admin role is assigned to the admin user.
When querying the AbpPermissionGrants table, I can verify that the permissions are attached to the admin role (ProviderName is R and ProviderKey is the name of the admin role). However, these AbpPermissionGrants records do not have a tenant ID.
Furthermore, only when I manually update the above-mentioned AbpPermissionGrants records with the correct tenant ID, and restart the ABP application, then does the user's permissions reflect in the application-configuration endpoint's response's auth.grantedPolicies property.
So: how can I, as the host admin, create an admin user for a tenant, and assign this user a new role with permissions?
Try switching to the tenant.
using(CurrentTenant.Change(tenantId))
{
await _permissionManager.SetForRoleAsync(tenantAdminRoleName, permission, true)
}
Thanks, that seems to have resolved the issue!