FIX: show proper message on invite error

This commit is contained in:
Arpit Jalan 2015-12-14 21:32:23 +05:30
parent 2470a0adbe
commit 4c86758f74
3 changed files with 46 additions and 18 deletions

View File

@ -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 })
});
}
}

View File

@ -41,11 +41,15 @@ class InvitesController < ApplicationController
guardian.ensure_can_send_multiple_invites!(current_user)
end
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
def create_invite_link
@ -59,12 +63,16 @@ class InvitesController < ApplicationController
guardian.ensure_can_send_multiple_invites!(current_user)
end
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
def create_disposable_invite

View File

@ -326,6 +326,7 @@ class TopicsController < ApplicationController
group_ids = Group.lookup_group_ids(params)
guardian.ensure_can_invite_to!(topic,group_ids)
begin
if topic.invite(current_user, username_or_email, group_ids)
user = User.find_by_username_or_email(username_or_email)
if user
@ -336,6 +337,9 @@ class TopicsController < ApplicationController
else
render json: failed_json, status: 422
end
rescue => e
render json: {errors: [e.message]}, status: 422
end
end
def set_notifications