i need to add new columns to permission table ,is it possible ?if not what is the solution for this ,i have to add extra information to the table
thanks aaron very much the problem is solved by your effort
var role = await _role.GetAllIncluding(a=>a.Permissions).AsNoTracking().FirstAsync(x => x.Id == input.Id.Value);
i think the problem is with caching because after i clear cache from maintenance page it works fine,how can i disable page to be cached
i think the problem because of the caching how can i disable cache of this page
no it has granted some permission of both (hard coded ones and injected ones), but GetGrantedPermissionsAsync() function returns only the granted permissions that matches hard coded ones
but i noticed that GetRoleByIdAsync() has a property called permission this property some times comes with my granted injected permissions and sometimes comes with null (mostly comes with null).
Yes , role.permission :some times comes with null and sometimes comes with my permissions that have been granted from my injected objects ,and it 's never comes from GetGrantedPermissionsAsync() function
public async Task<GetRoleForEditOutput> GetRoleForEdit(NullableIdDto input) { var permissions = PermissionManager.GetAllPermissions();
var grantedPermissions = new Permission[0];
var grantedPermissionsList = new List<Permission>();
RoleEditDto roleEditDto;
if (input.Id.HasValue) //Editing existing role?
{
var role = await _roleManager.GetRoleByIdAsync(input.Id.Value);
grantedPermissions = (await _roleManager.GetGrantedPermissionsAsync(role)).ToArray();
if (role.Permissions!=null)
{
foreach (var item in role.Permissions)
{
Permission p = new Permission(name: item.Name, displayName: L(item.Name));
grantedPermissionsList.Add(p);
}
if (grantedPermissionsList.Any())
{
grantedPermissions = grantedPermissionsList.ToArray();
}
}
roleEditDto = ObjectMapper.Map<RoleEditDto>(role);
}
else
{
roleEditDto = new RoleEditDto();
}
var model= new GetRoleForEditOutput
{
Role = roleEditDto,
Permissions = ObjectMapper.Map<List<FlatPermissionDto>>(permissions).OrderBy(p => p.DisplayName).ToList(),
GrantedPermissionNames = grantedPermissions.Select(p => p.Name).ToList()
};
var items = _SystemObjectRepository.GetAll().OrderBy(a => a.Id).ToList();
foreach (var item in items.Where(a => a.SystemObjectTypeId == 1))
{
var parentname = GetEnglishName(item.JsonName);
var parentnameForView = GetLocalizedJsonName(item.JsonName);
var parentPermession = "Pages." + parentname.Replace(" ", "");
model.Permissions.Add(new FlatPermissionDto() { DisplayName = parentnameForView, Name = parentPermession,ParentName= "Pages" });
var childs = DrawChilds(item.Id, parentPermession, items);
model.Permissions.AddRange(childs);
}
return model;
}
private List<FlatPermissionDto> DrawChilds(int id, string parentPermessionName, List<SystemObject> list) {
List<FlatPermissionDto> moduleList = new List<FlatPermissionDto>();
var childs = list.Where(a => a.ParentId == id);
if (childs.Any())
{
foreach (var item in childs)
{
//var curchild = list.Where(a => a.Id == item.Id).FirstOrDefault();
FlatPermissionDto curchildPermession = new FlatPermissionDto();
var subParentName = GetEnglishName(item.JsonName);
var subParentNameForView = GetLocalizedJsonName(item.JsonName);
var subParentPermession = parentPermessionName + "." + subParentName.Replace(" ", "");
curchildPermession.DisplayName = subParentNameForView;
curchildPermession.Name = subParentPermession;
curchildPermession.ParentName = parentPermessionName;
moduleList.Add(curchildPermession);
moduleList.AddRange(DrawChilds(item.Id, subParentPermession, list));
}
}
return moduleList;
}
grantedPermissions = (await _roleManager.GetGrantedPermissionsAsync(role)).ToArray(); //because this function doesn't return my injected objects i iterated permissions on role.permessions as shown in below but the data only exist at the first time if i open them again it becomes null
if (role.Permissions!=null)
{
foreach (var item in role.Permissions)
{
Permission p = new Permission(name: item.Name, displayName: L(item.Name));
grantedPermissionsList.Add(p);
}
if (grantedPermissionsList.Any())
{
grantedPermissions = grantedPermissionsList.ToArray();
}
}
Update... i found my added permissions at role object but Role.Permmissions but this property filled only for the first time if i closed the window and opened it again it becomes null
i use module zero, and i injected some permissions dynamically and it stored as granted after saving . but GetGrantedPermissionsAsync function doesn't return them it returns only the permissions that only matches the hard coded ones and i tried to append them manually but apppermissions table is inaccessible. i need to append them to be shown as checked permissions