hey all, i have an issue with permessions, i made a workaround solution for generating permessions dynamically from database and it can be set properly the problem is with this function SetGrantedPermissionsAsync(role, permissions) if i unselect some permessions it removes only predefined permessions,and i tried to make it manauly so i made custom repository and make a stroed to remove all permessions to be set again but it didn't work any help ?
9 Answer(s)
-
0
What do you mean by it didn't work?
-
0
the strored procedure doesnt executed ,it started and never ended
create PROCEDURE [dbo].[Core_Remove_permessions_By_RoleId] @roleId int AS BEGIN SET NOCOUNT ON; -- Insert statements for procedure here delete AbpPermissions where RoleId=@roleId END
-
0
here is my code
private async Task UpdateGrantedPermissionsAsync(Role role, List<string> grantedPermissionNames) {
var grantedPermissions = PermissionManager.GetPermissionsFromNamesByValidating(grantedPermissionNames); List<Permission> customList = new List<Permission>(); foreach (var item in grantedPermissions) { customList.Add(item); } var additionalPermessions = await GetGrantedPermessionsFromSystemObjectsAsync(grantedPermissionNames); customList.AddRange(additionalPermessions); await RemoveOldgarntedPermissionAsync(role.Id); await _roleManager.SetGrantedPermissionsAsync(role, customList); } private async Task RemoveOldgarntedPermissionAsync(int id) { var oldpermessionsToBeDeleted = await _sysobjectCustomRepo.RemoveGrantedPermessionsForRole(id); }
RemoveOldgarntedPermissionAsync:this function call stored procedure to delete but it doesn't execute till the end of function UpdateGrantedPermissionsAsync so it deletes after setting new permessions i don't know how to make it executes before setting the new permessions
-
0
What are the current and expected behaviors? Give an example with before and after permissions.
-
0
i expected when updating permessions for arole or user
first removes old roles with my custom stored procedure then set the new permessions with setgrantedpermessions function
but what happening now it removes the permessions at the end of the function although i put await befor my custom function the result is the whole permessions removed for this role
-
0
Try calling SaveChanges in RemoveOldgarntedPermissionAsync.
-
0
RemoveOldgarntedPermissionAsync is in application layer how can i call savechanges, i tried to call it from my custom repositry but it didn't removes the records till the end also.
this is the function in my custom repo. public async Task<string> RemoveGrantedPermessionsForRole(int id) { EnsureConnectionOpen();
using (var command = CreateCommand("Core_Remove_permessions_By_RoleId", CommandType.StoredProcedure, new SqlParameter("@roleId", id))) { using (var dataReader = await command.ExecuteReaderAsync()) { var result = ""; while (dataReader.Read()) { result = (dataReader["roleId"].ToString()); } Context.SaveChanges(); return result; } }
-
0
Okay, what's probably happening is:
- your stored procedure removes the permissions, but
- the role permission cache says the permissions are still there, so
- the role permissions don't get re-added. You can inject ICacheManager and clear the cache:
private async Task RemoveOldgarntedPermissionAsync(int id) { var oldpermessionsToBeDeleted = await _sysobjectCustomRepo.RemoveGrantedPermessionsForRole(id); _cacheManager.GetRolePermissionCache().Clear(); }
-
0
Thanks alot,this was my problem