Skip to content

Commit

Permalink
Fix admin authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Sep 10, 2024
1 parent 233dbfa commit 028ef2a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Empty file added .github/workflows/release.yml
Empty file.
1 change: 0 additions & 1 deletion frontend/src/layouts/components/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
</v-menu>

<v-btn
v-if="isAdmin"
icon="mdi-cog"
to="/admin/settings"
/>
Expand Down
35 changes: 27 additions & 8 deletions server/src/server/types/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ impl<const ADMIN: bool> FromRequest for Authorization<ADMIN> {
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
let req = req.clone();
Box::pin(async move {
if !Self::ADMIN {
// We do not want authorization where admin rights aren't needed
return Ok(Self { is_admin: false });
}

let token = match get_token(&req) {
Some(token) => token,
None => return Err(AuthorizationError::NoToken),
None => {
return if Self::ADMIN {
Err(AuthorizationError::NoToken)
} else {
Ok(Self {
is_admin: false,
})
}
},
};

let config: &WConfig = req.app_data().unwrap();
Expand All @@ -58,8 +61,24 @@ impl<const ADMIN: bool> FromRequest for Authorization<ADMIN> {
Ok(userinfo) => userinfo,
Err(e) => {
return match e.status() {
Some(StatusCode::UNAUTHORIZED) => Err(AuthorizationError::NoToken),
_ => Err(AuthorizationError::Koala),
Some(StatusCode::UNAUTHORIZED) => {
if Self::ADMIN {
Err(AuthorizationError::NoToken)
} else {
Ok(Self {
is_admin: false,
})
}
},
_ => {
if Self::ADMIN {
Err(AuthorizationError::Koala)
} else {
Ok(Self {
is_admin: false,
})
}
},
}
}
};
Expand Down

0 comments on commit 028ef2a

Please sign in to comment.