<s> from olympia import amo <EOL> def match_rules ( rules , app , action ) : <EOL> """<STR_LIT>""" <EOL> for rule in rules . split ( '<STR_LIT:U+002C>' ) : <EOL> rule_app , rule_action = rule . split ( '<STR_LIT::>' ) <EOL> if rule_app == '<STR_LIT:*>' or rule_app == app : <EOL> if rule_action == '<STR_LIT:*>' or rule_action == action or action == '<STR_LIT:%>' : <EOL> return True <EOL> return False <EOL> def action_allowed ( request , app , action ) : <EOL> """<STR_LIT>""" <EOL> return action_allowed_user ( request . user , app , action ) <EOL> def action_allowed_user ( user , app , action ) : <EOL> """<STR_LIT>""" <EOL> if not user . is_authenticated ( ) : <EOL> return False <EOL> return any ( <EOL> match_rules ( group . rules , app , action ) for group in user . groups_list ) <EOL> def submission_allowed ( user , parsed_addon_data ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> not parsed_addon_data . get ( '<STR_LIT>' , False ) or <EOL> action_allowed_user ( user , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def check_ownership ( request , obj , require_owner = False , require_author = False , <EOL> ignore_disabled = False , admin = True ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( obj , '<STR_LIT>' ) : <EOL> return obj . check_ownership ( request , require_owner = require_owner , <EOL> require_author = require_author , <EOL> ignore_disabled = ignore_disabled , <EOL> admin = admin ) <EOL> return False <EOL> def check_collection_ownership ( request , collection , require_owner = False ) : <EOL> if not request . user . is_authenticated ( ) : <EOL> return False <EOL> if action_allowed ( request , '<STR_LIT>' , '<STR_LIT:%>' ) : <EOL> return True <EOL> elif action_allowed ( request , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return True <EOL> elif request . user . id == collection . author_id : <EOL> return True <EOL> elif not require_owner : <EOL> return collection . publishable_by ( request . user ) <EOL> else : <EOL> return False <EOL> def check_addon_ownership ( request , addon , viewer = False , dev = False , <EOL> support = False , admin = True , ignore_disabled = False ) : <EOL> """<STR_LIT>""" <EOL> if not request . user . is_authenticated ( ) : <EOL> return False <EOL> if addon . is_deleted : <EOL> return False <EOL> if admin and action_allowed ( request , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return True <EOL> if addon . status == amo . STATUS_DISABLED and not ignore_disabled : <EOL> return False <EOL> roles = ( amo . AUTHOR_ROLE_OWNER , ) <EOL> if dev : <EOL> roles += ( amo . AUTHOR_ROLE_DEV , ) <EOL> elif viewer : <EOL> roles += ( amo . AUTHOR_ROLE_DEV , amo . AUTHOR_ROLE_VIEWER , <EOL> amo . AUTHOR_ROLE_SUPPORT ) <EOL> elif support : <EOL> roles += ( amo . AUTHOR_ROLE_SUPPORT , ) <EOL> return addon . authors . filter ( pk = request . user . pk , <EOL> addonuser__role__in = roles ) . exists ( ) <EOL> def check_addons_reviewer ( request ) : <EOL> return action_allowed ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def check_unlisted_addons_reviewer ( request ) : <EOL> return action_allowed ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def check_personas_reviewer ( request ) : <EOL> return action_allowed ( request , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def is_editor ( request , addon ) : <EOL> """<STR_LIT>""" <EOL> return ( check_addons_reviewer ( request ) or <EOL> ( check_personas_reviewer ( request ) and addon . is_persona ( ) ) ) </s>
