🏡 index : ~doyle/chartered.git

author Jordan Doyle <jordan@doyle.la> 2021-11-04 23:01:24.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2021-11-04 23:01:24.0 +00:00:00
commit
d35012210d260b473f7eacd034e491013deb34d4 [patch]
tree
8a792f7ed71083e69026f7500eddabb41216f663
parent
38739eaddd42ffdeeb08302dd99b98821e10d9e1
download
d35012210d260b473f7eacd034e491013deb34d4.tar.gz

Fix 500 when pushing to non-existent org

Closes #26

Diff

 chartered-db/src/crates.rs                       | 4 ++++
 chartered-web/src/endpoints/cargo_api/publish.rs | 7 ++++++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/chartered-db/src/crates.rs b/chartered-db/src/crates.rs
index f1db911..16f894c 100644
--- a/chartered-db/src/crates.rs
+++ a/chartered-db/src/crates.rs
@@ -301,7 +301,9 @@
                        .on(organisation_id.eq(id).and(user_id.eq(requesting_user_id))),
                )
                .select((id, permissions))
                .first::<(i32, UserPermission)>(&conn)?;
                .first::<(i32, UserPermission)>(&conn)
                .optional()?
                .ok_or(Error::MissingOrganisation)?;

            #[allow(clippy::if_not_else)]
            if !perms.contains(UserPermission::VISIBLE) {
diff --git a/chartered-web/src/endpoints/cargo_api/publish.rs b/chartered-web/src/endpoints/cargo_api/publish.rs
index 685c9ad..c256325 100644
--- a/chartered-web/src/endpoints/cargo_api/publish.rs
+++ a/chartered-web/src/endpoints/cargo_api/publish.rs
@@ -245,10 +245,11 @@
        use axum::http::StatusCode;

        match self {
            Self::JsonParse(_)
            | Self::MetadataParse
            | Self::InvalidCrateName
            | Self::Database(chartered_db::Error::MissingOrganisation) => StatusCode::BAD_REQUEST,
            Self::Database(e) => e.status_code(),
            Self::JsonParse(_) | Self::MetadataParse | Self::InvalidCrateName => {
                StatusCode::BAD_REQUEST
            }
            Self::File(_) => StatusCode::INTERNAL_SERVER_ERROR,
        }
    }