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(-)
@@ -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)?;
@@ -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"
@@ -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 }))
}