-
Notifications
You must be signed in to change notification settings - Fork 1
[47] Roles endpoints #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
jakubmanczak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial; will return to this in the evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few things I caught, incl. a major critical auth logic bug.
Would also be nice to get rid of the unused import warnings - they've multiplied to be quite numerous by now.
| match tournament_user.roles.is_empty() { | ||
| true => (), | ||
| false => return Err(OmniError::UnauthorizedError), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that was what you meant to do here - this would formerly reject users with roles and allow through users without them.
| match tournament_user.roles.is_empty() { | |
| true => (), | |
| false => return Err(OmniError::UnauthorizedError), | |
| } | |
| if tournament_user.roles.is_empty() { | |
| return Err(OmniError::UnauthorizedError); | |
| } |
| BadRequestError, | ||
| #[error("{INSUFFICIENT_PERMISSIONS_MESSAGE}")] | ||
| InsufficientPermissionsError, | ||
| #[error("ROLES_PARSING_MESSAGE")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #[error("ROLES_PARSING_MESSAGE")] | |
| #[error("{ROLES_PARSING_MESSAGE}")] |
| InsufficientPermissionsError, | ||
| #[error("ROLES_PARSING_MESSAGE")] | ||
| RolesParsingError, | ||
| #[error("REFERRING_TO_A_NONEXISTENT_RESOURCE")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #[error("REFERRING_TO_A_NONEXISTENT_RESOURCE")] | |
| #[error("{REFERRING_TO_A_NONEXISTENT_RESOURCE}")] |
| "Error deleting roles of user {} within tournament {}: {e}", | ||
| user_id, tournament_id | ||
| ); | ||
| Err(e)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Err(e)? | |
| Err(e) |
| "Error getting roles of user {} within tournament {}: {e}", | ||
| user_id, tournament_id | ||
| ); | ||
| Err(e)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Err(e)? | |
| Err(e) |
| "Error creating roles for user {} within tournament {}: {e}", | ||
| user_id, tournament_id | ||
| ); | ||
| Err(e)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Err(e)? | |
| Err(e) |
| ) -> Result<Vec<Role>, OmniError> { | ||
| let _ = tournament_id; | ||
| let roles_as_strings = Role::roles_vec_to_string_vec(&roles); | ||
| roles_as_strings.iter().for_each(|r| info!(r)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we logging every time? This will be straight spam.
| let mut string_vec: Vec<String> = vec![]; | ||
| roles | ||
| .iter() | ||
| .for_each(|role| string_vec.push(role.to_string())); | ||
| return string_vec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let mut string_vec: Vec<String> = vec![]; | |
| roles | |
| .iter() | |
| .for_each(|role| string_vec.push(role.to_string())); | |
| return string_vec; | |
| let string_vec: Vec<String> = roles.iter().map(|r| r.to_string()).collect(); | |
| return string_vec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If implementing the trait below, obviously remove the method.
| pool: &Pool<Postgres>, | ||
| ) -> Result<Vec<Role>, OmniError> { | ||
| let _ = tournament_id; | ||
| let roles_as_strings = Role::roles_vec_to_string_vec(&roles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nicer to implement a Vec<Role> to Vec<String> converter via an extending trait, rather than make a method on Role that takes in a Vec as arg...
See suggestion and relevant impl below.
| let roles_as_strings = Role::roles_vec_to_string_vec(&roles); | |
| let roles_as_strings = roles.to_string_vec(); |
| _ => Err(OmniError::RolesParsingError), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nicer to implement a Vec to Vec converter via an extending trait, rather than make a method on Role that takes in a Vec as arg...
| } | |
| } | |
| trait RoleVecExt { | |
| fn to_string_vec(&self) -> Vec<String>; | |
| } | |
| impl RoleVecExt for Vec<Role> { | |
| fn to_string_vec(&self) -> Vec<String> { | |
| self.iter().map(|role| role.to_string()).collect() | |
| } | |
| } |
|
It would be nice not to implement Display and FromStr for unit enums by hand. The strum crate does this for us, but this can definitely be done in a future pull request as it will require integration of strum errors into OmniError. |
|
Also; does your autoformatting work? When testing this PR locally a lot of changes are made on save. That's not supposed to happen. |
|
Merging master into this branch is also in order. |
Resolves #47. Builds up on #46 and #49.