Skip to content

Commit c02a2cc

Browse files
authored
Merge pull request #28 from rezo-labs/feature/add_current_user
Add $CURRENT_USER
2 parents 6457b2b + ac91613 commit c02a2cc

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/operations.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jest
88
describe('Test parseExpression', () => {
99
test('Dynamic variables', () => {
1010
expect(parseExpression('$NOW', {})).toStrictEqual(new Date());
11+
expect(parseExpression('$CURRENT_USER', {})).toBe(undefined);
12+
expect(parseExpression('$CURRENT_USER', { __currentUser: 1 })).toBe(1);
1113
});
1214

1315
test('INT op', () => {

src/operations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export function parseExpression(exp: string, values: Record<string, any>): any {
1313
if (exp === '$NOW') {
1414
return new Date();
1515
}
16+
if (exp === '$CURRENT_USER') {
17+
return values.__currentUser;
18+
}
1619

1720
const opMatch = parseOp(exp);
1821
if (opMatch) {

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const useDeepValues = (
5555
template: string
5656
) => {
5757
const api = useApi();
58+
const currentUser = useStores().useUserStore().currentUser.id;
5859
const finalValues = ref<Record<string, any>>({});
5960
let fieldCache: Record<string, any> = {};
6061
let itemCache: Record<string, any> = {};
@@ -189,7 +190,7 @@ export const useDeepValues = (
189190
relationalData[key] = isM2O ? arrayOfData[0] : arrayOfData;
190191
}
191192

192-
finalValues.value = { ...valObj, ...relationalData };
193+
finalValues.value = { ...valObj, ...relationalData, __currentUser: currentUser };
193194
},
194195
{
195196
deep: false,

0 commit comments

Comments
 (0)