Skip to content
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

controllers/version/yank: Use "403 Forbidden" for errors #8026

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/controllers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod cargo_prelude {
pub use super::prelude::*;
pub use crate::util::errors::cargo_err;
}

mod frontend_prelude {
Expand Down
7 changes: 5 additions & 2 deletions src/controllers/version/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::models::Rights;
use crate::models::{insert_version_owner_action, VersionAction};
use crate::rate_limiter::LimitedAction;
use crate::schema::versions;
use crate::util::errors::version_not_found;
use crate::util::errors::{custom, version_not_found};
use crate::worker::jobs;
use tokio::runtime::Handle;

Expand Down Expand Up @@ -77,7 +77,10 @@ fn modify_yank(
user.gh_login, krate.name, version.num
);
} else {
return Err(cargo_err("must already be an owner to yank or unyank"));
return Err(custom(
StatusCode::FORBIDDEN,
"must already be an owner to yank or unyank",
));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/routes/crates/versions/yank_unyank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn yank_by_a_non_owner_fails() {
});

let response = token.yank("foo_not", "1.0.0");
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.status(), StatusCode::FORBIDDEN);
assert_eq!(
response.json(),
json!({ "errors": [{ "detail": "must already be an owner to yank or unyank" }] })
Expand Down