mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
feat(base): guard system-source/primary type changes; allow rename mid-conversion
This commit is contained in:
@@ -198,9 +198,13 @@ export class BasePropertyService {
|
|||||||
await this.ensureNameUnique(dto.pageId, dto.name, dto.propertyId);
|
await this.ensureNameUnique(dto.pageId, dto.name, dto.propertyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block concurrent type changes — the worker still owns the previous
|
// Block competing type / typeOptions edits — the worker still owns
|
||||||
// conversion, and letting a second one through would race on `type`.
|
// the previous conversion. A name-only rename is safe and passes
|
||||||
if (property.pendingType) {
|
// through; it doesn't touch the type/cells the worker is rewriting.
|
||||||
|
if (
|
||||||
|
property.pendingType &&
|
||||||
|
(dto.type !== undefined || dto.typeOptions !== undefined)
|
||||||
|
) {
|
||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
'A type conversion is already in progress for this property',
|
'A type conversion is already in progress for this property',
|
||||||
);
|
);
|
||||||
@@ -211,6 +215,19 @@ export class BasePropertyService {
|
|||||||
const oldTypeOptions = property.typeOptions;
|
const oldTypeOptions = property.typeOptions;
|
||||||
const newType = (dto.type ?? property.type) as BasePropertyTypeValue;
|
const newType = (dto.type ?? property.type) as BasePropertyTypeValue;
|
||||||
|
|
||||||
|
if (isTypeChange && isSystemPropertyType(oldType)) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Cannot change the type of a system property',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isTypeChange &&
|
||||||
|
property.isPrimary &&
|
||||||
|
newType !== BasePropertyType.TEXT
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('The primary property must be text');
|
||||||
|
}
|
||||||
|
|
||||||
// --- Formula-specific type-option compilation ---------------------------
|
// --- Formula-specific type-option compilation ---------------------------
|
||||||
// If the update is a formula (either staying a formula and editing source,
|
// If the update is a formula (either staying a formula and editing source,
|
||||||
// or converting TO formula), compile the source, cycle-check, and replace
|
// or converting TO formula), compile the source, cycle-check, and replace
|
||||||
@@ -500,6 +517,12 @@ export class BasePropertyService {
|
|||||||
throw new BadRequestException('Cannot delete the primary property');
|
throw new BadRequestException('Cannot delete the primary property');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property.pendingType) {
|
||||||
|
throw new ConflictException(
|
||||||
|
'Cannot delete a property while a type conversion is in progress',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Compute dependents BEFORE the delete — once soft-deleted the graph
|
// Compute dependents BEFORE the delete — once soft-deleted the graph
|
||||||
// wouldn't include them.
|
// wouldn't include them.
|
||||||
const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
|
const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
|
||||||
|
|||||||
Reference in New Issue
Block a user