public async Task <Result> CreateAction([FromBody] PermissionActionCreateRequestDto dto) { //验证请求数据合法性 var result = dto.Valid(); if (!result.Success) { return(result); } //创建功能权限 var permission = dto.To(); result = await this._serviceProvider.GetRequiredService <PermissionCreateService>().CreateAction(permission); if (!result.Success) { return(result); } //数据持久化 _operateLog.Record(ASFPermissions.PermissionCreateAction, dto, "Success"); //记录日志 await _permissionRepository.AddAsync(permission); await _unitOfWork.CommitAsync(autoRollback : true); return(Result.ReSuccess()); }
public async Task <IResultModel> Add(PermissionAddModel model) { var list = new List <Permission>(); foreach (var action in model.Actions) { var entity = new Permission { Name = $"{model.ControllerName}-{action.Value}", ModuleCode = model.ModuleCode.ToLower(), Controller = model.Controller.ToLower(), Action = action.Key.ToLower(), CreatedBy = _loginInfo.AccountId }; if (await _permissionRepository.Exists(entity)) { return(ResultModel.Failed($"{action}操作已存在~")); } list.Add(entity); } var result = await _permissionRepository.AddAsync(list); return(ResultModel.Result(result)); }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { if (permissions == null || !permissions.Any()) { return(ResultModel.Failed("未找到权限信息")); } using (var tran = _permissionRepository.BeginTransaction()) { foreach (var permission in permissions) { if (!await _permissionRepository.Exists(permission, tran)) { if (!await _permissionRepository.AddAsync(permission, tran)) { tran.Rollback(); return(ResultModel.Failed("同步失败")); } } else { if (!await _permissionRepository.UpdateForSync(permission, tran)) { tran.Rollback(); return(ResultModel.Failed("同步失败")); } } } tran.Commit(); } return(ResultModel.Success()); }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { if (permissions == null || !permissions.Any()) { return(ResultModel.Failed("未找到权限信息")); } using (var uow = _dbContext.NewUnitOfWork()) { foreach (var permission in permissions) { if (!await _permissionRepository.Exists(permission, uow)) { if (!await _permissionRepository.AddAsync(permission, uow)) { uow.Rollback(); return(ResultModel.Failed("同步失败")); } } else { if (!await _permissionRepository.UpdateForSync(permission, uow)) { uow.Rollback(); return(ResultModel.Failed("同步失败")); } } } uow.Commit(); } return(ResultModel.Success()); }
public async Task HandleAsync(GrantPermission command) { var user = await _repository.LoadAsync <User>(command.UserId); var resource = await _repository.LoadAsync <DomainResource>(command.ResourceId); var permission = await _permissionRepo.Find(user, resource); if (permission != null) { throw new DomainException(DuplicatingGrant(permission)); } permission = new Permission(Guid.NewGuid(), $"Grant on {resource.Name} for {user.Name}") { User = user, Resource = resource, //ToDo:4 Restriction = command.Restriction, }; await _permissionRepo.AddAsync(permission); await _eventTransmitter.BroadcastAsync(new DomainEvent <Permission>(permission, Trigger.Added, command.InitiatorId)); }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { if (permissions == null || !permissions.Any()) { return(ResultModel.Failed("未找到权限信息")); } using var uow = _dbContext.NewUnitOfWork(); //先清除已有权限信息 if (await _repository.ClearAsync(uow)) { foreach (var permission in permissions) { if (!await _repository.AddAsync(permission, uow)) { uow.Rollback(); return(ResultModel.Failed("同步失败")); } } uow.Commit(); //删除所有账户的缓存信息 await _cacheHandler.RemoveByPrefixAsync(CacheKeys.AccountPermissions); return(ResultModel.Success()); } return(ResultModel.Failed("同步失败")); }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { if (permissions == null || !permissions.Any()) { return(ResultModel.Failed("未找到权限信息")); } using var uow = _dbContext.NewUnitOfWork(); //先清除已有权限信息 await _repository.ClearAsync(uow); foreach (var permission in permissions) { if (!await _repository.AddAsync(permission, uow)) { uow.Rollback(); return(ResultModel.Failed("同步失败")); } } uow.Commit(); return(ResultModel.Success()); }
public async Task <IActionResult> Post(CreatePermissionDto input) { var permissions = _mapper.Map <Permission>(input); permissions.Created = DateTime.Now; await _permissionRepository.AddAsync(permissions); return(Ok(new Response <Permission>(permissions))); }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { if (!_options.RefreshModuleOrPermission) { return(ResultModel.Success()); } if (permissions == null || !permissions.Any()) { return(ResultModel.Failed("未找到权限信息")); } _logger.LogDebug("Sync Permission Info"); using var uow = _dbContext.NewUnitOfWork(); //先清除已有权限信息 if (await _repository.ClearAsync(uow)) { foreach (var permission in permissions) { if (!await _repository.AddAsync(permission, uow)) { uow.Rollback(); return(ResultModel.Failed("同步失败")); } } uow.Commit(); //删除所有账户的权限缓存 await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS); return(ResultModel.Success()); } return(ResultModel.Failed("同步失败")); }
private async Task SyncUserPermissions(AppUser user, IList <int> permissionIds) { var currentPermissionIds = await GetPermissionIdsInUser(user); var needRemoveIds = currentPermissionIds.Where(i => !permissionIds.Contains(i)); if (!needRemoveIds.IsNullOrEmpty()) { var spec = new UserPermissionFilterSpecification(user, needRemoveIds.ToList()); var removeItems = await userPermissionRepository.ListAsync(spec); userPermissionRepository.DeleteRange(removeItems); } var needToAdd = permissionIds.Where(i => !currentPermissionIds.Contains(i)); if (!needToAdd.IsNullOrEmpty()) { foreach (var newPermissionId in needToAdd) { await userPermissionRepository.AddAsync(new UserPermission { AppUserId = user.Id, PermissionId = newPermissionId }); } } }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { using var uow = _dbContext.NewUnitOfWork(); #region ==同步模块信息== var modules = _moduleCollection.Select(m => new ModuleEntity { Number = m.Id, Name = m.Name, Code = m.Code, Icon = m.Icon, Version = m.Version, Remarks = m.Description }); _logger.LogDebug("Sync Module Info"); foreach (var module in modules) { if (!await _repository.Exists(module, uow)) { if (!await _repository.AddAsync(module)) { return(ResultModel.Failed()); } } else { if (!await _repository.UpdateByCode(module)) { return(ResultModel.Failed()); } } } #endregion #region ==同步权限信息= if (permissions != null && permissions.Any()) { _logger.LogDebug("Sync Permission Info"); //先清除已有权限信息 if (await _permissionRepository.ClearAsync(uow)) { foreach (var permission in permissions) { if (!await _permissionRepository.AddAsync(permission, uow)) { return(ResultModel.Failed("同步失败")); } } //删除所有账户的权限缓存 await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS); } } #endregion uow.Commit(); return(ResultModel.Success()); }
public async Task <AppUser> CreateAppUserAsync(AppUser user) { return(await appUserRepository.AddAsync(user)); }