🏡 index : ~doyle/chartered.git

author Jordan Doyle <jordan@doyle.la> 2021-10-13 0:44:33.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2021-10-13 0:44:33.0 +01:00:00
commit
fdbcd3d902dfeb969f36492e20b6d9366f39b8b2 [patch]
tree
c554f9214615f990dd399c02400dd422bbda1c1d
parent
162035b7b543c89c2a40f1a0fd160f9038dca9e6
download
fdbcd3d902dfeb969f36492e20b6d9366f39b8b2.tar.gz

Ability to mark org as public while creating in the UI



Diff

 chartered-db/src/organisations.rs                                 |  4 +++-
 chartered-frontend/src/pages/organisations/CreateOrganisation.tsx | 23 +++++++++++++++++++++--
 chartered-web/src/endpoints/web_api/organisations/crud.rs         |  3 ++-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/chartered-db/src/organisations.rs b/chartered-db/src/organisations.rs
index 964f9ab..00953b0 100644
--- a/chartered-db/src/organisations.rs
+++ a/chartered-db/src/organisations.rs
@@ -99,13 +99,14 @@
        conn: ConnectionPool,
        given_name: String,
        given_description: String,
        given_public: bool,
        requesting_user_id: i32,
    ) -> Result<()> {
        tokio::task::spawn_blocking(move || {
            let conn = conn.get()?;

            conn.transaction::<_, crate::Error, _>(|| {
                use organisations::dsl::{description, id, name, uuid};
                use organisations::dsl::{description, id, name, uuid, public};
                use user_organisation_permissions::dsl::{organisation_id, permissions, user_id};

                let generated_uuid = SqlUuid::random();
@@ -115,6 +116,7 @@
                        uuid.eq(generated_uuid),
                        name.eq(given_name),
                        description.eq(given_description),
                        public.eq(given_public),
                    ))
                    .execute(&conn)?;

diff --git a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx b/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx
index 3b1e9cd..75de76e 100644
--- a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx
+++ a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx
@@ -17,7 +17,10 @@

  const [name, setName] = useState("");
  const [description, setDescription] = useState("");
  const [publicOrg, setPublicOrg] = useState(false);

  console.log(publicOrg);

  const createOrganisation = async (evt) => {
    evt.preventDefault();

@@ -30,7 +33,7 @@
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ name, description }),
        body: JSON.stringify({ name, description, 'public': publicOrg }),
      });
      let json = await res.json();

@@ -67,7 +70,7 @@
            className="btn-close"
            aria-label="Close"
            onClick={() => setError("")}
          ></button>
            />
        </div>

        <div className="card border-0 shadow-sm text-black">
@@ -103,10 +106,24 @@
                  onChange={(e) => setDescription(e.target.value)}
                  disabled={loading}
                  value={description}
                />
              </div>

              <div className="mt-2 form-check">
                <input
                    type="checkbox"
                    checked={publicOrg}
                    id="org-public"
                    className="form-check-input"
                    onChange={(e) => setPublicOrg(e.target.checked)}
                    disabled={loading}
                />
                <label htmlFor="org-public" className="form-check-label">
                  Give <strong>VISIBLE</strong> permission to all logged in users
                </label>
              </div>

              <div className="clearfix"></div>
              <div className="clearfix" />

              <button
                type="submit"
diff --git a/chartered-web/src/endpoints/web_api/organisations/crud.rs b/chartered-web/src/endpoints/web_api/organisations/crud.rs
index 2751a32..7f91de2 100644
--- a/chartered-web/src/endpoints/web_api/organisations/crud.rs
+++ a/chartered-web/src/endpoints/web_api/organisations/crud.rs
@@ -26,6 +26,7 @@
pub struct PutRequest {
    name: String,
    description: String,
    public: bool,
}

pub async fn handle_put(
@@ -33,7 +34,7 @@
    extract::Extension(user): extract::Extension<Arc<User>>,
    extract::Json(req): extract::Json<PutRequest>,
) -> Result<Json<ErrorResponse>, Error> {
    Organisation::create(db, req.name, req.description, user.id).await?;
    Organisation::create(db, req.name, req.description, req.public, user.id).await?;

    Ok(Json(ErrorResponse { error: None }))
}