-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw error on user delete when owner of organization
- Loading branch information
1 parent
eb19d87
commit 1ad58a7
Showing
6 changed files
with
43 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { BadRequestException, CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { Request } from 'express'; | ||
import { Types } from 'mongoose'; | ||
import { OrganizationsService } from '../../organizations/organizations.service'; | ||
|
||
@Injectable() | ||
export class NotOrgOwnerGuard implements CanActivate { | ||
constructor(private readonly organizationsService: OrganizationsService) {} | ||
|
||
async canActivate(context: ExecutionContext) { | ||
const request = context.switchToHttp().getRequest<Request>(); | ||
const user = new Types.ObjectId(request.user.id); | ||
|
||
const isOwner = await this.organizationsService.isUserOwnerOfAny(user); | ||
|
||
if (isOwner) { | ||
throw new BadRequestException( | ||
'In order to delete account you must first transfer ownership of ' + | ||
'all organizations that you own.', | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
} |