mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
add ability to group leader to remove members, fix #1639
This commit is contained in:
@@ -38,6 +38,15 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
}
|
||||
}
|
||||
|
||||
$scope.removeMember = function(group, member){
|
||||
var yes = confirm("Do you really want to remove this member from the party?")
|
||||
if(yes){
|
||||
group.$removeMember({uuid: member._id}, function(){
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ------ Invites ------
|
||||
|
||||
$scope.invitee = '';
|
||||
@@ -118,8 +127,6 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A
|
||||
if (confirm("Create Guild for 4 Gems?")) {
|
||||
group.$save(function(){
|
||||
location.reload();
|
||||
}, function(error){
|
||||
alert(error.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ angular.module('groupServices', ['ngResource']).
|
||||
deleteChatMessage: {method: "DELETE", url: API_URL + '/api/v1/groups/:gid/chat/:messageId'},
|
||||
join: {method: "POST", url: API_URL + '/api/v1/groups/:gid/join'},
|
||||
leave: {method: "POST", url: API_URL + '/api/v1/groups/:gid/leave'},
|
||||
invite: {method: "POST", url: API_URL + '/api/v1/groups/:gid/invite'}
|
||||
invite: {method: "POST", url: API_URL + '/api/v1/groups/:gid/invite'},
|
||||
removeMember: {method: "POST", url: API_URL + '/api/v1/groups/:gid/removeMember'}
|
||||
});
|
||||
|
||||
// The user may not visit the public guilds, personal guilds, and tavern pages. So
|
||||
|
||||
@@ -261,8 +261,8 @@ api.leave = function(req, res, next) {
|
||||
|
||||
Group.update({_id:group._id},{$pull:{members:user._id}}, function(err, saved){
|
||||
if (err) return res.json(500,{err:err});
|
||||
res.send(200, {_id: saved._id});
|
||||
})
|
||||
return res.send(200, {_id: saved._id});
|
||||
});
|
||||
}
|
||||
|
||||
api.invite = function(req, res, next) {
|
||||
@@ -307,4 +307,24 @@ api.invite = function(req, res, next) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
api.removeMember = function(req, res, next){
|
||||
var group = res.locals.group;
|
||||
var uuid = req.query.uuid;
|
||||
var user = res.locals.user;
|
||||
|
||||
if(group.leader !== user._id){
|
||||
return res.json(401, {err: "Only group leader can remove a member!"});
|
||||
}
|
||||
|
||||
if(_.contains(group.members, uuid)){
|
||||
Group.update({_id:group._id},{$pull:{members:uuid}}, function(err, saved){
|
||||
if (err) return res.json(500,{err:err});
|
||||
return res.send(204);
|
||||
});
|
||||
}else{
|
||||
return res.json(400, {err: "User not found among group's members!"});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,6 +65,7 @@ router.post('/groups/:gid', auth.auth, groups.attachGroup, groups.updateGroup);
|
||||
router.post('/groups/:gid/join', auth.auth, groups.attachGroup, groups.join);
|
||||
router.post('/groups/:gid/leave', auth.auth, groups.attachGroup, groups.leave);
|
||||
router.post('/groups/:gid/invite', auth.auth, groups.attachGroup, groups.invite);
|
||||
router.post('/groups/:gid/removeMember', auth.auth, groups.attachGroup, groups.removeMember);
|
||||
|
||||
//GET /groups/:gid/chat
|
||||
router.post('/groups/:gid/chat', auth.auth, groups.attachGroup, groups.postChat);
|
||||
|
||||
@@ -63,7 +63,7 @@ a.pull-right.gem-wallet(popover-trigger='mouseenter', popover-title='Guild Bank'
|
||||
// allow leaders to ban members
|
||||
div(ng-show='group.leader == user.id && user.id!=member._id')
|
||||
// {{#with group.members[$index]}}
|
||||
a(x-bind='click:removeAt', data-refresh='true', data-confirm='Boot this member?')
|
||||
a(ng-click='removeMember(group, member)')
|
||||
i.icon-ban-circle(tooltip='Boot Member')
|
||||
// {{/}}
|
||||
a(data-toggle='modal', data-target='#avatar-modal-{{member._id}}')
|
||||
|
||||
Reference in New Issue
Block a user