Skip to content

Conversation

@Mateusz-Dobrzynski
Copy link
Member

Resolves #47. Builds up on #46 and #49.

@Mateusz-Dobrzynski Mateusz-Dobrzynski self-assigned this Feb 28, 2025
@Mateusz-Dobrzynski Mateusz-Dobrzynski linked an issue Feb 28, 2025 that may be closed by this pull request
Copy link
Member

@jakubmanczak jakubmanczak left a 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.

Copy link
Member

@jakubmanczak jakubmanczak left a 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.

Comment on lines +113 to +116
match tournament_user.roles.is_empty() {
true => (),
false => return Err(OmniError::UnauthorizedError),
}
Copy link
Member

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.

Suggested change
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")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[error("ROLES_PARSING_MESSAGE")]
#[error("{ROLES_PARSING_MESSAGE}")]

InsufficientPermissionsError,
#[error("ROLES_PARSING_MESSAGE")]
RolesParsingError,
#[error("REFERRING_TO_A_NONEXISTENT_RESOURCE")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(e)?
Err(e)

"Error getting roles of user {} within tournament {}: {e}",
user_id, tournament_id
);
Err(e)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(e)?
Err(e)

"Error creating roles for user {} within tournament {}: {e}",
user_id, tournament_id
);
Err(e)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));
Copy link
Member

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.

Comment on lines +88 to +92
let mut string_vec: Vec<String> = vec![];
roles
.iter()
.for_each(|role| string_vec.push(role.to_string()));
return string_vec;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Copy link
Member

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);
Copy link
Member

@jakubmanczak jakubmanczak Oct 27, 2025

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.

Suggested change
let roles_as_strings = Role::roles_vec_to_string_vec(&roles);
let roles_as_strings = roles.to_string_vec();

_ => Err(OmniError::RolesParsingError),
}
}
}
Copy link
Member

@jakubmanczak jakubmanczak Oct 27, 2025

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

Suggested change
}
}
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()
}
}

@jakubmanczak
Copy link
Member

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.

@jakubmanczak
Copy link
Member

Also; does your autoformatting work? When testing this PR locally a lot of changes are made on save. That's not supposed to happen.

@jakubmanczak
Copy link
Member

Merging master into this branch is also in order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roles endpoints

3 participants