Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9297459
feat(spec): move the wall-clock primitive below formula and add worki…
claude Nov 19, 2026
be23d90
wip(platform-objects,objectql): working-calendar objects, service, ho…
claude Nov 19, 2026
64687aa
wip(objectql): calendar service tests
claude Nov 19, 2026
9182347
wip(platform-objects): register the calendar objects in the nav and p…
claude Nov 19, 2026
affaa83
feat(platform-objects): translate the calendar objects, register thei…
claude Nov 19, 2026
ec6245d
fix(objectql,spec): field codes as plain literals, honest test double…
claude Nov 19, 2026
0122d6d
test(cli): the Setup tree pin counts the two working-calendar entries
claude Nov 19, 2026
5810363
Merge origin/main into the working-calendar branch
claude Nov 19, 2026
0d04210
refactor: keep the service, arithmetic and codes here; the objects an…
claude Nov 19, 2026
c3e3d1b
feat(platform-objects): working calendars in Setup — the two calendar…
claude Nov 19, 2026
ad45d08
fix(ui): allow the gantt scheduler's own isWorkingDay and addWorkingD…
claude Nov 19, 2026
320ed52
Merge the service branch's spec-symbol fix into the setup branch
claude Nov 19, 2026
b154176
Merge origin/main into claude/issue-35355-work-calendar-objects-setup
claude Nov 20, 2026
06d62d2
chore: regenerate the tenancy census after merging main
claude Nov 20, 2026
0ca2bf4
feat(plugin-form): a create form opens a required time-zone field on …
claude Nov 20, 2026
5f038a7
fix(platform-objects): calendar help says what the create form does; …
claude Nov 20, 2026
adc0b88
test(rest): the working-calendar objects on a real engine through the…
claude Nov 20, 2026
5a8eb4e
fix(objectql): the other-organization default refusal reads right for…
claude Nov 20, 2026
03fb5f7
docs: the two working-calendar Setup pages; changeset names the pair …
claude Nov 20, 2026
a21b8ad
test(rest): name the calendar code in a const so the error-code casin…
claude Nov 20, 2026
d0339ff
fix(objectql): a calendar that stays the default cannot move to anoth…
claude Nov 20, 2026
5e80649
test(objectql): the calendar move rule's organization_id read gets it…
claude Nov 20, 2026
262cd11
fix(objectql): a calendar and its exception dates stay in their organ…
claude Nov 20, 2026
0ceb0b5
fix(objectql): an exception date names a calendar of its own organiza…
claude Nov 20, 2026
5a02bbf
Merge origin/main into claude/issue-35355-work-calendar-objects-setup
claude Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/35355-working-calendar-objects-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/platform-objects': minor
'@objectstack/spec': patch
'@objectstack/cli': patch
'@objectstack/objectql': patch
'@object-ui/plugin-form': patch
---

feat: working calendars in Setup — `sys_work_calendar` and `sys_work_calendar_exception` (ADR-0157, part two of two)

Clause-②: yes (widening)
Metadata-protocol: added

Not released alone; pair #35641/#35642. The first half, #35641 (the calendar service and its arithmetic), is merged; this half ships in the same release as it, with the working-day formula functions (#35356) and the approval escalation's working-time clock (#35357), ADR-0157 D4.

