-
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.
[front] ♻️ refactor: view by role permission
- Loading branch information
1 parent
c92c684
commit 7f3e455
Showing
23 changed files
with
160 additions
and
93 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
apps/server/src/api/controllers/auth/get-permissions-controller.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,13 @@ | ||
import type { IHttp } from '@stocker/core/interfaces' | ||
import { HTTP_STATUS_CODE } from '@stocker/core/constants' | ||
|
||
import { companiesRepository } from '@/database' | ||
import { User } from '@stocker/core/entities' | ||
|
||
export class GetPermissionsController { | ||
async handle(http: IHttp) { | ||
const user = User.create(await http.getUser()) | ||
const role = await companiesRepository.findRoleById(user.role, user.companyId) | ||
return http.send(role?.permissions, HTTP_STATUS_CODE.ok) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -143,12 +143,12 @@ export async function seed() { | |
) | ||
|
||
const fakeUsers = UsersFaker.fakeMany(10, { | ||
role: RolesFaker.fake({ name: 'employee' }), | ||
role: 'employee', | ||
companyId: fakeCompany.id, | ||
}) | ||
fakeUsers.push( | ||
UsersFaker.fake({ | ||
role: RolesFaker.fake({ name: 'admin' }), | ||
role: 'admin', | ||
companyId: fakeCompany.id, | ||
email: '[email protected]', | ||
password: await new CryptoProvider().hash('stocker123'), | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { getCookieAction } from './get-cookie-action' | ||
export { setCookieAction } from './set-cookie-action' | ||
export { deleteCookieAction } from './delete-cookie-action' | ||
export { verifyUserRoleAction } from './verify-user-role-action' | ||
export { verifyRolePermissionAction } from './verify-role-permission-action' |
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,14 @@ | ||
'use server' | ||
|
||
import { NextServerApiClient } from '@/api/next/clients/next-server-api-client' | ||
import { AuthService } from '@/api/services' | ||
import type { RolePermission } from '@stocker/core/types' | ||
|
||
export async function verifyRolePermissionAction(permission: RolePermission) { | ||
const apiClient = await NextServerApiClient({ isCacheEnabled: false }) | ||
const authService = AuthService(apiClient) | ||
const response = await authService.getPermissions() | ||
if (response.isFailure) response.throwError() | ||
|
||
return response.body.includes(permission) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
2 changes: 2 additions & 0 deletions
2
apps/web/src/ui/components/contexts/auth-context/types/auth-context-value.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
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.