This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
90 lines (75 loc) · 2.51 KB
/
library.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(function(module) {
"use strict";
var async = module.parent.require('async'),
db = module.parent.require('./database'),
meta = module.parent.require('./meta'),
user = module.parent.require('./user'),
groups = module.parent.require('./groups');
var plugin = {};
plugin.init = function(params, callback) {
var app = params.router,
middleware = params.middleware;
app.get('/admin/plugins/latest-group', middleware.admin.buildHeader, renderAdmin);
app.get('/api/admin/plugins/latest-group', renderAdmin);
callback();
};
function renderAdmin(req, res, next) {
async.waterfall([
function(next) {
db.getSortedSetRevRange('groups:createtime', 0, -1, next);
},
function(groupNames, next) {
groupNames = groupNames.filter(function(name) {
return name.indexOf(':privileges:') === -1 && name !== 'registered-users';
});
groups.getGroupsData(groupNames, next);
}
], function(err, groupsData) {
if (err) {
return next(err);
}
res.render('latest-group-admin', {
groups: groupsData
});
});
}
plugin.updateGroupTitle = function(joinData) {
var uid = joinData.uid,
groupName = joinData.groupName;
if (groupName.indexOf(':privileges:') !== -1 ||
groupName === 'registered-users'
) {
return;
}
async.parallel({
settings: function(next) {
meta.settings.get('latest-group', next);
},
user: function(next) {
user.getUserFields(uid, ['uid', 'groupTitle'], next);
},
}, function(err, results) {
if (err) {
return;
}
var query = 'do not change ' + results.user.groupTitle;
if (results.settings[query] !== "on") {
user.setUserField(
uid,
'groupTitle',
groupName,
null
);
}
});
};
plugin.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/latest-group',
icon: 'fa-users',
name: 'Latest Group'
});
callback(null, header);
};
module.exports = plugin;
}(module));