- **Two platform objects** (`@objectstack/platform-objects`). `sys_work_calendar` holds a calendar's `code` (unique per organization, snake_case), `name`, required IANA `timezone`, `is_default` (one per organization), the required `maintained_from` .. `maintained_through` span its holidays are entered for, and one period column per weekday (`monday_periods` … `sunday_periods`, `HH:mm-HH:mm` periods separated by commas, blank for a day off). `sys_work_calendar_exception` holds dated overrides: `calendar`, `date`, `kind` (`off`, no periods; `on`, that date's full periods), `periods` and `note`, one row per calendar and date. Both are organization data an administrator keeps, audited, like `sys_exchange_rate`; a package may seed rows under the existing seed contract and name a calendar by code. Their names join the platform object name list (`@objectstack/spec`).
- **Setup.** Two entries under Exchange Rates: Working Calendars (with a Needs Maintenance list of every calendar whose maintained span ends within 60 days) and Calendar Exceptions, whose list page imports a year of holidays from a file; the `calendar` column names a calendar by its code or name. Labels and help text ship in all eleven locales.
- **Time zone on create** (`@object-ui/plugin-form`, ADR-0157 D7). A create form opens a required time-zone field that declares no default (`valueDomain: 'iana_time_zone'`) on the organization's time zone, as it opens a record-currency field on the organization's currency; the user can change it. A create that leaves the calendar's `timezone` out takes the same zone on the server. An optional time-zone field, where blank means "take the parent's", is not prefilled.
- **Refusal wording** (`@objectstack/objectql`). The refusal of a create that marks a calendar the default in another organization no longer assumes the writer is working in an organization.
- **A calendar stays in its organization** (`@objectstack/objectql`). An update that changes the organization of a calendar or of an exception date is refused with `400 VALIDATION_FAILED` on `organization_id` (`invalid_value`), before any read and for every writer, system writes included. To have a calendar in another organization, create it there. An edit that leaves `organization_id` out or repeats the stored one is judged as before; a predicate update is judged row by row, and one matched row whose organization would change refuses it.
- **An exception date names a calendar of its own organization** (`@objectstack/objectql`). On a create, and on an update that carries `calendar`, the calendar is read by id in the exception's organization; when it is not there, the write is refused with `400 VALIDATION_FAILED` on `calendar` (`invalid_value`). A calendar of another organization and an id that names no calendar get the same refusal, word for word. The import door is judged the same way, row by row.
- **Organization ownership** (`@objectstack/cli`). Both objects are organization-owned; an exception reaches its organization through its calendar.
13 changes: 12 additions & 1 deletion content/docs/ui/apps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ The Setup app's anchors:
| `group_people_org` | Users, organizations, business units, teams, invitations |
| `group_access_control` | Positions, permission sets, sharing rules, API keys |
| `group_approvals` | Approvals inbox, requests, history, delegations |
| `group_configuration` | Settings, localization, exchange rates, authentication, email, storage, AI, branding |
| `group_configuration` | Settings, localization, exchange rates, working calendars, authentication, email, storage, AI, branding |
| `group_diagnostics` | Sessions, notification events, audit log |
| `group_integrations` | Webhooks, cloud connection |
| `group_advanced` | OAuth applications |
Expand All @@ -899,6 +899,17 @@ of the row's currency, from its effective date until a later row for that curren
add one row per currency with the first day of the month as the effective date; a correction is an edit to that
row, and every change lands in the audit log.

**Working Calendars** (`sys_work_calendar`, after Exchange Rates) holds an organization's working calendars
(ADR-0157): each one's working periods per weekday, in the calendar's time zone; the span its holidays are
entered for (Maintained From to Maintained Through); and whether it is the default, which a calculation that
names no calendar uses. The create form opens with the organization's time zone (Localization → Default
timezone) in the Time Zone field. The **Needs Maintenance** list shows every calendar whose span ends within 60
days, so next year's holidays are entered before they are needed. **Calendar Exceptions**
(`sys_work_calendar_exception`) holds a calendar's dated overrides, one row per calendar and date: a Day Off, or
a Working Day carrying that date's full periods, such as a make-up workday. Its list page imports a year of
holidays from a file whose `calendar` column names the calendar by its code or name. Both pages need a grant on
their object, and every change lands in the audit log.

