-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlibrary.js
More file actions
45 lines (40 loc) · 1.36 KB
/
library.js
File metadata and controls
45 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const winston = require.main.require('winston');
const groups = require.main.require('./src/groups');
const Meta = require.main.require('./src/meta');
const routeHelpers = require.main.require('./src/routes/helpers');
const AssignNewUser = module.exports;
let userGroup = null;
AssignNewUser.init = async function(params) {
const { router } = params;
const settings = await Meta.settings.get('assign-newuser-to-group');
if (settings && settings.userGroup) {
userGroup = settings.userGroup;
} else {
winston.error('[plugins/assign-newuser-to-group] User group not set!');
}
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/assign-newuser-to-group', function (req, res, next) {
res.render('admin/plugins/assign-newuser-to-group', {
title: 'Assign new user to group',
});
});
};
AssignNewUser.assignUserToGroup = async function (hookData) {
if (userGroup != null && hookData && hookData.user) {
const exists = await groups.exists(userGroup);
if (!exists) {
winston.error(`[plugins/assign-newuser-to-group] User group "${userGroup}" does not exist!`);
return;
}
await groups.join(userGroup, hookData.user.uid);
}
};
AssignNewUser.admin = {
menu: async function(header) {
header.plugins.push({
"route": '/plugins/assign-newuser-to-group',
"icon": 'fa-check',
"name": 'Assign new user to group'
});
return header;
}
};