Skip to content

Commit bfdb84c

Browse files
committed
Add new permission
1 parent cad391d commit bfdb84c

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

app/lib/organization.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@ async function isMemberOrStaff (organizationId, osmId) {
265265
return result.length > 0
266266
}
267267

268+
/**
269+
* Checks if an osmId is a moderator of any team inside the org
270+
* @param {int} organizationId - organization id
271+
* @param {int} osmId - id of member we are testing
272+
*/
273+
async function isOrgTeamModerator (organizationId, osmId) {
274+
if (!organizationId) throw new PropertyRequiredError('organization id')
275+
if (!osmId) throw new PropertyRequiredError('osm id')
276+
const conn = await db()
277+
const subquery = conn('organization_team').select('team_id').where('organization_id', organizationId)
278+
const isModeratorOfAny = await conn('moderator').whereIn('team_id', subquery).debug()
279+
return isModeratorOfAny.length > 0
280+
}
281+
268282
/**
269283
* Checks if the osm user is an owner of a team
270284
* @param {int} organizationId - organization id
@@ -350,6 +364,7 @@ module.exports = {
350364
isOwner,
351365
isManager,
352366
isMember,
367+
isOrgTeamModerator,
353368
createOrgTeam,
354369
listMyOrganizations,
355370
getOrgStaff,

app/manage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function manageRouter (nextApp) {
221221
router.get('/api/profiles/keys/organizations/:id', can('organization:edit'), getProfileKeys('org', 'org'))
222222
router.post('/api/profiles/keys/organizations/:id', can('organization:edit'), createProfileKeys('org', 'org'))
223223

224-
router.get('/api/profiles/keys/organizations/:id/teams', can('organization:edit'), getProfileKeys('org', 'team'))
224+
router.get('/api/profiles/keys/organizations/:id/teams', can('organization:view-team-keys'), getProfileKeys('org', 'team'))
225225
router.post('/api/profiles/keys/organizations/:id/teams', can('organization:edit'), createProfileKeys('org', 'team'))
226226

227227
router.get('/api/profiles/keys/organizations/:id/users', can('organization:member'), getProfileKeys('org', 'user'))

app/manage/permissions/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const organizationPermissions = {
2626
'organization:edit': require('./edit-org'),
2727
'organization:create-team': require('./create-org-team'),
2828
'organization:member': require('./member-org'),
29-
'organization:view-members': require('./view-org-members')
29+
'organization:view-members': require('./view-org-members'),
30+
'organization:view-team-keys': require('./view-org-team-keys')
3031
}
3132

3233
const clientPermissions = {

0 commit comments

Comments
 (0)