Another batch of important updates and fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { getInstanceSetting } = require('../models/helpers')
|
||||
const Entry = require('../models/entry')
|
||||
|
||||
exports.enhanceLocals = async (req, res, next) => {
|
||||
res.locals.portalCode = await getInstanceSetting('portal_code')
|
||||
@@ -12,3 +13,11 @@ exports.adjustHeaders = async (req, res, next) => {
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
exports.setDerivedDictionaryIdFromEntryId = async (req, res, next) => {
|
||||
const { entryId } = req.query
|
||||
const { dictionary_id: dictionaryId } = await Entry.fetch(entryId)
|
||||
req.derivedDictionaryId = dictionaryId
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ user.isDictionaryEditor = (req, res, next) => {
|
||||
}
|
||||
|
||||
user.canAdministrateDictionary = (req, res, next) => {
|
||||
const dictionaryId = req.params.dictionaryId || req.dictionaryId
|
||||
const dictionaryId =
|
||||
req.params.dictionaryId || req.query.dictionaryId || req.dictionaryId
|
||||
const isAdmin = req.user.hasDictionaryRole(dictionaryId, 'administration')
|
||||
const isPortalAdmin = req.user.hasRole('portal admin')
|
||||
const isDictionariesAdmin = req.user.hasRole('dictionaries admin')
|
||||
@@ -73,7 +74,11 @@ user.canAdministrateDictionaries = (req, res, next) => {
|
||||
}
|
||||
|
||||
user.canContentEdit = (req, res, next) => {
|
||||
const { dictionaryId } = req.params
|
||||
const dictionaryId =
|
||||
req.params.dictionaryId ||
|
||||
req.query.dictionaryId ||
|
||||
req.body.dictionaryId ||
|
||||
req.derivedDictionaryId
|
||||
const isEditor = req.user.hasAnyDictionaryRole(dictionaryId)
|
||||
const isPortalAdmin = req.user.hasRole('portal admin')
|
||||
const isDictionariesAdmin = req.user.hasRole('dictionaries admin')
|
||||
|
||||
Reference in New Issue
Block a user