diff --git a/public/language/en_GB/groups.json b/public/language/en_GB/groups.json
index fcd15e21c6..08982e8d29 100644
--- a/public/language/en_GB/groups.json
+++ b/public/language/en_GB/groups.json
@@ -29,6 +29,7 @@
"details.has_no_posts": "This group's members have not made any posts.",
"details.latest_posts": "Latest Posts",
"details.private": "Private",
+ "details.disableJoinRequests": "Disable join requests",
"details.grant": "Grant/Rescind Ownership",
"details.kick": "Kick",
diff --git a/public/src/admin/manage/group.js b/public/src/admin/manage/group.js
index c708cc3a14..a98e64831d 100644
--- a/public/src/admin/manage/group.js
+++ b/public/src/admin/manage/group.js
@@ -157,8 +157,10 @@ define('admin/manage/group', [
description: $('#change-group-desc').val(),
icon: groupIcon.attr('value'),
labelColor: changeGroupLabelColor.val(),
+ userTitleEnabled: $('#group-userTitleEnabled').is(':checked'),
private: $('#group-private').is(':checked'),
- hidden: $('#group-hidden').is(':checked')
+ hidden: $('#group-hidden').is(':checked'),
+ disableJoinRequests: $('#group-disableJoinRequests').is(':checked')
}
}, function(err) {
if (err) {
diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js
index ee1a6aed17..989792dd3a 100644
--- a/public/src/modules/helpers.js
+++ b/public/src/modules/helpers.js
@@ -142,8 +142,10 @@
return '';
} else if (groupObj.isInvited) {
return '';
- } else {
+ } else if (!groupObj.disableJoinRequests) {
return '';
+ } else {
+ return '';
}
}
};
diff --git a/src/groups.js b/src/groups.js
index 194534839d..ccbfc24130 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -1,16 +1,14 @@
'use strict';
-var async = require('async'),
- winston = require('winston'),
- nconf = require('nconf'),
- validator = require('validator'),
-
- user = require('./user'),
- db = require('./database'),
- plugins = require('./plugins'),
- posts = require('./posts'),
- privileges = require('./privileges'),
- utils = require('../public/src/utils');
+var async = require('async');
+var validator = require('validator');
+
+var user = require('./user');
+var db = require('./database');
+var plugins = require('./plugins');
+var posts = require('./posts');
+var privileges = require('./privileges');
+var utils = require('../public/src/utils');
(function(Groups) {
@@ -184,6 +182,7 @@ var async = require('async'),
results.base.hidden = !!parseInt(results.base.hidden, 10);
results.base.system = !!parseInt(results.base.system, 10);
results.base.private = results.base.private ? !!parseInt(results.base.private, 10) : true;
+ results.base.disableJoinRequests = parseInt(results.base.disableJoinRequests, 10) === 1;
results.base.isMember = results.isMember;
results.base.isPending = results.isPending;
results.base.isInvited = results.isInvited;
@@ -228,7 +227,7 @@ var async = require('async'),
}
});
- results.members = results.members.filter(function(user, index, array) {
+ results.members = results.members.filter(function(user) {
return user && user.uid && ownerUids.indexOf(user.uid.toString()) === -1;
});
results.members = results.owners.concat(results.members);
@@ -369,19 +368,27 @@ var async = require('async'),
], callback);
};
+ Groups.getGroupData = function(groupName, callback) {
+ Groups.getGroupsData([groupName], function(err, groupsData) {
+ callback(err, Array.isArray(groupsData) && groupsData[0] ? groupsData[0] : null);
+ });
+ };
+
Groups.getGroupsData = function(groupNames, callback) {
if (!Array.isArray(groupNames) || !groupNames.length) {
return callback(null, []);
}
+
var keys = groupNames.map(function(groupName) {
- return 'group:' + groupName;
- }),
- ephemeralIdx = groupNames.reduce(function(memo, cur, idx) {
- if (ephemeralGroups.indexOf(cur) !== -1) {
- memo.push(idx);
- }
- return memo;
- }, []);
+ return 'group:' + groupName;
+ });
+
+ var ephemeralIdx = groupNames.reduce(function(memo, cur, idx) {
+ if (ephemeralGroups.indexOf(cur) !== -1) {
+ memo.push(idx);
+ }
+ return memo;
+ }, []);
db.getObjects(keys, function(err, groupData) {
if (err) {
@@ -403,6 +410,7 @@ var async = require('async'),
group.hidden = parseInt(group.hidden, 10) === 1;
group.system = parseInt(group.system, 10) === 1;
group.private = parseInt(group.private, 10) === 1;
+ group.disableJoinRequests = parseInt(group.disableJoinRequests) === 1;
group['cover:url'] = group['cover:url'] || require('./coverPhoto').getDefaultGroupCover(group.name);
group['cover:position'] = group['cover:position'] || '50% 50%';
diff --git a/src/groups/update.js b/src/groups/update.js
index 26d2b258be..cac4a02781 100644
--- a/src/groups/update.js
+++ b/src/groups/update.js
@@ -44,6 +44,10 @@ module.exports = function(Groups) {
payload.private = values.private ? '1' : '0';
}
+ if (values.hasOwnProperty('disableJoinRequests')) {
+ payload.disableJoinRequests = values.disableJoinRequests ? '1' : '0';
+ }
+
async.series([
async.apply(checkNameChange, groupName, values.name),
async.apply(updatePrivacy, groupName, values.private),
diff --git a/src/posts/user.js b/src/posts/user.js
index b27e63517e..d0702750bd 100644
--- a/src/posts/user.js
+++ b/src/posts/user.js
@@ -16,7 +16,7 @@ module.exports = function(Posts) {
groups: function(next) {
groups.getUserGroups(uids, next);
},
- userSettings: function(next){
+ userSettings: function(next) {
user.getMultipleUserSettings(uids, next);
},
userData: function(next) {
diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js
index 2321588d7f..79fc935819 100644
--- a/src/socket.io/groups.js
+++ b/src/socket.io/groups.js
@@ -37,13 +37,17 @@ SocketGroups.join = function(socket, data, callback) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
- isPrivate: async.apply(groups.isPrivate, data.groupName)
- }, function(err, checks) {
+ groupData: async.apply(groups.getGroupData, data.groupName)
+ }, function(err, results) {
if (err) {
return callback(err);
}
- if (!checks.isPrivate || checks.isAdmin) {
+ if (results.groupData.private && results.groupData.disableJoinRequests) {
+ return callback(new Error('[[error:join-requests-disabled]]'));
+ }
+
+ if (!results.groupData.isPrivate || results.isAdmin) {
groups.join(data.groupName, socket.uid, callback);
} else {
groups.requestMembership(data.groupName, socket.uid, callback);
@@ -261,6 +265,6 @@ SocketGroups.cover.remove = function(socket, data, callback) {
groups.removeCover(data, callback);
});
-}
+};
module.exports = SocketGroups;
diff --git a/src/views/admin/manage/group.tpl b/src/views/admin/manage/group.tpl
index 078da81b3e..28cd6c006e 100644
--- a/src/views/admin/manage/group.tpl
+++ b/src/views/admin/manage/group.tpl
@@ -28,6 +28,14 @@
+