diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..603fa38 --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +all: ci + +.PHONY: help +help: + @echo "Fallacious Rooster Makefile Help" + @echo "- ci-frontend Run CI only for the frontend" + @echo "- ci-server Run CI only for the server" + @echo "- ci Run all CI jobs" + @echo "- server-fmt-fix Apply fixes to formatting of the server" + +.PHONY: ci +ci: ci-frontend ci-server + +.PHONY: ci-frontend +ci-frontend: frontend-eslint + +.PHONY: ci-server +ci-server: server-fmt server-clippy server-test + +.PHONY: server-fmt +server-fmt: install-rustfmt + cd server && \ + cargo fmt --all --check + +.PHONY: server-fmt-fix +server-fmt-fix: install-rustfmt + cd server && \ + cargo fmt --all + +.PHONY: server-clippy +server-clippy: install-clippy + cd server && \ + cargo clippy + +.PHONY: server-test +server-test: install-rust + cd server && \ + cargo test + +.PHONY: frontend-eslint +frontend-eslint: install-frontend-modules + cd frontend && \ + yarn eslint + +.PHONY: install-rustfmt +install-rustfmt: install-rust + rustup component add rustfmt + +.PHONY: install-clippy +install-clippy: install-rust + rustup component add clippy + +.PHONY: install-frontend-modules +install-frontend-modules: + cd frontend && \ + yarn + +.PHONY: install-rust +install-rust: + rustup toolchain install stable --profile minimal diff --git a/README.md b/README.md index 33a5817..a6ed2b4 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,16 @@ Even though login is required, the application takes upmost care to ensure user The original idea for this application was put forward in [the policy of the 10th KKB on the kbALV on 2024-05-21, section 2.2](https://files.svsticky.nl/alv_stukken/2024_05_21_kbALV/Beleidsplan%2010e%20KKB.pdf). +## CI +Easily run CI locally with Make: +```bash +make +``` +See all commands with: +```bash +make help +``` + ## Development The guide below will tell you roughly how to get started with working on fallacious-rooster. diff --git a/frontend/src/layouts/AuthorizedMiddleware.vue b/frontend/src/layouts/UnauthorizedMiddleware.vue similarity index 89% rename from frontend/src/layouts/AuthorizedMiddleware.vue rename to frontend/src/layouts/UnauthorizedMiddleware.vue index 63a378c..d1de038 100644 --- a/frontend/src/layouts/AuthorizedMiddleware.vue +++ b/frontend/src/layouts/UnauthorizedMiddleware.vue @@ -11,10 +11,9 @@ - + @@ -28,7 +27,6 @@ import MaterialBanner from "@/views/components/MaterialBanner.vue"; interface Data { error: string | null, - loginOk: boolean, isAdmin: boolean, } @@ -49,11 +47,8 @@ export default defineComponent({ this.isAdmin = loginState.isAdmin; } else { - this.error = r.unwrapErr(); + this.isAdmin = false; } }, - methods: { - - } }) \ No newline at end of file diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 0d9cf25..b6caa9e 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -3,7 +3,7 @@ import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' const routes: Array = [ { path: '/', - component: () => import('@/layouts/AuthorizedMiddleware.vue'), + component: () => import('@/layouts/UnauthorizedMiddleware.vue'), children: [ { path: '', diff --git a/server/src/server/routes/config/confidential_advisors/list.rs b/server/src/server/routes/config/confidential_advisors/list.rs index 5b93009..6f8770c 100644 --- a/server/src/server/routes/config/confidential_advisors/list.rs +++ b/server/src/server/routes/config/confidential_advisors/list.rs @@ -13,7 +13,7 @@ pub struct Advisor { email: String, } -pub async fn list(_: Authorization, storage: WStorage) -> WResult> { +pub async fn list(_: Authorization, storage: WStorage) -> WResult> { Ok(web::Json(ListResponse { advisors: storage .0 diff --git a/server/src/server/types/authorization.rs b/server/src/server/types/authorization.rs index 025e88a..58a5575 100644 --- a/server/src/server/types/authorization.rs +++ b/server/src/server/types/authorization.rs @@ -6,7 +6,6 @@ use cabbage::oauth::ClientConfig; use cabbage::KoalaApi; use std::future::Future; use std::pin::Pin; -use std::str::FromStr; use thiserror::Error; pub struct Authorization { @@ -36,9 +35,9 @@ impl FromRequest for Authorization { fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { let req = req.clone(); Box::pin(async move { - #[cfg(debug_assertions)] - if is_debug_allow_unauthorized(&req) { - return Ok(Self { is_admin: true }); + 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) { @@ -76,19 +75,6 @@ impl FromRequest for Authorization { } } -/// Check if the `X-DebugAllowUnauthorized` header is present. -/// This is useful when working on the UI using the native Linux application, -/// which doesn't support browser redirects (obviously). -/// -/// During devlopment ACL can be ignored this way. -#[cfg(debug_assertions)] -fn is_debug_allow_unauthorized(req: &HttpRequest) -> bool { - match header(req, "X-DebugAllowUnauthorized") { - Some(hv) => bool::from_str(&hv).unwrap_or(false), - None => false, - } -} - fn get_token(req: &HttpRequest) -> Option { // Get the authorization from the Authorization header or an Authorization cookie let value = match header(req, "Authorization") {