From 1a9dd2311c378edbac4696ecc166e20ed7676c30 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 11 Nov 2016 12:17:12 +0300 Subject: [PATCH] closes #5175 --- public/src/modules/helpers.js | 22 +++++++++------------- src/groups/create.js | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js index 5de0cdbb3b..a913da80b7 100644 --- a/public/src/modules/helpers.js +++ b/public/src/modules/helpers.js @@ -153,22 +153,18 @@ // Groups helpers helpers.membershipBtn = function (groupObj) { - if (groupObj.name === 'administrators') { - return ''; + if (groupObj.isMember && groupObj.name !== 'administrators') { + return ''; } - if (groupObj.isMember) { - return ''; + if (groupObj.isPending && groupObj.name !== 'administrators') { + return ''; + } else if (groupObj.isInvited) { + return ''; + } else if (!groupObj.disableJoinRequests && groupObj.name !== 'administrators') { + return ''; } else { - if (groupObj.isPending) { - return ''; - } else if (groupObj.isInvited) { - return ''; - } else if (!groupObj.disableJoinRequests) { - return ''; - } else { - return ''; - } + return ''; } }; diff --git a/src/groups/create.js b/src/groups/create.js index b5864e5c44..0b38b3ebcc 100644 --- a/src/groups/create.js +++ b/src/groups/create.js @@ -9,12 +9,13 @@ var db = require('../database'); module.exports = function (Groups) { Groups.create = function (data, callback) { - var system = data.system === true || parseInt(data.system, 10) === 1 || - data.name === 'administrators' || data.name === 'registered-users' || data.name === 'Global Moderators' || - Groups.isPrivilegeGroup(data.name); + var system = isSystemGroup(data); var groupData; var timestamp = data.timestamp || Date.now(); - + var disableJoinRequests = parseInt(data.disableJoinRequests, 10) === 1 ? 1 : 0; + if (data.name === 'administrators') { + disableJoinRequests = 1; + } async.waterfall([ function (next) { validateGroupName(data.name, next); @@ -41,7 +42,7 @@ module.exports = function (Groups) { hidden: parseInt(data.hidden, 10) === 1 ? 1 : 0, system: system ? 1 : 0, private: isPrivate, - disableJoinRequests: parseInt(data.disableJoinRequests, 10) === 1 ? 1 : 0 + disableJoinRequests: disableJoinRequests }; plugins.fireHook('filter:group.create', {group: groupData, data: data}, next); }, @@ -76,6 +77,12 @@ module.exports = function (Groups) { }; + function isSystemGroup(data) { + return data.system === true || parseInt(data.system, 10) === 1 || + data.name === 'administrators' || data.name === 'registered-users' || data.name === 'Global Moderators' || + Groups.isPrivilegeGroup(data.name); + } + function validateGroupName(name, callback) { if (!name) { return callback(new Error('[[error:group-name-too-short]]'));