mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: option to allow auto-joining of groups (optionally skip the "request membership" step)
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
"edit.hidden-details": "If enabled, this group will not be found in the groups listing, and users will have to be invited manually",
|
||||
"edit.add-user": "Add User to Group",
|
||||
"edit.add-user-search": "Search Users",
|
||||
"edit.autojoin": "Enable Auto-Join",
|
||||
"edit.autojoin-details": "Allow any user with access to the group to join without confirmation",
|
||||
"edit.members": "Member List",
|
||||
"control-panel": "Groups Control Panel",
|
||||
"revert": "Revert",
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
"details.hidden_help": "If enabled, this group will not be found in the groups listing, and users will have to be invited manually",
|
||||
"details.delete_group": "Delete Group",
|
||||
"details.private_system_help": "Private groups is disabled at system level, this option does not do anything",
|
||||
"details.autojoin": "Enable Auto-Join",
|
||||
"details.autojoin_help": "Allow any user with access to the group to join without confirmation",
|
||||
|
||||
"event.updated": "Group details have been updated",
|
||||
"event.deleted": "The group \"%1\" has been deleted",
|
||||
|
||||
@@ -83,6 +83,7 @@ define('admin/manage/group', [
|
||||
memberPostCids: $('#memberPostCids').val(),
|
||||
disableJoinRequests: $('#group-disableJoinRequests').is(':checked'),
|
||||
disableLeave: $('#group-disableLeave').is(':checked'),
|
||||
autojoin: $('#group-autojoin').is(':checked'),
|
||||
},
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
|
||||
@@ -14,6 +14,7 @@ module.exports = function (Groups) {
|
||||
disableJoinRequests = 1;
|
||||
}
|
||||
const disableLeave = parseInt(data.disableLeave, 10) === 1 ? 1 : 0;
|
||||
const autojoin = parseInt(data.autojoin, 10) === 1 ? 1 : 0;
|
||||
const isHidden = parseInt(data.hidden, 10) === 1;
|
||||
|
||||
Groups.validateGroupName(data.name);
|
||||
@@ -38,6 +39,7 @@ module.exports = function (Groups) {
|
||||
private: isPrivate ? 1 : 0,
|
||||
disableJoinRequests: disableJoinRequests,
|
||||
disableLeave: disableLeave,
|
||||
autojoin: autojoin,
|
||||
};
|
||||
|
||||
await plugins.hooks.fire('filter:group.create', { group: groupData, data: data });
|
||||
|
||||
@@ -10,7 +10,7 @@ const translator = require('../translator');
|
||||
|
||||
const intFields = [
|
||||
'createtime', 'memberCount', 'hidden', 'system', 'private',
|
||||
'userTitleEnabled', 'disableJoinRequests', 'disableLeave',
|
||||
'userTitleEnabled', 'disableJoinRequests', 'disableLeave', 'autojoin',
|
||||
];
|
||||
|
||||
module.exports = function (Groups) {
|
||||
|
||||
@@ -67,11 +67,12 @@ module.exports = function (Groups) {
|
||||
async function inviteOrRequestMembership(groupName, uids, type) {
|
||||
uids = Array.isArray(uids) ? uids : [uids];
|
||||
uids = uids.filter(uid => parseInt(uid, 10) > 0);
|
||||
const [exists, isMember, isPending, isInvited] = await Promise.all([
|
||||
const [exists, isMember, isPending, isInvited, canAutojoin] = await Promise.all([
|
||||
Groups.exists(groupName),
|
||||
Groups.isMembers(uids, groupName),
|
||||
Groups.isPending(uids, groupName),
|
||||
Groups.isInvited(uids, groupName),
|
||||
Groups.getGroupField(groupName, 'autojoin'),
|
||||
]);
|
||||
|
||||
if (!exists) {
|
||||
@@ -80,6 +81,11 @@ module.exports = function (Groups) {
|
||||
|
||||
uids = uids.filter((uid, i) => !isMember[i] && ((type === 'invite' && !isInvited[i]) || (type === 'request' && !isPending[i])));
|
||||
|
||||
if (canAutojoin) {
|
||||
await Promise.all(uids.map(uid => Groups.join([groupName], uid)));
|
||||
return uids;
|
||||
}
|
||||
|
||||
const set = type === 'invite' ? 'group:' + groupName + ':invited' : 'group:' + groupName + ':pending';
|
||||
await db.setAdd(set, uids);
|
||||
const hookName = type === 'invite' ? 'action:group.inviteMember' : 'action:group.requestMembership';
|
||||
|
||||
@@ -55,6 +55,10 @@ module.exports = function (Groups) {
|
||||
payload.disableLeave = values.disableLeave ? '1' : '0';
|
||||
}
|
||||
|
||||
if (values.hasOwnProperty('autojoin')) {
|
||||
payload.autojoin = values.autojoin ? '1' : '0';
|
||||
}
|
||||
|
||||
if (values.hasOwnProperty('name')) {
|
||||
await checkNameChange(groupName, values.name);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,18 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input id="group-autojoin" name="hidden" data-property type="checkbox"<!-- IF group.autojoin --> checked<!-- ENDIF group.autojoin -->>
|
||||
<strong>[[admin/manage/groups:edit.autojoin]]</strong>
|
||||
<p class="help-block">
|
||||
[[admin/manage/groups:edit.autojoin-details]]
|
||||
</p>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
Reference in New Issue
Block a user