add: user last_policy_consent

This commit is contained in:
trisua 2025-08-13 02:22:00 -04:00
parent befd9096b1
commit 2edef9bd35
11 changed files with 107 additions and 9 deletions

View file

@ -121,6 +121,15 @@ pub struct PoliciesConfig {
///
/// Same deal as terms of service page.
pub privacy: String,
/// The time (in ms since unix epoch) in which the site's policies last updated.
///
/// This is required to automatically ask users to re-consent to policies.
///
/// In user whose consent time in LESS THAN this date will be shown a dialog to re-consent to the policies.
///
/// You can get this easily by running `echo "console.log(new Date().getTime())" | node`.
#[serde(default)]
pub last_updated: usize,
}
impl Default for PoliciesConfig {
@ -128,6 +137,7 @@ impl Default for PoliciesConfig {
Self {
terms_of_service: "/public/tos.html".to_string(),
privacy: "/public/privacy.html".to_string(),
last_updated: 0,
}
}
}

View file

@ -131,6 +131,7 @@ impl DataManager {
coins: get!(x->31(i32)),
checkouts: serde_json::from_str(&get!(x->32(String)).to_string()).unwrap(),
applied_configurations: serde_json::from_str(&get!(x->33(String)).to_string()).unwrap(),
last_policy_consent: get!(x->34(i64)) as usize,
}
}
@ -287,7 +288,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, $31, $32, $33, $34)",
"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, $32, $33, $34, $35)",
params![
&(data.id as i64),
&(data.created as i64),
@ -323,6 +324,7 @@ impl DataManager {
&(data.coins as i32),
&serde_json::to_string(&data.checkouts).unwrap(),
&serde_json::to_string(&data.applied_configurations).unwrap(),
&(data.last_policy_consent as i64)
]
);
@ -1161,6 +1163,7 @@ impl DataManager {
auto_method!(update_user_coins(i32)@get_user_by_id -> "UPDATE users SET coins = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_checkouts(Vec<String>)@get_user_by_id -> "UPDATE users SET checkouts = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_applied_configurations(Vec<(AppliedConfigType, usize)>)@get_user_by_id -> "UPDATE users SET applied_configurations = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_last_policy_consent(i64)@get_user_by_id -> "UPDATE users SET last_policy_consent = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
auto_method!(get_user_by_stripe_id(&str)@get_user_from_row -> "SELECT * FROM users WHERE stripe_id = $1" --name="user" --returns=User);
auto_method!(update_user_stripe_id(&str)@get_user_by_id -> "UPDATE users SET stripe_id = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);

View file

@ -32,5 +32,6 @@ CREATE TABLE IF NOT EXISTS users (
ban_expire BIGINT NOT NULL,
coins INT NOT NULL,
checkouts TEXT NOT NULL,
applied_configurations TEXT NOT NULL
applied_configurations TEXT NOT NULL,
last_policy_consent BIGINT NOT NULL
)

View file

@ -65,3 +65,7 @@ ADD COLUMN IF NOT EXISTS applied_configurations TEXT DEFAULT '[]';
-- products uploads
ALTER TABLE products
ADD COLUMN IF NOT EXISTS uploads TEXT DEFAULT '{}';
-- users last_policy_consent
ALTER TABLE users
ADD COLUMN IF NOT EXISTS last_policy_consent BIGINT DEFAULT 0;

View file

@ -104,6 +104,9 @@ pub struct User {
/// The IDs of products to be applied to the user's profile.
#[serde(default)]
pub applied_configurations: Vec<(AppliedConfigType, usize)>,
/// The time in which the user last consented to the site's policies.
#[serde(default)]
pub last_policy_consent: usize,
}
pub type UserConnections =
@ -180,8 +183,6 @@ impl Default for DefaultProfileTabChoice {
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct UserSettings {
#[serde(default)]
pub policy_consent: bool,
#[serde(default)]
pub display_name: String,
#[serde(default)]
@ -391,10 +392,11 @@ impl User {
pub fn new(username: String, password: String) -> Self {
let salt = salt();
let password = hash_salted(password, salt.clone());
let created = unix_epoch_timestamp();
Self {
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
created: unix_epoch_timestamp(),
created,
username,
password,
salt,
@ -405,7 +407,7 @@ impl User {
notification_count: 0,
follower_count: 0,
following_count: 0,
last_seen: unix_epoch_timestamp(),
last_seen: created,
totp: String::new(),
recovery_codes: Vec::new(),
post_count: 0,
@ -427,6 +429,7 @@ impl User {
coins: 0,
checkouts: Vec::new(),
applied_configurations: Vec::new(),
last_policy_consent: created,
}
}