mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +08:00
fix error handeling, refactoring
This commit is contained in:
parent
ac3601bd2e
commit
9d96bf668a
5 changed files with 63 additions and 50 deletions
|
@ -27,7 +27,14 @@ module ClientApi
|
||||||
|
|
||||||
def check_invite_users_permission
|
def check_invite_users_permission
|
||||||
@team = Team.find_by_id(params[:team_id])
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,10 +55,15 @@ class InviteUsersModal extends Component {
|
||||||
team_id: this.props.team.id
|
team_id: this.props.team.id
|
||||||
})
|
})
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
this.setState({ inviteResults: data });
|
this.setState({ inviteResults: data, showInviteUsersResults: true});
|
||||||
this.setState({ 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() {
|
render() {
|
||||||
|
|
|
@ -21,6 +21,43 @@ export default {
|
||||||
notifications_label: "Notifications",
|
notifications_label: "Notifications",
|
||||||
info_label: "Info"
|
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: {
|
settings_page: {
|
||||||
all_teams: "All teams",
|
all_teams: "All teams",
|
||||||
in_team: "You are member of {num} team",
|
in_team: "You are member of {num} team",
|
||||||
|
@ -145,43 +182,6 @@ export default {
|
||||||
greeting: "Hi, {name}",
|
greeting: "Hi, {name}",
|
||||||
settings: "Settings",
|
settings: "Settings",
|
||||||
log_out: "Log out"
|
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."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,14 +34,8 @@ module ClientApi
|
||||||
|
|
||||||
# Check if user already exists
|
# Check if user already exists
|
||||||
user = User.find_by_email(email) if User.exists?(email: email)
|
user = User.find_by_email(email) if User.exists?(email: email)
|
||||||
|
# Handle user invitation
|
||||||
result = if user.blank?
|
result = handle_user(result, email, user)
|
||||||
# User does not exist
|
|
||||||
handle_new_user(result, email, user)
|
|
||||||
else
|
|
||||||
# User exists
|
|
||||||
handle_existing_user(result, user)
|
|
||||||
end
|
|
||||||
invite_results << result
|
invite_results << result
|
||||||
end
|
end
|
||||||
invite_results
|
invite_results
|
||||||
|
@ -49,6 +43,11 @@ module ClientApi
|
||||||
|
|
||||||
private
|
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)
|
def handle_new_user(result, email, user)
|
||||||
password = generate_user_password
|
password = generate_user_password
|
||||||
# Validate the user data
|
# Validate the user data
|
||||||
|
@ -151,7 +150,7 @@ module ClientApi
|
||||||
message: sanitize_input(message)
|
message: sanitize_input(message)
|
||||||
)
|
)
|
||||||
|
|
||||||
if target_user.assignments_notification
|
if target_user.settings[:notifications][:assignments]
|
||||||
UserNotification.create(notification: notification, user: target_user)
|
UserNotification.create(notification: notification, user: target_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1825,3 +1825,5 @@ en:
|
||||||
user_teams:
|
user_teams:
|
||||||
leave_team_error: "An error occured."
|
leave_team_error: "An error occured."
|
||||||
leave_flash: "Successfuly left team %{team}."
|
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."
|
||||||
|
|
Loading…
Add table
Reference in a new issue