diff --git a/files/classes/user.py b/files/classes/user.py index e92cf54a0..032bbc134 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -171,6 +171,25 @@ class User(CreatedBase): accountAgeDays = self.age_timedelta.days return self.comment_count < minComments or accountAgeDays < minAge or self.truecoins < minKarma + + def can_change_user_privacy(self, v: "User") -> bool: + from files.__main__ import app # avoiding import loop + if v.admin_level >= PERMS['USER_SET_PROFILE_PRIVACY']: return True + if self.id != v.id: return False # non-admin changing someone else's things, hmm... + + # TODO: move settings out of app.config + site_settings = app.config['SETTINGS'] + min_comments: int = site_settings.get('min_comments_private_profile', 0) + min_truescore: int = site_settings.get('min_truescore_private_profile', 0) + min_age_days: int = site_settings.get('min_age_days_private_profile', 0) + user_age_days: int = self.age_timedelta.days + + return ( + self.comment_count >= min_comments + and self.truecoins >= min_truescore + and user_age_days >= min_age_days) + + @property @lazy def csslazy(self): diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index a3a4aa553..1305f7b62 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -152,6 +152,7 @@ PERMS = { "SCHEDULER_POSTS": 2, "SCHEDULER_TASK_TRACEBACK": 3, "USER_SHADOWBAN": 2, + 'USER_SET_PROFILE_PRIVACY': 2, } AWARDS = {} diff --git a/files/routes/settings.py b/files/routes/settings.py index 866e0d621..effb407fb 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -64,10 +64,6 @@ def settings_profile_post(v): elif request.values.get("over18", v.over_18) != v.over_18: updated = True v.over_18 = request.values.get("over18") == 'true' - - elif request.values.get("private", v.is_private) != v.is_private: - updated = True - v.is_private = request.values.get("private") == 'true' elif request.values.get("nofollow", v.is_nofollow) != v.is_nofollow: updated = True @@ -640,3 +636,16 @@ def settings_profile(v): if v.flairchanged: ti = datetime.utcfromtimestamp(v.flairchanged).strftime('%Y-%m-%d %H:%M:%S') else: ti = '' return render_template("settings_profile.html", v=v, ti=ti) + + +# other settings i guess + +@app.post("/id//private/") +@auth_required +def post_set_user_profile_privacy(v: User, id: int, enabled: int): + if enabled != 0 and enabled != 1: abort(400, "'enabled' must be '0' or '1'") + user: User = get_account(id) + if not user.can_change_user_privacy(v): abort(403) + user.is_private = bool(enabled) + g.db.commit() + return {"message": f"{'Enabled' if user.is_private else 'Disabled'} private mode successfully!"} diff --git a/files/routes/users.py b/files/routes/users.py index 25809fb07..9720e585a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -619,7 +619,7 @@ def api_is_available(name): def user_id(id:int): user = get_account(id) return redirect(user.url) - + @app.get("/u/") def redditor_moment_redirect(username:str): return redirect(f"/@{username}") @@ -803,6 +803,7 @@ def u_user_id_info(id, v=None): return user.json + @app.post("/follow/") @limiter.limit("1/second;30/minute;200/hour;1000/day") @auth_required diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 08a549dfd..9fd2dd37f 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -103,6 +103,11 @@ {{site_setting_int('FilterCommentsMinKarma', 'Minimum Karma')}} {{site_setting_int('FilterCommentsMinAgeDays', 'Minimum Account Age (Days)')}} +

Private Mode Requirements

+ {{site_setting_int('min_comments_private_profile', 'Minimum Comments')}} + {{site_setting_int('min_truescore_private_profile', 'Minimum Karma')}} + {{site_setting_int('min_age_days_private_profile', 'Minimum Account Age (Days)')}} + {% endif %} diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 0ccbdc142..22f411d1d 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -274,16 +274,23 @@ + {%- set can_change_profile_privacy = v.can_change_user_privacy(v) -%}
- +
- This will hide your post and comment history from others. We will also ask search engines to not index your profile page. (Your content will still be accessible via direct link.) + + {%- if can_change_profile_privacy -%} + This will hide your post and comment history from others. We will also ask search engines to not index your profile page. (Your content will still be accessible via direct link.) + {%- else -%} + If you want to hide your post and comment history from others, please contact us and we'll review your request. (Your content will still be accessible via direct link.) + {%- endif -%} +
diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 70375492b..9a7f0fa3f 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -250,6 +250,10 @@ {% endif %} + {% if v and v.admin_level >= PERMS['USER_SET_PROFILE_PRIVACY'] %} + Set Private Mode + Unset Private Mode + {% endif %}

 					

User ID: {{u.id}}

@@ -496,6 +500,10 @@ {% endif %} {% endif %} + {% if v and v.admin_level >= PERMS['USER_SET_PROFILE_PRIVACY'] %} + Set Private Mode + Unset Private Mode + {% endif %}

 				

User ID: {{u.id}}

@@ -513,6 +521,7 @@ {% if u.is_suspended %}

Banned by: @{{u.banned_by.username}}

{% endif %} +
diff --git a/site_settings.json b/site_settings.json index d0b75d448..52ae2dcd7 100644 --- a/site_settings.json +++ b/site_settings.json @@ -1 +1,12 @@ -{"Bots": true, "Read-only mode": false, "Signups": true, "FilterNewPosts": false, "FilterCommentsMinComments": 0, "FilterCommentsMinKarma": 0, "FilterCommentsMinAgeDays": 0} +{ + "Bots": true, + "Read-only mode": false, + "Signups": true, + "FilterNewPosts": false, + "FilterCommentsMinComments": 0, + "FilterCommentsMinKarma": 0, + "FilterCommentsMinAgeDays": 0, + "min_comments_private_profile": 0, + "min_truescore_private_profile": 0, + "min_age_days_private_profile": 0 +}