-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support builder service account
- Loading branch information
viet nguyen
committed
May 17, 2023
1 parent
6489fbb
commit 217be20
Showing
6 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
import { rule } from 'graphql-shield' | ||
import muuid from 'uuid-mongodb' | ||
|
||
export const isEditor = rule()(async (parent, args, ctx, info) => { | ||
return (ctx.user.uuid != null) && ctx.user.roles.includes('editor') | ||
return _hasUserUuid(ctx) && ctx.user.roles.includes('editor') | ||
}) | ||
|
||
export const isUserAdmin = rule()(async (parent, args, ctx, info) => { | ||
return (ctx.user.uuid != null) && ctx.user.roles.includes('user_admin') | ||
return _hasUserUuid(ctx) && ctx.user.roles.includes('user_admin') | ||
}) | ||
|
||
export const isOwner = rule()(async (parent, args, ctx, info) => { | ||
return _hasUserUuid(ctx) && ctx.user.uuid === muuid.from(args.userUuid) | ||
}) | ||
|
||
export const isBuilderServiceAccount = rule()(async (parent, args, ctx: Context, info) => { | ||
return _hasUserUuid(ctx) && ctx.user.isBuilder | ||
}) | ||
|
||
interface Context { | ||
user: { | ||
uuid?: string | ||
isBuilder: boolean | ||
} | ||
} | ||
|
||
const _hasUserUuid = (ctx: Context): boolean => ctx.user.uuid != null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters