public async Task <ActionResult> RemovePermission([FromBody] RemovePermissionDto permissionDto)
        {
            if (!IsAvailableOperation())
            {
                return(BadRequest());
            }

            var result = await _fileStorageService.RemovePermission(permissionDto, UserId, ClientId);

            AddLog(LogType.Remove, LogMessage.CreatePermissionMessage(permissionDto.FileStorageId, LogMessage.UpdateVerb, UserId));

            var recipient = result.Recipients.First();
            var message   = MessageUtil.GetRemovePermissionMessage(recipient, result.Storage, result.Sender);

            try
            {
                await _emailSender.Send(EmailType.Notification, new MailAddress(recipient.Email, recipient.UserName), message.Subject, message.MessageBody);

                await _notificationService.Add(recipient.Id, result.Storage.Id, message.Subject, message.MessageBody, Enums.NotificationType.Success);
            }
            catch (Exception ex)
            {
                await _notificationService.Add(recipient.Id, result.Storage.Id, message.Subject, message.MessageBody, Enums.NotificationType.NotSent);
            }

            return(Ok());
        }
Exemple #2
0
        public async Task <CheckPermissionResultDto> RemovePermission(RemovePermissionDto permissionDto, int userId, int clientId)
        {
            var fileStorageRepository = DataContextManager.CreateRepository <IFileStorageRepository>();
            var fileStorage           = await fileStorageRepository.GetById(permissionDto.FileStorageId, userId, clientId);

            var isAvailableToChange = await fileStorageRepository.IsAvailableToChange(fileStorage.Id, userId, clientId);

            if (!isAvailableToChange)
            {
                throw new UnavailableOperationException("remove permission", "Permission", fileStorage.Id, userId);
            }

            var sender = await _userService.GetById(userId);

            var recipient = await _userService.GetById(permissionDto.RecipientId);

            var fileStoragePermission = fileStorage.Permissions.FirstOrDefault(x => x.RecipientId == recipient.Id && !x.EndDate.HasValue);

            if (fileStoragePermission == null)
            {
                throw new NotFoundException("File storage permission", fileStorage.Id, recipient.Email);
            }

            fileStoragePermission.EndDate = DateTime.UtcNow;

            var parentFileStorages = await fileStorageRepository.GetParents(fileStorage.ParentFileStorageId, userId, clientId);

            if (!fileStorage.ClientId.HasValue && !fileStorage.OwnerId.HasValue || fileStorage.ClientId.HasValue && !fileStorage.OwnerId.HasValue)
            {
                parentFileStorages.ToList()
                .ForEach(storage =>
                {
                    var permission = storage.Permissions.FirstOrDefault(x => x.RecipientId == recipient.Id && !x.EndDate.HasValue);

                    if (permission != null)
                    {
                        permission.EndDate = DateTime.UtcNow;
                    }
                });
            }

            await SaveChanges(fileStorageRepository, fileStorage, parentFileStorages);

            return(new CheckPermissionResultDto
            {
                Storage = MapperFactory.CreateMapper <IFileStorageMapper>().MapToModel(fileStorage),
                Sender = sender,
                Recipients = new List <CheckPermissionResultDto.RecipientDto>
                {
                    new CheckPermissionResultDto.RecipientDto
                    {
                        Id = recipient.Id,
                        UserName = recipient.UserName,
                        Email = recipient.Email,
                        Type = CheckPermissionResultDto.UpdateType.Remove
                    }
                }
            });
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="removePermissionDto">权限删除信息</param>
        /// <returns>返回执行结果</returns>
        public Result RemovePermission(RemovePermissionDto removePermissionDto)
        {
            using (var businessWork = WorkManager.Create())
            {
                #region 参数判断

                if (removePermissionDto?.Ids.IsNullOrEmpty() ?? true)
                {
                    return(Result.FailedResult("没有指定要删除的权限"));
                }

                #endregion

                permissionService.Remove(removePermissionDto.Ids);
                var exectVal = businessWork.Commit();
                return(exectVal.ExecutedSuccess ? Result.SuccessResult("删除成功") : Result.FailedResult("删除失败"));
            }
        }
Exemple #4
0
 public async Task DeletePermissionsAsync(RemovePermissionDto permissionDto)
 {
     await _freeSql.Delete <LinGroupPermission>()
     .Where(r => permissionDto.PermissionIds.Contains(r.PermissionId) && r.GroupId == permissionDto.GroupId)
     .ExecuteAffrowsAsync();
 }
        public async Task <UnifyResponseDto> RemovePermissions(RemovePermissionDto permissionDto)
        {
            await _permissionService.DeletePermissionsAsync(permissionDto);

            return(UnifyResponseDto.Success("删除权限成功"));
        }
 public async Task DeletePermissionsAsync(RemovePermissionDto permissionDto)
 {
     await _groupPermissionRepository.DeleteAsync(r =>
                                                  permissionDto.PermissionIds.Contains(r.PermissionId) && r.GroupId == permissionDto.GroupId);
 }
 /// <summary>
 /// 删除权限
 /// </summary>
 /// <param name="removePermissionDto">权限删除信息</param>
 /// <returns>返回执行结果</returns>
 public Result RemovePermission(RemovePermissionDto removePermissionDto)
 {
     return(permissionBusiness.RemovePermission(removePermissionDto));
 }