admin.user.user
@@ -40,9 +40,10 @@
|
-
+
{{s.el.roles}}
-
+
|
@@ -76,9 +77,18 @@
} });
return {
- users: Object.values(users),
+ users,
};
},
+ methods: {
+ async setRole(userId, role) {
+ await this.$confirm(this.$t('admin.user.confirmRole', {username: this.users[userId].username, role}));
+
+ const response = await this.$axios.$post(`/user/${userId}/set-roles`, { roles: role });
+
+ this.users[userId].roles = role;
+ }
+ },
head() {
return head({
title: this.$t('admin.header'),
diff --git a/server/routes/user.js b/server/routes/user.js
index d1e8d4c2..101d715b 100644
--- a/server/routes/user.js
+++ b/server/routes/user.js
@@ -273,6 +273,16 @@ router.post('/user/delete', async (req, res) => {
return res.json(true);
});
+router.post('/user/:id/set-roles', async (req, res) => {
+ if (!req.admin) {
+ return res.status(401).json({error: 'Unauthorised'});
+ }
+
+ await req.db.get(SQL`UPDATE users SET roles = ${req.body.roles} WHERE id = ${req.params.id}`);
+
+ return res.json('ok');
+});
+
router.get('/user/social/:provider', async (req, res) => {
if (!req.session.grant || !req.session.grant.response || !req.session.grant.response.access_token || !socialLoginHandlers[req.params.provider]) {
return res.status(400).redirect('/' + config.user.route);
|