Skip to content

Commit

Permalink
Run cargo fmt --all to fix formatting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-oconnell committed Nov 15, 2024
1 parent 6cec500 commit 6b3ade7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
11 changes: 8 additions & 3 deletions thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,8 @@ impl MutationRoot {
) -> FieldResult<Location> {
context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?;
// Only superusers can create new locations where Location Platform is Thoth
if !context.account_access.is_superuser && data.location_platform == LocationPlatform::Thoth {
if !context.account_access.is_superuser && data.location_platform == LocationPlatform::Thoth
{
return Err(ThothError::ThothLocationError.into());
}
context
Expand Down Expand Up @@ -1976,7 +1977,9 @@ impl MutationRoot {
context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?;
let location = Location::from_id(&context.db, &data.location_id).unwrap();
// Only superusers can edit locations where Location Platform is Thoth
if !context.account_access.is_superuser && location.location_platform == LocationPlatform::Thoth {
if !context.account_access.is_superuser
&& location.location_platform == LocationPlatform::Thoth
{
return Err(ThothError::ThothLocationError.into());
}
context
Expand Down Expand Up @@ -2303,7 +2306,9 @@ impl MutationRoot {
context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?;
let location = Location::from_id(&context.db, &location_id).unwrap();
// Only superusers can delete locations where Location Platform is Thoth
if !context.account_access.is_superuser && location.location_platform == LocationPlatform::Thoth {
if !context.account_access.is_superuser
&& location.location_platform == LocationPlatform::Thoth
{
return Err(ThothError::ThothLocationError.into());
}
context
Expand Down
31 changes: 25 additions & 6 deletions thoth-app/src/component/locations_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,30 @@ impl Component for LocationsFormComponent {
FetchState::Fetching(_) => vec![],
FetchState::Fetched(body) => {
// remove Thoth from LocationPlatform enum for non-superusers
if ctx.props().current_user.resource_access.restricted_to().is_some() {
body.data.location_platforms.enum_values
if ctx
.props()
.current_user
.resource_access
.restricted_to()
.is_some()
{
body.data
.location_platforms
.enum_values
.clone()
.into_iter()
.filter(|platform| *platform != LocationPlatformValues { name: LocationPlatform::Thoth })
.filter(|platform| {
*platform
!= LocationPlatformValues {
name: LocationPlatform::Thoth,
}
})
.collect()
} else {
body.data.location_platforms.enum_values.clone()
}
}
FetchState::Failed(_, _err) => vec![],

};
true
}
Expand Down Expand Up @@ -478,7 +490,7 @@ impl LocationsFormComponent {
);
let mut edit_callback = Some(
ctx.link()
.callback(move |_| Msg::ToggleModalFormDisplay(true, Some(location.clone())))
.callback(move |_| Msg::ToggleModalFormDisplay(true, Some(location.clone()))),
);
let mut delete_deactivated = false;
let mut edit_deactivated = false;
Expand All @@ -488,7 +500,14 @@ impl LocationsFormComponent {
delete_callback = None;
delete_deactivated = true;
// Restrict deleting locations with Thoth as location platform to superusers
} else if ctx.props().current_user.resource_access.restricted_to().is_some() && l.location_platform == LocationPlatform::Thoth {
} else if ctx
.props()
.current_user
.resource_access
.restricted_to()
.is_some()
&& l.location_platform == LocationPlatform::Thoth
{
delete_callback = None;
delete_deactivated = true;
edit_callback = None;
Expand Down

0 comments on commit 6b3ade7

Please sign in to comment.