mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: show proper message on invite error
This commit is contained in:
parent
2470a0adbe
commit
4c86758f74
3 changed files with 46 additions and 18 deletions
|
@ -149,6 +149,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
|
||||
createInvite() {
|
||||
const Invite = require('discourse/models/invite').default;
|
||||
const self = this;
|
||||
|
||||
if (this.get('disabled')) { return; }
|
||||
|
||||
|
@ -168,11 +169,19 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
} else if (this.get('isMessage') && result && result.user) {
|
||||
this.get('model.details.allowed_users').pushObject(result.user);
|
||||
}
|
||||
}).catch(() => model.setProperties({ saving: false, error: true }));
|
||||
}).catch(function(e) {
|
||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||
self.set("errorMessage", e.jqXHR.responseJSON.errors[0]);
|
||||
} else {
|
||||
self.set("errorMessage", self.get('isMessage') ? I18n.t('topic.invite_private.error') : I18n.t('topic.invite_reply.error'));
|
||||
}
|
||||
model.setProperties({ saving: false, error: true })
|
||||
});
|
||||
},
|
||||
|
||||
generateInvitelink() {
|
||||
const Invite = require('discourse/models/invite').default;
|
||||
const self = this;
|
||||
|
||||
if (this.get('disabled')) { return; }
|
||||
|
||||
|
@ -193,7 +202,14 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
userInvitedController.set('model', invite_model);
|
||||
userInvitedController.set('totalInvites', invite_model.invites.length);
|
||||
});
|
||||
}).catch(() => model.setProperties({ saving: false, error: true }));
|
||||
}).catch(function(e) {
|
||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||
self.set("errorMessage", e.jqXHR.responseJSON.errors[0]);
|
||||
} else {
|
||||
self.set("errorMessage", self.get('isMessage') ? I18n.t('topic.invite_private.error') : I18n.t('topic.invite_reply.error'));
|
||||
}
|
||||
model.setProperties({ saving: false, error: true })
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,14 @@ class InvitesController < ApplicationController
|
|||
guardian.ensure_can_send_multiple_invites!(current_user)
|
||||
end
|
||||
|
||||
if Invite.invite_by_email(params[:email], current_user, _topic=nil, group_ids)
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
begin
|
||||
if Invite.invite_by_email(params[:email], current_user, _topic=nil, group_ids)
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
end
|
||||
rescue => e
|
||||
render json: {errors: [e.message]}, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -59,11 +63,15 @@ class InvitesController < ApplicationController
|
|||
guardian.ensure_can_send_multiple_invites!(current_user)
|
||||
end
|
||||
|
||||
# generate invite link
|
||||
if invite_link = Invite.generate_invite_link(params[:email], current_user, topic, group_ids)
|
||||
render_json_dump(invite_link)
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
begin
|
||||
# generate invite link
|
||||
if invite_link = Invite.generate_invite_link(params[:email], current_user, topic, group_ids)
|
||||
render_json_dump(invite_link)
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
end
|
||||
rescue => e
|
||||
render json: {errors: [e.message]}, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -326,15 +326,19 @@ class TopicsController < ApplicationController
|
|||
group_ids = Group.lookup_group_ids(params)
|
||||
guardian.ensure_can_invite_to!(topic,group_ids)
|
||||
|
||||
if topic.invite(current_user, username_or_email, group_ids)
|
||||
user = User.find_by_username_or_email(username_or_email)
|
||||
if user
|
||||
render_json_dump BasicUserSerializer.new(user, scope: guardian, root: 'user')
|
||||
begin
|
||||
if topic.invite(current_user, username_or_email, group_ids)
|
||||
user = User.find_by_username_or_email(username_or_email)
|
||||
if user
|
||||
render_json_dump BasicUserSerializer.new(user, scope: guardian, root: 'user')
|
||||
else
|
||||
render json: success_json
|
||||
end
|
||||
else
|
||||
render json: success_json
|
||||
render json: failed_json, status: 422
|
||||
end
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
rescue => e
|
||||
render json: {errors: [e.message]}, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue