Premium account option on edit profile screen

merge-requests/30/head
Bob Mottram 2024-03-20 21:31:13 +00:00
parent 6614880043
commit 296fc7fde2
3 changed files with 49 additions and 5 deletions

View File

@ -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 set_premium_account
from utils import is_premium_account
from utils import remove_avatar_from_cache
from utils import is_memorial_account
@ -1233,18 +1234,32 @@ 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,
premium: bool) -> bool:
""" HTTP POST approve followers
premium: bool, base_dir: str,
nickname: str, domain: str) -> bool:
""" HTTP POST approve followers and handle premium account flag
"""
if on_final_welcome_screen:
# Default setting created via the welcome screen
actor_json['manuallyApprovesFollowers'] = True
actor_changed = True
set_premium_account(base_dir, nickname, domain, False)
else:
approve_followers = premium
if fields.get('approveFollowers'):
if fields['approveFollowers'] == 'on':
approve_followers = True
premium_activated = False
if fields.get('premiumAccount'):
if fields['premiumAccount'] == 'on':
# turn on premium flag
set_premium_account(base_dir, nickname, domain, True)
approve_followers = True
premium_activated = True
if premium and not premium_activated:
# turn off premium flag
set_premium_account(base_dir, nickname, domain, False)
if approve_followers != actor_json['manuallyApprovesFollowers']:
actor_json['manuallyApprovesFollowers'] = approve_followers
actor_changed = True
@ -2847,7 +2862,8 @@ def profile_edit(self, calling_domain: str, cookie: str,
actor_changed = \
_profile_post_approve_followers(on_final_welcome_screen,
actor_json, fields,
actor_changed, premium)
actor_changed, premium,
base_dir, nickname, domain)
_profile_post_reject_spam_actors(base_dir,
nickname, domain, fields)

View File

@ -5220,3 +5220,24 @@ def is_premium_account(base_dir: str, nickname: str, domain: str) -> bool:
"""
premium_filename = acct_dir(base_dir, nickname, domain) + '/.premium'
return os.path.isfile(premium_filename)
def set_premium_account(base_dir: str, nickname: str, domain: str,
flag_state: bool) -> bool:
""" Set or clear the premium account flag
"""
premium_filename = acct_dir(base_dir, nickname, domain) + '/.premium'
if os.path.isfile(premium_filename):
if not flag_state:
try:
os.remove(premium_filename)
except OSError:
print('EX: unable to remove premium flag ' + premium_filename)
else:
if flag_state:
try:
with open(premium_filename, 'w+',
encoding='utf-8') as fp_premium:
fp_premium.write('\n')
except OSError:
print('EX: unable to set premium flag ' + premium_filename)

View File

@ -2718,10 +2718,13 @@ def _html_edit_profile_options(is_admin: bool,
show_vote_posts: bool,
show_replies_followers: bool,
show_replies_mutuals: bool,
hide_follows: bool) -> str:
hide_follows: bool,
premium: bool) -> str:
"""option checkboxes section of edit profile screen
"""
edit_profile_form = ' <div class="container">\n'
edit_profile_form += \
edit_check_box(translate['Premium account'], 'premiumAccount', premium)
edit_profile_form += \
edit_check_box(translate['Approve follower requests'],
'approveFollowers', manually_approves_followers)
@ -3191,6 +3194,9 @@ def html_edit_profile(server, translate: {},
if os.path.isfile(account_dir + '/.hideFollows'):
hide_follows = True
# is this a premium account?
premium = is_premium_account(base_dir, nickname, domain)
# Option checkboxes
edit_profile_form += \
_html_edit_profile_options(is_admin, manually_approves_followers,
@ -3203,7 +3209,8 @@ def html_edit_profile(server, translate: {},
nickname, min_images_for_accounts,
reverse_sequence, show_vote_posts,
show_replies_followers,
show_replies_mutuals, hide_follows)
show_replies_mutuals, hide_follows,
premium)
# Contact information
edit_profile_form += \