add: journal page memberships
add: "Joined" write access option
This commit is contained in:
parent
daa223d529
commit
e87ad74d43
11 changed files with 290 additions and 10 deletions
|
@ -1,7 +1,9 @@
|
|||
use super::*;
|
||||
use crate::cache::Cache;
|
||||
use crate::model::auth::User;
|
||||
use crate::model::{Error, Result, journal::JournalEntry, permissions::FinePermission};
|
||||
use crate::model::{
|
||||
Error, Result, auth::User, journal::JournalEntry, journal::JournalPageWriteAccess,
|
||||
permissions::FinePermission,
|
||||
};
|
||||
use crate::{auto_method, execute, get, query_row};
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
|
@ -39,6 +41,29 @@ impl DataManager {
|
|||
return Err(Error::DataTooLong("username".to_string()));
|
||||
}
|
||||
|
||||
// check permission in page
|
||||
let page = match self.get_page_by_id(data.journal).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
match page.write_access {
|
||||
JournalPageWriteAccess::Owner => {
|
||||
if data.owner != page.owner {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
}
|
||||
JournalPageWriteAccess::Joined => {
|
||||
if let Err(_) = self
|
||||
.get_membership_by_owner_journal(data.owner, page.id)
|
||||
.await
|
||||
{
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
// ...
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue