From 6614880043fccfa53a13dac1165d16324f011b83 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 20 Mar 2024 20:54:03 +0000 Subject: [PATCH] Premium accounts require follower approval --- daemon_post_profile.py | 9 ++++++--- utils.py | 7 +++++++ webapp_profile.py | 12 +++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 676092502..9e2938141 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -14,6 +14,7 @@ from socket import error as SocketError from blocking import save_blocked_military from httpheaders import redirect_headers from httpheaders import clear_login_details +from utils import is_premium_account from utils import remove_avatar_from_cache from utils import is_memorial_account from utils import save_json @@ -1231,7 +1232,8 @@ def _profile_post_reject_spam_actors(base_dir: str, def _profile_post_approve_followers(on_final_welcome_screen: bool, actor_json: {}, fields: {}, - actor_changed: bool) -> bool: + actor_changed: bool, + premium: bool) -> bool: """ HTTP POST approve followers """ if on_final_welcome_screen: @@ -1239,7 +1241,7 @@ def _profile_post_approve_followers(on_final_welcome_screen: bool, actor_json['manuallyApprovesFollowers'] = True actor_changed = True else: - approve_followers = False + approve_followers = premium if fields.get('approveFollowers'): if fields['approveFollowers'] == 'on': approve_followers = True @@ -2841,10 +2843,11 @@ def profile_edit(self, calling_domain: str, cookie: str, if fields['removeScheduledPosts'] == 'on': remove_scheduled_posts(base_dir, nickname, domain) + premium = is_premium_account(base_dir, nickname, domain) actor_changed = \ _profile_post_approve_followers(on_final_welcome_screen, actor_json, fields, - actor_changed) + actor_changed, premium) _profile_post_reject_spam_actors(base_dir, nickname, domain, fields) diff --git a/utils.py b/utils.py index 758781746..64e468fa4 100644 --- a/utils.py +++ b/utils.py @@ -5213,3 +5213,10 @@ def check_bad_path(path: str): print('WARN: bad path ' + path) return True return False + + +def is_premium_account(base_dir: str, nickname: str, domain: str) -> bool: + """ Is the given account a premium one? + """ + premium_filename = acct_dir(base_dir, nickname, domain) + '/.premium' + return os.path.isfile(premium_filename) diff --git a/webapp_profile.py b/webapp_profile.py index b8f2d6e4c..8a7a7bc02 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -10,6 +10,7 @@ __module_group__ = "Web Interface" import os from pprint import pprint from webfinger import webfinger_handle +from utils import is_premium_account from utils import time_days_ago from utils import uninvert_text from utils import get_attributed_to @@ -922,13 +923,6 @@ def _get_profile_header_after_search(base_dir: str, return html_str -def _is_premium_account(base_dir: str, nickname: str, domain: str) -> bool: - """ Is the given account a premium one? - """ - premium_filename = acct_dir(base_dir, nickname, domain) + '/.premium' - return os.path.isfile(premium_filename) - - def html_profile(signing_priv_key_pem: str, rss_icon_at_top: bool, icons_as_buttons: bool, @@ -1068,7 +1062,7 @@ def html_profile(signing_priv_key_pem: str, briar_address = get_briar_address(profile_json) cwtch_address = get_cwtch_address(profile_json) verified_site_checkmark = '✔' - premium = _is_premium_account(base_dir, nickname, domain) + premium = is_premium_account(base_dir, nickname, domain) if donate_url or website_url or repo_url or xmpp_address or \ matrix_address or ssb_address or tox_address or briar_address or \ cwtch_address or pgp_pub_key or enigma_pub_key or \ @@ -2882,7 +2876,7 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, bio_str: str, moved_to, 'https://...') donate_str = translate['Donations link'] - if _is_premium_account(base_dir, nickname, domain): + if is_premium_account(base_dir, nickname, domain): donate_str = translate['Subscribe'] edit_profile_form += \ edit_text_field(donate_str, 'donateUrl', donate_url, 'https://...')