add: profile is_verified
add: better profile not found page TODO: use error page for fallback service
This commit is contained in:
parent
7d96a3d20f
commit
5cfca49793
13 changed files with 234 additions and 20 deletions
|
@ -29,10 +29,11 @@ impl DataManager {
|
|||
settings: serde_json::from_str(&get!(x->5(String)).to_string()).unwrap(),
|
||||
tokens: serde_json::from_str(&get!(x->6(String)).to_string()).unwrap(),
|
||||
permissions: FinePermission::from_bits(get!(x->7(u32))).unwrap(),
|
||||
is_verified: if get!(x->8(i8)) == 1 { true } else { false },
|
||||
// counts
|
||||
notification_count: get!(x->8(i64)) as usize,
|
||||
follower_count: get!(x->9(i64)) as usize,
|
||||
following_count: get!(x->10(i64)) as usize,
|
||||
notification_count: get!(x->9(i64)) as usize,
|
||||
follower_count: get!(x->10(i64)) as usize,
|
||||
following_count: get!(x->11(i64)) as usize,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
||||
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
|
||||
&[
|
||||
&data.id.to_string().as_str(),
|
||||
&data.created.to_string().as_str(),
|
||||
|
@ -101,6 +102,7 @@ impl DataManager {
|
|||
&serde_json::to_string(&data.settings).unwrap().as_str(),
|
||||
&serde_json::to_string(&data.tokens).unwrap().as_str(),
|
||||
&(FinePermission::DEFAULT.bits()).to_string().as_str(),
|
||||
&(if data.is_verified { 1 } else { 0 }).to_string().as_str(),
|
||||
&0.to_string().as_str(),
|
||||
&0.to_string().as_str(),
|
||||
&0.to_string().as_str()
|
||||
|
@ -144,6 +146,34 @@ impl DataManager {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_user_verified_status(&self, id: usize, x: bool, user: User) -> Result<()> {
|
||||
if !user.permissions.check(FinePermission::MANAGE_VERIFIED) {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"UPDATE users SET is_verified = $1 WHERE id = $2",
|
||||
&[
|
||||
&(if x { 1 } else { 0 }).to_string().as_str(),
|
||||
&serde_json::to_string(&x).unwrap().as_str()
|
||||
]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.2.remove(format!("atto.user:{}", id)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
auto_method!(update_user_tokens(Vec<Token>) -> "UPDATE users SET tokens = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.user:{}");
|
||||
auto_method!(update_user_settings(UserSettings) -> "UPDATE users SET settings = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.user:{}");
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
settings TEXT NOT NULL,
|
||||
tokens TEXT NOT NULL,
|
||||
permissions INTEGER NOT NULL,
|
||||
verified INTEGER NOT NULL,
|
||||
-- counts
|
||||
notification_count INTEGER NOT NULL,
|
||||
follower_count INTEGER NOT NULL,
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::model::{
|
|||
Error, Result, auth::User, journal::JournalPost, journal::JournalWriteAccess,
|
||||
permissions::FinePermission,
|
||||
};
|
||||
use crate::{auto_method, execute, get, query_row};
|
||||
use crate::{auto_method, execute, get, query_row, query_rows};
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
use rusqlite::Row;
|
||||
|
@ -60,7 +60,7 @@ impl DataManager {
|
|||
|
||||
let res = query_row!(
|
||||
&conn,
|
||||
"SELECT * FROM posts WHERE replying_to = $1 LIMIT $2 OFFSET $3",
|
||||
"SELECT * FROM posts WHERE replying_to = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||
|x| { Ok(Self::get_post_from_row(x)) }
|
||||
);
|
||||
|
@ -72,6 +72,37 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all posts from the given user (from most recent).
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `id` - the ID of the user the requested posts belong to
|
||||
/// * `batch` - the limit of posts in each page
|
||||
/// * `page` - the page number
|
||||
pub async fn get_posts_by_user(
|
||||
&self,
|
||||
id: usize,
|
||||
batch: usize,
|
||||
page: usize,
|
||||
) -> Result<Vec<JournalPost>> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM posts WHERE owner = $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||
|x| { Self::get_post_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("post".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new journal entry in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -19,6 +19,7 @@ pub struct User {
|
|||
pub settings: UserSettings,
|
||||
pub tokens: Vec<Token>,
|
||||
pub permissions: FinePermission,
|
||||
pub is_verified: bool,
|
||||
pub notification_count: usize,
|
||||
pub follower_count: usize,
|
||||
pub following_count: usize,
|
||||
|
@ -62,6 +63,7 @@ impl User {
|
|||
settings: UserSettings::default(),
|
||||
tokens: Vec::new(),
|
||||
permissions: FinePermission::DEFAULT,
|
||||
is_verified: false,
|
||||
notification_count: 0,
|
||||
follower_count: 0,
|
||||
following_count: 0,
|
||||
|
|
|
@ -22,6 +22,7 @@ bitflags! {
|
|||
const MANAGE_MEMBERSHIPS = 1 << 11;
|
||||
const MANAGE_REACTIONS = 1 << 12;
|
||||
const MANAGE_FOLLOWS = 1 << 13;
|
||||
const MANAGE_VERIFIED = 1 << 14;
|
||||
|
||||
const _ = !0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue