mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 21:44:27 +00:00
fix(asset,webui): disallow dropping version stacks onto files and version stacks (#363)
* fix(asset,webui): disallow dropping version stacks onto files and version stacks * fix(webui): derive isSingleFile from total drag selection and remove unused hasVersionStacks
This commit is contained in:
@@ -570,6 +570,62 @@ describe('AssetService', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects reparenting a version_stack onto a file', async () => {
|
||||
const { user, assets } = await setupBasicAssets()
|
||||
await expect(
|
||||
assetService.reparentAssets({
|
||||
assetIds: [assets.stackB.id],
|
||||
newParentId: assets.fileA1.id,
|
||||
creatorId: user.id,
|
||||
}),
|
||||
).rejects.toThrow('Source asset must be a file to create a version stack')
|
||||
})
|
||||
|
||||
it('rejects reparenting a version_stack onto another version_stack', async () => {
|
||||
const { user, assets, project } = await setupBasicAssets()
|
||||
const stack2 = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'stack2',
|
||||
type: AssetType.version_stack,
|
||||
projectId: project.id,
|
||||
parentId: assets.folderA.id,
|
||||
creatorId: user.id,
|
||||
fileCount: 2,
|
||||
sizeByte: 100,
|
||||
status: 'uploaded',
|
||||
},
|
||||
})
|
||||
await expect(
|
||||
assetService.reparentAssets({
|
||||
assetIds: [assets.stackB.id],
|
||||
newParentId: stack2.id,
|
||||
creatorId: user.id,
|
||||
}),
|
||||
).rejects.toThrow('Cannot move version_stack asset into a version stack')
|
||||
})
|
||||
|
||||
it('rejects reparenting a folder onto a version_stack', async () => {
|
||||
const { user, assets } = await setupBasicAssets()
|
||||
await expect(
|
||||
assetService.reparentAssets({
|
||||
assetIds: [assets.folderA.id],
|
||||
newParentId: assets.stackB.id,
|
||||
creatorId: user.id,
|
||||
}),
|
||||
).rejects.toThrow('Cannot move folder asset into a version stack')
|
||||
})
|
||||
|
||||
it('rejects reparenting multiple files onto a version_stack at once', async () => {
|
||||
const { user, assets } = await setupBasicAssets()
|
||||
await expect(
|
||||
assetService.reparentAssets({
|
||||
assetIds: [assets.fileA1.id, assets.fileA2.id],
|
||||
newParentId: assets.stackB.id,
|
||||
creatorId: user.id,
|
||||
}),
|
||||
).rejects.toThrow('Can only move one file at a time into a version stack')
|
||||
})
|
||||
|
||||
describe('fileCount verification', () => {
|
||||
it('createAsset should increment parent fileCount', async () => {
|
||||
const { user, assets, project } = await setupBasicAssets()
|
||||
|
||||
@@ -211,6 +211,12 @@ export class AssetService {
|
||||
return this.reparentFileToFile(tx, newParent, req.assetIds, req.creatorId)
|
||||
}
|
||||
|
||||
if (newParent.type === AssetType.version_stack) {
|
||||
if (req.assetIds.length !== 1) {
|
||||
throw new Error('Can only move one file at a time into a version stack')
|
||||
}
|
||||
}
|
||||
|
||||
const assetsToMove = await tx.asset.findMany({
|
||||
where: { id: { in: req.assetIds } },
|
||||
include: { project: { include: { team: true } } },
|
||||
@@ -222,6 +228,14 @@ export class AssetService {
|
||||
|
||||
if (assetsToMove.length === 0) return
|
||||
|
||||
if (newParent.type === AssetType.version_stack) {
|
||||
for (const a of assetsToMove) {
|
||||
if (a.type !== AssetType.file) {
|
||||
throw new Error(`Cannot move ${a.type} asset into a version stack`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let totalSize = 0
|
||||
const oldParentId = assetsToMove[0].parentId
|
||||
if (!oldParentId) {
|
||||
@@ -524,6 +538,10 @@ export class AssetService {
|
||||
assetIds: string[],
|
||||
creatorId?: string,
|
||||
) {
|
||||
if (destFile.type !== AssetType.file) {
|
||||
throw new Error('Destination asset must be a file')
|
||||
}
|
||||
|
||||
if (assetIds.length !== 1) {
|
||||
throw new Error('Can only reparent one file to another file')
|
||||
}
|
||||
@@ -539,6 +557,10 @@ export class AssetService {
|
||||
|
||||
if (!sourceAsset) throw new Error('Source asset not found')
|
||||
|
||||
if (sourceAsset.type !== AssetType.file) {
|
||||
throw new Error('Source asset must be a file to create a version stack')
|
||||
}
|
||||
|
||||
if (!sourceAsset.project || !sourceAsset.project.team) {
|
||||
throw new Error(`Asset ${sourceAsset.id} is not associated with a team`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user