mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Merge branch 'develop' into common-convert
This commit is contained in:
@@ -65,15 +65,12 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
}
|
||||
}
|
||||
|
||||
// ------ Invites ------
|
||||
|
||||
$scope.invite = function(group){
|
||||
Groups.Group.invite({gid: group._id, uuid: group.invitee}, undefined, function(){
|
||||
group.invitee = '';
|
||||
}, function(){
|
||||
group.invitee = '';
|
||||
});
|
||||
}
|
||||
$scope.openInviteModal = function(group){
|
||||
$rootScope.openModal('invite-friends', {controller:'InviteToGroupCtrl', resolve:
|
||||
{injectedGroup: function(){
|
||||
return group;
|
||||
}}});
|
||||
};
|
||||
|
||||
//var serializeQs = function(obj, prefix){
|
||||
// var str = [];
|
||||
@@ -91,14 +88,6 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
//$scope.inviteLink = function(obj){
|
||||
// return window.env.BASE_URL + '?' + serializeQs({partyInvite: obj});
|
||||
//}
|
||||
$scope.emails = [{name:"",email:""},{name:"",email:""}];
|
||||
$scope.inviter = User.user.profile.name;
|
||||
$scope.inviteEmails = function(inviter, emails){
|
||||
$http.post('/api/v2/user/social/invite-friends', {inviter:inviter, emails:emails}).success(function(){
|
||||
Notification.text("Invitations sent!");
|
||||
$scope.emails = [{name:'',email:''},{name:'',email:''}];
|
||||
});
|
||||
}
|
||||
|
||||
$scope.quickReply = function(uid) {
|
||||
Members.selectMember(uid, function(){
|
||||
@@ -108,6 +97,31 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
}
|
||||
])
|
||||
|
||||
.controller('InviteToGroupCtrl', ['$scope', 'User', 'Groups', 'injectedGroup', '$http', 'Notification', function($scope, User, Groups, injectedGroup, $http, Notification){
|
||||
$scope.group = injectedGroup;
|
||||
|
||||
$scope.inviter = User.user.profile.name;
|
||||
$scope.emails = [{name:"",email:""},{name:"",email:""}];
|
||||
|
||||
$scope.inviteEmails = function(){
|
||||
Groups.Group.invite({gid: $scope.group._id}, {inviter: $scope.inviter, emails: $scope.emails}, function(){
|
||||
Notification.text("Invitation(s) sent!");
|
||||
$scope.emails = [{name:'',email:''},{name:'',email:''}];
|
||||
}, function(){
|
||||
$scope.emails = [{name:'',email:''},{name:'',email:''}];
|
||||
});
|
||||
};
|
||||
|
||||
$scope.invite = function(){
|
||||
Groups.Group.invite({gid: $scope.group._id}, {uuids: [$scope.invitee]}, function(){
|
||||
Notification.text("Invitation(s) sent!");
|
||||
$scope.invitee = '';
|
||||
}, function(){
|
||||
$scope.invitee = '';
|
||||
});
|
||||
};
|
||||
}])
|
||||
|
||||
.controller("MemberModalCtrl", ['$scope', '$rootScope', 'Members', 'Shared', '$http', 'Notification', 'Groups',
|
||||
function($scope, $rootScope, Members, Shared, $http, Notification, Groups) {
|
||||
$scope.timestamp = function(timestamp){
|
||||
|
||||
@@ -114,6 +114,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
||||
templateUrl: 'modals/' + template + '.html',
|
||||
controller: options.controller, // optional
|
||||
scope: options.scope, // optional
|
||||
resolve: options.resolve, // optional
|
||||
keyboard: (options.keyboard === undefined ? true : options.keyboard), // optional
|
||||
backdrop: (options.backdrop === undefined ? true : options.backdrop), // optional
|
||||
size: options.size, // optional, 'sm' or 'lg'
|
||||
|
||||
@@ -508,27 +508,25 @@ api.leave = function(req, res, next) {
|
||||
})
|
||||
}
|
||||
|
||||
api.invite = function(req, res, next) {
|
||||
var group = res.locals.group;
|
||||
var uuid = req.query.uuid;
|
||||
|
||||
var inviteByUUIDs = function(uuids, group, req, res, next){
|
||||
async.each(uuids, function(uuid, cb){
|
||||
User.findById(uuid, function(err,invite){
|
||||
if (err) return next(err);
|
||||
if (err) return cb(err);
|
||||
if (!invite)
|
||||
return res.json(400,{err:'User with id "' + uuid + '" not found'});
|
||||
return cb({code:400,err:'User with id "' + uuid + '" not found'});
|
||||
if (group.type == 'guild') {
|
||||
if (_.contains(group.members,uuid))
|
||||
return res.json(400,{err: "User already in that group"});
|
||||
return cb({code:400,err: "User already in that group"});
|
||||
if (invite.invitations && invite.invitations.guilds && _.find(invite.invitations.guilds, {id:group._id}))
|
||||
return res.json(400, {err:"User already invited to that group"});
|
||||
return cb({code:400,err:"User already invited to that group"});
|
||||
sendInvite();
|
||||
} else if (group.type == 'party') {
|
||||
if (invite.invitations && !_.isEmpty(invite.invitations.party))
|
||||
return res.json(400,{err:"User already pending invitation."});
|
||||
return cb({code:400,err:"User already pending invitation."});
|
||||
Group.find({type:'party', members:{$in:[uuid]}}, function(err, groups){
|
||||
if (err) return next(err);
|
||||
if (err) return cb(err);
|
||||
if (!_.isEmpty(groups))
|
||||
return res.json(400,{err:"User already in a party."})
|
||||
return cb({code:400,err:"User already in a party."})
|
||||
sendInvite();
|
||||
});
|
||||
}
|
||||
@@ -549,12 +547,9 @@ api.invite = function(req, res, next) {
|
||||
},
|
||||
function(cb){
|
||||
group.save(cb);
|
||||
},
|
||||
function(cb){
|
||||
populateQuery(group.type, Group.findById(group._id)).exec(cb);
|
||||
}
|
||||
], function(err, results){
|
||||
if (err) return next(err);
|
||||
if (err) return cb(err);
|
||||
|
||||
if(invite.preferences.emailNotifications['invited' + (group.type == 'guild' ? 'Guild' : 'Party')] !== false){
|
||||
var emailVars = [
|
||||
@@ -576,12 +571,85 @@ api.invite = function(req, res, next) {
|
||||
utils.txnEmail(invite, ('invited-' + (group.type == 'guild' ? 'guild' : 'party')), emailVars);
|
||||
}
|
||||
|
||||
// Have to return whole group and its members for angular to show the invited user
|
||||
res.json(results[2]);
|
||||
group = uuid = null;
|
||||
cb();
|
||||
});
|
||||
}
|
||||
});
|
||||
}, function(err){
|
||||
if(err) return err.code ? res.json(err.code, {err: err.err}) : next(err);
|
||||
|
||||
// TODO pass group from save above don't find it again, or you have to find it again in order to run populate?
|
||||
populateQuery(group.type, Group.findById(group._id)).exec(function(err, populatedGroup){
|
||||
if(err) return next(err);
|
||||
|
||||
res.json(populatedGroup);
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var inviteByEmails = function(invites, group, req, res, next){
|
||||
var usersAlreadyRegistered = [];
|
||||
|
||||
async.each(invites, function(invite, cb){
|
||||
if (invite.email) {
|
||||
User.findOne({$or: [
|
||||
{'auth.local.email': invite.email},
|
||||
{'auth.facebook.emails.value': invite.email}
|
||||
]}).select({_id: true, 'preferences.emailNotifications': true})
|
||||
.exec(function(err, userToContact){
|
||||
if(err) return next(err);
|
||||
|
||||
if(userToContact){
|
||||
usersAlreadyRegistered.push(userToContact._id);
|
||||
return cb();
|
||||
}
|
||||
|
||||
// yeah, it supports guild too but for backward compatibility we'll use partyInvite as query
|
||||
var link = nconf.get('BASE_URL')+'?partyInvite='+ utils.encrypt(JSON.stringify({id:group._id, inviter:res.locals.user._id, name:group.name}));
|
||||
|
||||
var variables = [
|
||||
{name: 'LINK', content: link},
|
||||
{name: 'INVITER', content: req.body.inviter || utils.getUserInfo(res.locals.user, ['name']).name}
|
||||
];
|
||||
|
||||
if(group.type == 'guild'){
|
||||
variables.push({name: 'GUILD_NAME', content: group.name});
|
||||
}
|
||||
|
||||
// TODO implement "users can only be invited once"
|
||||
invite.canSend = true; // Requested by utils.txnEmail
|
||||
utils.txnEmail(invite, ('invite-friend' + (group.type == 'guild' ? '-guild' : '')), variables);
|
||||
|
||||
cb();
|
||||
});
|
||||
}else{
|
||||
cb();
|
||||
}
|
||||
}, function(err){
|
||||
if(err) return err.code ? res.json(err.code, {err: err.err}) : next(err);
|
||||
|
||||
if(usersAlreadyRegistered.length > 0){
|
||||
inviteByUUIDs(usersAlreadyRegistered, group, req, res, next);
|
||||
}else{
|
||||
|
||||
// Send only status code down the line because it doesn't need
|
||||
// info on invited users since they are not yet registered
|
||||
res.send(200);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
api.invite = function(req, res, next){
|
||||
var group = res.locals.group;
|
||||
|
||||
if(req.body.uuids){
|
||||
inviteByUUIDs(req.body.uuids, group, req, res, next);
|
||||
}else if(req.body.emails){
|
||||
inviteByEmails(req.body.emails, group, req, res, next)
|
||||
}else{
|
||||
return res.json(400,{err: "Can invite only by email or uuid"});
|
||||
}
|
||||
}
|
||||
|
||||
api.removeMember = function(req, res, next){
|
||||
|
||||
@@ -409,54 +409,15 @@ api.cast = function(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /user/invite-friends
|
||||
*/
|
||||
api.inviteFriends = function(req, res, next) {
|
||||
Group.findOne({type:'party', members:{'$in': [res.locals.user._id]}}).select('_id name').exec(function(err,party){
|
||||
if (err) return next(err);
|
||||
|
||||
_.each(req.body.emails, function(invite){
|
||||
if (invite.email) {
|
||||
|
||||
User.findOne({$or: [
|
||||
{'auth.local.email': invite.email},
|
||||
{'auth.facebook.emails.value': invite.email}
|
||||
]}).select({_id: true, 'preferences.emailNotifications': true})
|
||||
.exec(function(err, userToContact){
|
||||
if(err) return next(err);
|
||||
|
||||
var link = nconf.get('BASE_URL')+'?partyInvite='+ utils.encrypt(JSON.stringify({id:party._id, inviter:res.locals.user._id, name:party.name}));
|
||||
|
||||
var variables = [
|
||||
{name: 'LINK', content: link},
|
||||
{name: 'INVITER', content: req.body.inviter || utils.getUserInfo(res.locals.user, ['name']).name}
|
||||
];
|
||||
|
||||
invite.canSend = true;
|
||||
|
||||
// We check for unsubscribeFromAll here because don't pass through utils.getUserInfo
|
||||
if(!userToContact || (userToContact.preferences.emailNotifications.invitedParty !== false &&
|
||||
userToContact.preferences.emailNotifications.unsubscribeFromAll !== true)){
|
||||
// TODO implement "users can only be invited once"
|
||||
utils.txnEmail(invite, 'invite-friend', variables);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
res.send(200);
|
||||
})
|
||||
}
|
||||
|
||||
// It supports guild too now but we'll stick to partyInvite for backward compatibility
|
||||
api.sessionPartyInvite = function(req,res,next){
|
||||
if (!req.session.partyInvite) return next();
|
||||
var inv = res.locals.user.invitations;
|
||||
if (inv.party && inv.party.id) return next(); // already invited to a party
|
||||
async.waterfall([
|
||||
function(cb){
|
||||
Group.findOne({_id:req.session.partyInvite.id, type:'party', members:{$in:[req.session.partyInvite.inviter]}})
|
||||
.select('invites members').exec(cb);
|
||||
Group.findOne({_id:req.session.partyInvite.id, members:{$in:[req.session.partyInvite.inviter]}})
|
||||
.select('invites members type').exec(cb);
|
||||
},
|
||||
function(group, cb){
|
||||
if (!group){
|
||||
@@ -464,6 +425,13 @@ api.sessionPartyInvite = function(req,res,next){
|
||||
delete req.session.partyInvite;
|
||||
return cb();
|
||||
}
|
||||
|
||||
if(group.type == 'guild'){
|
||||
inv.guilds.push(req.session.partyInvite);
|
||||
}else{
|
||||
//req.body.type in 'guild', 'party'
|
||||
inv.party = req.session.partyInvite;
|
||||
}
|
||||
inv.party = req.session.partyInvite;
|
||||
delete req.session.partyInvite;
|
||||
if (!~group.invites.indexOf(res.locals.user._id))
|
||||
|
||||
@@ -201,7 +201,8 @@ module.exports.locals = function(req, res, next) {
|
||||
worldDmg: (tavern && tavern.quest && tavern.quest.extra && tavern.quest.extra.worldDmg) || {}
|
||||
});
|
||||
|
||||
// Put query-string party invitations into session to be handled later
|
||||
// Put query-string party (& guild but use partyInvite for backward compatibility)
|
||||
// invitations into session to be handled later
|
||||
try{
|
||||
req.session.partyInvite = JSON.parse(utils.decrypt(req.query.partyInvite))
|
||||
} catch(e){}
|
||||
|
||||
@@ -365,15 +365,6 @@ module.exports = (swagger, v2) ->
|
||||
]
|
||||
action: user.deleteTag
|
||||
|
||||
"/user/social/invite-friends":
|
||||
spec:
|
||||
method: 'POST'
|
||||
description: 'Invite friends via email'
|
||||
parameters: [
|
||||
body 'invites','Array of [{name:"Friend\'s Name", email:"friends@email.com"}] to invite to play in your party','object'
|
||||
]
|
||||
action: user.inviteFriends
|
||||
|
||||
# Webhooks
|
||||
"/user/webhooks":
|
||||
spec:
|
||||
@@ -469,7 +460,7 @@ module.exports = (swagger, v2) ->
|
||||
description: "Invite a user to a group"
|
||||
parameters: [
|
||||
path 'gid','Group id','string'
|
||||
query 'uuid','User id to invite','string'
|
||||
body '','a payload of invites either under body.uuids or body.emails, only one of them!','object'
|
||||
]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action:groups.invite
|
||||
|
||||
@@ -55,7 +55,7 @@ a.pull-right.gem-wallet(ng-if='group.type!="party"', popover-trigger='mouseenter
|
||||
.panel-heading
|
||||
h3.panel-title
|
||||
=env.t('members')
|
||||
button.pull-right.btn.btn-primary(ng-click="openModal('invite-friends', {controller:'GroupsCtrl'})", ng-if='::group.type=="party"') Invite Friends
|
||||
button.pull-right.btn.btn-primary(ng-click="openInviteModal(group)") Invite Friends
|
||||
.panel-body.modal-fixed-height
|
||||
div.form-group(ng-if='::group.type=="party"')
|
||||
p=env.t('partyList')
|
||||
@@ -99,14 +99,6 @@ a.pull-right.gem-wallet(ng-if='group.type!="party"', popover-trigger='mouseenter
|
||||
a.media-body
|
||||
span(ng-click='clickMember(invite._id, true)')
|
||||
| {{invite.profile.name}}
|
||||
.panel-footer(ng-if='::group.type!="party"')
|
||||
form.form-inline(ng-submit='invite(group)')
|
||||
//.alert.alert-danger(ng-show='_groupError') {{_groupError}}
|
||||
.input-group
|
||||
input.form-control(type='text', placeholder=env.t('userId'), ng-model='group.invitee')
|
||||
span.input-group-btn
|
||||
input.btn.btn-default(type='submit', value=env.t('invite'))
|
||||
|
||||
|
||||
a.btn.btn-danger(data-id='{{group.id}}', ng-click='clickLeave(group, $event)')=env.t('leave')
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ script(type='text/ng-template', id='modals/invite-friends.html')
|
||||
.modal-body
|
||||
p.alert.alert-info Invite friends by <a href='http://habitrpg.wikia.com/wiki/API_Options' target='_blank'>User ID</a> here.
|
||||
|
||||
form.form-inline(ng-submit='invite(party)')
|
||||
form.form-inline(ng-submit='invite()')
|
||||
//-.alert.alert-danger(ng-show='_groupError') {{_groupError}}
|
||||
.form-group
|
||||
input.form-control(type='text', placeholder=env.t('userId'), ng-model='party.invitee')
|
||||
input.form-control(type='text', placeholder=env.t('userId'), ng-model='invitee')
|
||||
|
|
||||
button.btn.btn-primary(type='submit') Invite Existing User
|
||||
|
||||
@@ -15,7 +15,7 @@ script(type='text/ng-template', id='modals/invite-friends.html')
|
||||
|
||||
p.alert.alert-info Invite friends by email. If they join via your email, they'll automatically be invited to your party.
|
||||
|
||||
form.form-horizontal(ng-submit='inviteEmails(inviter, emails)')
|
||||
form.form-horizontal(ng-submit='inviteEmails()')
|
||||
table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
|
||||
Reference in New Issue
Block a user