UX: better error message if moderator is not allowed to invite to group

UX: do not show invite to group option if mod is not owner of any group
This commit is contained in:
Arpit Jalan 2020-07-13 18:09:36 +05:30
parent ba57dc57cc
commit 7532f24668
4 changed files with 42 additions and 30 deletions

View File

@ -1,7 +1,7 @@
import I18n from "I18n"; import I18n from "I18n";
import Component from "@ember/component"; import Component from "@ember/component";
import Group from "discourse/models/group"; import Group from "discourse/models/group";
import { readOnly } from "@ember/object/computed"; import { alias, readOnly } from "@ember/object/computed";
import { action } from "@ember/object"; import { action } from "@ember/object";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import Invite from "discourse/models/invite"; import Invite from "discourse/models/invite";
@ -17,6 +17,8 @@ export default Component.extend({
groupIds: null, groupIds: null,
allGroups: null, allGroups: null,
isAdmin: alias("currentUser.admin"),
init() { init() {
this._super(...arguments); this._super(...arguments);
@ -43,6 +45,13 @@ export default Component.extend({
errorMessage: I18n.t("user.invited.invite_link.error"), errorMessage: I18n.t("user.invited.invite_link.error"),
@discourseComputed("isAdmin", "inviteModel.group_users")
showGroups(isAdmin, groupUsers) {
return (
isAdmin || (groupUsers && groupUsers.some(groupUser => groupUser.owner))
);
},
reset() { reset() {
this.setProperties({ this.setProperties({
maxRedemptionAllowed: 5, maxRedemptionAllowed: 5,

View File

@ -9,16 +9,18 @@
{{generated-invite-link link=inviteModel.inviteLink}} {{generated-invite-link link=inviteModel.inviteLink}}
{{else}} {{else}}
<div class="group-access-control"> {{#if showGroups}}
<label class="instructions"> <div class="group-access-control">
{{i18n "topic.automatically_add_to_groups"}} <label class="instructions">
</label> {{i18n "topic.automatically_add_to_groups"}}
{{group-chooser </label>
content=allGroups {{group-chooser
value=groupIds content=allGroups
labelProperty="name" value=groupIds
onChange=(action (mut groupIds))}} labelProperty="name"
</div> onChange=(action (mut groupIds))}}
</div>
{{/if}}
<div class="max-redemptions-allowed"> <div class="max-redemptions-allowed">
<label class="instructions"> <label class="instructions">

View File

@ -122,7 +122,9 @@ class InvitesController < ApplicationController
group_ids: params[:group_ids], group_ids: params[:group_ids],
group_names: params[:group_names] group_names: params[:group_names]
) )
guardian.ensure_can_invite_to_forum!(groups) if !guardian.can_invite_to_forum?(groups)
raise StandardError.new I18n.t("invite.cant_invite_to_group")
end
group_ids = groups.map(&:id) group_ids = groups.map(&:id)
if is_single_invite if is_single_invite
@ -142,25 +144,23 @@ class InvitesController < ApplicationController
end end
end end
begin invite_link = if is_single_invite
invite_link = if is_single_invite Invite.generate_single_use_invite_link(params[:email], current_user, topic, group_ids)
Invite.generate_single_use_invite_link(params[:email], current_user, topic, group_ids) else
else Invite.generate_multiple_use_invite_link(
Invite.generate_multiple_use_invite_link( invited_by: current_user,
invited_by: current_user, max_redemptions_allowed: params[:max_redemptions_allowed],
max_redemptions_allowed: params[:max_redemptions_allowed], expires_at: params[:expires_at],
expires_at: params[:expires_at], group_ids: group_ids
group_ids: group_ids )
)
end
if invite_link.present?
render_json_dump(invite_link)
else
render json: failed_json, status: 422
end
rescue => e
render json: { errors: [e.message] }, status: 422
end end
if invite_link.present?
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 destroy def destroy

View File

@ -229,6 +229,7 @@ en:
error_message: "There was an error accepting invite. Please contact the site's administrator." error_message: "There was an error accepting invite. Please contact the site's administrator."
user_exists: "There's no need to invite <b>%{email}</b>, they <a href='%{base_path}/u/%{username}/summary'>already have an account!</a>" user_exists: "There's no need to invite <b>%{email}</b>, they <a href='%{base_path}/u/%{username}/summary'>already have an account!</a>"
confirm_email: "<p>Youre almost done! We sent an activation mail to your email address. Please follow the instructions in the mail to activate your account.</p><p>If it doesnt arrive, check your spam folder.</p>" confirm_email: "<p>Youre almost done! We sent an activation mail to your email address. Please follow the instructions in the mail to activate your account.</p><p>If it doesnt arrive, check your spam folder.</p>"
cant_invite_to_group: "You are not allowed to invite users to specified group(s). Make sure you are owner of the group(s) you are trying to invite to."
bulk_invite: bulk_invite:
file_should_be_csv: "The uploaded file should be of csv format." file_should_be_csv: "The uploaded file should be of csv format."