Skip to content

The open alternative to Salesforce, designed for AI.

feat(sdk): let apps set writability on objects and fields (#24255)

Abdul Rahman25fb4df6e380
diff --git a/packages/twenty-docs/developers/extend/apps/data/extending-objects.mdx b/packages/twenty-docs/developers/extend/apps/data/extending-objects.mdx
index 2254998406c..619f14fcbb7 100644
--- a/packages/twenty-docs/developers/extend/apps/data/extending-objects.mdx
+++ b/packages/twenty-docs/developers/extend/apps/data/extending-objects.mdx
@@ -40,6 +40,7 @@ export default defineField({
- When defining fields **inline inside `defineObject()`**, you do **not** need `objectUniversalIdentifier` — it's inherited from the parent object.
- `defineField()` is the only way to add fields to objects you didn't create with `defineObject()`.
- File location is up to you. The convention is `src/fields/<name>.field.ts`, but the SDK detects fields anywhere in `src/`.
+- `writability` can also be set per field: `MetadataWritability.APPLICATION` restricts writes to your app's own logic functions, `MetadataWritability.SYSTEM` is reserved for platform-managed data. A field's writability can only be stricter than its object's level, and reads are unaffected. See [Objects](/developers/extend/apps/data/objects) for the full semantics.
- To add a tab to a standard page layout (e.g. the Task or Company detail page), use [`definePageLayoutTab`](/developers/extend/apps/layout/page-layouts#definepagelayouttab) with `STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS` from `twenty-sdk/define`.
## Adding a relation to an existing object
diff --git a/packages/twenty-docs/developers/extend/apps/data/objects.mdx b/packages/twenty-docs/developers/extend/apps/data/objects.mdx
index 67c9924ef90..5c8bfc5d5d2 100644
--- a/packages/twenty-docs/developers/extend/apps/data/objects.mdx
+++ b/packages/twenty-docs/developers/extend/apps/data/objects.mdx
@@ -80,6 +80,7 @@ export default defineObject({
- Each field requires a `name`, `type`, `label`, and its own stable `universalIdentifier`.
- The `fields` array is optional — you can define objects without custom fields.
- `openRecordIn` sets where records of this object open when clicked: `ObjectOpenRecordIn.USER_CHOICE` (the default, following each workspace member's own preference from Settings → Experience), `ObjectOpenRecordIn.SIDE_PANEL`, or `ObjectOpenRecordIn.RECORD_PAGE`. Pin it to `RECORD_PAGE` for records that need a full page to be usable, the way workflows and dashboards do, or to `SIDE_PANEL` for records that only make sense as a quick panel, the way calendar events do.
+- `writability` controls who may write records of the object at all, before role permissions apply: `MetadataWritability.OPEN` (the default — workspace roles decide), `MetadataWritability.APPLICATION` (only your app's own logic functions can create, update, or delete records; use this for configuration-like objects whose records grant behavior, so workspace members with broad record access cannot edit them through the API), or `MetadataWritability.SYSTEM` (reserved for platform-managed data). Reads are unaffected — this is enforced server-side, unlike `isUIEditable`, which only hides UI affordances. It also exists per field, where it can only be stricter than the object's level.
- Inline fields defined here do **not** need an `objectUniversalIdentifier` — it's inherited from the parent object. Use [`defineField()`](/developers/extend/apps/data/extending-objects) to add fields to objects you don't own.
- You can scaffold new objects with `yarn twenty dev:add object`, which guides you through naming, fields, and relationships. See [Architecture → Scaffolding entities](/developers/extend/apps/getting-started/scaffolding).
diff --git a/packages/twenty-sdk/src/cli/utilities/build/common/plugins/__tests__/__snapshots__/stub-twenty-sdk-define.plugin.spec.ts.snap b/packages/twenty-sdk/src/cli/utilities/build/common/plugins/__tests__/__snapshots__/stub-twenty-sdk-define.plugin.spec.ts.snap
index dfdc9872618..4f037ef294f 100644
--- a/packages/twenty-sdk/src/cli/utilities/build/common/plugins/__tests__/__snapshots__/stub-twenty-sdk-define.plugin.spec.ts.snap
+++ b/packages/twenty-sdk/src/cli/utilities/build/common/plugins/__tests__/__snapshots__/stub-twenty-sdk-define.plugin.spec.ts.snap
@@ -8,6 +8,7 @@ exports[`stub-twenty-sdk-define plugin > matches the recorded export partition 1
"FieldMetadataSettingsOnClickAction",
"FieldType",
"HTTPMethod",
+ "MetadataWritability",
"NavigationMenuItemType",
"NumberDataType",
"ObjectOpenRecordIn",
diff --git a/packages/twenty-sdk/src/sdk/define/index.ts b/packages/twenty-sdk/src/sdk/define/index.ts
index 668d3b2f395..f638bc38553 100644
--- a/packages/twenty-sdk/src/sdk/define/index.ts
+++ b/packages/twenty-sdk/src/sdk/define/index.ts
@@ -189,6 +189,7 @@ export {
DateDisplayFormat,
FieldMetadataSettingsOnClickAction,
HTTPMethod,
+ MetadataWritability,
NavigationMenuItemType,
NumberDataType,
ObjectOpenRecordIn,
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-field-manifest-to-universal-flat-field-metadata.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-field-manifest-to-universal-flat-field-metadata.util.spec.ts
index d5f09cee583..60d07edc800 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-field-manifest-to-universal-flat-field-metadata.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-field-manifest-to-universal-flat-field-metadata.util.spec.ts
@@ -2,6 +2,7 @@ import { type FieldManifest } from 'twenty-shared/application';
import {
type FieldMetadataDefaultActor,
FieldMetadataType,
+ MetadataWritability,
} from 'twenty-shared/types';
import { fromFieldManifestToUniversalFlatFieldMetadata } from 'src/engine/core-modules/application/application-manifest/converters/from-field-manifest-to-universal-flat-field-metadata.util';
@@ -154,4 +155,28 @@ describe('fromFieldManifestToUniversalFlatFieldMetadata', () => {
expect(result.isUIEditable).toBe(true);
});
});
+
+ describe('writability', () => {
+ it('defaults to OPEN when omitted from the manifest', () => {
+ const result = fromFieldManifestToUniversalFlatFieldMetadata({
+ fieldManifest: buildFieldManifest({}),
+ applicationUniversalIdentifier: APP_UID,
+ now: NOW,
+ });
+
+ expect(result.writability).toBe(MetadataWritability.OPEN);
+ });
+
+ it('carries the manifest value through', () => {
+ const result = fromFieldManifestToUniversalFlatFieldMetadata({
+ fieldManifest: buildFieldManifest({
+ writability: MetadataWritability.APPLICATION,
+ }),
+ applicationUniversalIdentifier: APP_UID,
+ now: NOW,
+ });
+
+ expect(result.writability).toBe(MetadataWritability.APPLICATION);
+ });
+ });
});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-object-manifest-to-universal-flat-object-metadata.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-object-manifest-to-universal-flat-object-metadata.util.spec.ts
index 06f3f108070..e919a5cad38 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-object-manifest-to-universal-flat-object-metadata.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-object-manifest-to-universal-flat-object-metadata.util.spec.ts
@@ -1,4 +1,5 @@
import { type ObjectManifest } from 'twenty-shared/application';
+import { MetadataWritability } from 'twenty-shared/types';
import { fromObjectManifestToUniversalFlatObjectMetadata } from 'src/engine/core-modules/application/application-manifest/converters/from-object-manifest-to-universal-flat-object-metadata.util';
@@ -59,4 +60,28 @@ describe('fromObjectManifestToUniversalFlatObjectMetadata', () => {
expect(result.isUIEditable).toBe(true);
});
});
+
+ describe('writability', () => {
+ it('defaults to OPEN when omitted from the manifest', () => {
+ const result = fromObjectManifestToUniversalFlatObjectMetadata({
+ objectManifest: buildObjectManifest({}),
+ applicationUniversalIdentifier: APP_UID,
+ now: NOW,
+ });
+
+ expect(result.writability).toBe(MetadataWritability.OPEN);
+ });
+
+ it('carries the manifest value through', () => {
+ const result = fromObjectManifestToUniversalFlatObjectMetadata({
+ objectManifest: buildObjectManifest({
+ writability: MetadataWritability.APPLICATION,
+ }),
+ applicationUniversalIdentifier: APP_UID,
+ now: NOW,
+ });
+
+ expect(result.writability).toBe(MetadataWritability.APPLICATION);
+ });
+ });
});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-field-manifest-to-universal-flat-field-metadata.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-field-manifest-to-universal-flat-field-metadata.util.ts
index 8e1ced096c2..eea844d90ce 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-field-manifest-to-universal-flat-field-metadata.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-field-manifest-to-universal-flat-field-metadata.util.ts
@@ -93,7 +93,7 @@ export const fromFieldManifestToUniversalFlatFieldMetadata = ({
isSystem: false,
isSystemSideEffect: false,
isUIEditable: fieldManifest.isUIEditable ?? true,
- writability: MetadataWritability.OPEN,
+ writability: fieldManifest.writability ?? MetadataWritability.OPEN,
isNullable: fieldManifest.isNullable ?? true,
isUnique: fieldManifest.isUnique ?? false,
isLabelSyncedWithName: false,
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-object-manifest-to-universal-flat-object-metadata.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-object-manifest-to-universal-flat-object-metadata.util.ts
index eb67f3bed9b..9ad2de5e89d 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-object-manifest-to-universal-flat-object-metadata.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-object-manifest-to-universal-flat-object-metadata.util.ts
@@ -30,7 +30,7 @@ export const fromObjectManifestToUniversalFlatObjectMetadata = ({
isSystem: false,
isUIEditable: objectManifest.isUIEditable ?? true,
isUICreatable: objectManifest.isUICreatable ?? true,
- writability: MetadataWritability.OPEN,
+ writability: objectManifest.writability ?? MetadataWritability.OPEN,
isAuditLogged: true,
isSearchable: objectManifest.isSearchable ?? true,
duplicateCriteria: null,
diff --git a/packages/twenty-shared/src/application/fieldManifestType.ts b/packages/twenty-shared/src/application/fieldManifestType.ts
index 1d93f3f4f97..6bf5fb064c3 100644
--- a/packages/twenty-shared/src/application/fieldManifestType.ts
+++ b/packages/twenty-shared/src/application/fieldManifestType.ts
@@ -4,6 +4,7 @@ import {
type FieldMetadataOptions,
type FieldMetadataType,
type FieldMetadataUniversalSettings,
+ type MetadataWritability,
type RelationAndMorphRelationFieldMetadataType,
} from '@/types';
@@ -21,6 +22,7 @@ type BaseRegularFieldManifest<
options?: FieldMetadataOptions<T>;
universalSettings?: FieldMetadataUniversalSettings<T>;
isUIEditable?: boolean;
+ writability?: MetadataWritability;
isUnique?: boolean;
objectUniversalIdentifier: string;
};
diff --git a/packages/twenty-shared/src/application/objectManifestType.ts b/packages/twenty-shared/src/application/objectManifestType.ts
index a22d64e368d..fe31ef94e10 100644
--- a/packages/twenty-shared/src/application/objectManifestType.ts
+++ b/packages/twenty-shared/src/application/objectManifestType.ts
@@ -1,5 +1,6 @@
import { type ObjectFieldManifest } from '@/application/objectFieldManifest.type';
import { type SyncableEntityOptions } from '@/application/syncableEntityOptionsType';
+import { type MetadataWritability } from '@/types/MetadataWritability';
import { type ObjectOpenRecordIn } from '@/types/ObjectOpenRecordIn';
export type ObjectManifest = SyncableEntityOptions & {
@@ -14,6 +15,7 @@ export type ObjectManifest = SyncableEntityOptions & {
isUICreatable?: boolean;
// When false, records of this object are not editable through the generic UI
isUIEditable?: boolean;
+ writability?: MetadataWritability;
openRecordIn?: ObjectOpenRecordIn;
fields: ObjectFieldManifest[];
labelIdentifierFieldMetadataUniversalIdentifier: string;