mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
refactor: make item.userUuid non-null again
This commit is contained in:
-31
@@ -1,31 +0,0 @@
|
||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'
|
||||
|
||||
export class AllowItemUserUuidToBeNull1685276859271 implements MigrationInterface {
|
||||
name = 'allowItemUserUuidToBeNull1685276859271'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.changeColumn(
|
||||
'items',
|
||||
'user_uuid',
|
||||
new TableColumn({
|
||||
name: 'user_uuid',
|
||||
type: 'varchar',
|
||||
length: '36',
|
||||
isNullable: true,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.changeColumn(
|
||||
'items',
|
||||
'user_uuid',
|
||||
new TableColumn({
|
||||
name: 'user_uuid',
|
||||
type: 'varchar',
|
||||
length: '36',
|
||||
isNullable: false,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -78,10 +78,9 @@ export class Item {
|
||||
name: 'user_uuid',
|
||||
length: 36,
|
||||
type: 'varchar',
|
||||
nullable: true,
|
||||
})
|
||||
@Index('index_items_on_user_uuid')
|
||||
declare userUuid: string | null
|
||||
declare userUuid: string
|
||||
|
||||
@Column({
|
||||
name: 'last_edited_by_uuid',
|
||||
|
||||
@@ -213,10 +213,8 @@ export class ItemService implements ItemServiceInterface {
|
||||
|
||||
if (dto.itemHash.vault_uuid) {
|
||||
dto.existingItem.vaultUuid = dto.itemHash.vault_uuid
|
||||
dto.existingItem.userUuid = null
|
||||
} else {
|
||||
dto.existingItem.vaultUuid = null
|
||||
dto.existingItem.userUuid = dto.userUuid
|
||||
}
|
||||
|
||||
if (dto.itemHash.content) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
SaveToVaultSaveOperation,
|
||||
CreateToVaultSaveOperation,
|
||||
} from './VaultSaveOperation'
|
||||
import { Item } from '../Item'
|
||||
|
||||
export class VaultFilter implements ItemSaveRuleInterface {
|
||||
constructor(private vaultService: VaultServiceInterface, private vaultUserService: VaultUserServiceInterface) {}
|
||||
@@ -116,11 +117,12 @@ export class VaultFilter implements ItemSaveRuleInterface {
|
||||
return true
|
||||
}
|
||||
|
||||
private buildFailResult(operation: VaultSaveOperation, type: ConflictType) {
|
||||
private buildFailResult(operation: VaultSaveOperation, type: ConflictType, serverItem?: Item) {
|
||||
return {
|
||||
passed: false,
|
||||
conflict: {
|
||||
unsavedItem: operation.incomingItem,
|
||||
serverItem,
|
||||
type,
|
||||
},
|
||||
}
|
||||
@@ -156,7 +158,7 @@ export class VaultFilter implements ItemSaveRuleInterface {
|
||||
|
||||
const usesValidKey = await this.incomingItemUsesValidItemsKey(operation.incomingItem)
|
||||
if (!usesValidKey) {
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey)
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey, operation.existingItem)
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
@@ -172,6 +174,10 @@ export class VaultFilter implements ItemSaveRuleInterface {
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidState)
|
||||
}
|
||||
|
||||
if (operation.existingItem.userUuid === operation.userUuid) {
|
||||
return this.buildSuccessValue()
|
||||
}
|
||||
|
||||
if (!this.isAuthorizedToSaveContentType(operation.incomingItem.content_type, vaultPermissions)) {
|
||||
return this.buildFailResult(operation, ConflictType.VaultInsufficientPermissionsError)
|
||||
}
|
||||
@@ -182,7 +188,7 @@ export class VaultFilter implements ItemSaveRuleInterface {
|
||||
|
||||
const usesValidKey = await this.incomingItemUsesValidItemsKey(operation.incomingItem)
|
||||
if (!usesValidKey) {
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey)
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey, operation.existingItem)
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
@@ -213,7 +219,7 @@ export class VaultFilter implements ItemSaveRuleInterface {
|
||||
|
||||
const usesValidKey = await this.incomingItemUsesValidItemsKey(operation.incomingItem)
|
||||
if (!usesValidKey) {
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey)
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey, operation.existingItem)
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
@@ -236,7 +242,7 @@ export class VaultFilter implements ItemSaveRuleInterface {
|
||||
|
||||
const usesValidKey = await this.incomingItemUsesValidItemsKey(operation.incomingItem)
|
||||
if (!usesValidKey) {
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey)
|
||||
return this.buildFailResult(operation, ConflictType.VaultInvalidItemsKey, operation.existingItem)
|
||||
}
|
||||
|
||||
return this.buildSuccessValue()
|
||||
|
||||
Reference in New Issue
Block a user