🏡 index : ~doyle/chartered.git

author Jordan Doyle <jordan@doyle.la> 2021-10-21 1:01:27.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2021-10-21 1:02:11.0 +01:00:00
commit
ac74d20d41af005f793aae778083c38d63456ade [patch]
tree
4f1e4a1037d1266032bcb8ab6806a4742181ef2f
parent
7cbd5c3f58318ae8c94f0d5b670a0611c0fe46a9
download
ac74d20d41af005f793aae778083c38d63456ade.tar.gz

yarn fmt



Diff

 chartered-frontend/src/index.tsx                                  | 19 +++++++++++++------
 chartered-frontend/src/overscrollColourFixer.ts                   |  6 ++++--
 chartered-frontend/src/useAuth.tsx                                | 25 ++++++++++++++-----------
 chartered-frontend/src/pages/Dashboard.tsx                        | 32 +++++++++++++++++++++++++-------
 chartered-frontend/src/pages/Login.tsx                            | 12 ++++++++++--
 chartered-frontend/src/pages/Search.tsx                           | 17 ++++++-----------
 chartered-frontend/src/pages/User.tsx                             |  7 ++-----
 chartered-frontend/src/sections/Nav.tsx                           | 13 +++++++++++--
 chartered-web/src/middleware/auth.rs                              |  4 ++--
 chartered-frontend/src/pages/crate/CrateView.tsx                  | 17 ++++++++++-------
 chartered-frontend/src/pages/crate/Members.tsx                    | 17 +++++++----------
 chartered-frontend/src/pages/crate/OrganisationView.tsx           |  2 +-
 chartered-frontend/src/pages/organisations/CreateOrganisation.tsx |  2 +-
 chartered-frontend/src/pages/organisations/ListOrganisations.tsx  |  2 +-
 chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx              |  2 +-
 chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx             |  2 +-
 chartered-web/src/endpoints/web_api/auth/logout.rs                |  8 +++-----
 chartered-web/src/endpoints/web_api/auth/mod.rs                   | 17 ++++++++---------
 18 files changed, 115 insertions(+), 89 deletions(-)

diff --git a/chartered-frontend/src/index.tsx b/chartered-frontend/src/index.tsx
index f82144d..a983d10 100644
--- a/chartered-frontend/src/index.tsx
+++ a/chartered-frontend/src/index.tsx
@@ -25,17 +25,22 @@
import CreateOrganisation from "./pages/organisations/CreateOrganisation";
import User from "./pages/User";
import Search from "./pages/Search";
import {backgroundFix} from "./overscrollColourFixer";
import { backgroundFix } from "./overscrollColourFixer";

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
if (
  window.matchMedia &&
  window.matchMedia("(prefers-color-scheme: dark)").matches
) {
  document.querySelector("body")?.classList.add("dark");
}

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
  const body = document.querySelector("body");
  body?.classList.toggle("dark", e.matches);
  backgroundFix(body);
});
window
  .matchMedia("(prefers-color-scheme: dark)")
  .addEventListener("change", (e) => {
    const body = document.querySelector("body");
    body?.classList.toggle("dark", e.matches);
    backgroundFix(body);
  });

