add: ability to require account to view profile
This commit is contained in:
parent
dd4f8b6d58
commit
741fe1c986
4 changed files with 74 additions and 35 deletions
|
@ -98,6 +98,21 @@ macro_rules! get_lang {
|
|||
#[macro_export]
|
||||
macro_rules! check_user_blocked_or_private {
|
||||
($user:ident, $other_user:ident, $data:ident, $jar:ident) => {
|
||||
// check require_account
|
||||
if $user.is_none() && $other_user.settings.require_account {
|
||||
return Err(Html(
|
||||
render_error(
|
||||
Error::MiscError(
|
||||
"This profile requires you are logged in to view it.".to_string(),
|
||||
),
|
||||
&$jar,
|
||||
&$data,
|
||||
&$user,
|
||||
)
|
||||
.await,
|
||||
));
|
||||
}
|
||||
|
||||
// check if other user is banned
|
||||
if $other_user.permissions.check_banned() {
|
||||
let lang = get_lang!($jar, $data.0);
|
||||
|
|
|
@ -1216,6 +1216,14 @@
|
|||
profile_settings,
|
||||
[
|
||||
[[], "Privacy", "title"],
|
||||
[
|
||||
[
|
||||
"require_account",
|
||||
"Require an account to view my profile",
|
||||
],
|
||||
"{{ profile.settings.require_account }}",
|
||||
"checkbox",
|
||||
],
|
||||
[
|
||||
[
|
||||
"private_profile",
|
||||
|
|
|
@ -207,7 +207,9 @@ impl DataManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, ua1.id))
|
||||
if ua1.id != ua.id {
|
||||
if let Some(is_following) =
|
||||
seen_user_follow_statuses.get(&(ua.id, ua1.id))
|
||||
{
|
||||
if !is_following
|
||||
&& (ua.id != ua1.id)
|
||||
|
@ -230,6 +232,7 @@ impl DataManager {
|
|||
|
||||
seen_user_follow_statuses.insert((ua.id, ua1.id), true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// private post, but not authenticated
|
||||
continue;
|
||||
|
@ -307,7 +310,9 @@ impl DataManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, user_id)) {
|
||||
if user_id != ua.id {
|
||||
if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, user_id))
|
||||
{
|
||||
if !is_following && (ua.id != user_id) {
|
||||
// post owner is not following us
|
||||
continue;
|
||||
|
@ -326,6 +331,7 @@ impl DataManager {
|
|||
seen_user_follow_statuses.insert((ua.id, user_id), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
let community = self.get_community_by_id(community).await?;
|
||||
|
@ -1302,6 +1308,11 @@ impl DataManager {
|
|||
self.incr_question_answer_count(y.context.answering).await?;
|
||||
}
|
||||
}
|
||||
|
||||
// delete uploads
|
||||
for upload in y.uploads {
|
||||
self.delete_upload(upload).await?;
|
||||
}
|
||||
} else {
|
||||
// incr parent comment count
|
||||
if let Some(replying_to) = y.replying_to {
|
||||
|
@ -1323,6 +1334,8 @@ impl DataManager {
|
|||
self.decr_question_answer_count(y.context.answering).await?;
|
||||
}
|
||||
}
|
||||
|
||||
// unfortunately, uploads will not be restored
|
||||
}
|
||||
|
||||
// return
|
||||
|
|
|
@ -210,6 +210,9 @@ pub struct UserSettings {
|
|||
/// The mime type of the user's banner.
|
||||
#[serde(default = "mime_avif")]
|
||||
pub banner_mime: String,
|
||||
/// Require an account to view the user's profile.
|
||||
#[serde(default)]
|
||||
pub require_account: bool,
|
||||
}
|
||||
|
||||
fn mime_avif() -> String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue