Browse Source

add me abac

pull/1660/head
Bernd Storath 6 months ago
parent
commit
290bf07faf
  1. 3
      src/server/api/me/index.post.ts
  2. 3
      src/server/api/me/password.post.ts
  3. 10
      src/shared/utils/permissions.ts

3
src/server/api/me/index.post.ts

@ -1,7 +1,8 @@
import { UserUpdateSchema } from '#db/repositories/user/types'; import { UserUpdateSchema } from '#db/repositories/user/types';
export default definePermissionEventHandler( export default definePermissionEventHandler(
actions.CLIENT, 'me',
'update',
async ({ event, user }) => { async ({ event, user }) => {
const { name, email } = await readValidatedBody( const { name, email } = await readValidatedBody(
event, event,

3
src/server/api/me/password.post.ts

@ -1,7 +1,8 @@
import { UserUpdatePasswordSchema } from '#db/repositories/user/types'; import { UserUpdatePasswordSchema } from '#db/repositories/user/types';
export default definePermissionEventHandler( export default definePermissionEventHandler(
actions.CLIENT, 'me',
'update',
async ({ event, user }) => { async ({ event, user }) => {
const { newPassword, currentPassword } = await readValidatedBody( const { newPassword, currentPassword } = await readValidatedBody(
event, event,

10
src/shared/utils/permissions.ts

@ -47,6 +47,10 @@ export type Permissions = {
dataType: never; dataType: never;
action: 'any'; action: 'any';
}; };
me: {
dataType: UserType;
action: 'update';
};
}; };
export const ROLES = { export const ROLES = {
@ -61,6 +65,9 @@ export const ROLES = {
admin: { admin: {
any: true, any: true,
}, },
me: {
update: (loggedIn, toChange) => loggedIn.id === toChange.id,
},
}, },
CLIENT: { CLIENT: {
clients: { clients: {
@ -73,6 +80,9 @@ export const ROLES = {
admin: { admin: {
any: false, any: false,
}, },
me: {
update: (loggedIn, toChange) => loggedIn.id === toChange.id,
},
}, },
} as const satisfies RolesWithPermissions; } as const satisfies RolesWithPermissions;

Loading…
Cancel
Save