function App() {
  return (
diff --git a/chartered-frontend/src/overscrollColourFixer.ts b/chartered-frontend/src/overscrollColourFixer.ts
index 1cf8424..2b6a5d5 100644
--- a/chartered-frontend/src/overscrollColourFixer.ts
+++ a/chartered-frontend/src/overscrollColourFixer.ts
@@ -5,9 +5,11 @@

export const backgroundFix = (body: HTMLBodyElement | null) => {
  if (body?.classList.contains("dark")) {
    document.documentElement.style.backgroundColor = window.scrollY > 70 ? "#0e1825" : "#2a3746";
    document.documentElement.style.backgroundColor =
      window.scrollY > 70 ? "#0e1825" : "#2a3746";
  } else {
    document.documentElement.style.backgroundColor = window.scrollY > 70 ? "var(--bs-primary)" : "white";
    document.documentElement.style.backgroundColor =
      window.scrollY > 70 ? "var(--bs-primary)" : "white";
  }
};

diff --git a/chartered-frontend/src/useAuth.tsx b/chartered-frontend/src/useAuth.tsx
index cf90e5e..b64805f 100644
--- a/chartered-frontend/src/useAuth.tsx
+++ a/chartered-frontend/src/useAuth.tsx
@@ -1,6 +1,10 @@
import { useState, useEffect, useContext, createContext } from "react";
import { useLocation, Redirect } from "react-router-dom";
import {authenticatedEndpoint, BASE_URL, unauthenticatedEndpoint} from "./util";
import {
  authenticatedEndpoint,
  BASE_URL,
  unauthenticatedEndpoint,
} from "./util";
import LoadingPage from "./pages/Loading";

export interface OAuthProviders {
@@ -148,18 +152,15 @@
    }

    try {
      await fetch(
          `${BASE_URL}/a/${getAuthKey()}/web/v1/auth/logout`,
          {
            method: "GET",
            headers: {
              "Content-Type": "application/json",
              "User-Agent": window.navigator.userAgent,
            },
          }
      );
      await fetch(`${BASE_URL}/a/${getAuthKey()}/web/v1/auth/logout`, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
          "User-Agent": window.navigator.userAgent,
        },
      });
    } catch (e) {
      console.error("Failed to fully log user out of session", e)
      console.error("Failed to fully log user out of session", e);
    } finally {
      setAuth(null);
    }
diff --git a/chartered-frontend/src/pages/Dashboard.tsx b/chartered-frontend/src/pages/Dashboard.tsx
index 948355b..1c4abde 100644
--- a/chartered-frontend/src/pages/Dashboard.tsx
+++ a/chartered-frontend/src/pages/Dashboard.tsx
@@ -1,6 +1,6 @@
import { PropsWithChildren } from "react";

