feat: should be able to access shared item revisions as third party user (#807)

This commit is contained in:
Karol Sójko
2023-09-06 15:36:23 +02:00
committed by GitHub
parent 14d42b26bb
commit 794cd8734a
92 changed files with 1725 additions and 265 deletions
@@ -1,11 +1,19 @@
import { Uuid, Timestamps, Result, NotificationPayload, SharedVaultUserPermission } from '@standardnotes/domain-core'
import {
Uuid,
Timestamps,
Result,
NotificationPayload,
SharedVaultUserPermission,
SharedVaultUser,
} from '@standardnotes/domain-core'
import { SharedVault } from '../../../SharedVault/SharedVault'
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
import { RemoveUserFromSharedVault } from './RemoveUserFromSharedVault'
import { AddNotificationForUser } from '../../Messaging/AddNotificationForUser/AddNotificationForUser'
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
import { DomainEventInterface, DomainEventPublisherInterface } from '@standardnotes/domain-events'
describe('RemoveUserFromSharedVault', () => {
let sharedVaultRepository: SharedVaultRepositoryInterface
@@ -13,9 +21,17 @@ describe('RemoveUserFromSharedVault', () => {
let addNotificationForUser: AddNotificationForUser
let sharedVault: SharedVault
let sharedVaultUser: SharedVaultUser
let domainEventFactory: DomainEventFactoryInterface
let domainEventPublisher: DomainEventPublisherInterface
const createUseCase = () =>
new RemoveUserFromSharedVault(sharedVaultUserRepository, sharedVaultRepository, addNotificationForUser)
new RemoveUserFromSharedVault(
sharedVaultUserRepository,
sharedVaultRepository,
addNotificationForUser,
domainEventFactory,
domainEventPublisher,
)
beforeEach(() => {
sharedVault = SharedVault.create({
@@ -39,6 +55,14 @@ describe('RemoveUserFromSharedVault', () => {
addNotificationForUser = {} as jest.Mocked<AddNotificationForUser>
addNotificationForUser.execute = jest.fn().mockReturnValue(Result.ok())
domainEventFactory = {} as jest.Mocked<DomainEventFactoryInterface>
domainEventFactory.createUserRemovedFromSharedVaultEvent = jest
.fn()
.mockReturnValue({} as jest.Mocked<DomainEventInterface>)
domainEventPublisher = {} as jest.Mocked<DomainEventPublisherInterface>
domainEventPublisher.publish = jest.fn()
})
it('should remove user from shared vault', async () => {
@@ -1,15 +1,19 @@
import { NotificationPayload, NotificationType, Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
import { DomainEventPublisherInterface } from '@standardnotes/domain-events'
import { RemoveUserFromSharedVaultDTO } from './RemoveUserFromSharedVaultDTO'
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
import { AddNotificationForUser } from '../../Messaging/AddNotificationForUser/AddNotificationForUser'
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
export class RemoveUserFromSharedVault implements UseCaseInterface<void> {
constructor(
private sharedVaultUsersRepository: SharedVaultUserRepositoryInterface,
private sharedVaultRepository: SharedVaultRepositoryInterface,
private addNotificationForUser: AddNotificationForUser,
private domainEventFactory: DomainEventFactoryInterface,
private domainEventPublisher: DomainEventPublisherInterface,
) {}
async execute(dto: RemoveUserFromSharedVaultDTO): Promise<Result<void>> {
@@ -77,6 +81,13 @@ export class RemoveUserFromSharedVault implements UseCaseInterface<void> {
return Result.fail(result.getError())
}
await this.domainEventPublisher.publish(
this.domainEventFactory.createUserRemovedFromSharedVaultEvent({
sharedVaultUuid: dto.sharedVaultUuid,
userUuid: dto.userUuid,
}),
)
return Result.ok()
}
}