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

@ -469,10 +469,15 @@ pub(crate) async fn initial_context(
.check(SecondaryPermission::DEVELOPER_PASS),
);
ctx.insert("home", &ua.settings.default_timeline.relative_url());
ctx.insert(
"renew_policy_consent",
&(ua.last_policy_consent < config.policies.last_updated),
);
} else {
ctx.insert("is_helper", &false);
ctx.insert("is_manager", &false);
ctx.insert("home", &DefaultTimelineChoice::default().relative_url());
ctx.insert("renew_policy_consent", &false);
}
ctx.insert("lang", &lang.data);

View file

@ -151,7 +151,53 @@
}
});
}"))))))
(text "{% elif user.is_deactivated -%}")
(text "{% elif user and renew_policy_consent -%}")
; renew policy consent
(article
(main
(div
("class" "card_nest")
(div
("class" "card small flex items_center gap_2")
(icon (text "scroll-text"))
(text "Our policies have been updated!"))
(div
("class" "card flex flex_col gap_2 no_p_margin")
(p (text "Your consent is needed for the updated versions of our Terms of Service and Privacy Policy. Please reread them and click \"Accept\" if you agree to these updated terms."))
(ul
(li
(a
("href" "{{ config.policies.terms_of_service }}")
(text "Terms of service")))
(li
(a
("href" "{{ config.policies.privacy }}")
(text "Privacy policy"))))
(hr ("class" "margin"))
(button
("onclick" "update_policy_consent()")
(icon (text "check"))
(str (text "general:action.accept")))))))
(script
(text "globalThis.update_policy_consent = async () => {
fetch(\"/api/v1/auth/user/me/policy_consent\", {
method: \"POST\",
})
.then((res) => res.json())
.then((res) => {
trigger(\"atto::toast\", [
res.ok ? \"success\" : \"error\",
res.message,
]);
if (res.ok) {
window.location.reload();
}
});
};"))
(text "{% elif user and user.is_deactivated -%}")
; account deactivated message
(article
(main

View file

@ -190,7 +190,7 @@ pub async fn stripe_webhook(
return Json(e.into());
}
if data.0.0.security.enable_invite_codes && user.awaiting_purchase {
if user.awaiting_purchase {
if let Err(e) = data
.update_user_awaiting_purchased_status(user.id, false, user.clone(), false)
.await

View file

@ -84,7 +84,6 @@ pub async fn register_request(
// ...
let mut user = User::new(props.username.to_lowercase(), props.password);
user.settings.policy_consent = true;
// check invite code
if data.0.0.security.enable_invite_codes {

View file

@ -112,6 +112,29 @@ pub async fn me_request(jar: CookieJar, Extension(data): Extension<State>) -> im
})
}
pub async fn policy_consent_request(
jar: CookieJar,
Extension(data): Extension<State>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data
.update_user_last_policy_consent(user.id, unix_epoch_timestamp() as i64)
.await
{
Ok(_) => Json(ApiReturn {
ok: true,
message: "Consent given".to_string(),
payload: Some(user),
}),
Err(e) => Json(e.into()),
}
}
/// Update the settings of the given user.
pub async fn update_user_settings_request(
jar: CookieJar,

View file

@ -302,6 +302,10 @@ pub fn routes() -> Router {
)
// profile
.route("/auth/user/me", get(auth::profile::me_request))
.route(
"/auth/user/me/policy_consent",
post(auth::profile::policy_consent_request),
)
.route("/auth/user/{id}/avatar", get(auth::images::avatar_request))
.route("/auth/user/{id}/banner", get(auth::images::banner_request))
.route("/auth/user/{id}/follow", post(auth::social::follow_request))