mirror of
https://github.com/standardnotes/server
synced 2026-05-20 06:44:25 -04:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fee1f1a3a7 | |||
| b0fbe0bb58 | |||
| 0087c70007 | |||
| 36e496dd7c | |||
| f2e2030e85 | |||
| 0c3737dc19 | |||
| f7471119e1 | |||
| 9bd97b95e9 | |||
| b7400c198f | |||
| f87036e3a8 | |||
| a43e5ef724 | |||
| 913ced70b0 | |||
| 6ffce30a36 | |||
| f5a57d886c | |||
| e8ba49ecca | |||
| c79a5dc94b | |||
| 4db83ae678 | |||
| 84ceb7ffd2 | |||
| e215ac4343 | |||
| bc8048790f | |||
| 886ccf84c1 | |||
| c067cb9fe4 | |||
| 6b2389cdc3 | |||
| d93916b159 | |||
| c34f548e45 | |||
| 6fcd56cc86 | |||
| 8f88a87c93 | |||
| f8c2f84322 | |||
| 46c4947871 | |||
| 64759ec2da | |||
| 5f7e768e64 | |||
| 4bc189f1c5 | |||
| 71721ab198 | |||
| 5536a48966 | |||
| f77e29d3c9 | |||
| 4b1fc718a2 | |||
| 1708c3f8a0 | |||
| 352e02028d | |||
| 1bbb639c83 |
@@ -55,6 +55,7 @@ jobs:
|
||||
e2e-home-server:
|
||||
name: (Home Server) E2E Test Suite
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
db_type: [mysql, sqlite]
|
||||
cache_type: [redis, memory]
|
||||
@@ -106,20 +107,21 @@ jobs:
|
||||
sed -i "s/PSEUDO_KEY_PARAMS_KEY=/PSEUDO_KEY_PARAMS_KEY=$(openssl rand -hex 32)/g" packages/home-server/.env
|
||||
sed -i "s/VALET_TOKEN_SECRET=/VALET_TOKEN_SECRET=$(openssl rand -hex 32)/g" packages/home-server/.env
|
||||
echo "ACCESS_TOKEN_AGE=4" >> packages/home-server/.env
|
||||
echo "REFRESH_TOKEN_AGE=7" >> packages/home-server/.env
|
||||
echo "REFRESH_TOKEN_AGE=10" >> packages/home-server/.env
|
||||
echo "REVISIONS_FREQUENCY=5" >> packages/home-server/.env
|
||||
echo "DB_HOST=db" >> packages/home-server/.env
|
||||
echo "DB_HOST=localhost" >> packages/home-server/.env
|
||||
echo "DB_PORT=3306" >> packages/home-server/.env
|
||||
echo "DB_DATABASE=standardnotes" >> packages/home-server/.env
|
||||
echo "DB_USERNAME=standardnotes" >> packages/home-server/.env
|
||||
echo "DB_PASSWORD=standardnotes" >> packages/home-server/.env
|
||||
echo "DB_TYPE=${{ matrix.db_type }}" >> packages/home-server/.env
|
||||
echo "REDIS_URL=redis://cache" >> packages/home-server/.env
|
||||
echo "REDIS_URL=redis://localhost" >> packages/home-server/.env
|
||||
echo "CACHE_TYPE=${{ matrix.cache_type }}" >> packages/home-server/.env
|
||||
echo "FILES_SERVER_URL=http://localhost:3123" >> packages/home-server/.env
|
||||
echo "E2E_TESTING=true" >> packages/home-server/.env
|
||||
|
||||
- name: Run Server
|
||||
run: nohup yarn workspace @standardnotes/home-server start &
|
||||
run: nohup yarn workspace @standardnotes/home-server start > logs/output.log 2>&1 &
|
||||
env:
|
||||
PORT: 3123
|
||||
|
||||
@@ -128,3 +130,7 @@ jobs:
|
||||
|
||||
- name: Run E2E Test Suite
|
||||
run: yarn dlx mocha-headless-chrome --timeout 1200000 -f http://localhost:9001/mocha/test.html
|
||||
|
||||
- name: Show logs on failure
|
||||
if: ${{ failure() }}
|
||||
run: tail -n 500 logs/output.log
|
||||
|
||||
@@ -3,6 +3,7 @@ services:
|
||||
image: standardnotes/server
|
||||
env_file: .env
|
||||
container_name: server_self_hosted
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 3000:3000
|
||||
- 3125:3104
|
||||
|
||||
+2
-1
@@ -17,7 +17,8 @@
|
||||
"release": "lerna version --conventional-graduate --conventional-commits --yes -m \"chore(release): publish new version\"",
|
||||
"publish": "lerna publish from-git --yes --no-verify-access --loglevel verbose",
|
||||
"postversion": "./scripts/push-tags-one-by-one.sh",
|
||||
"upgrade:snjs": "yarn workspaces foreach --verbose run upgrade:snjs"
|
||||
"upgrade:snjs": "yarn workspaces foreach --verbose run upgrade:snjs",
|
||||
"e2e": "yarn build packages/home-server && PORT=3123 yarn workspace @standardnotes/home-server start"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.0.2",
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [2.25.6](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.25.5...@standardnotes/analytics@2.25.6) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/analytics
|
||||
|
||||
## [2.25.5](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.25.4...@standardnotes/analytics@2.25.5) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/analytics
|
||||
|
||||
## [2.25.4](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.25.3...@standardnotes/analytics@2.25.4) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/analytics
|
||||
|
||||
## [2.25.3](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.25.2...@standardnotes/analytics@2.25.3) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/analytics
|
||||
|
||||
## [2.25.2](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.25.1...@standardnotes/analytics@2.25.2) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/analytics
|
||||
|
||||
## [2.25.1](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.25.0...@standardnotes/analytics@2.25.1) (2023-07-19)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/analytics
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/analytics",
|
||||
"version": "2.25.1",
|
||||
"version": "2.25.6",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,32 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.68.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.68.0...@standardnotes/api-gateway@1.68.1) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api-gateway
|
||||
|
||||
# [1.68.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.67.4...@standardnotes/api-gateway@1.68.0) (2023-07-27)
|
||||
|
||||
### Features
|
||||
|
||||
* **syncing-server:** add deleting outbound messages ([e8ba49e](https://github.com/standardnotes/api-gateway/commit/e8ba49ecca38ab10c0ea0e1f4cf4db9fb17366db))
|
||||
|
||||
## [1.67.4](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.67.3...@standardnotes/api-gateway@1.67.4) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api-gateway
|
||||
|
||||
## [1.67.3](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.67.2...@standardnotes/api-gateway@1.67.3) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api-gateway
|
||||
|
||||
## [1.67.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.67.1...@standardnotes/api-gateway@1.67.2) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api-gateway
|
||||
|
||||
## [1.67.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.67.0...@standardnotes/api-gateway@1.67.1) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api-gateway
|
||||
|
||||
# [1.67.0](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.66.1...@standardnotes/api-gateway@1.67.0) (2023-07-20)
|
||||
|
||||
### Features
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/api-gateway",
|
||||
"version": "1.67.0",
|
||||
"version": "1.68.1",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -83,6 +83,16 @@ export class SharedVaultInvitesController extends BaseHttpController {
|
||||
)
|
||||
}
|
||||
|
||||
@httpDelete('/invites/outbound')
|
||||
async deleteOutboundUserInvites(request: Request, response: Response): Promise<void> {
|
||||
await this.httpService.callSyncingServer(
|
||||
request,
|
||||
response,
|
||||
this.endpointResolver.resolveEndpointOrMethodIdentifier('DELETE', 'shared-vaults/invites/outbound'),
|
||||
request.body,
|
||||
)
|
||||
}
|
||||
|
||||
@httpGet('/invites/outbound')
|
||||
async getOutboundUserInvites(request: Request, response: Response): Promise<void> {
|
||||
await this.httpService.callSyncingServer(
|
||||
|
||||
@@ -79,6 +79,7 @@ export class EndpointResolver implements EndpointResolverInterface {
|
||||
['[POST]:shared-vaults/:sharedVaultUuid/invites/:inviteUuid/accept', 'sync.shared-vault-invites.accept'],
|
||||
['[POST]:shared-vaults/:sharedVaultUuid/invites/:inviteUuid/decline', 'sync.shared-vault-invites.decline'],
|
||||
['[DELETE]:shared-vaults/invites/inbound', 'sync.shared-vault-invites.delete-inbound'],
|
||||
['[DELETE]:shared-vaults/invites/outbound', 'sync.shared-vault-invites.delete-outbound'],
|
||||
['[GET]:shared-vaults/invites/outbound', 'sync.shared-vault-invites.get-outbound'],
|
||||
['[GET]:shared-vaults/invites', 'sync.shared-vault-invites.get-user-invites'],
|
||||
['[GET]:shared-vaults/:sharedVaultUuid/invites', 'sync.shared-vault-invites.get-vault-invites'],
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.126.5](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.126.4...@standardnotes/auth-server@1.126.5) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/auth-server
|
||||
|
||||
## [1.126.4](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.126.3...@standardnotes/auth-server@1.126.4) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/auth-server
|
||||
|
||||
## [1.126.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.126.2...@standardnotes/auth-server@1.126.3) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/auth-server
|
||||
|
||||
## [1.126.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.126.1...@standardnotes/auth-server@1.126.2) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/auth-server
|
||||
|
||||
## [1.126.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.126.0...@standardnotes/auth-server@1.126.1) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/auth-server
|
||||
|
||||
# [1.126.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.125.1...@standardnotes/auth-server@1.126.0) (2023-07-20)
|
||||
|
||||
### Features
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/auth-server",
|
||||
"version": "1.126.0",
|
||||
"version": "1.126.5",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,36 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.24.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.24.0...@standardnotes/domain-core@1.24.1) (2023-07-27)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* setting env vars on home server in e2e environment ([f87036e](https://github.com/standardnotes/server/commit/f87036e3a8dc6b7784e74e5f32ffd220033724f5))
|
||||
|
||||
# [1.24.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.23.4...@standardnotes/domain-core@1.24.0) (2023-07-26)
|
||||
|
||||
### Features
|
||||
|
||||
* extract shared vault user permission to domain-core ([e215ac4](https://github.com/standardnotes/server/commit/e215ac4343e9f8818f40004d31390d6ac23e369d))
|
||||
|
||||
## [1.23.4](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.23.3...@standardnotes/domain-core@1.23.4) (2023-07-26)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-server:** persisting aggregate changes from root ([#674](https://github.com/standardnotes/server/issues/674)) ([c34f548](https://github.com/standardnotes/server/commit/c34f548e45bbd8defb8d490936e90755fd284e78))
|
||||
|
||||
## [1.23.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.23.2...@standardnotes/domain-core@1.23.3) (2023-07-21)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **domain-core:** notification payload creation from string ([1708c3f](https://github.com/standardnotes/server/commit/1708c3f8a00897369585e1ef8022950a7c3c610e))
|
||||
|
||||
## [1.23.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.23.1...@standardnotes/domain-core@1.23.2) (2023-07-21)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* user notifications structure ([#667](https://github.com/standardnotes/server/issues/667)) ([1bbb639](https://github.com/standardnotes/server/commit/1bbb639c83922ec09e3778f85419d76669d36ae3))
|
||||
|
||||
## [1.23.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-core@1.23.0...@standardnotes/domain-core@1.23.1) (2023-07-19)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/domain-core",
|
||||
"version": "1.23.1",
|
||||
"version": "1.24.1",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { Change } from './Change'
|
||||
import { Entity } from './Entity'
|
||||
|
||||
export abstract class Aggregate<T> extends Entity<T> {}
|
||||
export abstract class Aggregate<T> extends Entity<T> {
|
||||
private changesOnAggregateRoot: Change[] = []
|
||||
|
||||
addChange(change: Change): void {
|
||||
this.changesOnAggregateRoot.push(change)
|
||||
}
|
||||
|
||||
flushChanges(): void {
|
||||
this.changesOnAggregateRoot = []
|
||||
}
|
||||
|
||||
getChanges(): Change[] {
|
||||
return this.changesOnAggregateRoot
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { ChangeProps } from './ChangeProps'
|
||||
import { Result } from './Result'
|
||||
|
||||
export class Change {
|
||||
static readonly TYPES = {
|
||||
Add: 'add',
|
||||
Remove: 'remove',
|
||||
Modify: 'modify',
|
||||
}
|
||||
|
||||
public readonly props: ChangeProps
|
||||
|
||||
constructor(props: ChangeProps) {
|
||||
this.props = Object.freeze(props)
|
||||
}
|
||||
|
||||
static create(props: ChangeProps): Result<Change> {
|
||||
if (!Object.values(Change.TYPES).includes(props.changeType)) {
|
||||
return Result.fail('Invalid change type')
|
||||
}
|
||||
|
||||
return Result.ok(new Change(props))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { Entity } from './Entity'
|
||||
|
||||
export interface ChangeProps {
|
||||
aggregateRootUuid: string
|
||||
changeType: string
|
||||
changeData: Entity<unknown>
|
||||
}
|
||||
@@ -23,4 +23,12 @@ export abstract class AbstractEnv {
|
||||
|
||||
return <string>process.env[key]
|
||||
}
|
||||
|
||||
getAll(): { [key: string]: string } {
|
||||
if (!this.env) {
|
||||
this.load()
|
||||
}
|
||||
|
||||
return this.env as { [key: string]: string }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { ValueObject } from '../Core/ValueObject'
|
||||
import { Result } from '../Core/Result'
|
||||
|
||||
import { NotificationPayloadProps } from './NotificationPayloadProps'
|
||||
import { NotificationType } from './NotificationType'
|
||||
import { Uuid } from '../Common/Uuid'
|
||||
|
||||
export class NotificationPayload extends ValueObject<NotificationPayloadProps> {
|
||||
private constructor(props: NotificationPayloadProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
override toString(): string {
|
||||
return JSON.stringify({
|
||||
version: this.props.version,
|
||||
type: this.props.type.value,
|
||||
sharedVaultUuid: this.props.sharedVaultUuid.value,
|
||||
itemUuid: this.props.itemUuid ? this.props.itemUuid.value : undefined,
|
||||
})
|
||||
}
|
||||
|
||||
static createFromString(jsonPayload: string): Result<NotificationPayload> {
|
||||
try {
|
||||
const props = JSON.parse(jsonPayload)
|
||||
|
||||
const typeOrError = NotificationType.create(props.type)
|
||||
if (typeOrError.isFailed()) {
|
||||
return Result.fail<NotificationPayload>(typeOrError.getError())
|
||||
}
|
||||
const type = typeOrError.getValue()
|
||||
|
||||
const sharedVaultUuidOrError = Uuid.create(props.sharedVaultUuid)
|
||||
if (sharedVaultUuidOrError.isFailed()) {
|
||||
return Result.fail<NotificationPayload>(sharedVaultUuidOrError.getError())
|
||||
}
|
||||
const sharedVaultUuid = sharedVaultUuidOrError.getValue()
|
||||
|
||||
let itemUuid: Uuid | undefined = undefined
|
||||
if (props.itemUuid) {
|
||||
const itemUuidOrError = Uuid.create(props.itemUuid)
|
||||
if (itemUuidOrError.isFailed()) {
|
||||
return Result.fail<NotificationPayload>(itemUuidOrError.getError())
|
||||
}
|
||||
itemUuid = itemUuidOrError.getValue()
|
||||
}
|
||||
|
||||
return NotificationPayload.create({
|
||||
version: props.version,
|
||||
type,
|
||||
sharedVaultUuid,
|
||||
itemUuid,
|
||||
})
|
||||
} catch (error) {
|
||||
return Result.fail<NotificationPayload>((error as Error).message)
|
||||
}
|
||||
}
|
||||
|
||||
static create(props: NotificationPayloadProps): Result<NotificationPayload> {
|
||||
if (
|
||||
props.itemUuid === undefined &&
|
||||
props.type.equals(NotificationType.create(NotificationType.TYPES.SharedVaultItemRemoved).getValue())
|
||||
) {
|
||||
return Result.fail<NotificationPayload>(
|
||||
`Item uuid is required for ${NotificationType.TYPES.SharedVaultItemRemoved} notification type`,
|
||||
)
|
||||
}
|
||||
|
||||
return Result.ok<NotificationPayload>(new NotificationPayload(props))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Uuid } from '../Common/Uuid'
|
||||
import { NotificationType } from './NotificationType'
|
||||
|
||||
export interface NotificationPayloadProps {
|
||||
type: NotificationType
|
||||
sharedVaultUuid: Uuid
|
||||
version: string
|
||||
itemUuid?: Uuid
|
||||
}
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
import { ValueObject, Result } from '@standardnotes/domain-core'
|
||||
|
||||
import { Result } from '../Core/Result'
|
||||
import { ValueObject } from '../Core/ValueObject'
|
||||
import { NotificationTypeProps } from './NotificationTypeProps'
|
||||
|
||||
export class NotificationType extends ValueObject<NotificationTypeProps> {
|
||||
@@ -17,9 +17,9 @@ export class NotificationType extends ValueObject<NotificationTypeProps> {
|
||||
}
|
||||
|
||||
static create(notificationType: string): Result<NotificationType> {
|
||||
const isValidPermission = Object.values(this.TYPES).includes(notificationType)
|
||||
if (!isValidPermission) {
|
||||
return Result.fail<NotificationType>(`Invalid shared vault user permission ${notificationType}`)
|
||||
const isValidType = Object.values(this.TYPES).includes(notificationType)
|
||||
if (!isValidType) {
|
||||
return Result.fail<NotificationType>(`Invalid notification type: ${notificationType}`)
|
||||
} else {
|
||||
return Result.ok<NotificationType>(new NotificationType({ value: notificationType }))
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { Result, ValueObject } from '@standardnotes/domain-core'
|
||||
import { Result } from '../Core/Result'
|
||||
import { ValueObject } from '../Core/ValueObject'
|
||||
|
||||
import { SharedVaultUserPermissionProps } from './SharedVaultUserPermissionProps'
|
||||
|
||||
@@ -27,6 +27,8 @@ export * from './Common/Uuid'
|
||||
export * from './Common/UuidProps'
|
||||
|
||||
export * from './Core/Aggregate'
|
||||
export * from './Core/Change'
|
||||
export * from './Core/ChangeProps'
|
||||
export * from './Core/Entity'
|
||||
export * from './Core/Id'
|
||||
export * from './Core/Result'
|
||||
@@ -45,6 +47,11 @@ export * from './Env/AbstractEnv'
|
||||
|
||||
export * from './Mapping/MapperInterface'
|
||||
|
||||
export * from './Notification/NotificationPayload'
|
||||
export * from './Notification/NotificationPayloadProps'
|
||||
export * from './Notification/NotificationType'
|
||||
export * from './Notification/NotificationTypeProps'
|
||||
|
||||
export * from './Service/ServiceConfiguration'
|
||||
export * from './Service/ServiceContainer'
|
||||
export * from './Service/ServiceContainerInterface'
|
||||
@@ -52,6 +59,9 @@ export * from './Service/ServiceIdentifier'
|
||||
export * from './Service/ServiceIdentifierProps'
|
||||
export * from './Service/ServiceInterface'
|
||||
|
||||
export * from './SharedVault/SharedVaultUserPermission'
|
||||
export * from './SharedVault/SharedVaultUserPermissionProps'
|
||||
|
||||
export * from './Subscription/SubscriptionPlanName'
|
||||
export * from './Subscription/SubscriptionPlanNameProps'
|
||||
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.11.13](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.11.12...@standardnotes/event-store@1.11.13) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/event-store
|
||||
|
||||
## [1.11.12](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.11.11...@standardnotes/event-store@1.11.12) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/event-store
|
||||
|
||||
## [1.11.11](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.11.10...@standardnotes/event-store@1.11.11) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/event-store
|
||||
|
||||
## [1.11.10](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.11.9...@standardnotes/event-store@1.11.10) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/event-store
|
||||
|
||||
## [1.11.9](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.11.8...@standardnotes/event-store@1.11.9) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/event-store
|
||||
|
||||
## [1.11.8](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.11.7...@standardnotes/event-store@1.11.8) (2023-07-19)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/event-store
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/event-store",
|
||||
"version": "1.11.8",
|
||||
"version": "1.11.13",
|
||||
"description": "Event Store Service",
|
||||
"private": true,
|
||||
"main": "dist/src/index.js",
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.19.15](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.19.14...@standardnotes/files-server@1.19.15) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files-server
|
||||
|
||||
## [1.19.14](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.19.13...@standardnotes/files-server@1.19.14) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files-server
|
||||
|
||||
## [1.19.13](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.19.12...@standardnotes/files-server@1.19.13) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files-server
|
||||
|
||||
## [1.19.12](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.19.11...@standardnotes/files-server@1.19.12) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files-server
|
||||
|
||||
## [1.19.11](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.19.10...@standardnotes/files-server@1.19.11) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files-server
|
||||
|
||||
## [1.19.10](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.19.9...@standardnotes/files-server@1.19.10) (2023-07-19)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files-server
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/files-server",
|
||||
"version": "1.19.10",
|
||||
"version": "1.19.15",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,61 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.13.16](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.15...@standardnotes/home-server@1.13.16) (2023-07-27)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add logging error stack on home server failure ([f747111](https://github.com/standardnotes/server/commit/f7471119e1c4107dd36d37dcda4660870931fc83))
|
||||
* setting env vars on home server in e2e environment ([f87036e](https://github.com/standardnotes/server/commit/f87036e3a8dc6b7784e74e5f32ffd220033724f5))
|
||||
|
||||
## [1.13.15](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.14...@standardnotes/home-server@1.13.15) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.14](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.13...@standardnotes/home-server@1.13.14) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.13](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.12...@standardnotes/home-server@1.13.13) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.12](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.11...@standardnotes/home-server@1.13.12) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.11](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.10...@standardnotes/home-server@1.13.11) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.10](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.9...@standardnotes/home-server@1.13.10) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.9](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.8...@standardnotes/home-server@1.13.9) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.8](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.7...@standardnotes/home-server@1.13.8) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.7](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.6...@standardnotes/home-server@1.13.7) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.6](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.5...@standardnotes/home-server@1.13.6) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.5](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.4...@standardnotes/home-server@1.13.5) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.4](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.3...@standardnotes/home-server@1.13.4) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
## [1.13.3](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.13.2...@standardnotes/home-server@1.13.3) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/home-server
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
import { Env } from '../src/Bootstrap/Env'
|
||||
import { HomeServer } from '../src/Server/HomeServer'
|
||||
|
||||
const homeServer = new HomeServer()
|
||||
|
||||
Promise.resolve(
|
||||
homeServer.start({
|
||||
dataDirectoryPath: `${__dirname}/../data`,
|
||||
logStreamCallback: (chunk: Buffer) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(chunk.toString())
|
||||
},
|
||||
}),
|
||||
).catch((error) => {
|
||||
const env: Env = new Env()
|
||||
env.load()
|
||||
|
||||
try {
|
||||
Promise.resolve(
|
||||
homeServer.start({
|
||||
dataDirectoryPath: `${__dirname}/../data`,
|
||||
logStreamCallback: (chunk: Buffer) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(chunk.toString())
|
||||
},
|
||||
environment: env.getAll(),
|
||||
}),
|
||||
).catch((error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`Could not start server: ${error.message}`)
|
||||
})
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Could not start server: ${error.message}`)
|
||||
})
|
||||
console.error((error as Error).stack)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/home-server",
|
||||
"version": "1.13.3",
|
||||
"version": "1.13.16",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.25.6](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.25.5...@standardnotes/revisions-server@1.25.6) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/revisions-server
|
||||
|
||||
## [1.25.5](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.25.4...@standardnotes/revisions-server@1.25.5) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/revisions-server
|
||||
|
||||
## [1.25.4](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.25.3...@standardnotes/revisions-server@1.25.4) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/revisions-server
|
||||
|
||||
## [1.25.3](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.25.2...@standardnotes/revisions-server@1.25.3) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/revisions-server
|
||||
|
||||
## [1.25.2](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.25.1...@standardnotes/revisions-server@1.25.2) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/revisions-server
|
||||
|
||||
## [1.25.1](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.25.0...@standardnotes/revisions-server@1.25.1) (2023-07-19)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/revisions-server
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/revisions-server",
|
||||
"version": "1.25.1",
|
||||
"version": "1.25.6",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.20.15](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.20.14...@standardnotes/scheduler-server@1.20.15) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/scheduler-server
|
||||
|
||||
## [1.20.14](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.20.13...@standardnotes/scheduler-server@1.20.14) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/scheduler-server
|
||||
|
||||
## [1.20.13](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.20.12...@standardnotes/scheduler-server@1.20.13) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/scheduler-server
|
||||
|
||||
## [1.20.12](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.20.11...@standardnotes/scheduler-server@1.20.12) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/scheduler-server
|
||||
|
||||
## [1.20.11](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.20.10...@standardnotes/scheduler-server@1.20.11) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/scheduler-server
|
||||
|
||||
## [1.20.10](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.20.9...@standardnotes/scheduler-server@1.20.10) (2023-07-19)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/scheduler-server
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/scheduler-server",
|
||||
"version": "1.20.10",
|
||||
"version": "1.20.15",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.21.20](https://github.com/standardnotes/server/compare/@standardnotes/settings@1.21.19...@standardnotes/settings@1.21.20) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/settings
|
||||
|
||||
## [1.21.19](https://github.com/standardnotes/server/compare/@standardnotes/settings@1.21.18...@standardnotes/settings@1.21.19) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/settings
|
||||
|
||||
## [1.21.18](https://github.com/standardnotes/server/compare/@standardnotes/settings@1.21.17...@standardnotes/settings@1.21.18) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/settings
|
||||
|
||||
## [1.21.17](https://github.com/standardnotes/server/compare/@standardnotes/settings@1.21.16...@standardnotes/settings@1.21.17) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/settings
|
||||
|
||||
## [1.21.16](https://github.com/standardnotes/server/compare/@standardnotes/settings@1.21.15...@standardnotes/settings@1.21.16) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/settings
|
||||
|
||||
## [1.21.15](https://github.com/standardnotes/server/compare/@standardnotes/settings@1.21.14...@standardnotes/settings@1.21.15) (2023-07-19)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/settings
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/settings",
|
||||
"version": "1.21.15",
|
||||
"version": "1.21.20",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,80 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.72.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.72.0...@standardnotes/syncing-server@1.72.1) (2023-07-27)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/syncing-server
|
||||
|
||||
# [1.72.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.71.0...@standardnotes/syncing-server@1.72.0) (2023-07-27)
|
||||
|
||||
### Features
|
||||
|
||||
* **syncing-server:** add deleting outbound messages ([e8ba49e](https://github.com/standardnotes/syncing-server-js/commit/e8ba49ecca38ab10c0ea0e1f4cf4db9fb17366db))
|
||||
|
||||
# [1.71.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.70.5...@standardnotes/syncing-server@1.71.0) (2023-07-26)
|
||||
|
||||
### Features
|
||||
|
||||
* extract shared vault user permission to domain-core ([e215ac4](https://github.com/standardnotes/syncing-server-js/commit/e215ac4343e9f8818f40004d31390d6ac23e369d))
|
||||
|
||||
## [1.70.5](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.70.4...@standardnotes/syncing-server@1.70.5) (2023-07-26)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-server:** uuid comparison when removing user ([886ccf8](https://github.com/standardnotes/syncing-server-js/commit/886ccf84c1f3b9309ce7d01354ca815af1424b72))
|
||||
|
||||
## [1.70.4](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.70.3...@standardnotes/syncing-server@1.70.4) (2023-07-26)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-serve:** removing other users from shared vault ([6b2389c](https://github.com/standardnotes/syncing-server-js/commit/6b2389cdc3da6d522f9ce0ba3ddff3ef1e99674f))
|
||||
|
||||
## [1.70.3](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.70.2...@standardnotes/syncing-server@1.70.3) (2023-07-26)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-server:** persisting aggregate changes from root ([#674](https://github.com/standardnotes/syncing-server-js/issues/674)) ([c34f548](https://github.com/standardnotes/syncing-server-js/commit/c34f548e45bbd8defb8d490936e90755fd284e78))
|
||||
|
||||
## [1.70.2](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.70.1...@standardnotes/syncing-server@1.70.2) (2023-07-25)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-server:** remove notifications after adding item to vault ([#672](https://github.com/standardnotes/syncing-server-js/issues/672)) ([8f88a87](https://github.com/standardnotes/syncing-server-js/commit/8f88a87c93e21f52a029167f2408ff061e2a4e93))
|
||||
|
||||
## [1.70.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.70.0...@standardnotes/syncing-server@1.70.1) (2023-07-25)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-server:** allow sender to decline the invite ([#671](https://github.com/standardnotes/syncing-server-js/issues/671)) ([46c4947](https://github.com/standardnotes/syncing-server-js/commit/46c4947871f342f0a07c68562b0e3e77e7e114d4))
|
||||
|
||||
# [1.70.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.69.0...@standardnotes/syncing-server@1.70.0) (2023-07-25)
|
||||
|
||||
### Features
|
||||
|
||||
* **syncing-server:** filtering items by shared vault permissions ([#670](https://github.com/standardnotes/syncing-server-js/issues/670)) ([5f7e768](https://github.com/standardnotes/syncing-server-js/commit/5f7e768e64da0452e6efcf70e36cb5e867291456))
|
||||
|
||||
# [1.69.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.68.4...@standardnotes/syncing-server@1.69.0) (2023-07-24)
|
||||
|
||||
### Features
|
||||
|
||||
* **syncing-server:** determin shared vault operation type ([#669](https://github.com/standardnotes/syncing-server-js/issues/669)) ([71721ab](https://github.com/standardnotes/syncing-server-js/commit/71721ab1982b65feb4c84b44b267a249b573c537))
|
||||
|
||||
## [1.68.4](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.68.3...@standardnotes/syncing-server@1.68.4) (2023-07-24)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **syncing-server:** force remove shared vault owner when removing shared vault ([f77e29d](https://github.com/standardnotes/syncing-server-js/commit/f77e29d3c9c9a28be3c5624d2c9bf0ffd6348377))
|
||||
|
||||
## [1.68.3](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.68.2...@standardnotes/syncing-server@1.68.3) (2023-07-21)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/syncing-server
|
||||
|
||||
## [1.68.2](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.68.1...@standardnotes/syncing-server@1.68.2) (2023-07-21)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* user notifications structure ([#667](https://github.com/standardnotes/syncing-server-js/issues/667)) ([1bbb639](https://github.com/standardnotes/syncing-server-js/commit/1bbb639c83922ec09e3778f85419d76669d36ae3))
|
||||
|
||||
## [1.68.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.68.0...@standardnotes/syncing-server@1.68.1) (2023-07-21)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/syncing-server",
|
||||
"version": "1.68.1",
|
||||
"version": "1.72.1",
|
||||
"engines": {
|
||||
"node": ">=18.0.0 <21.0.0"
|
||||
},
|
||||
|
||||
@@ -150,6 +150,9 @@ import { MessageHttpMapper } from '../Mapping/Http/MessageHttpMapper'
|
||||
import { GetUserNotifications } from '../Domain/UseCase/Messaging/GetUserNotifications/GetUserNotifications'
|
||||
import { NotificationHttpMapper } from '../Mapping/Http/NotificationHttpMapper'
|
||||
import { NotificationHttpRepresentation } from '../Mapping/Http/NotificationHttpRepresentation'
|
||||
import { DetermineSharedVaultOperationOnItem } from '../Domain/UseCase/SharedVaults/DetermineSharedVaultOperationOnItem/DetermineSharedVaultOperationOnItem'
|
||||
import { SharedVaultFilter } from '../Domain/Item/SaveRule/SharedVaultFilter'
|
||||
import { RemoveNotificationsForUser } from '../Domain/UseCase/Messaging/RemoveNotificationsForUser/RemoveNotificationsForUser'
|
||||
|
||||
export class ContainerConfigLoader {
|
||||
private readonly DEFAULT_CONTENT_SIZE_TRANSFER_LIMIT = 10_000_000
|
||||
@@ -494,12 +497,24 @@ export class ContainerConfigLoader {
|
||||
.bind<TokenEncoderInterface<SharedVaultValetTokenData>>(TYPES.Sync_SharedVaultValetTokenEncoder)
|
||||
.toConstantValue(new TokenEncoder<SharedVaultValetTokenData>(container.get(TYPES.Sync_VALET_TOKEN_SECRET)))
|
||||
|
||||
container
|
||||
.bind<DetermineSharedVaultOperationOnItem>(TYPES.Sync_DetermineSharedVaultOperationOnItem)
|
||||
.toConstantValue(new DetermineSharedVaultOperationOnItem())
|
||||
|
||||
container.bind<OwnershipFilter>(TYPES.Sync_OwnershipFilter).toConstantValue(new OwnershipFilter())
|
||||
container
|
||||
.bind<TimeDifferenceFilter>(TYPES.Sync_TimeDifferenceFilter)
|
||||
.toConstantValue(new TimeDifferenceFilter(container.get(TYPES.Sync_Timer)))
|
||||
container.bind<ContentTypeFilter>(TYPES.Sync_ContentTypeFilter).toConstantValue(new ContentTypeFilter())
|
||||
container.bind<ContentFilter>(TYPES.Sync_ContentFilter).toConstantValue(new ContentFilter())
|
||||
container
|
||||
.bind<SharedVaultFilter>(TYPES.Sync_SharedVaultFilter)
|
||||
.toConstantValue(
|
||||
new SharedVaultFilter(
|
||||
container.get(TYPES.Sync_DetermineSharedVaultOperationOnItem),
|
||||
container.get(TYPES.Sync_SharedVaultUserRepository),
|
||||
),
|
||||
)
|
||||
container
|
||||
.bind<ItemSaveValidatorInterface>(TYPES.Sync_ItemSaveValidator)
|
||||
.toConstantValue(
|
||||
@@ -508,6 +523,7 @@ export class ContainerConfigLoader {
|
||||
container.get(TYPES.Sync_TimeDifferenceFilter),
|
||||
container.get(TYPES.Sync_ContentTypeFilter),
|
||||
container.get(TYPES.Sync_ContentFilter),
|
||||
container.get(TYPES.Sync_SharedVaultFilter),
|
||||
]),
|
||||
)
|
||||
|
||||
@@ -534,6 +550,14 @@ export class ContainerConfigLoader {
|
||||
container.get(TYPES.Sync_DomainEventFactory),
|
||||
),
|
||||
)
|
||||
container
|
||||
.bind<AddNotificationForUser>(TYPES.Sync_AddNotificationForUser)
|
||||
.toConstantValue(
|
||||
new AddNotificationForUser(container.get(TYPES.Sync_NotificationRepository), container.get(TYPES.Sync_Timer)),
|
||||
)
|
||||
container
|
||||
.bind<RemoveNotificationsForUser>(TYPES.Sync_RemoveNotificationsForUser)
|
||||
.toConstantValue(new RemoveNotificationsForUser(container.get(TYPES.Sync_NotificationRepository)))
|
||||
container
|
||||
.bind<UpdateExistingItem>(TYPES.Sync_UpdateExistingItem)
|
||||
.toConstantValue(
|
||||
@@ -543,6 +567,9 @@ export class ContainerConfigLoader {
|
||||
container.get(TYPES.Sync_DomainEventPublisher),
|
||||
container.get(TYPES.Sync_DomainEventFactory),
|
||||
container.get(TYPES.Sync_REVISIONS_FREQUENCY),
|
||||
container.get(TYPES.Sync_DetermineSharedVaultOperationOnItem),
|
||||
container.get(TYPES.Sync_AddNotificationForUser),
|
||||
container.get(TYPES.Sync_RemoveNotificationsForUser),
|
||||
),
|
||||
)
|
||||
container
|
||||
@@ -658,11 +685,6 @@ export class ContainerConfigLoader {
|
||||
container.get(TYPES.Sync_SharedVaultRepository),
|
||||
),
|
||||
)
|
||||
container
|
||||
.bind<AddNotificationForUser>(TYPES.Sync_AddNotificationForUser)
|
||||
.toConstantValue(
|
||||
new AddNotificationForUser(container.get(TYPES.Sync_NotificationRepository), container.get(TYPES.Sync_Timer)),
|
||||
)
|
||||
container
|
||||
.bind<RemoveUserFromSharedVault>(TYPES.Sync_RemoveSharedVaultUser)
|
||||
.toConstantValue(
|
||||
|
||||
@@ -57,6 +57,7 @@ const TYPES = {
|
||||
Sync_GetSharedVaultUsers: Symbol.for('Sync_GetSharedVaultUsers'),
|
||||
Sync_AddUserToSharedVault: Symbol.for('Sync_AddUserToSharedVault'),
|
||||
Sync_AddNotificationForUser: Symbol.for('Sync_AddNotificationForUser'),
|
||||
Sync_RemoveNotificationsForUser: Symbol.for('Sync_RemoveNotificationsForUser'),
|
||||
Sync_RemoveSharedVaultUser: Symbol.for('Sync_RemoveSharedVaultUser'),
|
||||
Sync_InviteUserToSharedVault: Symbol.for('Sync_InviteUserToSharedVault'),
|
||||
Sync_UpdateSharedVaultInvite: Symbol.for('Sync_UpdateSharedVaultInvite'),
|
||||
@@ -76,6 +77,7 @@ const TYPES = {
|
||||
Sync_GetItems: Symbol.for('Sync_GetItems'),
|
||||
Sync_SaveItems: Symbol.for('Sync_SaveItems'),
|
||||
Sync_GetUserNotifications: Symbol.for('Sync_GetUserNotifications'),
|
||||
Sync_DetermineSharedVaultOperationOnItem: Symbol.for('Sync_DetermineSharedVaultOperationOnItem'),
|
||||
// Handlers
|
||||
Sync_AccountDeletionRequestedEventHandler: Symbol.for('Sync_AccountDeletionRequestedEventHandler'),
|
||||
Sync_DuplicateItemSyncedEventHandler: Symbol.for('Sync_DuplicateItemSyncedEventHandler'),
|
||||
@@ -98,6 +100,7 @@ const TYPES = {
|
||||
Sync_ItemBackupService: Symbol.for('Sync_ItemBackupService'),
|
||||
Sync_ItemSaveValidator: Symbol.for('Sync_ItemSaveValidator'),
|
||||
Sync_OwnershipFilter: Symbol.for('Sync_OwnershipFilter'),
|
||||
Sync_SharedVaultFilter: Symbol.for('Sync_SharedVaultFilter'),
|
||||
Sync_TimeDifferenceFilter: Symbol.for('Sync_TimeDifferenceFilter'),
|
||||
Sync_ContentTypeFilter: Symbol.for('Sync_ContentTypeFilter'),
|
||||
Sync_ContentFilter: Symbol.for('Sync_ContentFilter'),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ContentType, Dates, Timestamps, UniqueEntityId, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { Item } from './Item'
|
||||
import { SharedVaultAssociation } from '../SharedVault/SharedVaultAssociation'
|
||||
import { KeySystemAssociation } from '../KeySystem/KeySystemAssociation'
|
||||
|
||||
describe('Item', () => {
|
||||
it('should create an aggregate', () => {
|
||||
@@ -44,4 +46,207 @@ describe('Item', () => {
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(() => entityOrError.getValue().uuid).toThrow()
|
||||
})
|
||||
|
||||
it('should tell if an item is associated with a shared vault', () => {
|
||||
const entityOrError = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(
|
||||
entityOrError
|
||||
.getValue()
|
||||
.isAssociatedWithSharedVault(Uuid.create('00000000-0000-0000-0000-000000000000').getValue()),
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should tell that an item is not associated with a shared vault', () => {
|
||||
const entityOrError = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
})
|
||||
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(
|
||||
entityOrError
|
||||
.getValue()
|
||||
.isAssociatedWithSharedVault(Uuid.create('00000000-0000-0000-0000-000000000000').getValue()),
|
||||
).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should tell if an item is associated with a key system', () => {
|
||||
const entityOrError = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
keySystemAssociation: KeySystemAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
keySystemIdentifier: 'key-system-identifier',
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(entityOrError.getValue().isAssociatedWithKeySystem('key-system-identifier')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should tell that an item is not associated with a key system', () => {
|
||||
const entityOrError = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
})
|
||||
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(entityOrError.getValue().isAssociatedWithKeySystem('key-system-identifier')).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should set shared vault association', () => {
|
||||
const sharedVaultAssociation = SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
const entity = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
entity.setSharedVaultAssociation(sharedVaultAssociation)
|
||||
|
||||
expect(entity.props.sharedVaultAssociation).toEqual(sharedVaultAssociation)
|
||||
expect(entity.getChanges()).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should unset a shared vault association', () => {
|
||||
const entity = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
}).getValue()
|
||||
|
||||
entity.unsetSharedVaultAssociation()
|
||||
|
||||
expect(entity.props.sharedVaultAssociation).toBeUndefined()
|
||||
expect(entity.getChanges()).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should set key system association', () => {
|
||||
const keySystemAssociation = KeySystemAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
keySystemIdentifier: 'key-system-identifier',
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
const entity = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
entity.setKeySystemAssociation(keySystemAssociation)
|
||||
|
||||
expect(entity.props.keySystemAssociation).toEqual(keySystemAssociation)
|
||||
expect(entity.getChanges()).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should unset a key system association', () => {
|
||||
const entity = Item.create({
|
||||
duplicateOf: null,
|
||||
itemsKeyId: 'items-key-id',
|
||||
content: 'content',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: 'enc-item-key',
|
||||
authHash: 'auth-hash',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
deleted: false,
|
||||
updatedWithSession: null,
|
||||
dates: Dates.create(new Date(123), new Date(123)).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
keySystemAssociation: KeySystemAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
keySystemIdentifier: 'key-system-identifier',
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
}).getValue()
|
||||
|
||||
entity.unsetKeySystemAssociation()
|
||||
|
||||
expect(entity.props.keySystemAssociation).toBeUndefined()
|
||||
expect(entity.getChanges()).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import { Aggregate, Result, UniqueEntityId, Uuid } from '@standardnotes/domain-core'
|
||||
import { Aggregate, Change, Result, UniqueEntityId, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { ItemProps } from './ItemProps'
|
||||
import { SharedVaultAssociation } from '../SharedVault/SharedVaultAssociation'
|
||||
import { KeySystemAssociation } from '../KeySystem/KeySystemAssociation'
|
||||
|
||||
export class Item extends Aggregate<ItemProps> {
|
||||
get uuid(): Uuid {
|
||||
const uuidOrError = Uuid.create(this._id.toString())
|
||||
if (uuidOrError.isFailed()) {
|
||||
throw new Error(uuidOrError.getError())
|
||||
}
|
||||
|
||||
return uuidOrError.getValue()
|
||||
}
|
||||
|
||||
private constructor(props: ItemProps, id?: UniqueEntityId) {
|
||||
super(props, id)
|
||||
}
|
||||
@@ -24,4 +17,95 @@ export class Item extends Aggregate<ItemProps> {
|
||||
|
||||
return Result.ok<Item>(new Item(props, id))
|
||||
}
|
||||
|
||||
get uuid(): Uuid {
|
||||
const uuidOrError = Uuid.create(this._id.toString())
|
||||
if (uuidOrError.isFailed()) {
|
||||
throw new Error(uuidOrError.getError())
|
||||
}
|
||||
|
||||
return uuidOrError.getValue()
|
||||
}
|
||||
|
||||
get sharedVaultUuid(): Uuid | null {
|
||||
if (!this.props.sharedVaultAssociation) {
|
||||
return null
|
||||
}
|
||||
|
||||
return this.props.sharedVaultAssociation.props.sharedVaultUuid
|
||||
}
|
||||
|
||||
isAssociatedWithASharedVault(): boolean {
|
||||
return this.sharedVaultUuid !== null
|
||||
}
|
||||
|
||||
isAssociatedWithSharedVault(sharedVaultUuid: Uuid): boolean {
|
||||
if (!this.isAssociatedWithASharedVault()) {
|
||||
return false
|
||||
}
|
||||
|
||||
return (this.sharedVaultUuid as Uuid).equals(sharedVaultUuid)
|
||||
}
|
||||
|
||||
isAssociatedWithKeySystem(keySystemIdentifier: string): boolean {
|
||||
if (!this.props.keySystemAssociation) {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.props.keySystemAssociation.props.keySystemIdentifier === keySystemIdentifier
|
||||
}
|
||||
|
||||
setSharedVaultAssociation(sharedVaultAssociation: SharedVaultAssociation): void {
|
||||
this.addChange(
|
||||
Change.create({
|
||||
aggregateRootUuid: this.uuid.value,
|
||||
changeType: this.props.sharedVaultAssociation ? Change.TYPES.Modify : Change.TYPES.Add,
|
||||
changeData: sharedVaultAssociation,
|
||||
}).getValue(),
|
||||
)
|
||||
|
||||
this.props.sharedVaultAssociation = sharedVaultAssociation
|
||||
}
|
||||
|
||||
unsetSharedVaultAssociation(): void {
|
||||
if (!this.props.sharedVaultAssociation) {
|
||||
return
|
||||
}
|
||||
|
||||
this.addChange(
|
||||
Change.create({
|
||||
aggregateRootUuid: this.uuid.value,
|
||||
changeType: Change.TYPES.Remove,
|
||||
changeData: this.props.sharedVaultAssociation,
|
||||
}).getValue(),
|
||||
)
|
||||
this.props.sharedVaultAssociation = undefined
|
||||
}
|
||||
|
||||
setKeySystemAssociation(keySystemAssociation: KeySystemAssociation): void {
|
||||
this.addChange(
|
||||
Change.create({
|
||||
aggregateRootUuid: this.uuid.value,
|
||||
changeType: this.props.keySystemAssociation ? Change.TYPES.Modify : Change.TYPES.Add,
|
||||
changeData: keySystemAssociation,
|
||||
}).getValue(),
|
||||
)
|
||||
|
||||
this.props.keySystemAssociation = keySystemAssociation
|
||||
}
|
||||
|
||||
unsetKeySystemAssociation(): void {
|
||||
if (!this.props.keySystemAssociation) {
|
||||
return
|
||||
}
|
||||
|
||||
this.addChange(
|
||||
Change.create({
|
||||
aggregateRootUuid: this.uuid.value,
|
||||
changeType: Change.TYPES.Remove,
|
||||
changeData: this.props.keySystemAssociation,
|
||||
}).getValue(),
|
||||
)
|
||||
this.props.keySystemAssociation = undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
import { ItemHash } from './ItemHash'
|
||||
|
||||
describe('ItemHash', () => {
|
||||
it('should create a value object', () => {
|
||||
const valueOrError = ItemHash.create({
|
||||
uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: null,
|
||||
})
|
||||
|
||||
expect(valueOrError.isFailed()).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should return error if shared vault uuid is not valid', () => {
|
||||
const valueOrError = ItemHash.create({
|
||||
uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: 'invalid',
|
||||
})
|
||||
|
||||
expect(valueOrError.isFailed()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Result, ValueObject } from '@standardnotes/domain-core'
|
||||
import { Result, Uuid, ValueObject } from '@standardnotes/domain-core'
|
||||
|
||||
import { ItemHashProps } from './ItemHashProps'
|
||||
|
||||
@@ -8,6 +8,13 @@ export class ItemHash extends ValueObject<ItemHashProps> {
|
||||
}
|
||||
|
||||
static create(props: ItemHashProps): Result<ItemHash> {
|
||||
if (props.shared_vault_uuid) {
|
||||
const sharedVaultUuidOrError = Uuid.create(props.shared_vault_uuid)
|
||||
if (sharedVaultUuidOrError.isFailed()) {
|
||||
return Result.fail<ItemHash>(sharedVaultUuidOrError.getError())
|
||||
}
|
||||
}
|
||||
|
||||
return Result.ok<ItemHash>(new ItemHash(props))
|
||||
}
|
||||
|
||||
@@ -15,6 +22,14 @@ export class ItemHash extends ValueObject<ItemHashProps> {
|
||||
return this.props.shared_vault_uuid !== null
|
||||
}
|
||||
|
||||
get sharedVaultUuid(): Uuid | null {
|
||||
if (!this.representsASharedVaultItem()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return Uuid.create(this.props.shared_vault_uuid as string).getValue()
|
||||
}
|
||||
|
||||
hasDedicatedKeySystemAssociation(): boolean {
|
||||
return this.props.key_system_identifier !== null
|
||||
}
|
||||
|
||||
@@ -59,6 +59,31 @@ describe('OwnershipFilter', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should deffer to the shared vault filter if the item hash represents a shared vault item or existing item is a shared vault item', async () => {
|
||||
const itemHash = ItemHash.create({
|
||||
uuid: '2-3-4',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
}).getValue()
|
||||
const result = await createFilter().check({
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
apiVersion: ApiVersion.v20200115,
|
||||
itemHash,
|
||||
existingItem,
|
||||
})
|
||||
|
||||
expect(result).toEqual({
|
||||
passed: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should leave items belonging to the same user', async () => {
|
||||
const result = await createFilter().check({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
|
||||
@@ -6,6 +6,14 @@ import { Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export class OwnershipFilter implements ItemSaveRuleInterface {
|
||||
async check(dto: ItemSaveValidationDTO): Promise<ItemSaveRuleResult> {
|
||||
const deferToSharedVaultFilter =
|
||||
dto.existingItem?.isAssociatedWithASharedVault() || dto.itemHash.representsASharedVaultItem()
|
||||
if (deferToSharedVaultFilter) {
|
||||
return {
|
||||
passed: true,
|
||||
}
|
||||
}
|
||||
|
||||
const userUuidOrError = Uuid.create(dto.userUuid)
|
||||
if (userUuidOrError.isFailed()) {
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,819 @@
|
||||
import {
|
||||
ContentType,
|
||||
Dates,
|
||||
Result,
|
||||
SharedVaultUserPermission,
|
||||
Timestamps,
|
||||
UniqueEntityId,
|
||||
Uuid,
|
||||
} from '@standardnotes/domain-core'
|
||||
import { SharedVaultUser } from '../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { DetermineSharedVaultOperationOnItem } from '../../UseCase/SharedVaults/DetermineSharedVaultOperationOnItem/DetermineSharedVaultOperationOnItem'
|
||||
import { SharedVaultFilter } from './SharedVaultFilter'
|
||||
import { ItemHash } from '../ItemHash'
|
||||
import { Item } from '../Item'
|
||||
import { SharedVaultOperationOnItem } from '../../SharedVault/SharedVaultOperationOnItem'
|
||||
import { SharedVaultAssociation } from '../../SharedVault/SharedVaultAssociation'
|
||||
|
||||
describe('SharedVaultFilter', () => {
|
||||
let determineSharedVaultOperationOnItem: DetermineSharedVaultOperationOnItem
|
||||
let sharedVaultUserRepository: SharedVaultUserRepositoryInterface
|
||||
let sharedVaultUser: SharedVaultUser
|
||||
let itemHash: ItemHash
|
||||
let existingItem: Item
|
||||
|
||||
const createFilter = () => new SharedVaultFilter(determineSharedVaultOperationOnItem, sharedVaultUserRepository)
|
||||
|
||||
beforeEach(() => {
|
||||
existingItem = Item.create(
|
||||
{
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
updatedWithSession: null,
|
||||
content: 'foobar',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: null,
|
||||
authHash: null,
|
||||
itemsKeyId: null,
|
||||
duplicateOf: null,
|
||||
deleted: false,
|
||||
dates: Dates.create(new Date(1616164633241311), new Date(1616164633241311)).getValue(),
|
||||
timestamps: Timestamps.create(1616164633241311, 1616164633241311).getValue(),
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
},
|
||||
new UniqueEntityId('00000000-0000-0000-0000-000000000000'),
|
||||
).getValue()
|
||||
|
||||
itemHash = ItemHash.create({
|
||||
uuid: '2-3-4',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: 'key-system-identifier',
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
}).getValue()
|
||||
|
||||
sharedVaultUser = SharedVaultUser.create({
|
||||
permission: SharedVaultUserPermission.create(SharedVaultUserPermission.PERMISSIONS.Write).getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem = {} as jest.Mocked<DetermineSharedVaultOperationOnItem>
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn()
|
||||
|
||||
sharedVaultUserRepository = {} as jest.Mocked<SharedVaultUserRepositoryInterface>
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(sharedVaultUser)
|
||||
.mockResolvedValueOnce(null)
|
||||
})
|
||||
|
||||
it('should return as passed if the item hash does not represent a shared vault item and existing item is not a shared vault item', async () => {
|
||||
itemHash = ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: null,
|
||||
}).getValue()
|
||||
existingItem = Item.create({
|
||||
...existingItem.props,
|
||||
sharedVaultAssociation: undefined,
|
||||
}).getValue()
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(true)
|
||||
})
|
||||
|
||||
it('should return as not passed if the operation could not be determined', async () => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(Result.fail('error'))
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the item is a shared vault item without a dedicated key system association', async () => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
itemHash = ItemHash.create({
|
||||
uuid: '2-3-4',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
}).getValue()
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
describe('when the shared vault operation on item is: move to other shared vault', () => {
|
||||
beforeEach(() => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000001').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(sharedVaultUser)
|
||||
.mockResolvedValueOnce(sharedVaultUser)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the target shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest
|
||||
.fn()
|
||||
.mockResolvedValue(sharedVaultUser)
|
||||
.mockResolvedValue(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as passed if the user is a member of both shared vaults', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(true)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the target shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce(sharedVaultUser)
|
||||
.mockReturnValueOnce(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the item is deleted', async () => {
|
||||
existingItem = Item.create(
|
||||
{
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
updatedWithSession: null,
|
||||
content: 'foobar',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: null,
|
||||
authHash: null,
|
||||
itemsKeyId: null,
|
||||
duplicateOf: null,
|
||||
deleted: true,
|
||||
dates: Dates.create(new Date(1616164633241311), new Date(1616164633241311)).getValue(),
|
||||
timestamps: Timestamps.create(1616164633241311, 1616164633241311).getValue(),
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
},
|
||||
new UniqueEntityId('00000000-0000-0000-0000-000000000000'),
|
||||
).getValue()
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000001').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the item is being deleted', async () => {
|
||||
itemHash = ItemHash.create({
|
||||
uuid: '2-3-4',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
deleted: true,
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000001').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user has insufficient permissions to write key system items key', async () => {
|
||||
sharedVaultUser = SharedVaultUser.create({
|
||||
permission: SharedVaultUserPermission.create(SharedVaultUserPermission.PERMISSIONS.Read).getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
itemHash = ItemHash.create({
|
||||
...itemHash.props,
|
||||
content_type: ContentType.TYPES.KeySystemItemsKey,
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000001').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the shared vault operation on item is: add to shared vault', () => {
|
||||
beforeEach(() => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as passed if the user is a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(true)
|
||||
})
|
||||
|
||||
it('should return as not passed if the item is deleted', async () => {
|
||||
existingItem = Item.create(
|
||||
{
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
updatedWithSession: null,
|
||||
content: 'foobar',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: null,
|
||||
authHash: null,
|
||||
itemsKeyId: null,
|
||||
duplicateOf: null,
|
||||
deleted: true,
|
||||
dates: Dates.create(new Date(1616164633241311), new Date(1616164633241311)).getValue(),
|
||||
timestamps: Timestamps.create(1616164633241311, 1616164633241311).getValue(),
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
},
|
||||
new UniqueEntityId('00000000-0000-0000-0000-000000000000'),
|
||||
).getValue()
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not the owner of the item', async () => {
|
||||
existingItem = Item.create({
|
||||
...existingItem.props,
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000001').getValue(),
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000002').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user has insufficient permissions to write key system items key', async () => {
|
||||
sharedVaultUser = SharedVaultUser.create({
|
||||
permission: SharedVaultUserPermission.create(SharedVaultUserPermission.PERMISSIONS.Read).getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
itemHash = ItemHash.create({
|
||||
...itemHash.props,
|
||||
content_type: ContentType.TYPES.KeySystemItemsKey,
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the shared vault operation on item is: remove from shared vault', () => {
|
||||
beforeEach(() => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as passed if the user is a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(true)
|
||||
})
|
||||
|
||||
it('should return as not passed if the item is deleted', async () => {
|
||||
existingItem = Item.create(
|
||||
{
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
updatedWithSession: null,
|
||||
content: 'foobar',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: null,
|
||||
authHash: null,
|
||||
itemsKeyId: null,
|
||||
duplicateOf: null,
|
||||
deleted: true,
|
||||
dates: Dates.create(new Date(1616164633241311), new Date(1616164633241311)).getValue(),
|
||||
timestamps: Timestamps.create(1616164633241311, 1616164633241311).getValue(),
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
},
|
||||
new UniqueEntityId('00000000-0000-0000-0000-000000000000'),
|
||||
).getValue()
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not the owner of the item', async () => {
|
||||
existingItem = Item.create({
|
||||
...existingItem.props,
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000001').getValue(),
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000002').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user has insufficient permissions to write key system items key', async () => {
|
||||
sharedVaultUser = SharedVaultUser.create({
|
||||
permission: SharedVaultUserPermission.create(SharedVaultUserPermission.PERMISSIONS.Read).getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
itemHash = ItemHash.create({
|
||||
...itemHash.props,
|
||||
content_type: ContentType.TYPES.KeySystemItemsKey,
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the shared vault operation on item is: save to shared vault', () => {
|
||||
beforeEach(() => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.SaveToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as passed if the user is a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(true)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user has insufficient permissions', async () => {
|
||||
sharedVaultUser = SharedVaultUser.create({
|
||||
permission: SharedVaultUserPermission.create(SharedVaultUserPermission.PERMISSIONS.Read).getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the shared vault operation on item is: create to shared vault', () => {
|
||||
beforeEach(() => {
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.CreateToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
existingItem,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user is not a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(null)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
|
||||
it('should return as passed if the user is a member of the shared vault', async () => {
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(true)
|
||||
})
|
||||
|
||||
it('should return as not passed if the user has insufficient permissions to write key system items key', async () => {
|
||||
sharedVaultUser = SharedVaultUser.create({
|
||||
permission: SharedVaultUserPermission.create(SharedVaultUserPermission.PERMISSIONS.Read).getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
itemHash = ItemHash.create({
|
||||
...itemHash.props,
|
||||
content_type: ContentType.TYPES.KeySystemItemsKey,
|
||||
}).getValue()
|
||||
|
||||
determineSharedVaultOperationOnItem.execute = jest.fn().mockReturnValue(
|
||||
Result.ok(
|
||||
SharedVaultOperationOnItem.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.CreateToSharedVault,
|
||||
incomingItemHash: itemHash,
|
||||
}).getValue(),
|
||||
),
|
||||
)
|
||||
|
||||
sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid = jest.fn().mockResolvedValue(sharedVaultUser)
|
||||
|
||||
const filter = createFilter()
|
||||
const result = await filter.check({
|
||||
apiVersion: '001',
|
||||
existingItem: existingItem,
|
||||
itemHash: itemHash,
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.passed).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,230 @@
|
||||
import { ConflictType } from '@standardnotes/responses'
|
||||
import { ContentType, Result, SharedVaultUserPermission, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { ItemSaveValidationDTO } from '../SaveValidator/ItemSaveValidationDTO'
|
||||
import { ItemSaveRuleResult } from './ItemSaveRuleResult'
|
||||
import { ItemSaveRuleInterface } from './ItemSaveRuleInterface'
|
||||
import { DetermineSharedVaultOperationOnItem } from '../../UseCase/SharedVaults/DetermineSharedVaultOperationOnItem/DetermineSharedVaultOperationOnItem'
|
||||
import { SharedVaultOperationOnItem } from '../../SharedVault/SharedVaultOperationOnItem'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
|
||||
export class SharedVaultFilter implements ItemSaveRuleInterface {
|
||||
constructor(
|
||||
private determineSharedVaultOperationOnItem: DetermineSharedVaultOperationOnItem,
|
||||
private sharedVaultUserRepository: SharedVaultUserRepositoryInterface,
|
||||
) {}
|
||||
|
||||
async check(dto: ItemSaveValidationDTO): Promise<ItemSaveRuleResult> {
|
||||
if (!dto.itemHash.representsASharedVaultItem() && !dto.existingItem?.isAssociatedWithASharedVault()) {
|
||||
return {
|
||||
passed: true,
|
||||
}
|
||||
}
|
||||
|
||||
const operationOrError = await this.determineSharedVaultOperationOnItem.execute({
|
||||
userUuid: dto.userUuid,
|
||||
itemHash: dto.itemHash,
|
||||
existingItem: dto.existingItem,
|
||||
})
|
||||
if (operationOrError.isFailed()) {
|
||||
return {
|
||||
passed: false,
|
||||
conflict: {
|
||||
unsavedItem: dto.itemHash,
|
||||
type: ConflictType.SharedVaultInvalidState,
|
||||
},
|
||||
}
|
||||
}
|
||||
const operation = operationOrError.getValue()
|
||||
|
||||
if (dto.itemHash.representsASharedVaultItem() && !dto.itemHash.hasDedicatedKeySystemAssociation()) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInvalidState)
|
||||
}
|
||||
|
||||
const sharedVaultPermission = await this.getSharedVaultUserPermission(
|
||||
operation.props.userUuid,
|
||||
operation.props.sharedVaultUuid,
|
||||
)
|
||||
|
||||
if (!sharedVaultPermission) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultNotMemberError)
|
||||
}
|
||||
|
||||
let targetSharedVaultPermission: SharedVaultUserPermission | null = null
|
||||
if (operation.props.targetSharedVaultUuid) {
|
||||
targetSharedVaultPermission = await this.getSharedVaultUserPermission(
|
||||
operation.props.userUuid,
|
||||
operation.props.targetSharedVaultUuid,
|
||||
)
|
||||
|
||||
if (!targetSharedVaultPermission) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultNotMemberError)
|
||||
}
|
||||
}
|
||||
|
||||
const resultOrError = await this.getResultForOperation(
|
||||
operation,
|
||||
sharedVaultPermission,
|
||||
targetSharedVaultPermission,
|
||||
)
|
||||
/* istanbul ignore next */
|
||||
if (resultOrError.isFailed()) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInvalidState)
|
||||
}
|
||||
|
||||
return resultOrError.getValue()
|
||||
}
|
||||
|
||||
private async getResultForOperation(
|
||||
operation: SharedVaultOperationOnItem,
|
||||
sharedVaultPermission: SharedVaultUserPermission,
|
||||
targetSharedVaultPermission: SharedVaultUserPermission | null,
|
||||
): Promise<Result<ItemSaveRuleResult>> {
|
||||
switch (operation.props.type) {
|
||||
case SharedVaultOperationOnItem.TYPES.AddToSharedVault:
|
||||
case SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault:
|
||||
return Result.ok(await this.handleAddOrRemoveToSharedVaultOperation(operation, sharedVaultPermission))
|
||||
case SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault:
|
||||
return Result.ok(
|
||||
await this.handleMoveToOtherSharedVaultOperation(
|
||||
operation,
|
||||
sharedVaultPermission,
|
||||
targetSharedVaultPermission as SharedVaultUserPermission,
|
||||
),
|
||||
)
|
||||
case SharedVaultOperationOnItem.TYPES.SaveToSharedVault:
|
||||
case SharedVaultOperationOnItem.TYPES.CreateToSharedVault:
|
||||
return Result.ok(await this.handleSaveOrCreateToSharedVaultOperation(operation, sharedVaultPermission))
|
||||
/* istanbul ignore next */
|
||||
default:
|
||||
return Result.fail(`Unsupported sharedVault operation: ${operation}`)
|
||||
}
|
||||
}
|
||||
|
||||
private isAuthorizedToSaveContentType(contentType: string | null, permission: SharedVaultUserPermission): boolean {
|
||||
if (contentType === ContentType.TYPES.KeySystemItemsKey) {
|
||||
return permission.value === SharedVaultUserPermission.PERMISSIONS.Admin
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private async handleAddOrRemoveToSharedVaultOperation(
|
||||
operation: SharedVaultOperationOnItem,
|
||||
sharedVaultPermission: SharedVaultUserPermission,
|
||||
): Promise<ItemSaveRuleResult> {
|
||||
if (this.isItemDeletedOrBeingDeleted(operation)) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInvalidState)
|
||||
}
|
||||
|
||||
if (!this.isOwnerOfTheItem(operation)) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInsufficientPermissionsError)
|
||||
}
|
||||
|
||||
if (!this.hasSufficientPermissionsToWriteInVault(operation, sharedVaultPermission)) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInsufficientPermissionsError)
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
}
|
||||
|
||||
private async handleMoveToOtherSharedVaultOperation(
|
||||
operation: SharedVaultOperationOnItem,
|
||||
sourceSharedVaultPermission: SharedVaultUserPermission,
|
||||
targetSharedVaultPermission: SharedVaultUserPermission,
|
||||
): Promise<ItemSaveRuleResult> {
|
||||
if (this.isItemDeletedOrBeingDeleted(operation)) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInvalidState)
|
||||
}
|
||||
|
||||
for (const permission of [sourceSharedVaultPermission, targetSharedVaultPermission]) {
|
||||
if (!this.hasSufficientPermissionsToWriteInVault(operation, permission)) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInsufficientPermissionsError)
|
||||
}
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
}
|
||||
|
||||
private async handleSaveOrCreateToSharedVaultOperation(
|
||||
operation: SharedVaultOperationOnItem,
|
||||
sharedVaultPermission: SharedVaultUserPermission,
|
||||
): Promise<ItemSaveRuleResult> {
|
||||
if (!this.hasSufficientPermissionsToWriteInVault(operation, sharedVaultPermission)) {
|
||||
return this.buildFailResult(operation, ConflictType.SharedVaultInsufficientPermissionsError)
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
}
|
||||
|
||||
private isItemDeletedOrBeingDeleted(operation: SharedVaultOperationOnItem): boolean {
|
||||
if (operation.props.existingItem?.props.deleted || operation.props.incomingItemHash.props.deleted) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private isOwnerOfTheItem(operation: SharedVaultOperationOnItem): boolean {
|
||||
if (operation.props.userUuid.equals(operation.props.existingItem?.props.userUuid)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private hasSufficientPermissionsToWriteInVault(
|
||||
operation: SharedVaultOperationOnItem,
|
||||
sharedVaultPermission: SharedVaultUserPermission,
|
||||
): boolean {
|
||||
if (
|
||||
!this.isAuthorizedToSaveContentType(operation.props.incomingItemHash.props.content_type, sharedVaultPermission)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (sharedVaultPermission.value === SharedVaultUserPermission.PERMISSIONS.Read) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private async getSharedVaultUserPermission(
|
||||
userUuid: Uuid,
|
||||
sharedVaultUuid: Uuid,
|
||||
): Promise<SharedVaultUserPermission | null> {
|
||||
const sharedVaultUser = await this.sharedVaultUserRepository.findByUserUuidAndSharedVaultUuid({
|
||||
userUuid,
|
||||
sharedVaultUuid,
|
||||
})
|
||||
|
||||
if (sharedVaultUser) {
|
||||
return sharedVaultUser.props.permission
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private buildFailResult(operation: SharedVaultOperationOnItem, type: ConflictType): ItemSaveRuleResult {
|
||||
const includeServerItem = [
|
||||
ConflictType.SharedVaultInvalidState,
|
||||
ConflictType.SharedVaultInsufficientPermissionsError,
|
||||
].includes(type)
|
||||
|
||||
return {
|
||||
passed: false,
|
||||
conflict: {
|
||||
unsavedItem: operation.props.incomingItemHash,
|
||||
serverItem: includeServerItem ? operation.props.existingItem : undefined,
|
||||
type,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
private buildSuccessValue(): ItemSaveRuleResult {
|
||||
return {
|
||||
passed: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { NotificationPayload, NotificationType, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { Notification } from './Notification'
|
||||
import { NotificationType } from './NotificationType'
|
||||
|
||||
describe('Notification', () => {
|
||||
it('should create an entity', () => {
|
||||
const payload = NotificationPayload.create({
|
||||
sharedVaultUuid: Uuid.create('0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e').getValue(),
|
||||
type: NotificationType.create(NotificationType.TYPES.RemovedFromSharedVault).getValue(),
|
||||
version: '1.0',
|
||||
}).getValue()
|
||||
|
||||
const entityOrError = Notification.create({
|
||||
timestamps: Timestamps.create(123456789, 123456789).getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
payload: 'payload',
|
||||
payload,
|
||||
type: NotificationType.create(NotificationType.TYPES.SharedVaultItemRemoved).getValue(),
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { NotificationType } from './NotificationType'
|
||||
import { NotificationPayload, NotificationType, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export interface NotificationProps {
|
||||
userUuid: Uuid
|
||||
type: NotificationType
|
||||
payload: string
|
||||
payload: NotificationPayload
|
||||
timestamps: Timestamps
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Uuid } from '@standardnotes/domain-core'
|
||||
import { NotificationType, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { Notification } from './Notification'
|
||||
|
||||
@@ -6,4 +6,6 @@ export interface NotificationRepositoryInterface {
|
||||
save(notification: Notification): Promise<void>
|
||||
findByUserUuidUpdatedAfter(userUuid: Uuid, lastSyncTime: number): Promise<Notification[]>
|
||||
findByUserUuid(userUuid: Uuid): Promise<Notification[]>
|
||||
findByUserUuidAndType(userUuid: Uuid, type: NotificationType): Promise<Notification[]>
|
||||
remove(notification: Notification): Promise<void>
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { Timestamps, UniqueEntityId, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVault } from './SharedVault'
|
||||
|
||||
@@ -13,5 +13,21 @@ describe('SharedVault', () => {
|
||||
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(entityOrError.getValue().id).not.toBeNull()
|
||||
expect(entityOrError.getValue().uuid.value).toEqual(entityOrError.getValue().id.toString())
|
||||
})
|
||||
|
||||
it('should throw an error if id cannot be cast to uuid', () => {
|
||||
const entityOrError = SharedVault.create(
|
||||
{
|
||||
fileUploadBytesLimit: 1_000_000,
|
||||
fileUploadBytesUsed: 0,
|
||||
timestamps: Timestamps.create(123456789, 123456789).getValue(),
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
},
|
||||
new UniqueEntityId(1),
|
||||
)
|
||||
|
||||
expect(entityOrError.isFailed()).toBeFalsy()
|
||||
expect(() => entityOrError.getValue().uuid).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Entity, Result, UniqueEntityId } from '@standardnotes/domain-core'
|
||||
import { Entity, Result, UniqueEntityId, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultProps } from './SharedVaultProps'
|
||||
|
||||
@@ -7,6 +7,15 @@ export class SharedVault extends Entity<SharedVaultProps> {
|
||||
super(props, id)
|
||||
}
|
||||
|
||||
get uuid(): Uuid {
|
||||
const uuidOrError = Uuid.create(this._id.toString())
|
||||
if (uuidOrError.isFailed()) {
|
||||
throw new Error(uuidOrError.getError())
|
||||
}
|
||||
|
||||
return uuidOrError.getValue()
|
||||
}
|
||||
|
||||
static create(props: SharedVaultProps, id?: UniqueEntityId): Result<SharedVault> {
|
||||
return Result.ok<SharedVault>(new SharedVault(props, id))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { ContentType, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { ItemHash } from '../Item/ItemHash'
|
||||
import { SharedVaultOperationOnItem } from './SharedVaultOperationOnItem'
|
||||
|
||||
describe('SharedVaultOperationOnItem', () => {
|
||||
let itemHash: ItemHash
|
||||
|
||||
beforeEach(() => {
|
||||
itemHash = ItemHash.create({
|
||||
uuid: '2-3-4',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: null,
|
||||
}).getValue()
|
||||
})
|
||||
|
||||
it('should create a value object', () => {
|
||||
const valueOrError = SharedVaultOperationOnItem.create({
|
||||
incomingItemHash: itemHash,
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
})
|
||||
|
||||
expect(valueOrError.isFailed()).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should return error if shared vault operation type is invalid', () => {
|
||||
const valueOrError = SharedVaultOperationOnItem.create({
|
||||
incomingItemHash: itemHash,
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: 'invalid',
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
})
|
||||
|
||||
expect(valueOrError.isFailed()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should return error if operation type is move to other shared vault and target shared vault uuid is not provided', () => {
|
||||
const valueOrError = SharedVaultOperationOnItem.create({
|
||||
incomingItemHash: itemHash,
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
targetSharedVaultUuid: undefined,
|
||||
type: SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault,
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
})
|
||||
|
||||
expect(valueOrError.isFailed()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ValueObject, Result } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultOperationOnItemProps } from './SharedVaultOperationOnItemProps'
|
||||
|
||||
export class SharedVaultOperationOnItem extends ValueObject<SharedVaultOperationOnItemProps> {
|
||||
static readonly TYPES = {
|
||||
AddToSharedVault: 'add-to-shared-vault',
|
||||
RemoveFromSharedVault: 'remove-from-shared-vault',
|
||||
MoveToOtherSharedVault: 'move-to-other-shared-vault',
|
||||
SaveToSharedVault: 'save-to-shared-vault',
|
||||
CreateToSharedVault: 'create-to-shared-vault',
|
||||
}
|
||||
|
||||
private constructor(props: SharedVaultOperationOnItemProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
static create(props: SharedVaultOperationOnItemProps): Result<SharedVaultOperationOnItem> {
|
||||
const isValidType = Object.values(this.TYPES).includes(props.type)
|
||||
if (!isValidType) {
|
||||
return Result.fail<SharedVaultOperationOnItem>(`Invalid shared vault operation type: ${props.type}`)
|
||||
}
|
||||
|
||||
if (props.type === this.TYPES.MoveToOtherSharedVault && !props.targetSharedVaultUuid) {
|
||||
return Result.fail<SharedVaultOperationOnItem>('Missing target shared vault uuid')
|
||||
}
|
||||
|
||||
return Result.ok<SharedVaultOperationOnItem>(new SharedVaultOperationOnItem(props))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { Item } from '../Item/Item'
|
||||
import { ItemHash } from '../Item/ItemHash'
|
||||
|
||||
export interface SharedVaultOperationOnItemProps {
|
||||
incomingItemHash: ItemHash
|
||||
userUuid: Uuid
|
||||
type: string
|
||||
sharedVaultUuid: Uuid
|
||||
targetSharedVaultUuid?: Uuid
|
||||
existingItem?: Item
|
||||
}
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultInvite } from './SharedVaultInvite'
|
||||
import { SharedVaultUserPermission } from '../SharedVaultUserPermission'
|
||||
|
||||
describe('SharedVaultInvite', () => {
|
||||
it('should create an entity', () => {
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission } from '../SharedVaultUserPermission'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export interface SharedVaultInviteProps {
|
||||
sharedVaultUuid: Uuid
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultUser } from './SharedVaultUser'
|
||||
import { SharedVaultUserPermission } from './SharedVaultUserPermission'
|
||||
|
||||
describe('SharedVaultUser', () => {
|
||||
it('should create an entity', () => {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultUserPermission } from './SharedVaultUserPermission'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export interface SharedVaultUserProps {
|
||||
sharedVaultUuid: Uuid
|
||||
|
||||
+12
-19
@@ -1,14 +1,14 @@
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
import { NotificationPayload, NotificationType, Result, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
|
||||
import { Notification } from '../../../Notifications/Notification'
|
||||
import { AddNotificationForUser } from './AddNotificationForUser'
|
||||
import { NotificationType } from '../../../Notifications/NotificationType'
|
||||
|
||||
describe('AddNotificationForUser', () => {
|
||||
let notificationRepository: NotificationRepositoryInterface
|
||||
let timer: TimerInterface
|
||||
let payload: NotificationPayload
|
||||
|
||||
const createUseCase = () => new AddNotificationForUser(notificationRepository, timer)
|
||||
|
||||
@@ -18,6 +18,12 @@ describe('AddNotificationForUser', () => {
|
||||
|
||||
timer = {} as jest.Mocked<TimerInterface>
|
||||
timer.getTimestampInMicroseconds = jest.fn().mockReturnValue(123456789)
|
||||
|
||||
payload = NotificationPayload.create({
|
||||
sharedVaultUuid: Uuid.create('0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e').getValue(),
|
||||
type: NotificationType.create(NotificationType.TYPES.RemovedFromSharedVault).getValue(),
|
||||
version: '1.0',
|
||||
}).getValue()
|
||||
})
|
||||
|
||||
it('should save notification', async () => {
|
||||
@@ -26,7 +32,7 @@ describe('AddNotificationForUser', () => {
|
||||
const result = await useCase.execute({
|
||||
userUuid: '0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e',
|
||||
type: NotificationType.TYPES.RemovedFromSharedVault,
|
||||
payload: 'payload',
|
||||
payload,
|
||||
version: '1.0',
|
||||
})
|
||||
|
||||
@@ -39,7 +45,7 @@ describe('AddNotificationForUser', () => {
|
||||
const result = await useCase.execute({
|
||||
userUuid: 'invalid',
|
||||
type: NotificationType.TYPES.RemovedFromSharedVault,
|
||||
payload: 'payload',
|
||||
payload,
|
||||
version: '1.0',
|
||||
})
|
||||
|
||||
@@ -52,20 +58,7 @@ describe('AddNotificationForUser', () => {
|
||||
const result = await useCase.execute({
|
||||
userUuid: '0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e',
|
||||
type: 'invalid',
|
||||
payload: 'payload',
|
||||
version: '1.0',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should return error if notification payload is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e',
|
||||
type: NotificationType.TYPES.RemovedFromSharedVault,
|
||||
payload: '',
|
||||
payload,
|
||||
version: '1.0',
|
||||
})
|
||||
|
||||
@@ -83,7 +76,7 @@ describe('AddNotificationForUser', () => {
|
||||
const result = await useCase.execute({
|
||||
userUuid: '0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e',
|
||||
type: NotificationType.TYPES.RemovedFromSharedVault,
|
||||
payload: 'payload',
|
||||
payload,
|
||||
version: '1.0',
|
||||
})
|
||||
|
||||
|
||||
+1
-7
@@ -1,10 +1,9 @@
|
||||
import { Result, Timestamps, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core'
|
||||
import { NotificationType, Result, Timestamps, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
|
||||
import { AddNotificationForUserDTO } from './AddNotificationForUserDTO'
|
||||
import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
|
||||
import { Notification } from '../../../Notifications/Notification'
|
||||
import { NotificationType } from '../../../Notifications/NotificationType'
|
||||
|
||||
export class AddNotificationForUser implements UseCaseInterface<Notification> {
|
||||
constructor(private notificationRepository: NotificationRepositoryInterface, private timer: TimerInterface) {}
|
||||
@@ -22,11 +21,6 @@ export class AddNotificationForUser implements UseCaseInterface<Notification> {
|
||||
}
|
||||
const type = typeOrError.getValue()
|
||||
|
||||
const paylodNotEmptyValidationResult = Validator.isNotEmpty(dto.payload)
|
||||
if (paylodNotEmptyValidationResult.isFailed()) {
|
||||
return Result.fail(paylodNotEmptyValidationResult.getError())
|
||||
}
|
||||
|
||||
const notificationOrError = Notification.create({
|
||||
userUuid,
|
||||
type,
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
import { NotificationPayload } from '@standardnotes/domain-core'
|
||||
|
||||
export interface AddNotificationForUserDTO {
|
||||
version: string
|
||||
type: string
|
||||
userUuid: string
|
||||
payload: string
|
||||
payload: NotificationPayload
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import { NotificationPayload, NotificationType, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
|
||||
import { RemoveNotificationsForUser } from './RemoveNotificationsForUser'
|
||||
import { Notification } from '../../../Notifications/Notification'
|
||||
|
||||
describe('RemoveNotificationsForUser', () => {
|
||||
let notificationRepository: NotificationRepositoryInterface
|
||||
let notification: Notification
|
||||
|
||||
const createUseCase = () => new RemoveNotificationsForUser(notificationRepository)
|
||||
|
||||
beforeEach(() => {
|
||||
notification = Notification.create({
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: NotificationType.create(NotificationType.TYPES.SharedVaultItemRemoved).getValue(),
|
||||
payload: NotificationPayload.create({
|
||||
itemUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
type: NotificationType.create(NotificationType.TYPES.SharedVaultItemRemoved).getValue(),
|
||||
version: '1.0',
|
||||
}).getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
|
||||
notificationRepository = {} as jest.Mocked<NotificationRepositoryInterface>
|
||||
notificationRepository.findByUserUuidAndType = jest.fn().mockResolvedValue([notification])
|
||||
notificationRepository.remove = jest.fn()
|
||||
})
|
||||
|
||||
it('should remove notifications for user', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
type: NotificationType.TYPES.SharedVaultItemRemoved,
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(notificationRepository.remove).toHaveBeenCalledWith(notification)
|
||||
})
|
||||
|
||||
it('should fail if user uuid is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: 'invalid',
|
||||
type: NotificationType.TYPES.SharedVaultItemRemoved,
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should fail if notification type is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
type: 'invalid',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { NotificationType, Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { RemoveNotificationsForUserDTO } from './RemoveNotificationsForUserDTO'
|
||||
import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
|
||||
|
||||
export class RemoveNotificationsForUser implements UseCaseInterface<void> {
|
||||
constructor(private notificationRepository: NotificationRepositoryInterface) {}
|
||||
|
||||
async execute(dto: RemoveNotificationsForUserDTO): Promise<Result<void>> {
|
||||
const userUuidOrError = Uuid.create(dto.userUuid)
|
||||
if (userUuidOrError.isFailed()) {
|
||||
return Result.fail(userUuidOrError.getError())
|
||||
}
|
||||
const userUuid = userUuidOrError.getValue()
|
||||
|
||||
const typeOrError = NotificationType.create(dto.type)
|
||||
if (typeOrError.isFailed()) {
|
||||
return Result.fail(typeOrError.getError())
|
||||
}
|
||||
const type = typeOrError.getValue()
|
||||
|
||||
const notifications = await this.notificationRepository.findByUserUuidAndType(userUuid, type)
|
||||
for (const notification of notifications) {
|
||||
await this.notificationRepository.remove(notification)
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export interface RemoveNotificationsForUserDTO {
|
||||
type: string
|
||||
userUuid: string
|
||||
}
|
||||
+1
-2
@@ -1,9 +1,8 @@
|
||||
import { Result, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { Result, SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { AddUserToSharedVault } from '../AddUserToSharedVault/AddUserToSharedVault'
|
||||
import { AcceptInviteToSharedVault } from './AcceptInviteToSharedVault'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
describe('AcceptInviteToSharedVault', () => {
|
||||
let addUserToSharedVault: AddUserToSharedVault
|
||||
|
||||
+1
-2
@@ -1,11 +1,10 @@
|
||||
import { Result, Timestamps, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { Result, SharedVaultUserPermission, Timestamps, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
|
||||
import { AddUserToSharedVaultDTO } from './AddUserToSharedVaultDTO'
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
export class AddUserToSharedVault implements UseCaseInterface<SharedVaultUser> {
|
||||
constructor(
|
||||
|
||||
+1
-2
@@ -4,8 +4,7 @@ import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/Sh
|
||||
import { CreateSharedVaultFileValetToken } from './CreateSharedVaultFileValetToken'
|
||||
import { SharedVault } from '../../../SharedVault/SharedVault'
|
||||
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
describe('CreateSharedVaultFileValetToken', () => {
|
||||
let sharedVaultRepository: SharedVaultRepositoryInterface
|
||||
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
import { SharedVaultValetTokenData, TokenEncoderInterface, ValetTokenOperation } from '@standardnotes/security'
|
||||
import { Result, SharedVaultUserPermission, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { CreateSharedVaultFileValetTokenDTO } from './CreateSharedVaultFileValetTokenDTO'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
export class CreateSharedVaultFileValetToken implements UseCaseInterface<string> {
|
||||
constructor(
|
||||
|
||||
+7
-8
@@ -1,8 +1,7 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { DeclineInviteToSharedVault } from './DeclineInviteToSharedVault'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
describe('DeclineInviteToSharedVault', () => {
|
||||
let sharedVaultInviteRepository: SharedVaultInviteRepositoryInterface
|
||||
@@ -30,7 +29,7 @@ describe('DeclineInviteToSharedVault', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
inviteUuid: 'invalid',
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000000',
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
@@ -42,7 +41,7 @@ describe('DeclineInviteToSharedVault', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
inviteUuid: '00000000-0000-0000-0000-000000000000',
|
||||
originatorUuid: 'invalid',
|
||||
userUuid: 'invalid',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
@@ -56,7 +55,7 @@ describe('DeclineInviteToSharedVault', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
inviteUuid: '00000000-0000-0000-0000-000000000000',
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000000',
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
@@ -68,11 +67,11 @@ describe('DeclineInviteToSharedVault', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
inviteUuid: '00000000-0000-0000-0000-000000000000',
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000001',
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Only the recipient of the invite can decline it')
|
||||
expect(result.getError()).toBe('Only the recipient or the sender can decline the invite')
|
||||
})
|
||||
|
||||
it('should delete invite', async () => {
|
||||
@@ -80,7 +79,7 @@ describe('DeclineInviteToSharedVault', () => {
|
||||
|
||||
await useCase.execute({
|
||||
inviteUuid: '00000000-0000-0000-0000-000000000000',
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000000',
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(sharedVaultInviteRepository.remove).toHaveBeenCalled()
|
||||
|
||||
+6
-6
@@ -12,19 +12,19 @@ export class DeclineInviteToSharedVault implements UseCaseInterface<void> {
|
||||
}
|
||||
const inviteUuid = inviteUuidOrError.getValue()
|
||||
|
||||
const originatorUuidOrError = Uuid.create(dto.originatorUuid)
|
||||
if (originatorUuidOrError.isFailed()) {
|
||||
return Result.fail(originatorUuidOrError.getError())
|
||||
const userUuidOrError = Uuid.create(dto.userUuid)
|
||||
if (userUuidOrError.isFailed()) {
|
||||
return Result.fail(userUuidOrError.getError())
|
||||
}
|
||||
const originatorUuid = originatorUuidOrError.getValue()
|
||||
const userUuid = userUuidOrError.getValue()
|
||||
|
||||
const invite = await this.sharedVaultInviteRepository.findByUuid(inviteUuid)
|
||||
if (!invite) {
|
||||
return Result.fail('Invite not found')
|
||||
}
|
||||
|
||||
if (!invite.props.userUuid.equals(originatorUuid)) {
|
||||
return Result.fail('Only the recipient of the invite can decline it')
|
||||
if (!invite.props.userUuid.equals(userUuid) && !invite.props.senderUuid.equals(userUuid)) {
|
||||
return Result.fail('Only the recipient or the sender can decline the invite')
|
||||
}
|
||||
|
||||
await this.sharedVaultInviteRepository.remove(invite)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export interface DeclineInviteToSharedVaultDTO {
|
||||
inviteUuid: string
|
||||
originatorUuid: string
|
||||
userUuid: string
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
import { Uuid, Timestamps, Result } from '@standardnotes/domain-core'
|
||||
import { Uuid, Timestamps, Result, SharedVaultUserPermission } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
@@ -6,7 +6,6 @@ import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/Sh
|
||||
import { DeleteSharedVault } from './DeleteSharedVault'
|
||||
import { SharedVault } from '../../../SharedVault/SharedVault'
|
||||
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { RemoveUserFromSharedVault } from '../RemoveUserFromSharedVault/RemoveUserFromSharedVault'
|
||||
|
||||
describe('DeleteSharedVault', () => {
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ export class DeleteSharedVault implements UseCaseInterface<void> {
|
||||
originatorUuid: originatorUuid.value,
|
||||
sharedVaultUuid: sharedVaultUuid.value,
|
||||
userUuid: sharedVaultUser.props.userUuid.value,
|
||||
forceRemoveOwner: true,
|
||||
})
|
||||
|
||||
if (result.isFailed()) {
|
||||
|
||||
+13
-2
@@ -1,9 +1,8 @@
|
||||
import { Result, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { Result, SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { DeclineInviteToSharedVault } from '../DeclineInviteToSharedVault/DeclineInviteToSharedVault'
|
||||
import { DeleteSharedVaultInvitesSentByUser } from './DeleteSharedVaultInvitesSentByUser'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
describe('DeleteSharedVaultInvitesSentByUser', () => {
|
||||
let sharedVaultInviteRepository: SharedVaultInviteRepositoryInterface
|
||||
@@ -25,6 +24,7 @@ describe('DeleteSharedVaultInvitesSentByUser', () => {
|
||||
|
||||
sharedVaultInviteRepository = {} as jest.Mocked<SharedVaultInviteRepositoryInterface>
|
||||
sharedVaultInviteRepository.findBySenderUuidAndSharedVaultUuid = jest.fn().mockReturnValue([sharedVaultInvite])
|
||||
sharedVaultInviteRepository.findBySenderUuid = jest.fn().mockReturnValue([sharedVaultInvite])
|
||||
|
||||
declineInviteToSharedVault = {} as jest.Mocked<DeclineInviteToSharedVault>
|
||||
declineInviteToSharedVault.execute = jest.fn().mockReturnValue(Result.ok())
|
||||
@@ -76,4 +76,15 @@ describe('DeleteSharedVaultInvitesSentByUser', () => {
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should decline all invites by user to all shared vaults', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(declineInviteToSharedVault.execute).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
+16
-10
@@ -16,20 +16,26 @@ export class DeleteSharedVaultInvitesSentByUser implements UseCaseInterface<void
|
||||
}
|
||||
const userUuid = userUuidOrError.getValue()
|
||||
|
||||
const sharedVaultUuidOrError = Uuid.create(dto.sharedVaultUuid)
|
||||
if (sharedVaultUuidOrError.isFailed()) {
|
||||
return Result.fail(sharedVaultUuidOrError.getError())
|
||||
}
|
||||
const sharedVaultUuid = sharedVaultUuidOrError.getValue()
|
||||
let inboundInvites = []
|
||||
if (dto.sharedVaultUuid !== undefined) {
|
||||
const sharedVaultUuidOrError = Uuid.create(dto.sharedVaultUuid)
|
||||
if (sharedVaultUuidOrError.isFailed()) {
|
||||
return Result.fail(sharedVaultUuidOrError.getError())
|
||||
}
|
||||
const sharedVaultUuid = sharedVaultUuidOrError.getValue()
|
||||
|
||||
inboundInvites = await this.sharedVaultInviteRepository.findBySenderUuidAndSharedVaultUuid({
|
||||
senderUuid: userUuid,
|
||||
sharedVaultUuid,
|
||||
})
|
||||
} else {
|
||||
inboundInvites = await this.sharedVaultInviteRepository.findBySenderUuid(userUuid)
|
||||
}
|
||||
|
||||
const inboundInvites = await this.sharedVaultInviteRepository.findBySenderUuidAndSharedVaultUuid({
|
||||
senderUuid: userUuid,
|
||||
sharedVaultUuid,
|
||||
})
|
||||
for (const invite of inboundInvites) {
|
||||
const result = await this.declineInviteToSharedVault.execute({
|
||||
inviteUuid: invite.id.toString(),
|
||||
originatorUuid: userUuid.value,
|
||||
userUuid: userUuid.value,
|
||||
})
|
||||
if (result.isFailed()) {
|
||||
return Result.fail(result.getError())
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export interface DeleteSharedVaultInvitesSentByUserDTO {
|
||||
userUuid: string
|
||||
sharedVaultUuid: string
|
||||
sharedVaultUuid?: string
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,9 +1,8 @@
|
||||
import { Result, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { Result, SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { DeclineInviteToSharedVault } from '../DeclineInviteToSharedVault/DeclineInviteToSharedVault'
|
||||
import { DeleteSharedVaultInvitesToUser } from './DeleteSharedVaultInvitesToUser'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
describe('DeleteSharedVaultInvitesToUser', () => {
|
||||
let sharedVaultInviteRepository: SharedVaultInviteRepositoryInterface
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ export class DeleteSharedVaultInvitesToUser implements UseCaseInterface<void> {
|
||||
for (const invite of inboundInvites) {
|
||||
const result = await this.declineInviteToSharedVault.execute({
|
||||
inviteUuid: invite.id.toString(),
|
||||
originatorUuid: userUuid.value,
|
||||
userUuid: userUuid.value,
|
||||
})
|
||||
if (result.isFailed()) {
|
||||
return Result.fail(result.getError())
|
||||
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
import { ContentType, Uuid, Dates, Timestamps, UniqueEntityId, Result } from '@standardnotes/domain-core'
|
||||
import { Item } from '../../../Item/Item'
|
||||
import { ItemHash } from '../../../Item/ItemHash'
|
||||
import { DetermineSharedVaultOperationOnItem } from './DetermineSharedVaultOperationOnItem'
|
||||
import { SharedVaultOperationOnItem } from '../../../SharedVault/SharedVaultOperationOnItem'
|
||||
import { SharedVaultAssociation } from '../../../SharedVault/SharedVaultAssociation'
|
||||
|
||||
describe('DetermineSharedVaultOperationOnItem', () => {
|
||||
let itemHash: ItemHash
|
||||
let existingItem: Item
|
||||
|
||||
const createUseCase = () => new DetermineSharedVaultOperationOnItem()
|
||||
|
||||
beforeEach(() => {
|
||||
itemHash = ItemHash.create({
|
||||
uuid: '2-3-4',
|
||||
content_type: ContentType.TYPES.Note,
|
||||
user_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
content: 'foobar',
|
||||
created_at: '2020-01-01T00:00:00.000Z',
|
||||
updated_at: '2020-01-01T00:00:00.000Z',
|
||||
created_at_timestamp: 123,
|
||||
updated_at_timestamp: 123,
|
||||
key_system_identifier: null,
|
||||
shared_vault_uuid: null,
|
||||
}).getValue()
|
||||
|
||||
existingItem = Item.create(
|
||||
{
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
updatedWithSession: null,
|
||||
content: 'foobar',
|
||||
contentType: ContentType.create(ContentType.TYPES.Note).getValue(),
|
||||
encItemKey: null,
|
||||
authHash: null,
|
||||
itemsKeyId: null,
|
||||
duplicateOf: null,
|
||||
deleted: false,
|
||||
dates: Dates.create(new Date(1616164633241311), new Date(1616164633241311)).getValue(),
|
||||
timestamps: Timestamps.create(1616164633241311, 1616164633241311).getValue(),
|
||||
},
|
||||
new UniqueEntityId('00000000-0000-0000-0000-000000000000'),
|
||||
).getValue()
|
||||
})
|
||||
|
||||
it('should return an error if user uuid is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: 'invalid',
|
||||
existingItem,
|
||||
itemHash,
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
expect(result.getError()).toEqual('Given value is not a valid uuid: invalid')
|
||||
})
|
||||
|
||||
it('should return an operation representing moving to another shared vault', async () => {
|
||||
existingItem = Item.create({
|
||||
...existingItem.props,
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: existingItem.uuid,
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
}).getValue()
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000001',
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(result.getValue().props.type).toEqual(SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault)
|
||||
expect(result.getValue().props.sharedVaultUuid.value).toEqual('00000000-0000-0000-0000-000000000000')
|
||||
expect(result.getValue().props.targetSharedVaultUuid?.value).toEqual('00000000-0000-0000-0000-000000000001')
|
||||
})
|
||||
|
||||
it('should return an operation representing removing from shared vault', async () => {
|
||||
existingItem = Item.create({
|
||||
...existingItem.props,
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: existingItem.uuid,
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
}).getValue()
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: null,
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(result.getValue().props.type).toEqual(SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault)
|
||||
expect(result.getValue().props.sharedVaultUuid.value).toEqual('00000000-0000-0000-0000-000000000000')
|
||||
})
|
||||
|
||||
it('should return an operation representing adding to shared vault', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000001',
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(result.getValue().props.type).toEqual(SharedVaultOperationOnItem.TYPES.AddToSharedVault)
|
||||
expect(result.getValue().props.sharedVaultUuid.value).toEqual('00000000-0000-0000-0000-000000000001')
|
||||
})
|
||||
|
||||
it('should return an operation representing saving to shared vault', async () => {
|
||||
existingItem = Item.create({
|
||||
...existingItem.props,
|
||||
sharedVaultAssociation: SharedVaultAssociation.create({
|
||||
itemUuid: existingItem.uuid,
|
||||
lastEditedBy: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
sharedVaultUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue(),
|
||||
}).getValue()
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000000',
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(result.getValue().props.type).toEqual(SharedVaultOperationOnItem.TYPES.SaveToSharedVault)
|
||||
expect(result.getValue().props.sharedVaultUuid.value).toEqual('00000000-0000-0000-0000-000000000000')
|
||||
})
|
||||
|
||||
it('should return an operation representing creating to shared vault', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem: null,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000001',
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(result.getValue().props.type).toEqual(SharedVaultOperationOnItem.TYPES.CreateToSharedVault)
|
||||
expect(result.getValue().props.sharedVaultUuid.value).toEqual('00000000-0000-0000-0000-000000000001')
|
||||
})
|
||||
|
||||
it('should return an error if both existing and incoming item hash do not have shared vault uuid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem: null,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: null,
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
expect(result.getError()).toEqual('Invalid save operation')
|
||||
})
|
||||
|
||||
it('should return error if operation could not be determined based on input values', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem: null,
|
||||
itemHash,
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
expect(result.getError()).toEqual('Invalid save operation')
|
||||
})
|
||||
|
||||
it('should return error if shared vault operation on item could not be created', async () => {
|
||||
const mock = jest.spyOn(SharedVaultOperationOnItem, 'create')
|
||||
mock.mockImplementationOnce(() => Result.fail('error'))
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
existingItem: null,
|
||||
itemHash: ItemHash.create({
|
||||
...itemHash.props,
|
||||
shared_vault_uuid: '00000000-0000-0000-0000-000000000001',
|
||||
}).getValue(),
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
|
||||
mock.mockRestore()
|
||||
})
|
||||
})
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
import { Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultOperationOnItem } from '../../../SharedVault/SharedVaultOperationOnItem'
|
||||
import { DetermineSharedVaultOperationOnItemDTO } from './DetermineSharedVaultOperationOnItemDTO'
|
||||
import { Item } from '../../../Item/Item'
|
||||
|
||||
export class DetermineSharedVaultOperationOnItem implements UseCaseInterface<SharedVaultOperationOnItem> {
|
||||
async execute(dto: DetermineSharedVaultOperationOnItemDTO): Promise<Result<SharedVaultOperationOnItem>> {
|
||||
const userUuidOrError = Uuid.create(dto.userUuid)
|
||||
if (userUuidOrError.isFailed()) {
|
||||
return Result.fail(userUuidOrError.getError())
|
||||
}
|
||||
const userUuid = userUuidOrError.getValue()
|
||||
|
||||
let existingItemSharedVaultUuid = null
|
||||
if (dto.existingItem) {
|
||||
existingItemSharedVaultUuid = dto.existingItem.sharedVaultUuid
|
||||
}
|
||||
const targetItemSharedVaultUuid = dto.itemHash.sharedVaultUuid
|
||||
|
||||
if (!existingItemSharedVaultUuid && !targetItemSharedVaultUuid) {
|
||||
return Result.fail('Invalid save operation')
|
||||
}
|
||||
|
||||
const isMovingToOtherSharedVault =
|
||||
dto.existingItem &&
|
||||
existingItemSharedVaultUuid &&
|
||||
targetItemSharedVaultUuid &&
|
||||
!existingItemSharedVaultUuid.equals(targetItemSharedVaultUuid)
|
||||
const isRemovingFromSharedVault = dto.existingItem && existingItemSharedVaultUuid && !targetItemSharedVaultUuid
|
||||
const isAddingToSharedVault = dto.existingItem && !existingItemSharedVaultUuid && targetItemSharedVaultUuid
|
||||
const isSavingToSharedVault =
|
||||
dto.existingItem &&
|
||||
existingItemSharedVaultUuid &&
|
||||
targetItemSharedVaultUuid &&
|
||||
existingItemSharedVaultUuid.equals(targetItemSharedVaultUuid)
|
||||
|
||||
let operationOrError: Result<SharedVaultOperationOnItem>
|
||||
if (isMovingToOtherSharedVault) {
|
||||
operationOrError = SharedVaultOperationOnItem.create({
|
||||
existingItem: dto.existingItem as Item,
|
||||
sharedVaultUuid: existingItemSharedVaultUuid as Uuid,
|
||||
targetSharedVaultUuid: targetItemSharedVaultUuid,
|
||||
incomingItemHash: dto.itemHash,
|
||||
userUuid: userUuid,
|
||||
type: SharedVaultOperationOnItem.TYPES.MoveToOtherSharedVault,
|
||||
})
|
||||
} else if (isRemovingFromSharedVault) {
|
||||
operationOrError = SharedVaultOperationOnItem.create({
|
||||
existingItem: dto.existingItem as Item,
|
||||
sharedVaultUuid: existingItemSharedVaultUuid as Uuid,
|
||||
incomingItemHash: dto.itemHash,
|
||||
userUuid: userUuid,
|
||||
type: SharedVaultOperationOnItem.TYPES.RemoveFromSharedVault,
|
||||
})
|
||||
} else if (isAddingToSharedVault) {
|
||||
operationOrError = SharedVaultOperationOnItem.create({
|
||||
existingItem: dto.existingItem as Item,
|
||||
sharedVaultUuid: targetItemSharedVaultUuid,
|
||||
incomingItemHash: dto.itemHash,
|
||||
userUuid: userUuid,
|
||||
type: SharedVaultOperationOnItem.TYPES.AddToSharedVault,
|
||||
})
|
||||
} else if (isSavingToSharedVault) {
|
||||
operationOrError = SharedVaultOperationOnItem.create({
|
||||
existingItem: dto.existingItem as Item,
|
||||
sharedVaultUuid: existingItemSharedVaultUuid as Uuid,
|
||||
incomingItemHash: dto.itemHash,
|
||||
userUuid: userUuid,
|
||||
type: SharedVaultOperationOnItem.TYPES.SaveToSharedVault,
|
||||
})
|
||||
} else {
|
||||
operationOrError = SharedVaultOperationOnItem.create({
|
||||
sharedVaultUuid: targetItemSharedVaultUuid as Uuid,
|
||||
incomingItemHash: dto.itemHash,
|
||||
userUuid: userUuid,
|
||||
type: SharedVaultOperationOnItem.TYPES.CreateToSharedVault,
|
||||
})
|
||||
}
|
||||
|
||||
if (operationOrError.isFailed()) {
|
||||
return Result.fail(operationOrError.getError())
|
||||
}
|
||||
|
||||
return Result.ok(operationOrError.getValue())
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { ItemHash } from '../../../Item/ItemHash'
|
||||
import { Item } from '../../../Item/Item'
|
||||
|
||||
export interface DetermineSharedVaultOperationOnItemDTO {
|
||||
userUuid: string
|
||||
itemHash: ItemHash
|
||||
existingItem: Item | null
|
||||
}
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { Uuid, Timestamps } from '@standardnotes/domain-core'
|
||||
import { Uuid, Timestamps, SharedVaultUserPermission } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { GetSharedVaultInvitesSentByUser } from './GetSharedVaultInvitesSentByUser'
|
||||
|
||||
describe('GetSharedVaultInvitesSentByUser', () => {
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { Uuid, Timestamps } from '@standardnotes/domain-core'
|
||||
import { Uuid, Timestamps, SharedVaultUserPermission } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { GetSharedVaultInvitesSentToUser } from './GetSharedVaultInvitesSentToUser'
|
||||
|
||||
describe('GetSharedVaultInvitesSentToUser', () => {
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { Uuid, Timestamps } from '@standardnotes/domain-core'
|
||||
import { Uuid, Timestamps, SharedVaultUserPermission } from '@standardnotes/domain-core'
|
||||
import { SharedVault } from '../../../SharedVault/SharedVault'
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { GetSharedVaultUsers } from './GetSharedVaultUsers'
|
||||
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVault } from '../../../SharedVault/SharedVault'
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { GetSharedVaults } from './GetSharedVaults'
|
||||
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
import { Uuid, Timestamps, Result, SharedVaultUserPermission } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { InviteUserToSharedVault } from './InviteUserToSharedVault'
|
||||
import { SharedVault } from '../../../SharedVault/SharedVault'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { Uuid, Timestamps, Result } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
describe('InviteUserToSharedVault', () => {
|
||||
let sharedVaultRepository: SharedVaultRepositoryInterface
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
import { Result, Timestamps, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { Result, SharedVaultUserPermission, Timestamps, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { InviteUserToSharedVaultDTO } from './InviteUserToSharedVaultDTO'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
|
||||
export class InviteUserToSharedVault implements UseCaseInterface<SharedVaultInvite> {
|
||||
constructor(
|
||||
|
||||
+39
-4
@@ -1,9 +1,8 @@
|
||||
import { Uuid, Timestamps, Result } from '@standardnotes/domain-core'
|
||||
import { Uuid, Timestamps, Result, NotificationPayload, SharedVaultUserPermission } from '@standardnotes/domain-core'
|
||||
|
||||
import { SharedVault } from '../../../SharedVault/SharedVault'
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultUser } from '../../../SharedVault/User/SharedVaultUser'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { RemoveUserFromSharedVault } from './RemoveUserFromSharedVault'
|
||||
import { AddNotificationForUser } from '../../Messaging/AddNotificationForUser/AddNotificationForUser'
|
||||
@@ -45,12 +44,13 @@ describe('RemoveUserFromSharedVault', () => {
|
||||
|
||||
it('should remove user from shared vault', async () => {
|
||||
const useCase = createUseCase()
|
||||
await useCase.execute({
|
||||
const result = await useCase.execute({
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000000',
|
||||
sharedVaultUuid: '00000000-0000-0000-0000-000000000000',
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(sharedVaultUserRepository.remove).toHaveBeenCalledWith(sharedVaultUser)
|
||||
})
|
||||
|
||||
@@ -99,7 +99,27 @@ describe('RemoveUserFromSharedVault', () => {
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Only owner can remove users from shared vault')
|
||||
expect(result.getError()).toBe('Only owner can remove other users from shared vault')
|
||||
})
|
||||
|
||||
it('should remove shared vault user if user is owner and is being force removed', async () => {
|
||||
sharedVault = SharedVault.create({
|
||||
fileUploadBytesLimit: 100,
|
||||
fileUploadBytesUsed: 2,
|
||||
userUuid: Uuid.create('00000000-0000-0000-0000-000000000002').getValue(),
|
||||
timestamps: Timestamps.create(123, 123).getValue(),
|
||||
}).getValue()
|
||||
sharedVaultRepository.findByUuid = jest.fn().mockResolvedValue(sharedVault)
|
||||
|
||||
const useCase = createUseCase()
|
||||
await useCase.execute({
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000002',
|
||||
sharedVaultUuid: '00000000-0000-0000-0000-000000000000',
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
forceRemoveOwner: true,
|
||||
})
|
||||
|
||||
expect(sharedVaultUserRepository.remove).toHaveBeenCalledWith(sharedVaultUser)
|
||||
})
|
||||
|
||||
it('should return error when user is owner of shared vault', async () => {
|
||||
@@ -173,4 +193,19 @@ describe('RemoveUserFromSharedVault', () => {
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
})
|
||||
|
||||
it('should return error if notification payload could not be created', async () => {
|
||||
const mock = jest.spyOn(NotificationPayload, 'create')
|
||||
mock.mockReturnValue(Result.fail('Oops'))
|
||||
|
||||
const useCase = createUseCase()
|
||||
const result = await useCase.execute({
|
||||
originatorUuid: '00000000-0000-0000-0000-000000000000',
|
||||
sharedVaultUuid: '00000000-0000-0000-0000-000000000000',
|
||||
userUuid: '00000000-0000-0000-0000-000000000001',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Oops')
|
||||
})
|
||||
})
|
||||
|
||||
+16
-8
@@ -1,9 +1,8 @@
|
||||
import { Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
import { NotificationPayload, NotificationType, Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { RemoveUserFromSharedVaultDTO } from './RemoveUserFromSharedVaultDTO'
|
||||
import { SharedVaultRepositoryInterface } from '../../../SharedVault/SharedVaultRepositoryInterface'
|
||||
import { SharedVaultUserRepositoryInterface } from '../../../SharedVault/User/SharedVaultUserRepositoryInterface'
|
||||
import { NotificationType } from '../../../Notifications/NotificationType'
|
||||
import { AddNotificationForUser } from '../../Messaging/AddNotificationForUser/AddNotificationForUser'
|
||||
|
||||
export class RemoveUserFromSharedVault implements UseCaseInterface<void> {
|
||||
@@ -38,12 +37,13 @@ export class RemoveUserFromSharedVault implements UseCaseInterface<void> {
|
||||
}
|
||||
|
||||
const originatorIsOwner = sharedVault.props.userUuid.equals(originatorUuid)
|
||||
if (!originatorIsOwner) {
|
||||
return Result.fail('Only owner can remove users from shared vault')
|
||||
const removingSomeoneElseWhenNotOwner = !originatorIsOwner && !userUuid.equals(originatorUuid)
|
||||
if (removingSomeoneElseWhenNotOwner) {
|
||||
return Result.fail('Only owner can remove other users from shared vault')
|
||||
}
|
||||
|
||||
const removingOwner = sharedVault.props.userUuid.equals(userUuid)
|
||||
if (removingOwner) {
|
||||
if (removingOwner && !dto.forceRemoveOwner) {
|
||||
return Result.fail('Owner cannot be removed from shared vault')
|
||||
}
|
||||
|
||||
@@ -57,12 +57,20 @@ export class RemoveUserFromSharedVault implements UseCaseInterface<void> {
|
||||
|
||||
await this.sharedVaultUsersRepository.remove(sharedVaultUser)
|
||||
|
||||
const notificationPayloadOrError = NotificationPayload.create({
|
||||
sharedVaultUuid: sharedVault.uuid,
|
||||
type: NotificationType.create(NotificationType.TYPES.RemovedFromSharedVault).getValue(),
|
||||
version: '1.0',
|
||||
})
|
||||
if (notificationPayloadOrError.isFailed()) {
|
||||
return Result.fail(notificationPayloadOrError.getError())
|
||||
}
|
||||
const notificationPayload = notificationPayloadOrError.getValue()
|
||||
|
||||
const result = await this.addNotificationForUser.execute({
|
||||
userUuid: sharedVaultUser.props.userUuid.value,
|
||||
type: NotificationType.TYPES.RemovedFromSharedVault,
|
||||
payload: JSON.stringify({
|
||||
sharedVaultUuid: sharedVault.id.toString(),
|
||||
}),
|
||||
payload: notificationPayload,
|
||||
version: '1.0',
|
||||
})
|
||||
if (result.isFailed()) {
|
||||
|
||||
+1
@@ -2,4 +2,5 @@ export interface RemoveUserFromSharedVaultDTO {
|
||||
sharedVaultUuid: string
|
||||
originatorUuid: string
|
||||
userUuid: string
|
||||
forceRemoveOwner?: boolean
|
||||
}
|
||||
|
||||
+1
-2
@@ -2,8 +2,7 @@ import { TimerInterface } from '@standardnotes/time'
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { UpdateSharedVaultInvite } from './UpdateSharedVaultInvite'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
import { Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { SharedVaultUserPermission, Timestamps, Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
describe('UpdateSharedVaultInvite', () => {
|
||||
let sharedVaultInviteRepository: SharedVaultInviteRepositoryInterface
|
||||
|
||||
+9
-3
@@ -1,9 +1,15 @@
|
||||
import { Result, Timestamps, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core'
|
||||
import {
|
||||
Result,
|
||||
SharedVaultUserPermission,
|
||||
Timestamps,
|
||||
UseCaseInterface,
|
||||
Uuid,
|
||||
Validator,
|
||||
} from '@standardnotes/domain-core'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
|
||||
import { SharedVaultInviteRepositoryInterface } from '../../../SharedVault/User/Invite/SharedVaultInviteRepositoryInterface'
|
||||
import { UpdateSharedVaultInviteDTO } from './UpdateSharedVaultInviteDTO'
|
||||
import { SharedVaultUserPermission } from '../../../SharedVault/User/SharedVaultUserPermission'
|
||||
import { TimerInterface } from '@standardnotes/time'
|
||||
import { SharedVaultInvite } from '../../../SharedVault/User/Invite/SharedVaultInvite'
|
||||
|
||||
export class UpdateSharedVaultInvite implements UseCaseInterface<SharedVaultInvite> {
|
||||
|
||||
@@ -303,23 +303,6 @@ describe('SaveNewItem', () => {
|
||||
})
|
||||
|
||||
describe('when item hash represents a shared vault item', () => {
|
||||
it('returns a failure if the shared vault uuid is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
itemHash1 = ItemHash.create({
|
||||
...itemHash1.props,
|
||||
shared_vault_uuid: '1-2-3',
|
||||
}).getValue()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
sessionUuid: '00000000-0000-0000-0000-000000000001',
|
||||
itemHash: itemHash1,
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should create a shared vault association between the item and the shared vault', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
|
||||
@@ -87,17 +87,31 @@ export class SaveNewItem implements UseCaseInterface<Item> {
|
||||
}
|
||||
const timestamps = timestampsOrError.getValue()
|
||||
|
||||
let sharedVaultAssociation = undefined
|
||||
if (dto.itemHash.representsASharedVaultItem()) {
|
||||
const sharedVaultUuidOrError = Uuid.create(dto.itemHash.props.shared_vault_uuid as string)
|
||||
if (sharedVaultUuidOrError.isFailed()) {
|
||||
return Result.fail(sharedVaultUuidOrError.getError())
|
||||
}
|
||||
const sharedVaultUuid = sharedVaultUuidOrError.getValue()
|
||||
const itemOrError = Item.create(
|
||||
{
|
||||
updatedWithSession,
|
||||
content: dto.itemHash.props.content ?? null,
|
||||
userUuid,
|
||||
contentType,
|
||||
encItemKey: dto.itemHash.props.enc_item_key ?? null,
|
||||
authHash: dto.itemHash.props.auth_hash ?? null,
|
||||
itemsKeyId: dto.itemHash.props.items_key_id ?? null,
|
||||
duplicateOf,
|
||||
deleted: dto.itemHash.props.deleted ?? false,
|
||||
dates,
|
||||
timestamps,
|
||||
},
|
||||
new UniqueEntityId(uuid.value),
|
||||
)
|
||||
if (itemOrError.isFailed()) {
|
||||
return Result.fail(itemOrError.getError())
|
||||
}
|
||||
const newItem = itemOrError.getValue()
|
||||
|
||||
if (dto.itemHash.representsASharedVaultItem()) {
|
||||
const sharedVaultAssociationOrError = SharedVaultAssociation.create({
|
||||
lastEditedBy: userUuid,
|
||||
sharedVaultUuid,
|
||||
sharedVaultUuid: dto.itemHash.sharedVaultUuid as Uuid,
|
||||
timestamps: Timestamps.create(
|
||||
this.timer.getTimestampInMicroseconds(),
|
||||
this.timer.getTimestampInMicroseconds(),
|
||||
@@ -107,10 +121,9 @@ export class SaveNewItem implements UseCaseInterface<Item> {
|
||||
if (sharedVaultAssociationOrError.isFailed()) {
|
||||
return Result.fail(sharedVaultAssociationOrError.getError())
|
||||
}
|
||||
sharedVaultAssociation = sharedVaultAssociationOrError.getValue()
|
||||
newItem.setSharedVaultAssociation(sharedVaultAssociationOrError.getValue())
|
||||
}
|
||||
|
||||
let keySystemAssociation = undefined
|
||||
if (dto.itemHash.hasDedicatedKeySystemAssociation()) {
|
||||
const keySystemIdentifiedValidationResult = Validator.isNotEmptyString(dto.itemHash.props.key_system_identifier)
|
||||
if (keySystemIdentifiedValidationResult.isFailed()) {
|
||||
@@ -129,32 +142,9 @@ export class SaveNewItem implements UseCaseInterface<Item> {
|
||||
if (keySystemAssociationOrError.isFailed()) {
|
||||
return Result.fail(keySystemAssociationOrError.getError())
|
||||
}
|
||||
keySystemAssociation = keySystemAssociationOrError.getValue()
|
||||
newItem.setKeySystemAssociation(keySystemAssociationOrError.getValue())
|
||||
}
|
||||
|
||||
const itemOrError = Item.create(
|
||||
{
|
||||
updatedWithSession,
|
||||
content: dto.itemHash.props.content ?? null,
|
||||
userUuid,
|
||||
contentType,
|
||||
encItemKey: dto.itemHash.props.enc_item_key ?? null,
|
||||
authHash: dto.itemHash.props.auth_hash ?? null,
|
||||
itemsKeyId: dto.itemHash.props.items_key_id ?? null,
|
||||
duplicateOf,
|
||||
deleted: dto.itemHash.props.deleted ?? false,
|
||||
dates,
|
||||
timestamps,
|
||||
keySystemAssociation,
|
||||
sharedVaultAssociation,
|
||||
},
|
||||
new UniqueEntityId(uuid.value),
|
||||
)
|
||||
if (itemOrError.isFailed()) {
|
||||
return Result.fail(itemOrError.getError())
|
||||
}
|
||||
const newItem = itemOrError.getValue()
|
||||
|
||||
await this.itemRepository.save(newItem)
|
||||
|
||||
if (contentType.value !== null && [ContentType.TYPES.Note, ContentType.TYPES.File].includes(contentType.value)) {
|
||||
|
||||
@@ -177,7 +177,7 @@ describe('SyncItems', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should sync items and return items keys on top for first sync', async () => {
|
||||
it('should sync items and return items keys on top for first sync that is not a shared vault exclusive sync', async () => {
|
||||
const result = await createUseCase().execute({
|
||||
userUuid: '1-2-3',
|
||||
itemHashes: [itemHash],
|
||||
@@ -202,6 +202,32 @@ describe('SyncItems', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should sync items and not return items keys on top for first sync that is a shared vault exclusive sync', async () => {
|
||||
const result = await createUseCase().execute({
|
||||
userUuid: '1-2-3',
|
||||
itemHashes: [itemHash],
|
||||
computeIntegrityHash: false,
|
||||
limit: 10,
|
||||
readOnlyAccess: false,
|
||||
sessionUuid: '2-3-4',
|
||||
contentType: 'Note',
|
||||
apiVersion: ApiVersion.v20200115,
|
||||
snjsVersion: '1.2.3',
|
||||
sharedVaultUuids: ['00000000-0000-0000-0000-000000000000'],
|
||||
})
|
||||
expect(result.getValue()).toEqual({
|
||||
conflicts: [],
|
||||
cursorToken: 'asdzxc',
|
||||
retrievedItems: [item1],
|
||||
savedItems: [item2],
|
||||
syncToken: 'qwerty',
|
||||
sharedVaults: [],
|
||||
sharedVaultInvites: [],
|
||||
notifications: [],
|
||||
messages: [],
|
||||
})
|
||||
})
|
||||
|
||||
it('should sync items and return filtered out sync conflicts for consecutive sync operations', async () => {
|
||||
getItemsUseCase.execute = jest.fn().mockReturnValue(
|
||||
Result.ok({
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user