import {Link, Redirect} from "react-router-dom";
import { Link, Redirect } from "react-router-dom";
import { useAuth } from "../useAuth";
import Nav from "../sections/Nav";
import { Calendar3, ChevronRight, Download } from "react-bootstrap-icons";
@@ -87,9 +87,13 @@
        <div className="row">
          <div className="col-12 col-md-4">
            <h4>Newly Created</h4>
            {recentlyCreatedError ? <div className="alert alert-danger" role="alert">
              {recentlyCreatedError}
            </div> : <></>}
            {recentlyCreatedError ? (
              <div className="alert alert-danger" role="alert">
                {recentlyCreatedError}
              </div>
            ) : (
              <></>
            )}
            {(recentlyCreated?.crates || []).map((v) => (
              <CrateCard
                key={v.name}
@@ -114,9 +118,13 @@

          <div className="col-12 col-md-4">
            <h4>Recently Updated</h4>
            {recentlyUpdatedError ? <div className="alert alert-danger" role="alert">
              {recentlyUpdatedError}
            </div> : <></>}
            {recentlyUpdatedError ? (
              <div className="alert alert-danger" role="alert">
                {recentlyUpdatedError}
              </div>
            ) : (
              <></>
            )}
            {(recentlyUpdated?.versions || []).map((v) => (
              <CrateCard
                key={v.name}
@@ -130,9 +138,13 @@

          <div className="col-12 col-md-4">
            <h4>Most Downloaded</h4>
            {mostDownloadedError ? <div className="alert alert-danger" role="alert">
              {mostDownloadedError}
            </div> : <></>}
            {mostDownloadedError ? (
              <div className="alert alert-danger" role="alert">
                {mostDownloadedError}
              </div>
            ) : (
              <></>
            )}
            {(mostDownloaded?.crates || []).map((v) => (
              <CrateCard
                key={v.name}
diff --git a/chartered-frontend/src/pages/Login.tsx b/chartered-frontend/src/pages/Login.tsx
index e81a4bf..b1f3bc0 100644
--- a/chartered-frontend/src/pages/Login.tsx
+++ a/chartered-frontend/src/pages/Login.tsx
@@ -1,4 +1,10 @@
import {useState, useEffect, useRef, SyntheticEvent, MouseEventHandler} from "react";
import {
  useState,
  useEffect,
  useRef,
  SyntheticEvent,
  MouseEventHandler,
} from "react";
import { useLocation } from "react-router-dom";

import { useAuth } from "../useAuth";
@@ -37,7 +43,9 @@
    }

    isMountedRef.current = true;
    return () => { isMountedRef.current = false };
    return () => {
      isMountedRef.current = false;
    };
  });

  const handleSubmit = async (evt: SyntheticEvent) => {
diff --git a/chartered-frontend/src/pages/Search.tsx b/chartered-frontend/src/pages/Search.tsx
index 92350a8..561a5da 100644
--- a/chartered-frontend/src/pages/Search.tsx
+++ a/chartered-frontend/src/pages/Search.tsx
@@ -1,11 +1,8 @@
import { Link, useLocation } from "react-router-dom";

import Nav from "../sections/Nav";
import { useAuth } from "../useAuth";
import {
  ProfilePicture,
  useAuthenticatedRequest,
} from "../util";
import { ProfilePicture, useAuthenticatedRequest } from "../util";

import { BoxSeam } from "react-bootstrap-icons";
import { LoadingSpinner } from "./Loading";
@@ -46,7 +43,7 @@
  const auth = useAuth();

  if (!auth) {
      return <></>;
    return <></>;
  }

  const { response: results, error } =
@@ -59,7 +56,7 @@
    );

  if (error) {
      return <div className="alert alert-danger">{error}</div>;
    return <div className="alert alert-danger">{error}</div>;
  }

  if (!results) {
@@ -125,7 +122,7 @@
  const auth = useAuth();

  if (!auth) {
      return <></>;
    return <></>;
  }

  const { response: results, error } =
@@ -138,7 +135,7 @@
    );

  if (error) {
      return <div className="alert alert-danger">{error}</div>
    return <div className="alert alert-danger">{error}</div>;
  }

  if (!results) {
@@ -175,9 +172,7 @@
                      className="text-decoration-none"
                    >
                      <h4 className="text-primary d-inline px-2 m-0">
                        <span className="text-muted">
                          {crate.organisation}
                        </span>
                        <span className="text-muted">{crate.organisation}</span>
                        /{crate.name}
                      </h4>
                    </Link>
diff --git a/chartered-frontend/src/pages/User.tsx b/chartered-frontend/src/pages/User.tsx
index e1bc288..0e9e7e9 100644
--- a/chartered-frontend/src/pages/User.tsx
+++ a/chartered-frontend/src/pages/User.tsx
@@ -1,9 +1,6 @@
import {Redirect, useParams} from "react-router-dom";
import { Redirect, useParams } from "react-router-dom";
import { useAuth } from "../useAuth";
import {
  ProfilePicture,
  useAuthenticatedRequest,
} from "../util";
import { ProfilePicture, useAuthenticatedRequest } from "../util";
import Nav from "../sections/Nav";
import ErrorPage from "./ErrorPage";
import ReactPlaceholder from "react-placeholder/lib";
diff --git a/chartered-frontend/src/sections/Nav.tsx b/chartered-frontend/src/sections/Nav.tsx
index ed6a58f..a8d7bad 100644
--- a/chartered-frontend/src/sections/Nav.tsx
+++ a/chartered-frontend/src/sections/Nav.tsx
@@ -1,4 +1,4 @@
import {SyntheticEvent, useState} from "react";
import { SyntheticEvent, useState } from "react";
import { useHistory, useLocation } from "react-router-dom";
import { NavLink, Link } from "react-router-dom";

@@ -51,7 +51,16 @@
              </NavLink>
            </li>
            <li className="nav-item">
              <NavLink to="/organisations" className="nav-link">
              <NavLink
                to="/organisations"
                className="nav-link"
                isActive={(match, location) => {
                  return (
                    location.pathname.startsWith("/organisations/") ||
                    location.pathname.startsWith("/crates/")
                  );
                }}
              >
                Organisations
              </NavLink>
            </li>
diff --git a/chartered-web/src/middleware/auth.rs b/chartered-web/src/middleware/auth.rs
index 2544106..4c66dbf 100644
--- a/chartered-web/src/middleware/auth.rs
+++ a/chartered-web/src/middleware/auth.rs
@@ -1,17 +1,17 @@
use axum::{
    body::{box_body, Body, BoxBody},
    extract::{self, FromRequest, RequestParts},
    http::{Request, Response, StatusCode},
};
use chartered_db::users::User;
use chartered_db::ConnectionPool;
use futures::future::BoxFuture;
use std::sync::Arc;
use std::{
    collections::HashMap,
    task::{Context, Poll},
};
use std::sync::Arc;
use tower::Service;
use chartered_db::users::User;

use crate::endpoints::ErrorResponse;

diff --git a/chartered-frontend/src/pages/crate/CrateView.tsx b/chartered-frontend/src/pages/crate/CrateView.tsx
index bb45286..697609f 100644
--- a/chartered-frontend/src/pages/crate/CrateView.tsx
+++ a/chartered-frontend/src/pages/crate/CrateView.tsx
@@ -73,7 +73,11 @@

export default function SingleCrate() {
  const auth = useAuth();
  const { organisation, crate, subview: currentTab } = useParams<UrlParameters>();
  const {
    organisation,
    crate,
    subview: currentTab,
  } = useParams<UrlParameters>();

  if (!auth) {
    return <Redirect to="/login" />;
@@ -315,13 +319,12 @@
  crate: string;
}

function Members({
  organisation,
  crate,
}: MembersProps) {
function Members({ organisation, crate }: MembersProps) {
  const auth = useAuth();

  if (!auth) { return <></>; }
  if (!auth) {
    return <></>;
  }

  const [reload, setReload] = useState(0);
  const { response, error } = useAuthenticatedRequest<CratesMembersResponse>(
@@ -349,7 +352,7 @@
  const saveMemberPermissions = async (
    prospectiveMember: boolean,
    uuid: string,
    selectedPermissions: string[],
    selectedPermissions: string[]
  ) => {
    let res = await fetch(
      authenticatedEndpoint(auth, `crates/${organisation}/${crate}/members`),
diff --git a/chartered-frontend/src/pages/crate/Members.tsx b/chartered-frontend/src/pages/crate/Members.tsx
index 6f9613f..a671ede 100644
--- a/chartered-frontend/src/pages/crate/Members.tsx
+++ a/chartered-frontend/src/pages/crate/Members.tsx
@@ -1,14 +1,7 @@
import { useState, useEffect, useRef } from "react";
import { Link } from "react-router-dom";
import {
  Trash,
  CheckLg,
  PlusLg, PersonPlusFill,
} from "react-bootstrap-icons";
import {
  authenticatedEndpoint,
  ProfilePicture,
} from "../../util";
import { Trash, CheckLg, PlusLg, PersonPlusFill } from "react-bootstrap-icons";
import { authenticatedEndpoint, ProfilePicture } from "../../util";
import { useAuth } from "../../useAuth";
import { Button, Modal } from "react-bootstrap";
import { AsyncTypeahead } from "react-bootstrap-typeahead";
@@ -250,7 +243,11 @@

interface MemberListInserterProps {
  existingMembers: Member[];
  onInsert: (username: string, user_uuid: string, picture_url: string | null) => any;
  onInsert: (
    username: string,
    user_uuid: string,
    picture_url: string | null
  ) => any;
}

interface SearchOption {
diff --git a/chartered-frontend/src/pages/crate/OrganisationView.tsx b/chartered-frontend/src/pages/crate/OrganisationView.tsx
index 138e59f..e14faa6 100644
--- a/chartered-frontend/src/pages/crate/OrganisationView.tsx
+++ a/chartered-frontend/src/pages/crate/OrganisationView.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
import {Link, Redirect, useParams} from "react-router-dom";
import { Link, Redirect, useParams } from "react-router-dom";

import Nav from "../../sections/Nav";
import { useAuth } from "../../useAuth";
diff --git a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx b/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx
index d8feeac..c53968a 100644
--- a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx
+++ a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx
@@ -1,4 +1,4 @@
import {SyntheticEvent, useState} from "react";
import { SyntheticEvent, useState } from "react";
import { Link, useHistory } from "react-router-dom";

import Nav from "../../sections/Nav";
diff --git a/chartered-frontend/src/pages/organisations/ListOrganisations.tsx b/chartered-frontend/src/pages/organisations/ListOrganisations.tsx
index 9ef34dc..8859099 100644
--- a/chartered-frontend/src/pages/organisations/ListOrganisations.tsx
+++ a/chartered-frontend/src/pages/organisations/ListOrganisations.tsx
@@ -1,5 +1,5 @@
import { Plus } from "react-bootstrap-icons";
import {Link, Redirect} from "react-router-dom";
import { Link, Redirect } from "react-router-dom";

import Nav from "../../sections/Nav";
import { useAuth } from "../../useAuth";
diff --git a/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx b/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx
index cf15065..f213501 100644
--- a/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx
+++ a/chartered-frontend/src/pages/ssh-keys/AddSshKeys.tsx
@@ -1,4 +1,4 @@
import {SyntheticEvent, useState} from "react";
import { SyntheticEvent, useState } from "react";
import { Link, useHistory } from "react-router-dom";

import Nav from "../../sections/Nav";
diff --git a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx b/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx
index bbce0bd..d4603f8 100644
--- a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx
+++ a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
import {Link, Redirect} from "react-router-dom";
import { Link, Redirect } from "react-router-dom";

import Nav from "../../sections/Nav";
import { useAuth } from "../../useAuth";
diff --git a/chartered-web/src/endpoints/web_api/auth/logout.rs b/chartered-web/src/endpoints/web_api/auth/logout.rs
index 3d0696e..85d0526 100644
--- a/chartered-web/src/endpoints/web_api/auth/logout.rs
+++ a/chartered-web/src/endpoints/web_api/auth/logout.rs
@@ -1,9 +1,9 @@
use std::sync::Arc;
use axum::{extract, Json};
use chartered_db::users::UserSession;
use chartered_db::ConnectionPool;
use serde::Serialize;
use std::sync::Arc;
use thiserror::Error;
use chartered_db::users::UserSession;

pub async fn handle(
    extract::Extension(session): extract::Extension<Arc<UserSession>>,
@@ -11,9 +11,7 @@
) -> Result<Json<LogoutResponse>, Error> {
    session.delete(db).await?;

    Ok(Json(LogoutResponse {
        success: true,
    }))
    Ok(Json(LogoutResponse { success: true }))
}

#[derive(Debug, Serialize)]
diff --git a/chartered-web/src/endpoints/web_api/auth/mod.rs b/chartered-web/src/endpoints/web_api/auth/mod.rs
index 1445227..094ecbb 100644
--- a/chartered-web/src/endpoints/web_api/auth/mod.rs
+++ a/chartered-web/src/endpoints/web_api/auth/mod.rs
@@ -14,21 +14,20 @@
use serde::Serialize;
use std::convert::Infallible;

pub mod logout;
pub mod openid;
pub mod password;
pub mod logout;

pub fn authenticated_routes() -> Router<
    impl tower::Service<
        Request<Body>,
        Response = Response<BoxBody>,
        Error = Infallible,
        Future = impl Future<Output = Result<Response<BoxBody>, Infallible>> + Send,
    > + Clone
    + Send,
            Request<Body>,
            Response = Response<BoxBody>,
            Error = Infallible,
            Future = impl Future<Output = Result<Response<BoxBody>, Infallible>> + Send,
        > + Clone
        + Send,
> {
    crate::axum_box_after_every_route!(Router::new()
        .route("/logout", get(logout::handle)))
    crate::axum_box_after_every_route!(Router::new().route("/logout", get(logout::handle)))
}

pub fn unauthenticated_routes() -> Router<