feat: I can delete my account easily (#977)
* Add support for account deletion Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Add more fixes Co-authored-by: Benjamin Mayanja <vibenjamin6@gmail.com> * Add more fixes Co-authored-by: v1b3m <vibenjamin6@gmail.com> --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com>
This commit is contained in:
@ -59,7 +59,7 @@ export class AbilityFactory {
|
||||
},
|
||||
});
|
||||
can(AbilityAction.Update, 'User', { id: user.id });
|
||||
cannot(AbilityAction.Delete, 'User');
|
||||
can(AbilityAction.Delete, 'User', { id: user.id });
|
||||
|
||||
// Workspace
|
||||
can(AbilityAction.Read, 'Workspace');
|
||||
|
||||
@ -65,6 +65,7 @@ export class UpdateUserAbilityHandler implements IAbilityHandler {
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<UserArgs>();
|
||||
// TODO: Confirm if this is correct
|
||||
const user = await this.prismaService.client.user.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
@ -92,8 +93,14 @@ export class DeleteUserAbilityHandler implements IAbilityHandler {
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<UserArgs>();
|
||||
|
||||
// obtain the auth user from the context
|
||||
const reqUser = gqlContext.getContext().req.user;
|
||||
|
||||
// FIXME: When `args.where` is undefined(which it is in almost all the cases I've tested),
|
||||
// this query will return the first user entry in the DB, which is most likely not the current user
|
||||
const user = await this.prismaService.client.user.findFirst({
|
||||
where: args.where,
|
||||
where: { ...args.where, id: reqUser.user.id },
|
||||
});
|
||||
assert(user, '', NotFoundException);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user