-
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.
Move role check to proper authorization service
- Loading branch information
Showing
5 changed files
with
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { AuthorizationService } from "./authorization.service"; | ||
|
||
@Module({ | ||
providers: [AuthorizationService], | ||
exports: [AuthorizationService], | ||
}) | ||
export class AuthorizationModule {} |
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,26 @@ | ||
import { Injectable, Logger, UnauthorizedException } from "@nestjs/common"; | ||
import { BoltService } from "../bolt/bolt.service"; | ||
import { UserNotFoundException } from "../common/exceptions/user-not-found.exception"; | ||
|
||
@Injectable() | ||
export class AuthorizationService { | ||
logger = new Logger(AuthorizationService.name); | ||
|
||
constructor(private boltService: BoltService) {} | ||
|
||
async requireOwnerRole(userId: string): Promise<void> { | ||
const bolt = this.boltService.getBolt(); | ||
const { user } = await bolt.client.users.info({ user: userId }); | ||
|
||
if (!user) { | ||
throw new UserNotFoundException(); | ||
} | ||
|
||
if (!user.is_owner) { | ||
this.logger.warn( | ||
`User ${userId} tried to access a protected resource requiring workspace owner privileges.`, | ||
); | ||
throw new UnauthorizedException(); | ||
} | ||
} | ||
} |
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,8 @@ | ||
import { HttpStatus } from "@nestjs/common"; | ||
import { KaikuAppException } from "./kaiku-app.exception"; | ||
|
||
export class UserNotFoundException extends KaikuAppException { | ||
constructor() { | ||
super("User was not found in Slack workspace.", HttpStatus.NOT_FOUND); | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
app/src/gui/home-tab/views/settings/office-management/office-management.module.ts
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