Skip to content

Commit

Permalink
fixed runtime error when user has not access to a survey (#1847)
Browse files Browse the repository at this point in the history
* fixed runtime error when user has not access to a survey

* code cleanup

* code cleanup

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Oct 12, 2021
1 parent da373cb commit a0ac1b2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions core/auth/authorizer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as R from 'ramda'

import * as Survey from '@core/survey/survey'
import * as Record from '@core/record/record'
import * as User from '@core/user/user'
Expand All @@ -18,10 +16,18 @@ const _getSurveyUserGroup = (user, surveyInfo, defaultToMainGroup = true) => {
return User.getAuthGroupBySurveyUuid({ surveyUuid, defaultToMainGroup })(user)
}

const _hasSurveyPermission = (permission) => (user, surveyInfo) =>
user &&
(User.isSystemAdmin(user) ||
(surveyInfo && R.includes(permission, R.pipe(_getSurveyUserGroup, AuthGroup.getPermissions)(user, surveyInfo))))
const _hasSurveyPermission = (permission) => (user, surveyInfo) => {
if (!user) return false

if (User.isSystemAdmin(user)) return true

if (!surveyInfo) return false

const authGroup = _getSurveyUserGroup(user, surveyInfo)
if (!authGroup) return false

return AuthGroup.getPermissions(authGroup).includes(permission)
}

const _hasPermissionInSomeGroup = (permission) => (user) => {
if (User.isSystemAdmin(user)) return true
Expand Down

0 comments on commit a0ac1b2

Please sign in to comment.