[team] add "basic" permissions

This commit is contained in:
Avris 2021-08-11 12:23:29 +02:00
parent 04b0d062d1
commit 8f51cda81e
6 changed files with 12 additions and 11 deletions

View File

@ -38,6 +38,7 @@
allLocales, allLocales,
allAreas: [ allAreas: [
'*', '*',
'basic',
'panel', 'panel',
'users', 'users',
'sources', 'sources',

View File

@ -12,7 +12,7 @@ export default ({app, store}) => {
} }
Vue.prototype.$user = _ => store.state.user; Vue.prototype.$user = _ => store.state.user;
Vue.prototype.$isGranted = (area) => { Vue.prototype.$isGranted = (area = '') => {
return store.state.user && store.state.user.authenticated && isGranted(store.state.user, config.locale, area); return store.state.user && store.state.user.authenticated && isGranted(store.state.user, config.locale, area);
} }
} }

View File

@ -15,7 +15,7 @@
</div> </div>
<form @submit.prevent="save" :class="[saving ? 'saving' : '']"> <form @submit.prevent="save" :class="[saving ? 'saving' : '']">
<div v-if="$isGranted('users')" class="border border-primary rounded p-4"> <div v-if="$isGranted()" class="border border-primary rounded p-4">
<h3 class="h4 mb-3"> <h3 class="h4 mb-3">
<Icon v="user-cog"/> <Icon v="user-cog"/>
Admin section Admin section

View File

@ -62,7 +62,7 @@ app.use(async function (req, res, next) {
try { try {
req.rawUser = authenticate(req); req.rawUser = authenticate(req);
req.user = req.rawUser && req.rawUser.authenticated ? req.rawUser : null; req.user = req.rawUser && req.rawUser.authenticated ? req.rawUser : null;
req.isGranted = (area, locale = global.config.locale) => req.user && isGranted(req.user, locale, area); req.isGranted = (area = '', locale = global.config.locale) => req.user && isGranted(req.user, locale, area);
req.db = new LazyDatabase(); req.db = new LazyDatabase();
res.on('finish', async () => { res.on('finish', async () => {
await req.db.close(); await req.db.close();

View File

@ -144,9 +144,9 @@ router.post('/profile/save', handleErrorAsync(async (req, res) => {
flags = ${JSON.stringify(req.body.flags)}, flags = ${JSON.stringify(req.body.flags)},
customFlags = ${JSON.stringify(req.body.customFlags)}, customFlags = ${JSON.stringify(req.body.customFlags)},
words = ${JSON.stringify(req.body.words)}, words = ${JSON.stringify(req.body.words)},
teamName = ${req.isGranted('users') ? req.body.teamName || null : ''}, teamName = ${req.isGranted() ? req.body.teamName || null : ''},
footerName = ${req.isGranted('users') ? req.body.footerName || null : ''}, footerName = ${req.isGranted() ? req.body.footerName || null : ''},
footerAreas = ${req.isGranted('users') ? req.body.footerAreas.join(',') || null : ''}, footerAreas = ${req.isGranted() ? req.body.footerAreas.join(',') || null : ''},
card = NULL card = NULL
WHERE id = ${ids[0]} WHERE id = ${ids[0]}
`); `);
@ -155,9 +155,9 @@ router.post('/profile/save', handleErrorAsync(async (req, res) => {
VALUES (${ulid()}, ${req.user.id}, ${global.config.locale}, ${JSON.stringify(req.body.names)}, ${JSON.stringify(req.body.pronouns)}, VALUES (${ulid()}, ${req.user.id}, ${global.config.locale}, ${JSON.stringify(req.body.names)}, ${JSON.stringify(req.body.pronouns)},
${req.body.description}, ${req.body.birthday || null}, ${JSON.stringify(req.body.links.filter(x => !!x))}, ${JSON.stringify(req.body.flags)}, ${JSON.stringify(req.body.customFlags)}, ${req.body.description}, ${req.body.birthday || null}, ${JSON.stringify(req.body.links.filter(x => !!x))}, ${JSON.stringify(req.body.flags)}, ${JSON.stringify(req.body.customFlags)},
${JSON.stringify(req.body.words)}, 1, ${JSON.stringify(req.body.words)}, 1,
${req.isGranted('users') ? req.body.teamName || null : ''}, ${req.isGranted() ? req.body.teamName || null : ''},
${req.isGranted('users') ? req.body.footerName || null : ''}, ${req.isGranted() ? req.body.footerName || null : ''},
${req.isGranted('users') ? req.body.footerAreas.join(',') || null : ''} ${req.isGranted() ? req.body.footerAreas.join(',') || null : ''}
)`); )`);
} }

View File

@ -173,7 +173,7 @@ export const shuffle = a => {
return a; return a;
} }
export const isGranted = (user, locale, area) => { export const isGranted = (user, locale, area = '') => {
if (area === '*') { if (area === '*') {
return user.roles.split('|').includes('*'); return user.roles.split('|').includes('*');
} }
@ -183,7 +183,7 @@ export const isGranted = (user, locale, area) => {
return true; return true;
} }
const [ permissionLocale, permissionArea ] = permission.split('-'); const [ permissionLocale, permissionArea ] = permission.split('-');
if ((permissionLocale === '*' || permissionLocale === locale) && (permissionArea === '*' || permissionArea === area)) { if ((permissionLocale === '*' || permissionLocale === locale) && (permissionArea === '*' || permissionArea === area || area === '')) {
return true; return true;
} }
} }