Revoking granted feature authorizations

main
bashrc 2026-07-20 11:47:26 +01:00
parent d5d5ff3f21
commit 531e755f7d
3 changed files with 20 additions and 29 deletions

View File

@ -299,10 +299,13 @@ def store_feature_authorization(base_dir: str, nickname: str, domain: str,
accounts_dir: str = acct_dir(base_dir, nickname, domain) accounts_dir: str = acct_dir(base_dir, nickname, domain)
if not is_a_dir(accounts_dir + '/stamps'): if not is_a_dir(accounts_dir + '/stamps'):
makedir(accounts_dir + '/stamps') makedir(accounts_dir + '/stamps')
if not is_a_dir(accounts_dir + '/stamps/granted'):
makedir(accounts_dir + '/stamps/granted')
stamp_number = featured_item['featureAuthorization'].split('/stamps/')[1] stamp_number = featured_item['featureAuthorization'].split('/stamps/')[1]
if '/' in stamp_number: if '/' in stamp_number:
stamp_number = stamp_number.split('/')[0] stamp_number = stamp_number.split('/')[0]
feature_authorization_filename = accounts_dir + '/stamps/' + stamp_number feature_authorization_filename = \
accounts_dir + '/stamps/granted/' + stamp_number
if not is_a_file(feature_authorization_filename): if not is_a_file(feature_authorization_filename):
return False return False
return save_json(featured_item, feature_authorization_filename) return save_json(featured_item, feature_authorization_filename)

View File

@ -44,7 +44,7 @@ def get_feature_authorization(self, calling_domain: str,
return return
# does the stamp exist? # does the stamp exist?
account_dir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
stamp_filename = account_dir + '/stamps/' + stamp_number stamp_filename = account_dir + '/stamps/granted/' + stamp_number
if not is_a_file(stamp_filename): if not is_a_file(stamp_filename):
return return
# load the stamp from file # load the stamp from file

View File

@ -1941,33 +1941,23 @@ def _receive_delete_feature_authorization(handle: str, base_dir: str,
return False return False
if http_prefix + '://' + domain not in message_json['object']['id']: if http_prefix + '://' + domain not in message_json['object']['id']:
return False return False
if '/stamps/' not in message_json['object']['id']:
return False
stamp_number = message_json['object']['id'].split('/stamps/')[1]
if '/' in stamp_number:
stamp_number = stamp_number.split('/')[0]
if not stamp_number.isdigit():
return False
handle_nickname = handle.split('@')[0] handle_nickname = handle.split('@')[0]
handle_domain = handle.split('@')[1] handle_domain = handle.split('@')[1]
account_dir = acct_dir(base_dir, handle_nickname, handle_domain) account_dir = acct_dir(base_dir, handle_nickname, handle_domain)
stamp_filename = account_dir + '/stamps/' + stamp_number
if not is_a_file(stamp_filename):
return False
stamp_json = load_json(stamp_filename)
if not stamp_json:
return False
# the featured url is typically an actor # the featured url is typically an actor
featured_url = stamp_json['object'] featured_url = message_json['object']['interactionTarget']
if featured_url != message_json['object']['interactionTarget']: granted_filename = \
return False account_dir + '/stamps/granted/' + featured_url.replace('/', '#')
if erase_file(stamp_filename, if is_a_file(granted_filename):
if erase_file(granted_filename,
"EX: unable to remove feature authorization " + "EX: unable to remove feature authorization " +
stamp_filename): granted_filename):
if debug: if debug:
print('Revoked feature authorization ' + stamp_filename) print('Revoked feature authorization ' + granted_filename)
# remove link from featured collections # remove link from featured collections
collection_filename: str = account_dir + '/featured_collections.txt' collection_filename: str = account_dir + '/featured_collections.txt'
collections_text = ''
if text_in_file(featured_url, collection_filename, True):
collections_text = load_string(collection_filename, collections_text = load_string(collection_filename,
'EX: unable to load ' + 'EX: unable to load ' +
'featured_collections.txt of ' + 'featured_collections.txt of ' +
@ -1997,8 +1987,6 @@ def _receive_delete_feature_authorization(handle: str, base_dir: str,
if debug: if debug:
print('Unauthorized link removed from featured collections ' + print('Unauthorized link removed from featured collections ' +
featured_url + ' ' + collection_filename) featured_url + ' ' + collection_filename)
if debug:
print('feature authorization stamp removed ' + stamp_filename)
return True return True