Skip to content

Commit 04feb02

Browse files
committed
Refactor UserStamped -> Audited, reference Actors, & change globals to align
1 parent 2ec0eaf commit 04feb02

File tree

11 files changed

+32
-25
lines changed

11 files changed

+32
-25
lines changed

dbschema/common.esdl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module default {
2-
global currentUserId: uuid;
3-
alias currentUser := <User>(global currentUserId);
2+
global currentActorId: uuid;
3+
global currentActor := (select Actor filter .id = global currentActorId);
4+
global currentUser := (select User filter .id = global currentActorId);
45

56
scalar type ReportPeriod extending enum<Monthly, Quarterly>;
67

dbschema/engagement.esdl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ module default {
7676
insert Engagement::DedicationCeremony {
7777
createdAt := datetime_of_statement(),
7878
modifiedAt := datetime_of_statement(),
79-
createdBy := assert_exists(currentUser),
80-
modifiedBy := assert_exists(currentUser),
79+
createdBy := assert_exists(global currentActor),
80+
modifiedBy := assert_exists(global currentActor),
8181
engagement := __new__,
8282
project := __new__.project,
8383
projectContext := __new__.projectContext,
@@ -130,8 +130,8 @@ module default {
130130
insert Engagement::CertificationCeremony {
131131
createdAt := datetime_of_statement(),
132132
modifiedAt := datetime_of_statement(),
133-
createdBy := assert_exists(currentUser),
134-
modifiedBy := assert_exists(currentUser),
133+
createdBy := assert_exists(global currentActor),
134+
modifiedBy := assert_exists(global currentActor),
135135
engagement := __new__,
136136
project := __new__.project,
137137
projectContext := __new__.projectContext,

dbschema/progress-report.esdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module ProgressReport {
7575
};
7676
required who: default::User {
7777
readonly := true;
78-
default := default::currentUser;
78+
default := global default::currentUser;
7979
};
8080
required at: datetime {
8181
readonly := true;

dbschema/project.esdl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module default {
7272
financialReportPeriod: ReportPeriod;
7373

7474
multi link members := .<project[is Project::Member];
75-
single link membership := (select .members filter .user.id = global default::currentUserId limit 1);
75+
single link membership := (select .members filter .user = global default::currentUser limit 1);
7676

7777
# multi link engagements := .<project[is Engagement];
7878
property engagementTotal := count(.<project[is Engagement]);
@@ -106,8 +106,8 @@ module default {
106106
insert default::Budget {
107107
createdAt := datetime_of_statement(),
108108
modifiedAt := datetime_of_statement(),
109-
createdBy := assert_exists(currentUser),
110-
modifiedBy := assert_exists(currentUser),
109+
createdBy := assert_exists(global currentActor),
110+
modifiedBy := assert_exists(global currentActor),
111111
project := __new__,
112112
projectContext := __new__.projectContext,
113113
}

dbschema/prompt-variant-response.esdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Prompt {
66
responses := .<pvr[is VariantResponse];
77
}
88

9-
type VariantResponse extending Mixin::UserStamped, Mixin::Timestamped {
9+
type VariantResponse extending Mixin::Audited {
1010
annotation description := "A response (for a variant) to an instance of a prompt.";
1111

1212
required pvr: PromptVariantResponse;

dbschema/resource.esdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module default {
2-
abstract type Resource extending Mixin::UserStamped, Mixin::Timestamped;
2+
abstract type Resource extending Mixin::Audited;
33
}

dbschema/z.pinnable.esdl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Mixin {
22
abstract type Pinnable {
3-
property pinned := __source__ in (<default::User>global default::currentUserId).pins;
3+
property pinned := (
4+
with user := (select default::User filter .id = global default::currentActorId)
5+
select __source__ in user.pins
6+
);
47
};
58
};

dbschema/z.stamped.esdl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module Mixin {
2-
abstract type UserStamped {
3-
required createdBy: default::User {
2+
abstract type Audited extending Timestamped {
3+
required createdBy: default::Actor {
44
readonly := true;
5-
default := default::currentUser;
5+
default := global default::currentActor;
66
};
7-
required modifiedBy: default::User {
8-
default := default::currentUser;
9-
rewrite update using (default::currentUser);
7+
required modifiedBy: default::Actor {
8+
default := global default::currentActor;
9+
rewrite update using (global default::currentActor);
1010
};
1111

12-
required isCreator := .createdBy ?= <default::User>(global default::currentUserId)
12+
required isCreator := .createdBy ?= global default::currentActor;
1313
}
1414

1515
abstract type Timestamped {

src/components/authentication/current-user.provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ export class EdgeDBCurrentUserProvider
7272
) {
7373
// TODO temporarily check if UUID before applying global.
7474
// Once migration is complete this can be removed.
75-
const currentUserId =
75+
const currentActorId =
7676
session?.userId && isUUID(session.userId) ? session.userId : undefined;
7777
optionsHolder.next((options) =>
78-
currentUserId ? options.withGlobals({ currentUserId }) : options,
78+
currentActorId ? options.withGlobals({ currentActorId }) : options,
7979
);
8080
}
8181
}

src/components/authorization/policies/conditions/self.condition.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { inspect, InspectOptionsStylized } from 'util';
33
import { User } from '../../../user/dto';
44
import {
55
AsCypherParams,
6+
AsEdgeQLParams,
67
Condition,
8+
fqnRelativeTo,
79
IsAllowedParams,
810
} from '../../policy/conditions';
911

@@ -40,8 +42,9 @@ class SelfCondition<TResourceStatic extends typeof User>
4042
return `node:User AND node.id = ${requester}`;
4143
}
4244

43-
asEdgeQLCondition() {
44-
return '.id ?= global default::currentUserId';
45+
asEdgeQLCondition({ namespace }: AsEdgeQLParams<any>) {
46+
const currentId = fqnRelativeTo('default::currentActorId', namespace);
47+
return `.id ?= global ${currentId}`;
4548
}
4649

4750
union(this: void, conditions: this[]) {

0 commit comments

Comments
 (0)