fix error handeling, refactoring

This commit is contained in:
mlorb 2017-09-21 16:42:56 +02:00
parent ac3601bd2e
commit 9d96bf668a
5 changed files with 63 additions and 50 deletions

View file

@ -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

View file

@ -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() {

View file

@ -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."
}
}
}
};

View file

@ -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

View file

@ -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."