refactor: vault files

This commit is contained in:
Mo
2023-05-28 14:11:31 -05:00
parent 690f18708a
commit 94deab2ee0
69 changed files with 761 additions and 212 deletions
+6 -6
View File
@@ -139,12 +139,12 @@ import {
ValetTokenData,
WebSocketConnectionTokenData,
} from '@standardnotes/security'
import { FileUploadedEventHandler } from '../Domain/Handler/FileUploadedEventHandler'
import { UserFileUploadedEventHandler } from '../Domain/Handler/UserFileUploadedEventHandler'
import { CreateValetToken } from '../Domain/UseCase/CreateValetToken/CreateValetToken'
import { CreateListedAccount } from '../Domain/UseCase/CreateListedAccount/CreateListedAccount'
import { ListedAccountCreatedEventHandler } from '../Domain/Handler/ListedAccountCreatedEventHandler'
import { ListedAccountDeletedEventHandler } from '../Domain/Handler/ListedAccountDeletedEventHandler'
import { FileRemovedEventHandler } from '../Domain/Handler/FileRemovedEventHandler'
import { UserFileRemovedEventHandler } from '../Domain/Handler/UserFileRemovedEventHandler'
import { UserDisabledSessionUserAgentLoggingEventHandler } from '../Domain/Handler/UserDisabledSessionUserAgentLoggingEventHandler'
import { SettingInterpreterInterface } from '../Domain/Setting/SettingInterpreterInterface'
import { SettingInterpreter } from '../Domain/Setting/SettingInterpreter'
@@ -834,8 +834,8 @@ export class ContainerConfigLoader {
.bind<SubscriptionReassignedEventHandler>(TYPES.SubscriptionReassignedEventHandler)
.to(SubscriptionReassignedEventHandler)
container.bind<UserEmailChangedEventHandler>(TYPES.UserEmailChangedEventHandler).to(UserEmailChangedEventHandler)
container.bind<FileUploadedEventHandler>(TYPES.FileUploadedEventHandler).to(FileUploadedEventHandler)
container.bind<FileRemovedEventHandler>(TYPES.FileRemovedEventHandler).to(FileRemovedEventHandler)
container.bind<UserFileUploadedEventHandler>(TYPES.UserFileUploadedEventHandler).to(UserFileUploadedEventHandler)
container.bind<UserFileRemovedEventHandler>(TYPES.UserFileRemovedEventHandler).to(UserFileRemovedEventHandler)
container
.bind<ListedAccountCreatedEventHandler>(TYPES.ListedAccountCreatedEventHandler)
.to(ListedAccountCreatedEventHandler)
@@ -873,8 +873,8 @@ export class ContainerConfigLoader {
['EXTENSION_KEY_GRANTED', container.get(TYPES.ExtensionKeyGrantedEventHandler)],
['SUBSCRIPTION_REASSIGNED', container.get(TYPES.SubscriptionReassignedEventHandler)],
['USER_EMAIL_CHANGED', container.get(TYPES.UserEmailChangedEventHandler)],
['FILE_UPLOADED', container.get(TYPES.FileUploadedEventHandler)],
['FILE_REMOVED', container.get(TYPES.FileRemovedEventHandler)],
['USER_FILE_UPLOADED', container.get(TYPES.UserFileUploadedEventHandler)],
['USER_FILE_REMOVED', container.get(TYPES.UserFileRemovedEventHandler)],
['LISTED_ACCOUNT_CREATED', container.get(TYPES.ListedAccountCreatedEventHandler)],
['LISTED_ACCOUNT_DELETED', container.get(TYPES.ListedAccountDeletedEventHandler)],
[
+2 -2
View File
@@ -164,8 +164,8 @@ const TYPES = {
SubscriptionSyncRequestedEventHandler: Symbol.for('SubscriptionSyncRequestedEventHandler'),
ExtensionKeyGrantedEventHandler: Symbol.for('ExtensionKeyGrantedEventHandler'),
UserEmailChangedEventHandler: Symbol.for('UserEmailChangedEventHandler'),
FileUploadedEventHandler: Symbol.for('FileUploadedEventHandler'),
FileRemovedEventHandler: Symbol.for('FileRemovedEventHandler'),
UserFileUploadedEventHandler: Symbol.for('UserFileUploadedEventHandler'),
UserFileRemovedEventHandler: Symbol.for('UserFileRemovedEventHandler'),
ListedAccountCreatedEventHandler: Symbol.for('ListedAccountCreatedEventHandler'),
ListedAccountDeletedEventHandler: Symbol.for('ListedAccountDeletedEventHandler'),
UserDisabledSessionUserAgentLoggingEventHandler: Symbol.for('UserDisabledSessionUserAgentLoggingEventHandler'),
@@ -7,12 +7,13 @@ import {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
results,
} from 'inversify-express-utils'
import { CreateValetTokenPayload, ErrorTag } from '@standardnotes/responses'
import { ErrorTag } from '@standardnotes/responses'
import { ValetTokenOperation } from '@standardnotes/security'
import { Uuid } from '@standardnotes/domain-core'
import TYPES from '../Bootstrap/Types'
import { CreateValetToken } from '../Domain/UseCase/CreateValetToken/CreateValetToken'
import { CreateValetTokenPayload } from '../Domain/ValetToken/CreateValetTokenPayload'
@controller('/valet-tokens', TYPES.ApiGatewayAuthMiddleware)
export class ValetTokenController extends BaseHttpController {
@@ -1,25 +1,26 @@
import 'reflect-metadata'
import { FileRemovedEvent } from '@standardnotes/domain-events'
import { UserFileRemovedEvent } from '@standardnotes/domain-events'
import { Logger } from 'winston'
import { User } from '../User/User'
import { FileRemovedEventHandler } from './FileRemovedEventHandler'
import { UserFileRemovedEventHandler } from './UserFileRemovedEventHandler'
import { SubscriptionSettingServiceInterface } from '../Setting/SubscriptionSettingServiceInterface'
import { UserSubscription } from '../Subscription/UserSubscription'
import { UserSubscriptionType } from '../Subscription/UserSubscriptionType'
import { UserSubscriptionServiceInterface } from '../Subscription/UserSubscriptionServiceInterface'
describe('FileRemovedEventHandler', () => {
describe('UserFileRemovedEventHandler', () => {
let userSubscriptionService: UserSubscriptionServiceInterface
let logger: Logger
let user: User
let event: FileRemovedEvent
let event: UserFileRemovedEvent
let subscriptionSettingService: SubscriptionSettingServiceInterface
let regularSubscription: UserSubscription
let sharedSubscription: UserSubscription
const createHandler = () => new FileRemovedEventHandler(userSubscriptionService, subscriptionSettingService, logger)
const createHandler = () =>
new UserFileRemovedEventHandler(userSubscriptionService, subscriptionSettingService, logger)
beforeEach(() => {
user = {
@@ -47,7 +48,7 @@ describe('FileRemovedEventHandler', () => {
subscriptionSettingService.findSubscriptionSettingWithDecryptedValue = jest.fn().mockReturnValue(null)
subscriptionSettingService.createOrReplace = jest.fn()
event = {} as jest.Mocked<FileRemovedEvent>
event = {} as jest.Mocked<UserFileRemovedEvent>
event.createdAt = new Date(1)
event.payload = {
userUuid: '1-2-3',
@@ -1,4 +1,4 @@
import { DomainEventHandlerInterface, FileRemovedEvent } from '@standardnotes/domain-events'
import { DomainEventHandlerInterface, UserFileRemovedEvent } from '@standardnotes/domain-events'
import { SettingName } from '@standardnotes/settings'
import { inject, injectable } from 'inversify'
import { Logger } from 'winston'
@@ -10,14 +10,14 @@ import { UserSubscription } from '../Subscription/UserSubscription'
import { UserSubscriptionServiceInterface } from '../Subscription/UserSubscriptionServiceInterface'
@injectable()
export class FileRemovedEventHandler implements DomainEventHandlerInterface {
export class UserFileRemovedEventHandler implements DomainEventHandlerInterface {
constructor(
@inject(TYPES.UserSubscriptionService) private userSubscriptionService: UserSubscriptionServiceInterface,
@inject(TYPES.SubscriptionSettingService) private subscriptionSettingService: SubscriptionSettingServiceInterface,
@inject(TYPES.Logger) private logger: Logger,
) {}
async handle(event: FileRemovedEvent): Promise<void> {
async handle(event: UserFileRemovedEvent): Promise<void> {
const { regularSubscription, sharedSubscription } =
await this.userSubscriptionService.findRegularSubscriptionForUserUuid(event.payload.userUuid)
if (regularSubscription === null) {
@@ -1,11 +1,11 @@
import 'reflect-metadata'
import { FileUploadedEvent } from '@standardnotes/domain-events'
import { UserFileUploadedEvent } from '@standardnotes/domain-events'
import { Logger } from 'winston'
import { User } from '../User/User'
import { UserRepositoryInterface } from '../User/UserRepositoryInterface'
import { FileUploadedEventHandler } from './FileUploadedEventHandler'
import { UserFileUploadedEventHandler } from './UserFileUploadedEventHandler'
import { SubscriptionSettingServiceInterface } from '../Setting/SubscriptionSettingServiceInterface'
import { UserSubscription } from '../Subscription/UserSubscription'
import { UserSubscriptionServiceInterface } from '../Subscription/UserSubscriptionServiceInterface'
@@ -16,13 +16,13 @@ describe('FileUploadedEventHandler', () => {
let userSubscriptionService: UserSubscriptionServiceInterface
let logger: Logger
let user: User
let event: FileUploadedEvent
let event: UserFileUploadedEvent
let subscriptionSettingService: SubscriptionSettingServiceInterface
let regularSubscription: UserSubscription
let sharedSubscription: UserSubscription
const createHandler = () =>
new FileUploadedEventHandler(userRepository, userSubscriptionService, subscriptionSettingService, logger)
new UserFileUploadedEventHandler(userRepository, userSubscriptionService, subscriptionSettingService, logger)
beforeEach(() => {
user = {
@@ -53,7 +53,7 @@ describe('FileUploadedEventHandler', () => {
subscriptionSettingService.findSubscriptionSettingWithDecryptedValue = jest.fn().mockReturnValue(null)
subscriptionSettingService.createOrReplace = jest.fn()
event = {} as jest.Mocked<FileUploadedEvent>
event = {} as jest.Mocked<UserFileUploadedEvent>
event.createdAt = new Date(1)
event.payload = {
userUuid: '1-2-3',
@@ -1,4 +1,4 @@
import { DomainEventHandlerInterface, FileUploadedEvent } from '@standardnotes/domain-events'
import { DomainEventHandlerInterface, UserFileUploadedEvent } from '@standardnotes/domain-events'
import { SettingName } from '@standardnotes/settings'
import { inject, injectable } from 'inversify'
import { Logger } from 'winston'
@@ -11,7 +11,7 @@ import { UserSubscriptionServiceInterface } from '../Subscription/UserSubscripti
import { UserRepositoryInterface } from '../User/UserRepositoryInterface'
@injectable()
export class FileUploadedEventHandler implements DomainEventHandlerInterface {
export class UserFileUploadedEventHandler implements DomainEventHandlerInterface {
constructor(
@inject(TYPES.UserRepository) private userRepository: UserRepositoryInterface,
@inject(TYPES.UserSubscriptionService) private userSubscriptionService: UserSubscriptionServiceInterface,
@@ -19,7 +19,7 @@ export class FileUploadedEventHandler implements DomainEventHandlerInterface {
@inject(TYPES.Logger) private logger: Logger,
) {}
async handle(event: FileUploadedEvent): Promise<void> {
async handle(event: UserFileUploadedEvent): Promise<void> {
const user = await this.userRepository.findOneByUuid(event.payload.userUuid)
if (user === null) {
this.logger.warn(`Could not find user with uuid: ${event.payload.userUuid}`)
@@ -2,7 +2,7 @@ import { inject, injectable } from 'inversify'
import { SubscriptionName } from '@standardnotes/common'
import { TimerInterface } from '@standardnotes/time'
import { TokenEncoderInterface, ValetTokenData } from '@standardnotes/security'
import { CreateValetTokenPayload, CreateValetTokenResponseData } from '@standardnotes/responses'
import { CreateValetTokenResponseData } from '@standardnotes/responses'
import { SettingName } from '@standardnotes/settings'
import TYPES from '../../../Bootstrap/Types'
@@ -12,6 +12,7 @@ import { SubscriptionSettingServiceInterface } from '../../Setting/SubscriptionS
import { CreateValetTokenDTO } from './CreateValetTokenDTO'
import { SubscriptionSettingsAssociationServiceInterface } from '../../Setting/SubscriptionSettingsAssociationServiceInterface'
import { UserSubscriptionServiceInterface } from '../../Subscription/UserSubscriptionServiceInterface'
import { CreateValetTokenPayload } from '../../ValetToken/CreateValetTokenPayload'
@injectable()
export class CreateValetToken implements UseCaseInterface {
@@ -0,0 +1,7 @@
export type CreateValetTokenPayload = {
operation: 'read' | 'write' | 'delete' | 'move'
resources: Array<{
remoteIdentifier: string
unencryptedFileSize?: number
}>
}