This commit is contained in:
@@ -262,6 +262,24 @@ export const unassign = mutation({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Owner check — true for the bootstrap admin flag (isAdmin) AND for
|
||||
* anyone bearing the reserved "Owner" role. Exposed as a query so
|
||||
* the UI can gate destructive "whole-server" actions (Danger Zone)
|
||||
* behind owner-only visibility without duplicating the rule.
|
||||
*/
|
||||
export const isOwner = query({
|
||||
args: { userId: v.id("userProfiles") },
|
||||
returns: v.boolean(),
|
||||
handler: async (ctx, args) => {
|
||||
const user = await ctx.db.get(args.userId);
|
||||
if (!user) return false;
|
||||
if (user.isAdmin) return true;
|
||||
const roles = await getRolesForUser(ctx, args.userId);
|
||||
return roles.some((r) => r.name === "Owner");
|
||||
},
|
||||
});
|
||||
|
||||
// Get current user's aggregated permissions
|
||||
export const getMyPermissions = query({
|
||||
args: { userId: v.id("userProfiles") },
|
||||
|
||||
Reference in New Issue
Block a user