Setup is for platform administration and needs `setup.access`. For
project-specific administration pages, declare an app of your own.

Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/utils/organization-ownership-inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ export const ORGANIZATION_OWNERSHIP_INVENTORY: readonly InventoryEntry[] = [
// organization's administrators author its own units; the platform ships no
// row, and no parent row anchors a unit.
{ object: 'sys_unit', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
// Working calendars (`@objectstack/platform-objects`, ADR-0157 D1): an
// organization's administrators author its calendars, and an exception's
// calendar carries the organization.
{ object: 'sys_work_calendar', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); ${D10_SINGLE}`, anchors: [] },
{ object: 'sys_work_calendar_exception', census: PMAIN, fate: 'attribution', citation: `${CENSUS_MAIN} (in reach, added since the first census); the exception's calendar carries the organization`, anchors: [parent('calendar', 'sys_work_calendar')] },
// The recycle bin (`@objectstack/platform-objects`, ADR-0148, #30237): the
// engine writes each entry with the organization of the record it holds,
// else the deleting context's. A NULL row comes only from a delete with
Expand Down
13 changes: 8 additions & 5 deletions packages/cli/test/connect-agent-both-halves-wire.pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', (
// The Setup tree the platform admin is served BY THIS COMPOSITION: 9
// authored groups less `group_approvals`, `group_integrations` and
// `group_apps`, which nothing in it contributes into and the filter
// collapses, plus the 24 entries `SETUP_NAV_CONTRIBUTIONS` carries,
// collapses, plus the 27 entries `SETUP_NAV_CONTRIBUTIONS` carries,
// plus the MCP one.
// (25 until #25098 moved the unfiltered Packages entry to Studio; 24
// until #30204 removed the Feature Flags entry with its namespace; 32
Expand All @@ -276,13 +276,16 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', (
// the Packaged Actions entry, `nav_packaged_actions`, the one entry
// `group_apps` held here, so that group collapses too; 31 until the
// Units of Measure entry, `nav_units_of_measure`, joined Configuration
// (#35488).)
// (#35488); 32 until the working-calendar pair, `nav_work_calendars`
// and `nav_work_calendar_exceptions`, joined it, ADR-0157.)
// `nav_settings_branding` is not among them, and not because of a
// tenancy wall (this harness boots none): since #24766 it is
// contributed by `@objectstack/service-settings` together with the
// `branding` namespace, offered only where no organization wall stands,
// and this harness composes platform-objects and the MCP bundle alone.
expect(allowedIds).toHaveLength(32);
expect(allowedIds).toHaveLength(34);
expect(allowedIds).toContain('nav_work_calendars');
expect(allowedIds).toContain('nav_work_calendar_exceptions');
expect(allowedIds).not.toContain('nav_packaged_actions');
expect(allowedIds).toContain('nav_settings_access_policy');
expect(allowedIds).toContain('nav_recycle_bin');
Expand All @@ -309,8 +312,8 @@ describe('#17647 — Connect-an-Agent visibility: BOTH halves, over the wire', (
expect(withAccountHalf.statusCode).toBe(200);
expect(withoutAccountHalf.statusCode).toBe(200);
expect(navIds(withAccountHalf.body?.item)).toEqual(navIds(withoutAccountHalf.body?.item));
// 32: the composition the count in the test above states.
expect(navIds(withAccountHalf.body?.item)).toHaveLength(32);
// 34: the composition the count in the test above states.
expect(navIds(withAccountHalf.body?.item)).toHaveLength(34);

// The mechanism behind the invariance, asserted rather than assumed:
// the bundle aims exactly one contribution at `setup` and one at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ const READERS: Record<string, Row> = {
disposition: 'not-a-read',
why: 'names the column in refusal text',
},
// ADR-0157 D2: a calendar or exception update may not change the row's organization.
'work-calendar-service.ts#refuseOrganizationChange :: organization_id': {
disposition: 'row-value',
why:
'compares the update payload in hand with the stored row the engine passed the hook, and names the column ' +
'in the refusal; it reads no storage, and its objects, sys_work_calendar and sys_work_calendar_exception, ' +
'are platform objects, never federated',
},
'federated-object.ts#isFederatedUnprovisionedInjectedColumn :: isFederatedObject()': {
disposition: 'definition',
why: 'the general predicate',
Expand Down
1 change: 1 addition & 0 deletions packages/objectql/src/work-calendar-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ describe('the calendar objects\' write door (ADR-0157 D2, D7, D10)', () => {
});

it('refuses an off row with periods and an on row without them (D10)', async () => {
await insertCalendar({ id: 'cal_cn' }); // the calendar the rows name, so the CONTROL lands
const insertException = (row: Row) => engine.insert(WORK_CALENDAR_EXCEPTION_OBJECT, row, { context: { isSystem: true } });
const off = await refusal(insertException({ id: 'x1', calendar: 'cal_cn', date: '2026-10-01', kind: 'off', periods: '09:00-12:00' }));
expect(resolveThrownHttpError(off)).toMatchObject({ status: 400, code: 'VALIDATION_FAILED' });
Expand Down
87 changes: 78 additions & 9 deletions packages/objectql/src/work-calendar-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
* one. Judged: the period columns (D7: no period crosses midnight; D10:
* `24:00` is a legal end; `off` carries none, `on` carries its date's full
* periods); `maintained_from` on or before `maintained_through`; one default
* per organization. A create that leaves `timezone` out takes the
* per organization; an exception's calendar is one of its own organization's.
* A create that leaves `timezone` out takes the
* organization's `localization.timezone` (D7), stored as the calendar's own.
*
* The hooks take the organization from the session, every writer's alike: a
Expand All @@ -72,6 +73,26 @@
* calendar's default must therefore load pinned to its organization, or set
* the default by an update afterwards. Such a create without a default passes,
* and gets no time-zone fill.
*
* A calendar, and each of its exception dates, stays in the organization it
* was created in: an update whose `organization_id` differs from the stored
* row's is refused at the door on `organization_id`, before any read, every
* writer's alike, system writes included. To have the calendar in another
* organization, create it there. An update that repeats the stored
* organization is no change and is judged as any other edit. A predicate
* update is judged row by row, as the engine hands the hook each matched row
* with its stored image: one matched row whose organization would change
* refuses the whole write.
*
* An exception date names a calendar of its own organization. On a create,
* and on an update that carries `calendar`, the hooks read the calendar by id
* in the exception's organization (the session's on a create, by the rule
* above; the stored row's on an update) and refuse on `calendar` when none
* comes back. A calendar of another organization and an id that names no
* calendar meet the same refusal, word for word, so it tells a writer nothing
* about any other organization. A create the hooks cannot read for (its row
* names an organization other than the session's, or it has no organization
* outside `single`) is refused the same way: write it under its organization.
*/

import {
Expand Down Expand Up @@ -293,6 +314,12 @@ function periodsRefusal(field: string, value: unknown): FieldRefusal | undefined
return { field, code: 'invalid_value', message, value };
}

/** Where an update's elevated reads run: the stored row's own organization (see the module note). */
function updateReadOrganization(previous: Row, posture: TenancyPosture): ReadScope {
const organizationId = organizationOf(previous.organization_id);
return mayReadIn(organizationId, posture) ? { read: true, organizationId } : { read: false };
}

/**
* Where an insert's elevated reads run: the session's organization (see the
* module note), `read: false` when the hooks make none.
Expand Down Expand Up @@ -351,7 +378,7 @@ async function judgeCalendar(
field: 'is_default',
code: 'invalid_value',
message:
'This calendar is created in an organization other than the one you are working in, so it cannot be marked ' +
'This calendar names an organization this write does not run in, so it cannot be marked ' +
'the default here. Create it while working in that organization, or create it without Default and set ' +
'Default afterwards by editing it.',
value: true,
Expand All @@ -375,6 +402,43 @@ async function judgeCalendar(
if (problems.length > 0) refuse(WORK_CALENDAR_OBJECT, problems);
}

/** The fixed reasons for an update that changes a row's organization (ADR-0157 D2). */
const STAYS_IN_ORGANIZATION: Record<string, string> = {
[WORK_CALENDAR_OBJECT]: 'A calendar stays in the organization it was created in; create it in the other organization instead.',
[WORK_CALENDAR_EXCEPTION_OBJECT]: "An exception date stays in its calendar's organization.",
};

/** Refuse an update that changes the stored row's organization, before any read (see the module note). */
function refuseOrganizationChange(object: string, data: Row, previous: Row): void {
if (!hasOwn(data, 'organization_id')) return;
if (organizationOf(data.organization_id) === organizationOf(previous.organization_id)) return;
refuse(object, [{ field: 'organization_id', code: 'invalid_value', message: STAYS_IN_ORGANIZATION[object]! }]);
}

/** The fixed reason for an exception whose calendar its organization does not hold: no organization, code or id. */
const CALENDAR_OF_OWN_ORGANIZATION = 'An exception date names a calendar of its own organization.';

/**
* Refuse an exception whose `calendar` its own organization does not hold:
* one read by id in `scope`'s organization (see the module note). A blank is
* left to `required`.
*/
async function refuseForeignCalendar(engine: WorkCalendarReadEngine, ctx: any, data: Row, scope: ReadScope): Promise<void> {
if (!hasOwn(data, 'calendar')) return;
const ref = data.calendar;
if (ref === undefined || ref === null || ref === '') return;
if (scope.read && (typeof ref === 'string' || typeof ref === 'number')) {
const held = (await engine.find(WORK_CALENDAR_OBJECT, {
where: { id: String(ref) },
fields: ['id'],
limit: 1,
context: readContext(scope.organizationId, ctx?.transaction),
})).filter(isRow);
if (held.length > 0) return;
}
refuse(WORK_CALENDAR_EXCEPTION_OBJECT, [{ field: 'calendar', code: 'invalid_value', message: CALENDAR_OF_OWN_ORGANIZATION }]);
}

/** Judge an exception row's post-image (ADR-0157 D10) when the write carries its kind or periods. */
function judgeException(data: Row, previous: Row | undefined): void {
if (!hasOwn(data, 'kind') && !hasOwn(data, 'periods')) return;
Expand Down Expand Up @@ -431,18 +495,23 @@ export function installWorkCalendarHooks(
const data = ctx?.input?.data;
const previous = isRow(ctx?.previous) ? ctx.previous : undefined;
if (!isRow(data) || !previous) return;
refuseOrganizationChange(WORK_CALENDAR_OBJECT, data, previous);
// The stored row's own organization: the engine read it under the write's own scope.
const organizationId = organizationOf(previous.organization_id);
const scope: ReadScope = mayReadIn(organizationId, postureNow()) ? { read: true, organizationId } : { read: false };
await judgeCalendar(engine, ctx, data, previous, scope);
await judgeCalendar(engine, ctx, data, previous, updateReadOrganization(previous, postureNow()));
});
bind('beforeInsert', WORK_CALENDAR_EXCEPTION_OBJECT, (ctx: any) => {
bind('beforeInsert', WORK_CALENDAR_EXCEPTION_OBJECT, async (ctx: any) => {
const row = ctx?.input?.data;
if (isRow(row)) judgeException(row, undefined);
if (!isRow(row)) return;
judgeException(row, undefined);
await refuseForeignCalendar(engine, ctx, row, insertReadOrganization(ctx, row, postureNow()));
});
bind('beforeUpdate', WORK_CALENDAR_EXCEPTION_OBJECT, (ctx: any) => {
bind('beforeUpdate', WORK_CALENDAR_EXCEPTION_OBJECT, async (ctx: any) => {
const data = ctx?.input?.data;
if (isRow(data) && isRow(ctx?.previous)) judgeException(data, ctx.previous);
const previous = isRow(ctx?.previous) ? ctx.previous : undefined;
if (!isRow(data) || !previous) return;
refuseOrganizationChange(WORK_CALENDAR_EXCEPTION_OBJECT, data, previous);
judgeException(data, previous);
await refuseForeignCalendar(engine, ctx, data, updateReadOrganization(previous, postureNow()));
});
const both = [WORK_CALENDAR_OBJECT, WORK_CALENDAR_EXCEPTION_OBJECT];
for (const event of ['afterInsert', 'afterUpdate', 'afterDelete']) bind(event, both, () => service.invalidate());
Expand Down
4 changes: 4 additions & 0 deletions packages/platform-objects/scripts/i18n-extract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ import {
SysMigration,
SysExchangeRate,
SysUnit,
SysWorkCalendar,
SysWorkCalendarException,
} from '../src/system/index.js';

// ── Existing Setup app + dashboards + translations ────────────────────────
Expand Down Expand Up @@ -362,6 +364,8 @@ const config: ObjectStackDefinition = defineStack({
SysMigration,
SysExchangeRate,
SysUnit,
SysWorkCalendar,
SysWorkCalendarException,
] as any,

apps: [SETUP_APP, STUDIO_APP, ACCOUNT_APP] as any,
Expand Down
Loading
Loading