mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 10:16:12 +01:00
newly created groups automatically assign the creator as the owner, some tweaks to isPrivate parsing, added groups link to header, #2588
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
"header.tags": "Tags",
|
||||
"header.popular": "Popular",
|
||||
"header.users": "Users",
|
||||
"header.groups": "Groups",
|
||||
"header.chats": "Chats",
|
||||
"header.notifications": "Notifications",
|
||||
"header.search": "Search",
|
||||
|
||||
@@ -49,7 +49,7 @@ define('admin/manage/groups', [
|
||||
},
|
||||
errorText;
|
||||
|
||||
socket.emit('admin.groups.create', submitObj, function(err, data) {
|
||||
socket.emit('admin.groups.create', submitObj, function(err) {
|
||||
if (err) {
|
||||
switch (err) {
|
||||
case 'group-exists':
|
||||
@@ -68,7 +68,7 @@ define('admin/manage/groups', [
|
||||
createModalError.addClass('hide');
|
||||
createGroupName.val('');
|
||||
createModal.on('hidden.bs.modal', function() {
|
||||
ajaxify.go('admin/manage/groups');
|
||||
ajaxify.refresh();
|
||||
});
|
||||
createModal.modal('hide');
|
||||
}
|
||||
|
||||
@@ -204,7 +204,13 @@ var async = require('async'),
|
||||
|
||||
Groups.isPrivate = function(groupName, callback) {
|
||||
db.getObjectField('group:' + groupName, 'private', function(err, isPrivate) {
|
||||
callback(err, isPrivate || isPrivate === null); // Private, if not set at all
|
||||
isPrivate = isPrivate || isPrivate === null;
|
||||
|
||||
if (typeof isPrivate === 'string') {
|
||||
isPrivate = (isPrivate === '0' ? false : true);
|
||||
}
|
||||
|
||||
callback(err, isPrivate); // Private, if not set at all
|
||||
});
|
||||
};
|
||||
|
||||
@@ -358,16 +364,16 @@ var async = require('async'),
|
||||
}
|
||||
};
|
||||
|
||||
Groups.create = function(name, description, callback) {
|
||||
if (name.length === 0) {
|
||||
Groups.create = function(data, callback) {
|
||||
if (data.name.length === 0) {
|
||||
return callback(new Error('[[error:group-name-too-short]]'));
|
||||
}
|
||||
|
||||
if (name === 'administrators' || name === 'registered-users') {
|
||||
if (data.name === 'administrators' || data.name === 'registered-users') {
|
||||
var system = true;
|
||||
}
|
||||
|
||||
meta.userOrGroupExists(name, function (err, exists) {
|
||||
meta.userOrGroupExists(data.name, function (err, exists) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -377,24 +383,25 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
var groupData = {
|
||||
name: name,
|
||||
userTitle: name,
|
||||
description: description,
|
||||
deleted: '0',
|
||||
hidden: '0',
|
||||
system: system ? '1' : '0'
|
||||
};
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.setAdd('groups', name, next);
|
||||
name: data.name,
|
||||
userTitle: data.name,
|
||||
description: data.description,
|
||||
deleted: '0',
|
||||
hidden: '0',
|
||||
system: system ? '1' : '0',
|
||||
'private': data.private || '1'
|
||||
},
|
||||
function(next) {
|
||||
db.setObject('group:' + name, groupData, function(err) {
|
||||
Groups.get(name, {}, next);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
tasks = [
|
||||
async.apply(db.setAdd, 'groups', data.name),
|
||||
async.apply(db.setObject, 'group:' + data.name, groupData)
|
||||
];
|
||||
|
||||
if (data.hasOwnProperty('ownerUid')) {
|
||||
tasks.push(async.apply(db.setAdd, 'group:' + data.name + ':owners', data.ownerUid));
|
||||
tasks.push(async.apply(db.setAdd, 'group:' + data.name + ':members', data.ownerUid));
|
||||
}
|
||||
|
||||
async.parallel(tasks, callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -529,7 +536,10 @@ var async = require('async'),
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
Groups.create(groupName, '', function(err) {
|
||||
Groups.create({
|
||||
name: groupName,
|
||||
description: ''
|
||||
}, function(err) {
|
||||
if (err && err.message !== '[[error:group-already-exists]]') {
|
||||
winston.error('[groups.join] Could not create new hidden group: ' + err.message);
|
||||
return callback(err);
|
||||
|
||||
@@ -8,9 +8,11 @@ Groups.create = function(socket, data, callback) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
groups.create(data.name, data.description, function(err, groupObj) {
|
||||
callback(err, groupObj || undefined);
|
||||
});
|
||||
groups.create({
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
ownerUid: socket.uid
|
||||
}, callback);
|
||||
};
|
||||
|
||||
Groups.delete = function(socket, groupName, callback) {
|
||||
|
||||
Reference in New Issue
Block a user