Skip to content

Commit

Permalink
feat: k1ch/ introduce clients/client_id/roles?includePermissions=true
Browse files Browse the repository at this point in the history
  • Loading branch information
k1ch committed Oct 9, 2024
1 parent c37becb commit 9cf122a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions database/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion database/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dmgt-tech/the-usher-server-database",
"version": "2.3.0-rc.3",
"version": "2.3.0-rc.4",
"description": "Database layer for TheUsher",
"scripts": {
"test": "mocha --exit",
Expand Down
6 changes: 3 additions & 3 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dmgt-tech/the-usher-server",
"version": "2.3.0-rc.3",
"version": "2.3.0-rc.4",
"description": "The Usher Authorization Server",
"engines": {
"node": ">=18"
Expand Down
36 changes: 23 additions & 13 deletions server/src/api_endpoints/clients/roles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const createError = require('http-errors')
const dbAdminRole = require('database/layer/admin-role')

module.exports = {
listClientRoles,
createClientRole
}
const dbAdminRoles = require('database/layer/admin-role')
const dbAdminPermissions = require('database/layer/admin-permission')

/**
* Client Admin function to get a list of Roles for given Client
Expand All @@ -13,11 +9,20 @@ module.exports = {
* @param {*} res
* @param {*} next
*/
async function listClientRoles (req, res, next) {
const clientId = req.params.client_id

const roles = await dbAdminRole.listRoles(clientId)
res.status(200).send({ data: roles })
const listClientRoles = async (req, res, next) => {
try {
const { client_id: clientId } = req.params
const { includePermissions } = req.query
const roles = await dbAdminRoles.listRoles(clientId)
if (includePermissions === 'true') {
for (const role of roles) {
role.permissions = await dbAdminPermissions.getPermissionsByRoleKey(role.key)
}
}
res.status(200).send({ data: roles })
} catch ({ httpStatusCode = 500, message }) {
return next(createError(httpStatusCode, { message }))
}
}

/**
Expand All @@ -27,15 +32,20 @@ async function listClientRoles (req, res, next) {
* @param {*} res
* @param {*} next
*/
async function createClientRole (req, res, next) {
const createClientRole = async (req, res, next) => {
const clientId = req.params.client_id
const name = req.body.name
const description = req.body.description

try {
const role = await dbAdminRole.insertRoleByClientId(clientId, name, description)
const role = await dbAdminRoles.insertRoleByClientId(clientId, name, description)
res.status(201).send(role)
} catch (err) {
return next(createError(500, err))
}
}

module.exports = {
listClientRoles,
createClientRole,
}
8 changes: 8 additions & 0 deletions server/the-usher-openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,16 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/CollectionOfRoles'
400:
$ref: '#/components/responses/BadRequest'
401:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
500:
$ref: '#/components/responses/InternalError'
503:
$ref: '#/components/responses/ServiceUnavailableError'
post:
'x-swagger-router-controller': 'clients/roles'
operationId: createClientRole
Expand Down

0 comments on commit 9cf122a

Please sign in to comment.