diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 80edf53d65..d672da2e85 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -12,7 +12,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity, get_user_profile_by_id, PreregistrationUser, get_display_recipient, \ to_dict_cache_key, get_realm, stringify_message_dict, bulk_get_recipients, \ resolve_email_to_domain, email_to_username, display_recipient_cache_key, \ - get_stream_cache_key, to_dict_cache_key_id, is_super_user, \ + get_stream_cache_key, to_dict_cache_key_id, \ UserActivityInterval, get_active_user_dicts_in_realm, get_active_streams, \ realm_filters_for_domain, RealmFilter, receives_offline_notifications, \ ScheduledJob, realm_filters_for_domain, RealmFilter, get_active_bot_dicts_in_realm @@ -762,8 +762,8 @@ def check_message(sender, client, message_type_name, message_to, elif subscribed_to_stream(sender, stream): # Or it is private, but your are subscribed pass - elif is_super_user(sender) or (forwarder_user_profile is not None and - is_super_user(forwarder_user_profile)): + elif sender.is_api_super_user() or (forwarder_user_profile is not None and + forwarder_user_profile.is_api_super_user()): # Or this request is being done on behalf of a super user pass elif sender.is_bot and subscribed_to_stream(sender.bot_owner, stream): @@ -2820,7 +2820,7 @@ def get_occupied_streams(realm): def do_get_streams(user_profile, include_public=True, include_subscribed=True, include_all_active=False): - if include_all_active and not is_super_user(user_profile): + if include_all_active and not user_profile.is_api_super_user(): raise JsonableError("User not authorized for this query") # Listing public streams are disabled for the mit.edu realm. diff --git a/zerver/models.py b/zerver/models.py index fa1b21c54f..019bd37484 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -34,12 +34,6 @@ bugdown = None MAX_SUBJECT_LENGTH = 60 MAX_MESSAGE_LENGTH = 10000 -def is_super_user(user_profile): - return user_profile.is_api_super_user() - -def is_super_user_api(request): - return request.user.is_authenticated() and is_super_user(request.user) - # Doing 1000 memcached requests to get_display_recipient is quite slow, # so add a local cache as well as the memcached cache. per_request_display_recipient_cache = {} diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index 90b560c55b..155f31fa2e 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -23,7 +23,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \ RealmFilter, bulk_get_recipients, \ PreregistrationUser, get_client, MitUser, UserActivity, PushDeviceToken, \ get_stream, bulk_get_streams, UserPresence, \ - get_recipient, valid_stream_name, is_super_user_api, \ + get_recipient, valid_stream_name, \ split_email_to_domain, resolve_email_to_domain, email_to_username, get_realm, \ completely_open, get_unique_open_realm, get_active_user_dicts_in_realm, remote_user_to_email from zerver.lib.actions import bulk_remove_subscriptions, do_change_password, \ diff --git a/zerver/views/messages.py b/zerver/views/messages.py index 761e48cff4..6b4ba6cd0b 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -25,7 +25,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, \ Recipient, UserMessage, bulk_get_recipients, get_recipient, \ get_user_profile_by_email, get_stream, valid_stream_name, \ parse_usermessage_flags, to_dict_cache_key_id, extract_message_dict, \ - stringify_message_dict, is_super_user, is_super_user_api, \ + stringify_message_dict, \ resolve_email_to_domain, get_realm, get_active_streams, \ bulk_get_streams @@ -718,7 +718,7 @@ def send_message_backend(request, user_profile, local_id = REQ(default=None), queue_id = REQ(default=None)): client = request.client - is_super_user = is_super_user_api(request) + is_super_user = request.user.is_api_super_user() if forged and not is_super_user: return json_error("User not authorized for this query")