//private async Task DeleteMenuPermissions(string permission) //{ // await _permissionRepository.DeleteAsync(c => c.Name.Contains(permission)); // await _cachingAppService.ClearCache(new EntityDto<string>(CacheName.PermissionCache)); //} private async Task ModifyMenuPermissions(Menu menu, string permission, FlatPermissionDto page, int sort, IReadOnlyCollection <DictionaryDto> types = null) { await _permissionRepository.DeleteAsync(c => c.Name.Contains(permission)); var code = $"{page.LevelCode}.{Guid.NewGuid().ToString("D").Split('-')[0]}"; var temp = new YtPermission() { DisplayName = $"{menu.DisplayName}权限", IsActive = true, IsStatic = false, Name = permission, ParentId = page.Id, PermissionType = PermissionType.Operation, LevelCode = code, Sort = sort }; if (types != null && types.Any()) { temp.Children = types.Where(c => c.IsCheck).Select((w, i) => new YtPermission() { DisplayName = w.DisplayName, IsActive = true, LevelCode = $"{code}.{Guid.NewGuid().ToString("D").Split('-')[0]}", Name = $"{permission}.{w.Name}", PermissionType = PermissionType.Operation, IsStatic = false, Sort = i }).ToList(); } await _permissionRepository.InsertAsync(temp); await _cachingAppService.ClearCache(new EntityDto <string>(SystemCacheName.PermissionCache)); }
/// <summary> /// Prohibits a permission for a role. /// </summary> /// <param name="role">Role</param> /// <param name="permission">Permission</param> public async Task ProhibitPermissionAsync(Role role, YtPermission permission) { if (!await IsGrantedAsync(role.Id, permission.Name)) { return; } await RemovePermissionAsync(role, new PermissionGrantInfo(permission.Name, true)); }
/// <summary> /// Grants a permission for a role. /// </summary> /// <param name="role">Role</param> /// <param name="permission">Permission</param> public async Task GrantPermissionAsync(Role role, YtPermission permission) { if (await IsGrantedAsync(role.Id, permission.Name)) { return; } //await _rolePermissionRepository.InsertAsync(new RolePermissionSetting() //{ // IsGranted = true, // Name = permission.Name, // RoleId = role.Id, // TenantId = AbpSession.TenantId //}); await AddPermissionAsync(role, new PermissionGrantInfo(permission.Name, true)); }
/// <summary> /// /// </summary> /// <param name="permission"></param> /// <param name="result"></param> /// <param name="level"></param> private void AddPermission(YtPermission permission, List <FlatPermissionWithLevelDto> result, int level) { var flatPermission = permission.MapTo <FlatPermissionWithLevelDto>(); flatPermission.Level = level; flatPermission.ParentName = permission.Parent?.DisplayName; result.Add(flatPermission); if (permission.Children == null) { return; } // var children = allPermissions.Where(p => p.Parent != null && p.Parent.Name == permission.Name).ToList(); foreach (var childPermission in permission.Children) { AddPermission(childPermission, result, level + 1); } }