diff --git a/app/controllers/client_api/users/invitations_controller.rb b/app/controllers/client_api/users/invitations_controller.rb index 87789769e..7765cf609 100644 --- a/app/controllers/client_api/users/invitations_controller.rb +++ b/app/controllers/client_api/users/invitations_controller.rb @@ -27,7 +27,14 @@ module ClientApi def check_invite_users_permission @team = Team.find_by_id(params[:team_id]) - render_403 if @team && !is_admin_of_team(@team) + if @team && !is_admin_of_team(@team) + respond_to do |format| + format.json do + render json: t('client_api.invite_users.permission_error'), + status: 422 + end + end + end end end end diff --git a/app/javascript/src/components/InviteUsersModal/index.jsx b/app/javascript/src/components/InviteUsersModal/index.jsx index 8d702cfa2..a6a82a0d2 100644 --- a/app/javascript/src/components/InviteUsersModal/index.jsx +++ b/app/javascript/src/components/InviteUsersModal/index.jsx @@ -55,10 +55,15 @@ class InviteUsersModal extends Component { team_id: this.props.team.id }) .then(({ data }) => { - this.setState({ inviteResults: data }); - this.setState({ showInviteUsersResults: true }); + this.setState({ inviteResults: data, showInviteUsersResults: true}); }) - .catch(error => {}); + .catch(error => { + console.log("Invite As Error: ", error); + if (error.response) { + console.log("Error message:", error.response.data); + // TO DO: put this error in flash msg + } + }); } render() { diff --git a/app/javascript/src/config/locales/messages.js b/app/javascript/src/config/locales/messages.js index b1f64bd33..07c3295eb 100644 --- a/app/javascript/src/config/locales/messages.js +++ b/app/javascript/src/config/locales/messages.js @@ -21,6 +21,43 @@ export default { notifications_label: "Notifications", info_label: "Info" }, + invite_users: { + modal_title: "Invite users to team {team}", + input_text: "Invite more people to team {team} and start using sciNote.", + input_help: + "Input one or multiple emails, confirm each email with ENTER key.", + dropdown_button: { + invite: "Invite user/s", + guest: "as Guest/s", + normal_user: "as Normal user/s", + admin: "as Administrator/s" + }, + results_title: "Invitation results:", + roles: { + guest: "Guest", + normal_user: "Normal user", + admin: "Administrator" + }, + results_msg: { + user_exists: "User is already a member of sciNote.", + user_exists_unconfirmed: + "User is already a member of sciNote but is not confirmed yet.", + user_exists_and_in_team_unconfirmed: + "User is already a member of sciNote and team {team} as {role} but is not confirmed yet.", + user_exists_invited_to_team_unconfirmed: + "User is already a member of sciNote but is not confirmed yet - successfully invited to team {team} as {role}.", + user_exists_and_in_team: + "User is already a member of sciNote and team {team} as {role}.", + user_exists_invited_to_team: + "User was already a member of sciNote - successfully invited to team {team} as {role}.", + user_created: "User succesfully invited to sciNote.", + user_created_invited_to_team: + "User successfully invited to sciNote and team {team} as {role}.", + user_invalid: "Invalid email.", + too_many_emails: + "Only invited first {nr} emails. To invite more users, fill in another invitation form." + } + }, settings_page: { all_teams: "All teams", in_team: "You are member of {num} team", @@ -145,43 +182,6 @@ export default { greeting: "Hi, {name}", settings: "Settings", log_out: "Log out" - }, - invite_users: { - modal_title: "Invite users to team {team}", - input_text: "Invite more people to team {team} and start using sciNote.", - input_help: - "Input one or multiple emails, confirm each email with ENTER key.", - dropdown_button: { - invite: "Invite user/s", - guest: "as Guest/s", - normal_user: "as Normal user/s", - admin: "as Administrator/s" - }, - results_title: "Invitation results:", - roles: { - guest: "Guest", - normal_user: "Normal user", - admin: "Administrator" - }, - results_msg: { - user_exists: "User is already a member of sciNote.", - user_exists_unconfirmed: - "User is already a member of sciNote but is not confirmed yet.", - user_exists_and_in_team_unconfirmed: - "User is already a member of sciNote and team {team} as {role} but is not confirmed yet.", - user_exists_invited_to_team_unconfirmed: - "User is already a member of sciNote but is not confirmed yet - successfully invited to team {team} as {role}.", - user_exists_and_in_team: - "User is already a member of sciNote and team {team} as {role}.", - user_exists_invited_to_team: - "User was already a member of sciNote - successfully invited to team {team} as {role}.", - user_created: "User succesfully invited to sciNote.", - user_created_invited_to_team: - "User successfully invited to sciNote and team {team} as {role}.", - user_invalid: "Invalid email.", - too_many_emails: - "Only invited first {nr} emails. To invite more users, fill in another invitation form." - } } } }; diff --git a/app/services/client_api/invitations_service.rb b/app/services/client_api/invitations_service.rb index 4abb0e04f..a605b55f0 100644 --- a/app/services/client_api/invitations_service.rb +++ b/app/services/client_api/invitations_service.rb @@ -34,14 +34,8 @@ module ClientApi # Check if user already exists user = User.find_by_email(email) if User.exists?(email: email) - - result = if user.blank? - # User does not exist - handle_new_user(result, email, user) - else - # User exists - handle_existing_user(result, user) - end + # Handle user invitation + result = handle_user(result, email, user) invite_results << result end invite_results @@ -49,6 +43,11 @@ module ClientApi private + def handle_user(result, email, user) + return handle_new_user(result, email, user) if user.blank? + handle_existing_user(result, user) + end + def handle_new_user(result, email, user) password = generate_user_password # Validate the user data @@ -151,7 +150,7 @@ module ClientApi message: sanitize_input(message) ) - if target_user.assignments_notification + if target_user.settings[:notifications][:assignments] UserNotification.create(notification: notification, user: target_user) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c266d562c..e5112418b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1825,3 +1825,5 @@ en: user_teams: leave_team_error: "An error occured." leave_flash: "Successfuly left team %{team}." + invite_users: + permission_error: "You don't have permission to invite additional users to team. Contact its administrator/s."