add: user is_deactivated
This commit is contained in:
parent
9ccbc69405
commit
63d3c2350d
13 changed files with 243 additions and 30 deletions
|
@ -121,6 +121,7 @@ impl DataManager {
|
|||
seller_data: serde_json::from_str(&get!(x->27(String)).to_string()).unwrap(),
|
||||
ban_reason: get!(x->28(String)),
|
||||
channel_mutes: serde_json::from_str(&get!(x->29(String)).to_string()).unwrap(),
|
||||
is_deactivated: get!(x->30(i32)) as i8 == 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,7 +278,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30)",
|
||||
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31)",
|
||||
params![
|
||||
&(data.id as i64),
|
||||
&(data.created as i64),
|
||||
|
@ -309,6 +310,7 @@ impl DataManager {
|
|||
&serde_json::to_string(&data.seller_data).unwrap(),
|
||||
&data.ban_reason,
|
||||
&serde_json::to_string(&data.channel_mutes).unwrap(),
|
||||
&if data.is_deactivated { 1_i32 } else { 0_i32 },
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -626,6 +628,44 @@ impl DataManager {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_user_is_deactivated(&self, id: usize, x: bool, user: User) -> Result<()> {
|
||||
if id != user.id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
let other_user = self.get_user_by_id(id).await?;
|
||||
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"UPDATE users SET is_deactivated = $1 WHERE id = $2",
|
||||
params![&{ if x { 1 } else { 0 } }, &(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
self.cache_clear_user(&other_user).await;
|
||||
|
||||
// create audit log entry
|
||||
self.create_audit_log_entry(AuditLogEntry::new(
|
||||
user.id,
|
||||
format!(
|
||||
"invoked `update_user_is_deactivated` with x value `{}` and y value `{}`",
|
||||
other_user.id, x
|
||||
),
|
||||
))
|
||||
.await?;
|
||||
|
||||
// ...
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_user_password(
|
||||
&self,
|
||||
id: usize,
|
||||
|
|
|
@ -44,7 +44,10 @@ impl DataManager {
|
|||
execute!(&conn, common::CREATE_TABLE_SERVICES).unwrap();
|
||||
execute!(&conn, common::CREATE_TABLE_PRODUCTS).unwrap();
|
||||
execute!(&conn, common::CREATE_TABLE_APP_DATA).unwrap();
|
||||
execute!(&conn, common::VERSION_MIGRATIONS).unwrap();
|
||||
|
||||
for x in common::VERSION_MIGRATIONS.split(";") {
|
||||
execute!(&conn, x).unwrap();
|
||||
}
|
||||
|
||||
self.0
|
||||
.1
|
||||
|
|
|
@ -28,5 +28,6 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
browser_session TEXT NOT NULL,
|
||||
seller_data TEXT NOT NULL,
|
||||
ban_reason TEXT NOT NULL,
|
||||
channel_mutes TEXT NOT NULL
|
||||
channel_mutes TEXT NOT NULL,
|
||||
is_deactivated INT NOT NULL
|
||||
)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
-- users channel_mutes
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS channel_mutes TEXT DEFAULT '[]';
|
||||
|
||||
-- users is_deactivated
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS is_deactivated INT DEFAULT 0;
|
||||
|
|
|
@ -397,7 +397,9 @@ impl DataManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ua.permissions.check_banned() | ignore_users.contains(&owner)
|
||||
if (ua.permissions.check_banned()
|
||||
| ignore_users.contains(&owner)
|
||||
| ua.is_deactivated)
|
||||
&& !ua.permissions.check(FinePermission::MANAGE_POSTS)
|
||||
{
|
||||
continue;
|
||||
|
|
|
@ -89,6 +89,10 @@ pub struct User {
|
|||
/// IDs of channels the user has muted.
|
||||
#[serde(default)]
|
||||
pub channel_mutes: Vec<usize>,
|
||||
/// If the user is deactivated. Deactivated users act almost like deleted
|
||||
/// users, but their data is not wiped.
|
||||
#[serde(default)]
|
||||
pub is_deactivated: bool,
|
||||
}
|
||||
|
||||
pub type UserConnections =
|
||||
|
@ -391,6 +395,7 @@ impl User {
|
|||
seller_data: StripeSellerData::default(),
|
||||
ban_reason: String::new(),
|
||||
channel_mutes: Vec::new(),
|
||||
is_deactivated: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue