-
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.
- Loading branch information
1 parent
079f4f9
commit 01e059d
Showing
11 changed files
with
172 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { yarsService } from '../services'; | ||
|
||
import type { NextFunction, Request, Response } from '../interfaces/IExpress'; | ||
|
||
const controller = { | ||
getPermissions: async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const roles = await yarsService.getIdentityRoles((req.currentUser?.tokenPayload as any).preferred_username); | ||
|
||
const permissions = await Promise.all(roles.map((x) => yarsService.getRolePermissions(x.roleId))).then((x) => | ||
x.flat() | ||
); | ||
|
||
res.status(200).json(permissions); | ||
} catch (e: unknown) { | ||
next(e); | ||
} | ||
} | ||
}; | ||
|
||
export default controller; |
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,15 @@ | ||
import express from 'express'; | ||
|
||
import { yarsController } from '../../controllers'; | ||
import { requireSomeAuth } from '../../middleware/requireSomeAuth'; | ||
|
||
import type { NextFunction, Request, Response } from '../../interfaces/IExpress'; | ||
|
||
const router = express.Router(); | ||
router.use(requireSomeAuth); | ||
|
||
router.get('/permissions', (req: Request, res: Response, next: NextFunction): void => { | ||
yarsController.getPermissions(req, res, next); | ||
}); | ||
|
||
export default router; |
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,11 @@ | ||
import { appAxios } from './interceptors'; | ||
|
||
import type { AxiosResponse } from 'axios'; | ||
|
||
const PATH = 'yars'; | ||
|
||
export default { | ||
getPermissions(): Promise<AxiosResponse> { | ||
return appAxios().get(`${PATH}/permissions`); | ||
} | ||
}; |
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,43 @@ | ||
import { defineStore } from 'pinia'; | ||
import { computed, readonly, ref } from 'vue'; | ||
|
||
import type { Ref } from 'vue'; | ||
|
||
export type PermissionStoreState = { | ||
permissions: Ref<Array<any>>; | ||
}; | ||
|
||
export const usePermissionStore = defineStore('permission', () => { | ||
// State | ||
const state: PermissionStoreState = { | ||
permissions: ref([]) | ||
}; | ||
|
||
// Getters | ||
const getters = { | ||
can: computed( | ||
() => (initiative: string, resource: string, action: string) => | ||
state.permissions.value.find( | ||
(x) => x.initiative === initiative && x.resource === resource && x.action === action | ||
) | ||
) | ||
}; | ||
|
||
// Actions | ||
function setPermissions(data: any) { | ||
state.permissions.value = data; | ||
} | ||
|
||
return { | ||
// State | ||
state: readonly(state), | ||
|
||
// Getters | ||
...getters, | ||
|
||
// Actions | ||
setPermissions | ||
}; | ||
}); | ||
|
||
export default usePermissionStore; |
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