Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit db7a856

Browse files
#31 - Support non admin roles
1 parent 2d9ca31 commit db7a856

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/common/es-helper.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,11 @@ async function searchElasticSearch (resource, ...args) {
10421042
}
10431043

10441044
// for non-admin, only return entities that the user created
1045-
if (authUser.roles && !checkIfExists(authUser.roles, [appConst.UserRoles.admin, appConst.UserRoles.administrator])) {
1045+
if (
1046+
authUser.roles &&
1047+
!checkIfExists(authUser.roles, appConst.AdminUser) &&
1048+
!checkIfExists(authUser.roles, [appConst.UserRoles.ubahn])
1049+
) {
10461050
setFilterValueToEsQuery(esQuery, 'createdBy', getAuthUser(authUser), 'createdBy')
10471051
}
10481052

@@ -1197,7 +1201,11 @@ async function searchUsers (authUser, filter, params) {
11971201
}
11981202

11991203
// for non-admin, only return entities that the user created
1200-
if (authUser.roles && !checkIfExists(authUser.roles, [appConst.UserRoles.admin, appConst.UserRoles.administrator])) {
1204+
if (
1205+
authUser.roles &&
1206+
!checkIfExists(authUser.roles, appConst.AdminUser) &&
1207+
!checkIfExists(authUser.roles, [appConst.UserRoles.ubahn])
1208+
) {
12011209
setFilterValueToEsQuery(esQuery, 'createdBy', getAuthUser(authUser), 'createdBy')
12021210
}
12031211

src/common/service-helper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ function getServiceMethods (Model, createSchema, patchSchema, searchSchema, buil
267267

268268
// user token
269269
// for non-admin users, this endpoint will only return entities that the user has created.
270-
if (auth.roles && !checkIfExists(auth.roles, [appConst.UserRoles.admin, appConst.UserRoles.administrator])) {
270+
if (
271+
auth.roles &&
272+
!checkIfExists(auth.roles, appConst.AdminUser) &&
273+
!checkIfExists(auth.roles, [appConst.UserRoles.ubahn])
274+
) {
271275
dbQueries.push(`${Model.tableName}.createdBy = '${getAuthUser(auth)}'`)
272276
}
273277
const items = await models.DBHelper.find(Model, dbQueries)

0 commit comments

Comments
 (0)