2020-12-30 15:03:30 -08:00
|
|
|
<template>
|
|
|
|
<form v-if="$isGranted('*')">
|
|
|
|
<ListInput v-model="roles" v-slot="s" :prototype="{locale: config.locale, area: '*'}">
|
|
|
|
<select v-model="s.val.locale" class="form-control">
|
|
|
|
<option v-for="l in allLocales" :value="l">{{l}}</option>
|
|
|
|
</select>
|
|
|
|
<select v-model="s.val.area" class="form-control">
|
|
|
|
<option v-for="a in allAreas" :value="a">{{a}}</option>
|
|
|
|
</select>
|
|
|
|
</ListInput>
|
|
|
|
<button class="btn btn-outline-primary" @click.prevent="save">Save</button>
|
|
|
|
</form>
|
|
|
|
<ul v-else class="list-unstyled">
|
|
|
|
<li v-for="role in user.roles.split('|')">
|
2021-04-01 09:24:47 -07:00
|
|
|
<span class="badge bg-primary text-white">{{role}}</span>
|
2020-12-30 15:03:30 -08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-04 23:25:38 -07:00
|
|
|
import locales from '../src/locales';
|
|
|
|
const allLocales = ['*'];
|
|
|
|
for (let [code,] of locales) {
|
|
|
|
allLocales.push(code);
|
|
|
|
}
|
|
|
|
|
2020-12-30 15:03:30 -08:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
user: { required: true },
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
roles: (this.user.roles ? this.user.roles.split('|') : []).map(r => {
|
|
|
|
if (r === '*') { r = '*-*'; }
|
|
|
|
const [ locale, area ] = r.split('-');
|
|
|
|
return { locale, area };
|
|
|
|
}),
|
2021-08-04 23:25:38 -07:00
|
|
|
allLocales,
|
2020-12-30 15:03:30 -08:00
|
|
|
allAreas: [
|
|
|
|
'*',
|
2021-08-11 03:23:29 -07:00
|
|
|
'basic',
|
2020-12-30 15:03:30 -08:00
|
|
|
'panel',
|
|
|
|
'users',
|
|
|
|
'sources',
|
|
|
|
'nouns',
|
|
|
|
'terms',
|
|
|
|
'inclusive',
|
|
|
|
'census',
|
2021-09-25 05:55:53 -07:00
|
|
|
'names',
|
2020-12-30 15:03:30 -08:00
|
|
|
],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async save() {
|
|
|
|
const roles = this.roles.map(r => {
|
|
|
|
if (r.locale === '*' && r.area === '*') {
|
|
|
|
return '*';
|
|
|
|
}
|
|
|
|
return `${r.locale}-${r.area}`;
|
|
|
|
}).join('|');
|
|
|
|
|
|
|
|
await this.$confirm(this.$t('admin.user.confirmRole', {username: this.user.username, role: roles}));
|
|
|
|
|
2021-06-09 09:06:32 -07:00
|
|
|
const response = await this.$post(`/user/${this.user.id}/set-roles`, { roles: roles});
|
2020-12-30 15:03:30 -08:00
|
|
|
|
|
|
|
this.user.roles = roles;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|