public FileLockDto Handle(GetFileLockQuery query)
        {
            const string sql = "GetFileWithoutOwner";

            FileDto fileDto = dbConnection
                              .Query <FileDto>(sql, new { FileId = query.FileId }, commandType: CommandType.StoredProcedure)
                              .FirstOrDefault();

            UserDto lockOwner = fileLockingService.GetLockOwner(mapper.Map(fileDto));

            return(FileLockDto.ForUser(lockOwner));
        }
        public void Handle(AcquireFileLockCommand command)
        {
            File file = fileRepository.GetById(command.FileId).EnsureFound(command.FileId);

            User currentUser = currentUserSource.GetCurrentUser();

            if (!file.CanBeModifiedBy(currentUser))
            {
                throw new PermissionException($"The user doesn't have a permission to lock the file with id {command.FileId}");
            }

            fileLockingService.Lock(file, currentUser);
            UserDto lockOwner = fileLockingService.GetLockOwner(file);

            eventBus.PublishAfterCommit <FileLockChangedEvent, FileLockChangedMessage>(
                new FileLockChangedMessage(command.FileId, FileLockDto.ForUser(lockOwner)));
        }
예제 #3
0
        public void Handle(RemoveFileLockCommand command)
        {
            File file = fileRepository.GetById(command.FileId);

            UserDto lockOwner = fileLockingService.GetRequiredLockOwner(file);

            if (lockOwner.Id != currentUser.Id)
            {
                throw new PermissionException("The current user is not the lock owner");
            }

            fileLockingService.Unlock(file, currentUser.ToDomainUser());

            UserDto newLockOwner = fileLockingService.GetLockOwner(file);

            eventBus.PublishAfterCommit <FileLockChangedEvent, FileLockChangedMessage>(
                new FileLockChangedMessage(command.FileId, FileLockDto.ForUser(newLockOwner)));
        }
예제 #4
0
 public static UserDto GetRequiredLockOwner(this IFileLockingService fileLockingService, File file)
 {
     return(fileLockingService.GetLockOwner(file)
            ?? throw new NotFoundException($"The file with id {file.Id} is not locked."));;
 }