-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
552 additions
and
366 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
9 changes: 9 additions & 0 deletions
9
packages/backend/src/auth/decorators/current-structure.decorator.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createParamDecorator, ExecutionContext } from "@nestjs/common"; | ||
import { Structure } from "@domifa/common"; | ||
|
||
export const CurrentStructure = createParamDecorator( | ||
(_data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.structure as Structure; | ||
} | ||
); |
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
56 changes: 56 additions & 0 deletions
56
packages/backend/src/auth/guards/structure-access.guard.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
HttpException, | ||
HttpStatus, | ||
Injectable, | ||
} from "@nestjs/common"; | ||
|
||
import { appLogger } from "../../util"; | ||
import { structureRepository } from "../../database"; | ||
|
||
@Injectable() | ||
export class StructureAccessGuard implements CanActivate { | ||
public async canActivate(context: ExecutionContext) { | ||
const r = context.switchToHttp().getRequest(); | ||
|
||
console.log(r?.params?.structureId); | ||
console.log(r?.user?.isSuperAdminDomifa); | ||
if (!r?.params?.structureId || !r?.user?.isSuperAdminDomifa) { | ||
appLogger.error("[StructureAccessGuard] invalid structureId for admin", { | ||
sentry: true, | ||
context: { | ||
usagerRef: r?.params?.uui, | ||
structureId: r?.user?.structureId, | ||
user: r?.user?._id, | ||
}, | ||
}); | ||
throw new HttpException( | ||
"STRUCTURE_INFORMATION_NOT_FOUND", | ||
HttpStatus.BAD_REQUEST | ||
); | ||
} | ||
|
||
const structureId = parseInt(r.params.structureId, 10); | ||
|
||
try { | ||
const structure = await structureRepository.findOneOrFail({ | ||
where: { | ||
id: structureId, | ||
}, | ||
}); | ||
r.structure = structure; | ||
return r; | ||
} catch (e) { | ||
appLogger.error("[UsagerAccessGuard] Structure not found", { | ||
sentry: true, | ||
context: { | ||
structureId, | ||
user: r?.user?._id, | ||
role: r?.user?.role, | ||
}, | ||
}); | ||
throw new HttpException("USAGER_NOT_FOUND", HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.