diff --git a/public/src/admin/manage/groups.js b/public/src/admin/manage/groups.js index 19f0bf31e9..5833f99b66 100644 --- a/public/src/admin/manage/groups.js +++ b/public/src/admin/manage/groups.js @@ -102,12 +102,14 @@ define('admin/manage/groups', [ case 'delete': bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) { if (confirm) { - socket.emit('admin.groups.delete', groupName, function(err, data) { + socket.emit('groups.delete', { + groupName: groupName + }, function(err, data) { if(err) { return app.alertError(err.message); } - ajaxify.go('admin/manage/groups'); + ajaxify.refresh(); }); } }); diff --git a/src/socket.io/admin/groups.js b/src/socket.io/admin/groups.js index b78380428e..9700bee3ca 100644 --- a/src/socket.io/admin/groups.js +++ b/src/socket.io/admin/groups.js @@ -15,10 +15,6 @@ Groups.create = function(socket, data, callback) { }, callback); }; -Groups.delete = function(socket, groupName, callback) { - groups.destroy(groupName, callback); -}; - Groups.get = function(socket, groupName, callback) { groups.get(groupName, { expand: true diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index 3c9dc9b069..c517cbabb2 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -101,4 +101,18 @@ SocketGroups.update = function(socket, data, callback) { }); }; +SocketGroups.delete = function(socket, data, callback) { + if(!data) { + return callback(new Error('[[error:invalid-data]]')); + } + + groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) { + if (!isOwner) { + return callback(new Error('[[error:no-privileges]]')); + } + + groups.destroy(data.groupName, callback); + }); +}; + module.exports = SocketGroups;