Simple pot-based access control

This commit is contained in:
Philip (a-0) 2024-01-21 12:24:05 +01:00
parent a768ce0f4e
commit d1b12e1562
15 changed files with 340 additions and 64 deletions

View file

@ -1,7 +1,7 @@
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::types::PotId;
use crate::types::{PotId, Pot};
use super::UbisyncRequest;
@ -68,6 +68,27 @@ impl UbisyncRequest for AppSetDefaultPotRequest {
Method::POST
}
fn path(&self, _: Self::PathParameters) -> String {
"/app/pot/default".to_string()
}
}
#[derive(Serialize, Deserialize)]
pub struct AppGetDefaultPotRequest;
#[derive(Serialize, Deserialize)]
pub struct AppGetDefaultPotResponse {
pub pot: Pot,
}
impl UbisyncRequest for AppGetDefaultPotRequest {
type PathParameters = ();
type Response = AppGetDefaultPotResponse;
fn method(&self) -> Method {
Method::GET
}
fn path(&self, _: Self::PathParameters) -> String {
"/app/pot/default".to_string()
}

View file

@ -1,13 +1,14 @@
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::types::{Element, ElementContent, ElementId};
use crate::types::{Element, ElementContent, ElementId, PotId};
use super::UbisyncRequest;
#[derive(Serialize, Deserialize)]
pub struct ElementCreateRequest {
pub content: ElementContent,
pub pot: Option<PotId>,
}
#[derive(Serialize, Deserialize)]

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::{ElementContent, ElementId, MessageId};
use crate::types::{ElementContent, ElementId, MessageId, PotId};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Message {
@ -22,6 +22,7 @@ pub enum MessageContent {
CreateElement {
id: ElementId,
content: ElementContent,
pot: PotId,
},
SetElement {
id: ElementId,
@ -30,6 +31,10 @@ pub enum MessageContent {
RemoveElement {
id: ElementId,
},
AddPot {
id: PotId,
app_type: String,
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]

View file

@ -1,23 +1,26 @@
use serde::{Deserialize, Serialize};
use super::{ElementContent, ElementId, MessageId};
use super::{ElementContent, ElementId, MessageId, PotId};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Element {
// Uuid identifying the element itself
id: ElementId,
pot: Option<PotId>,
content: ElementContent,
latest_message: Option<MessageId>,
local_changes: bool,
}
impl From<(ElementId, ElementContent, Option<MessageId>, bool)> for Element {
fn from(value: (ElementId, ElementContent, Option<MessageId>, bool)) -> Self {
impl From<(ElementId, Option<PotId>, ElementContent, Option<MessageId>, bool)> for Element {
fn from(value: (ElementId, Option<PotId>, ElementContent, Option<MessageId>, bool)) -> Self {
Element {
id: value.0,
content: value.1,
latest_message: value.2,
local_changes: value.3,
pot: value.1,
content: value.2,
latest_message: value.3,
local_changes: value.4,
}
}
}
@ -27,6 +30,7 @@ impl Element {
// A new element with no latest message must have local changes
Element {
id: id,
pot: None,
content: content,
latest_message: None,
local_changes: true,

View file

@ -4,8 +4,8 @@ use super::PotId;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Pot {
id: PotId,
app_type: String,
pub id: PotId,
pub app_type: String,
}
impl Pot {