mirror of https://github.com/zulip/zulip.git
Rename models.get_realm_by_string_id to get_realm.
Finishes the refactoring started in c1bbd8d
. The goal of the refactoring is
to change the argument to get_realm from a Realm.domain to a
Realm.string_id. The steps were
* Add a new function, get_realm_by_string_id.
* Change all calls to get_realm to use get_realm_by_string_id instead.
* Remove get_realm.
* (This commit) Rename get_realm_by_string_id to get_realm.
Part of a larger migration to remove the Realm.domain field entirely.
This commit is contained in:
parent
0a6d960f37
commit
2b0a7fd0ba
|
@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand
|
|||
from django.db.models import Count, QuerySet
|
||||
|
||||
from zerver.models import UserActivity, UserProfile, Realm, \
|
||||
get_realm_by_string_id, get_user_profile_by_email
|
||||
get_realm, get_user_profile_by_email
|
||||
|
||||
import datetime
|
||||
|
||||
|
@ -72,7 +72,7 @@ Usage examples:
|
|||
except UserProfile.DoesNotExist:
|
||||
try:
|
||||
# Report activity for a realm.
|
||||
realm = get_realm_by_string_id(arg)
|
||||
realm = get_realm(arg)
|
||||
self.compute_activity(UserActivity.objects.filter(
|
||||
user_profile__realm=realm))
|
||||
except Realm.DoesNotExist:
|
||||
|
|
|
@ -11,7 +11,7 @@ import pytz
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count
|
||||
from zerver.models import UserProfile, Realm, Stream, Message, Recipient, UserActivity, \
|
||||
Subscription, UserMessage, get_realm_by_string_id
|
||||
Subscription, UserMessage, get_realm
|
||||
|
||||
MOBILE_CLIENT_LIST = ["Android", "ios"]
|
||||
HUMAN_CLIENT_LIST = MOBILE_CLIENT_LIST + ["website"]
|
||||
|
@ -86,7 +86,7 @@ class Command(BaseCommand):
|
|||
# type: (*Any, **Any) -> None
|
||||
if options['realms']:
|
||||
try:
|
||||
realms = [get_realm_by_string_id(string_id) for string_id in options['realms']]
|
||||
realms = [get_realm(string_id) for string_id in options['realms']]
|
||||
except Realm.DoesNotExist as e:
|
||||
print(e)
|
||||
exit(1)
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any
|
|||
from argparse import ArgumentParser
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Q
|
||||
from zerver.models import Realm, Stream, Message, Subscription, Recipient, get_realm_by_string_id
|
||||
from zerver.models import Realm, Stream, Message, Subscription, Recipient, get_realm
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generate statistics on the streams for a realm."
|
||||
|
@ -20,7 +20,7 @@ class Command(BaseCommand):
|
|||
# type: (*Any, **str) -> None
|
||||
if options['realms']:
|
||||
try:
|
||||
realms = [get_realm_by_string_id(string_id) for string_id in options['realms']]
|
||||
realms = [get_realm(string_id) for string_id in options['realms']]
|
||||
except Realm.DoesNotExist as e:
|
||||
print(e)
|
||||
exit(1)
|
||||
|
|
|
@ -7,7 +7,7 @@ import pytz
|
|||
from typing import Any
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from zerver.models import UserProfile, Realm, Stream, Message, get_realm_by_string_id
|
||||
from zerver.models import UserProfile, Realm, Stream, Message, get_realm
|
||||
from six.moves import range
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -28,7 +28,7 @@ class Command(BaseCommand):
|
|||
# type: (*Any, **Any) -> None
|
||||
if options['realms']:
|
||||
try:
|
||||
realms = [get_realm_by_string_id(string_id) for string_id in options['realms']]
|
||||
realms = [get_realm(string_id) for string_id in options['realms']]
|
||||
except Realm.DoesNotExist as e:
|
||||
print(e)
|
||||
exit(1)
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Dict, Any
|
|||
from django.http import HttpRequest
|
||||
from django.conf import settings
|
||||
|
||||
from zerver.models import UserProfile, get_realm_by_string_id
|
||||
from zerver.models import UserProfile, get_realm
|
||||
from zproject.backends import (password_auth_enabled, dev_auth_enabled,
|
||||
google_auth_enabled, github_auth_enabled)
|
||||
from zerver.lib.utils import get_subdomain
|
||||
|
@ -27,7 +27,7 @@ def add_settings(request):
|
|||
realm = request.user.realm
|
||||
elif settings.REALMS_HAVE_SUBDOMAINS:
|
||||
subdomain = get_subdomain(request)
|
||||
realm = get_realm_by_string_id(subdomain)
|
||||
realm = get_realm(subdomain)
|
||||
|
||||
if realm is not None:
|
||||
realm_uri = realm.uri
|
||||
|
|
|
@ -15,7 +15,7 @@ from zerver.lib.actions import do_change_password, is_inactive, user_email_is_un
|
|||
from zerver.lib.name_restrictions import is_reserved_subdomain, is_disposable_domain
|
||||
from zerver.lib.utils import get_subdomain, check_subdomain
|
||||
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
|
||||
get_realm_by_email_domain, get_realm_by_string_id, \
|
||||
get_realm_by_email_domain, get_realm, \
|
||||
get_unique_open_realm, email_to_domain, email_allowed_for_realm
|
||||
from zproject.backends import password_auth_enabled
|
||||
|
||||
|
@ -93,7 +93,7 @@ class RegistrationForm(forms.Form):
|
|||
if not re.match('^[a-z0-9-]*$', subdomain):
|
||||
raise ValidationError(error_strings['bad character'])
|
||||
if is_reserved_subdomain(subdomain) or \
|
||||
get_realm_by_string_id(subdomain) is not None:
|
||||
get_realm(subdomain) is not None:
|
||||
raise ValidationError(error_strings['unavailable'])
|
||||
return subdomain
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
|
|||
Client, DefaultStream, UserPresence, Referral, PushDeviceToken, MAX_SUBJECT_LENGTH, \
|
||||
MAX_MESSAGE_LENGTH, get_client, get_stream, get_recipient, get_huddle, \
|
||||
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
|
||||
get_realm_by_string_id, bulk_get_recipients, \
|
||||
get_realm, bulk_get_recipients, \
|
||||
email_allowed_for_realm, email_to_username, display_recipient_cache_key, \
|
||||
get_user_profile_by_email, get_stream_cache_key, \
|
||||
UserActivityInterval, get_active_user_dicts_in_realm, get_active_streams, \
|
||||
|
@ -2142,7 +2142,7 @@ def do_change_stream_description(realm, stream_name, new_description):
|
|||
def do_create_realm(string_id, name, restricted_to_domain=None,
|
||||
invite_required=None, org_type=None):
|
||||
# type: (Text, Text, Optional[bool], Optional[bool], Optional[int]) -> Tuple[Realm, bool]
|
||||
realm = get_realm_by_string_id(string_id)
|
||||
realm = get_realm(string_id)
|
||||
created = not realm
|
||||
if created:
|
||||
kwargs = {} # type: Dict[str, Any]
|
||||
|
|
|
@ -8,7 +8,7 @@ from typing import Any
|
|||
from django.core.management.base import BaseCommand, CommandParser
|
||||
|
||||
from zerver.lib.actions import create_stream_if_needed, bulk_add_subscriptions
|
||||
from zerver.models import UserProfile, get_realm_by_string_id, get_user_profile_by_email
|
||||
from zerver.models import UserProfile, get_realm, get_user_profile_by_email
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Add some or all users in a realm to a set of streams."""
|
||||
|
@ -48,7 +48,7 @@ class Command(BaseCommand):
|
|||
exit(1)
|
||||
|
||||
stream_names = set([stream.strip() for stream in options["streams"].split(",")])
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
|
||||
if options["all_users"]:
|
||||
user_profiles = UserProfile.objects.filter(realm=realm)
|
||||
|
|
|
@ -7,7 +7,7 @@ from typing import Any, Text
|
|||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from zerver.lib.actions import Realm, do_create_realm, set_default_streams
|
||||
from zerver.models import RealmAlias, can_add_alias, get_realm_by_string_id
|
||||
from zerver.models import RealmAlias, can_add_alias, get_realm
|
||||
|
||||
if settings.ZILENCER_ENABLED:
|
||||
from zilencer.models import Deployment
|
||||
|
@ -94,7 +94,7 @@ Usage: ./manage.py create_realm --string_id=acme --name='Acme'"""
|
|||
if domain is not None:
|
||||
self.validate_domain(domain)
|
||||
|
||||
if get_realm_by_string_id(string_id) is not None:
|
||||
if get_realm(string_id) is not None:
|
||||
raise ValueError("string_id taken. Please choose another one.")
|
||||
|
||||
realm, created = do_create_realm(string_id, name, org_type=options["org_type"])
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand
|
|||
|
||||
from zerver.lib.actions import do_create_stream
|
||||
from zerver.lib.str_utils import force_text
|
||||
from zerver.models import Realm, get_realm_by_string_id
|
||||
from zerver.models import Realm, get_realm
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import sys
|
||||
|
@ -31,7 +31,7 @@ the command."""
|
|||
encoding = sys.getfilesystemencoding()
|
||||
stream_name = options['stream_name']
|
||||
|
||||
realm = get_realm_by_string_id(force_text(string_id, encoding))
|
||||
realm = get_realm(force_text(string_id, encoding))
|
||||
if realm is None:
|
||||
print("Unknown string_id %s" % (string_id,))
|
||||
exit(1)
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.core.exceptions import ValidationError
|
|||
from django.db.utils import IntegrityError
|
||||
from django.core import validators
|
||||
|
||||
from zerver.models import Realm, get_realm_by_string_id, email_to_username
|
||||
from zerver.models import Realm, get_realm, email_to_username
|
||||
from zerver.lib.actions import do_create_user
|
||||
from zerver.lib.actions import notify_new_user
|
||||
from zerver.lib.initial_password import initial_password
|
||||
|
@ -52,7 +52,7 @@ Terms of Service by passing --this-user-has-accepted-the-tos.""")
|
|||
raise CommandError("""Please specify a realm by passing --realm.""")
|
||||
|
||||
try:
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
except Realm.DoesNotExist:
|
||||
raise CommandError("Realm does not exist.")
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from argparse import ArgumentParser
|
|||
import sys
|
||||
|
||||
from zerver.lib.actions import do_deactivate_realm
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Script to deactivate a realm."""
|
||||
|
@ -21,7 +21,7 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
if realm is None:
|
||||
print("Could not find realm %s" % (options["string_id"],))
|
||||
sys.exit(1)
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
|||
|
||||
from optparse import make_option
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from zerver.models import get_realm_by_string_id, Message, Realm, Stream, Recipient
|
||||
from zerver.models import get_realm, Message, Realm, Stream, Recipient
|
||||
|
||||
import datetime
|
||||
import time
|
||||
|
@ -27,7 +27,7 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
streams = Stream.objects.filter(realm=realm, invite_only=False)
|
||||
recipients = Recipient.objects.filter(
|
||||
type=Recipient.STREAM, type_id__in=[stream.id for stream in streams])
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.conf import settings
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
from zerver.lib.queue import queue_json_publish
|
||||
from zerver.models import UserActivity, UserProfile, get_realm_by_string_id, Realm
|
||||
from zerver.models import UserActivity, UserProfile, get_realm, Realm
|
||||
|
||||
## Logging setup ##
|
||||
|
||||
|
@ -105,7 +105,7 @@ in a while.
|
|||
|
||||
string_id = realm.string_id
|
||||
user_profiles = UserProfile.objects.filter(
|
||||
realm=get_realm_by_string_id(string_id), is_active=True, is_bot=False,
|
||||
realm=get_realm(string_id), is_active=True, is_bot=False,
|
||||
enable_digest_emails=True)
|
||||
|
||||
for user_profile in user_profiles:
|
||||
|
|
|
@ -16,7 +16,7 @@ import ujson
|
|||
from zerver.lib.export import (
|
||||
do_export_realm, do_write_stats_file_for_realm_export
|
||||
)
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Exports all data from a Zulip realm
|
||||
|
@ -112,7 +112,7 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
try:
|
||||
realm = get_realm_by_string_id(options["realm"])
|
||||
realm = get_realm(options["realm"])
|
||||
except ValidationError:
|
||||
raise CommandError("No such realm.")
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from argparse import ArgumentParser
|
|||
from django.core.management.base import BaseCommand
|
||||
from confirmation.models import Confirmation
|
||||
from zerver.models import UserProfile, PreregistrationUser, \
|
||||
get_user_profile_by_email, get_realm_by_string_id, email_allowed_for_realm
|
||||
get_user_profile_by_email, get_realm, email_allowed_for_realm
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generate activation links for users and print them to stdout."
|
||||
|
@ -44,7 +44,7 @@ class Command(BaseCommand):
|
|||
realm = None
|
||||
string_id = options["string_id"]
|
||||
if string_id:
|
||||
realm = get_realm_by_string_id(string_id)
|
||||
realm = get_realm(string_id)
|
||||
if not realm:
|
||||
print("The realm %s doesn't exist yet, please create it first." % (string_id,))
|
||||
print("Don't forget default streams!")
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand
|
|||
|
||||
from zerver.lib.actions import delete_all_user_sessions, \
|
||||
delete_realm_user_sessions, delete_all_deactivated_user_sessions
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Log out all users."
|
||||
|
@ -27,7 +27,7 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
if options["realm"]:
|
||||
realm = get_realm_by_string_id(options["realm"])
|
||||
realm = get_realm(options["realm"])
|
||||
delete_realm_user_sessions(realm)
|
||||
elif options["deactivated_only"]:
|
||||
delete_all_deactivated_user_sessions()
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.core.management.base import BaseCommand
|
|||
import sys
|
||||
|
||||
from zerver.lib.actions import do_reactivate_realm
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Script to reactivate a deactivated realm."""
|
||||
|
@ -21,7 +21,7 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
if realm is None:
|
||||
print("Could not find realm %s" % (options["string_id"],))
|
||||
sys.exit(1)
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
|||
|
||||
from argparse import ArgumentParser
|
||||
from django.core.management.base import BaseCommand
|
||||
from zerver.models import Realm, RealmAlias, get_realm_by_string_id, can_add_alias
|
||||
from zerver.models import Realm, RealmAlias, get_realm, can_add_alias
|
||||
from zerver.lib.actions import realm_aliases
|
||||
import sys
|
||||
|
||||
|
@ -29,7 +29,7 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
if options["op"] == "show":
|
||||
print("Aliases for %s:" % (realm.domain,))
|
||||
for alias in realm_aliases(realm):
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any
|
|||
|
||||
from argparse import ArgumentParser
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from zerver.models import Realm, get_realm_by_string_id
|
||||
from zerver.models import Realm, get_realm
|
||||
from zerver.lib.actions import check_add_realm_emoji, do_remove_realm_emoji
|
||||
import sys
|
||||
import six
|
||||
|
@ -46,7 +46,7 @@ Example: ./manage.py realm_emoji --realm=zulip.com --op=show
|
|||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
if options["op"] == "show":
|
||||
for name, url in six.iteritems(realm.get_emoji()):
|
||||
print(name, url)
|
||||
|
|
|
@ -7,7 +7,7 @@ from argparse import ArgumentParser
|
|||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from zerver.models import RealmFilter, all_realm_filters, get_realm_by_string_id
|
||||
from zerver.models import RealmFilter, all_realm_filters, get_realm
|
||||
from zerver.lib.actions import do_add_realm_filter, do_remove_realm_filter
|
||||
import sys
|
||||
|
||||
|
@ -44,7 +44,7 @@ Example: ./manage.py realm_filters --realm=zulip --op=show
|
|||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
if options["op"] == "show":
|
||||
print("%s: %s" % (realm.string_id, all_realm_filters().get(realm.id, [])))
|
||||
sys.exit(0)
|
||||
|
|
|
@ -9,7 +9,7 @@ from optparse import make_option
|
|||
from django.core.management.base import BaseCommand, CommandParser
|
||||
|
||||
from zerver.lib.actions import bulk_remove_subscriptions
|
||||
from zerver.models import Realm, UserProfile, get_realm_by_string_id, get_stream, \
|
||||
from zerver.models import Realm, UserProfile, get_realm, get_stream, \
|
||||
get_user_profile_by_email
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -46,7 +46,7 @@ class Command(BaseCommand):
|
|||
self.print_help("./manage.py", "remove_users_from_stream")
|
||||
exit(1)
|
||||
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
stream_name = options["stream"].strip()
|
||||
stream = get_stream(stream_name, realm)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand
|
|||
|
||||
from zerver.lib.actions import do_rename_stream
|
||||
from zerver.lib.str_utils import force_text
|
||||
from zerver.models import Realm, get_realm_by_string_id
|
||||
from zerver.models import Realm, get_realm
|
||||
|
||||
import sys
|
||||
|
||||
|
@ -31,7 +31,7 @@ class Command(BaseCommand):
|
|||
new_name = options['new_name']
|
||||
encoding = sys.getfilesystemencoding()
|
||||
|
||||
realm = get_realm_by_string_id(force_text(string_id, encoding))
|
||||
realm = get_realm(force_text(string_id, encoding))
|
||||
if realm is None:
|
||||
print("Unknown subdomain or string_id %s" % (string_id,))
|
||||
exit(1)
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand, CommandError
|
|||
from django.conf import settings
|
||||
from django.core.mail import send_mail, BadHeaderError
|
||||
from zerver.forms import PasswordResetForm
|
||||
from zerver.models import UserProfile, get_user_profile_by_email, get_realm_by_string_id
|
||||
from zerver.models import UserProfile, get_user_profile_by_email, get_realm
|
||||
from django.template import loader
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Command(BaseCommand):
|
|||
if options["to"]:
|
||||
users = [get_user_profile_by_email(options["to"])]
|
||||
elif options["realm"]:
|
||||
realm = get_realm_by_string_id(options["realm"])
|
||||
realm = get_realm(options["realm"])
|
||||
users = UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False,
|
||||
is_mirror_dummy=False)
|
||||
elif options["server"] == "YES":
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any, Text
|
|||
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
from zerver.lib.actions import set_default_streams
|
||||
|
||||
from optparse import make_option
|
||||
|
@ -58,5 +58,5 @@ set of streams (which can be empty, with `--streams=`).", file=sys.stderr)
|
|||
stream.strip(): {"description": stream.strip(), "invite_only": False}
|
||||
for stream in options["streams"].split(",")
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
set_default_streams(realm, stream_dict)
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any
|
|||
|
||||
from argparse import ArgumentParser
|
||||
from django.core.management.base import BaseCommand
|
||||
from zerver.models import get_realm_by_string_id, Realm
|
||||
from zerver.models import get_realm, Realm
|
||||
import sys
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -21,7 +21,7 @@ class Command(BaseCommand):
|
|||
realm_name = options['realm']
|
||||
|
||||
try:
|
||||
realm = get_realm_by_string_id(realm_name)
|
||||
realm = get_realm(realm_name)
|
||||
except Realm.DoesNotExist:
|
||||
print('There is no realm called %s.' % (realm_name,))
|
||||
sys.exit(1)
|
||||
|
|
|
@ -8,7 +8,7 @@ from optparse import make_option
|
|||
from django.core.management.base import BaseCommand, CommandParser
|
||||
|
||||
from zerver.lib.actions import do_change_enable_digest_emails
|
||||
from zerver.models import Realm, UserProfile, get_realm_by_string_id, get_user_profile_by_email
|
||||
from zerver.models import Realm, UserProfile, get_realm, get_user_profile_by_email
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Turn off digests for a subdomain/string_id or specified set of email addresses."""
|
||||
|
@ -33,7 +33,7 @@ class Command(BaseCommand):
|
|||
exit(1)
|
||||
|
||||
if options["string_id"]:
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
user_profiles = UserProfile.objects.filter(realm=realm)
|
||||
else:
|
||||
emails = set([email.strip() for email in options["users"].split(",")])
|
||||
|
|
|
@ -14,7 +14,7 @@ from zerver.lib.utils import statsd, get_subdomain
|
|||
from zerver.lib.queue import queue_json_publish
|
||||
from zerver.lib.cache import get_remote_cache_time, get_remote_cache_requests
|
||||
from zerver.lib.bugdown import get_bugdown_time, get_bugdown_requests
|
||||
from zerver.models import flush_per_request_caches, get_realm_by_string_id
|
||||
from zerver.models import flush_per_request_caches, get_realm
|
||||
from zerver.exceptions import RateLimited
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.views.csrf import csrf_failure as html_csrf_failure
|
||||
|
@ -357,7 +357,7 @@ class SessionHostDomainMiddleware(SessionMiddleware):
|
|||
return redirect("%s%s" % (settings.EXTERNAL_URI_SCHEME,
|
||||
settings.EXTERNAL_HOST))
|
||||
if subdomain != "":
|
||||
realm = get_realm_by_string_id(subdomain)
|
||||
realm = get_realm(subdomain)
|
||||
if (realm is None):
|
||||
return render_to_response("zerver/invalid_realm.html")
|
||||
"""
|
||||
|
|
|
@ -242,9 +242,7 @@ class Realm(ModelReprMixin, models.Model):
|
|||
|
||||
post_save.connect(flush_realm, sender=Realm)
|
||||
|
||||
# Added to assist with the domain to string_id transition. Will eventually
|
||||
# be renamed and replace get_realm.
|
||||
def get_realm_by_string_id(string_id):
|
||||
def get_realm(string_id):
|
||||
# type: (Text) -> Optional[Realm]
|
||||
if not string_id:
|
||||
return None
|
||||
|
|
|
@ -23,7 +23,7 @@ from zerver.lib.test_classes import (
|
|||
ZulipTestCase,
|
||||
)
|
||||
from zerver.models import \
|
||||
get_realm_by_string_id, get_user_profile_by_email, email_to_username, UserProfile, \
|
||||
get_realm, get_user_profile_by_email, email_to_username, UserProfile, \
|
||||
PreregistrationUser, Realm
|
||||
|
||||
from confirmation.models import Confirmation
|
||||
|
@ -1345,7 +1345,7 @@ class TestLDAP(ZulipTestCase):
|
|||
with self.settings(AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map):
|
||||
backend = self.backend
|
||||
email = 'nonexisting@zulip.com'
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
do_deactivate_realm(realm)
|
||||
with self.assertRaisesRegex(Exception, 'Realm has been deactivated'):
|
||||
backend.get_or_create_user(email, _LDAPUser())
|
||||
|
@ -1518,7 +1518,7 @@ class TestAdminSetBackends(ZulipTestCase):
|
|||
result = self.client_patch("/json/realm", {
|
||||
'authentication_methods': ujson.dumps({u'Email': False, u'Dev': True})})
|
||||
self.assert_json_success(result)
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.assertFalse(password_auth_enabled(realm))
|
||||
self.assertTrue(dev_auth_enabled(realm))
|
||||
|
||||
|
@ -1529,7 +1529,7 @@ class TestAdminSetBackends(ZulipTestCase):
|
|||
result = self.client_patch("/json/realm", {
|
||||
'authentication_methods': ujson.dumps({u'Email': False, u'Dev': False})})
|
||||
self.assert_json_error(result, 'At least one authentication method must be enabled.', status_code=403)
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.assertTrue(password_auth_enabled(realm))
|
||||
self.assertTrue(dev_auth_enabled(realm))
|
||||
|
||||
|
@ -1541,7 +1541,7 @@ class TestAdminSetBackends(ZulipTestCase):
|
|||
result = self.client_patch("/json/realm", {
|
||||
'authentication_methods': ujson.dumps({u'Email': False, u'Dev': True, u'GitHub': False})})
|
||||
self.assert_json_success(result)
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
# Check that unsupported backend is not enabled
|
||||
self.assertFalse(github_auth_enabled(realm))
|
||||
self.assertTrue(dev_auth_enabled(realm))
|
||||
|
|
|
@ -9,7 +9,7 @@ from zerver.lib.actions import (
|
|||
check_add_realm_emoji,
|
||||
do_remove_realm_emoji,
|
||||
do_set_alert_words,
|
||||
get_realm_by_string_id,
|
||||
get_realm,
|
||||
)
|
||||
from zerver.lib.alert_words import alert_words_in_realm
|
||||
from zerver.lib.camo import get_camo_url
|
||||
|
@ -26,7 +26,7 @@ from zerver.models import (
|
|||
flush_per_request_caches,
|
||||
flush_realm_filter,
|
||||
get_client,
|
||||
get_realm_by_string_id,
|
||||
get_realm,
|
||||
get_user_profile_by_email,
|
||||
get_stream,
|
||||
realm_filters_for_realm,
|
||||
|
@ -159,7 +159,7 @@ class FencedBlockPreprocessorTest(TestCase):
|
|||
|
||||
def bugdown_convert(text):
|
||||
# type: (Text) -> Text
|
||||
return bugdown.convert(text, get_realm_by_string_id('zulip').id)
|
||||
return bugdown.convert(text, get_realm('zulip').id)
|
||||
|
||||
class BugdownTest(TestCase):
|
||||
def common_bugdown_test(self, text, expected):
|
||||
|
@ -410,7 +410,7 @@ class BugdownTest(TestCase):
|
|||
# type: (Text, Text) -> Text
|
||||
return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, get_camo_url(url), name)
|
||||
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
url = "https://zulip.com/test_realm_emoji.png"
|
||||
check_add_realm_emoji(realm, "test", url)
|
||||
|
||||
|
@ -435,7 +435,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_realm_patterns(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
url_format_string = r"https://trac.zulip.net/ticket/%(id)s"
|
||||
realm_filter = RealmFilter(realm=realm,
|
||||
pattern=r"#(?P<id>[0-9]{2,8})",
|
||||
|
@ -469,7 +469,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_maybe_update_realm_filters(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
url_format_string = r"https://trac.zulip.net/ticket/%(id)s"
|
||||
realm_filter = RealmFilter(realm=realm,
|
||||
pattern=r"#(?P<id>[0-9]{2,8})",
|
||||
|
@ -486,7 +486,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_flush_realm_filter(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
|
||||
def flush():
|
||||
# type: () -> None
|
||||
|
@ -526,7 +526,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_realm_patterns_negative(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
RealmFilter(realm=realm, pattern=r"#(?P<id>[0-9]{2,8})",
|
||||
url_format_string=r"https://trac.zulip.net/ticket/%(id)s").save()
|
||||
boring_msg = Message(sender=get_user_profile_by_email("othello@zulip.com"),
|
||||
|
@ -649,7 +649,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_stream_single(self):
|
||||
# type: () -> None
|
||||
denmark = get_stream('Denmark', get_realm_by_string_id('zulip'))
|
||||
denmark = get_stream('Denmark', get_realm('zulip'))
|
||||
sender_user_profile = get_user_profile_by_email("othello@zulip.com")
|
||||
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
|
||||
content = "#**Denmark**"
|
||||
|
@ -663,7 +663,7 @@ class BugdownTest(TestCase):
|
|||
# type: () -> None
|
||||
sender_user_profile = get_user_profile_by_email("othello@zulip.com")
|
||||
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
denmark = get_stream('Denmark', realm)
|
||||
scotland = get_stream('Scotland', realm)
|
||||
content = "Look to #**Denmark** and #**Scotland**, there something"
|
||||
|
@ -679,7 +679,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_stream_case_sensitivity(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
case_sens = Stream.objects.create(name='CaseSens', realm=realm)
|
||||
sender_user_profile = get_user_profile_by_email("othello@zulip.com")
|
||||
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
|
||||
|
@ -695,7 +695,7 @@ class BugdownTest(TestCase):
|
|||
"""#StreamName requires the stream be spelled with the correct case
|
||||
currently. If we change that in the future, we'll need to change this
|
||||
test."""
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
Stream.objects.create(name='CaseSens', realm=realm)
|
||||
sender_user_profile = get_user_profile_by_email("othello@zulip.com")
|
||||
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
|
||||
|
@ -706,7 +706,7 @@ class BugdownTest(TestCase):
|
|||
|
||||
def test_stream_unicode(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
uni = Stream.objects.create(name=u'привет', realm=realm)
|
||||
sender_user_profile = get_user_profile_by_email("othello@zulip.com")
|
||||
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
|
||||
|
@ -861,7 +861,7 @@ class BugdownApiTests(ZulipTestCase):
|
|||
self.assert_json_success(result)
|
||||
data = ujson.loads(result.content)
|
||||
self.assertEqual(data['rendered'],
|
||||
u'<p>This mentions <a class="stream" data-stream-id="%s" href="/#narrow/stream/Denmark">#Denmark</a> and <span class="user-mention" data-user-email="hamlet@zulip.com">@King Hamlet</span>.</p>' % (get_stream("Denmark", get_realm_by_string_id("zulip")).id),)
|
||||
u'<p>This mentions <a class="stream" data-stream-id="%s" href="/#narrow/stream/Denmark">#Denmark</a> and <span class="user-mention" data-user-email="hamlet@zulip.com">@King Hamlet</span>.</p>' % (get_stream("Denmark", get_realm("zulip")).id),)
|
||||
|
||||
class BugdownErrorTests(ZulipTestCase):
|
||||
def test_bugdown_error_handling(self):
|
||||
|
|
|
@ -34,7 +34,7 @@ from zerver.lib.validator import (
|
|||
check_string, check_dict, check_bool, check_int, check_list
|
||||
)
|
||||
from zerver.models import \
|
||||
get_realm_by_string_id, get_user_profile_by_email, UserProfile, Client
|
||||
get_realm, get_user_profile_by_email, UserProfile, Client
|
||||
|
||||
import ujson
|
||||
|
||||
|
@ -484,8 +484,8 @@ class DeactivatedRealmTest(ZulipTestCase):
|
|||
rest_dispatch rejects requests in a deactivated realm, both /json and api
|
||||
|
||||
"""
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
do_deactivate_realm(get_realm_by_string_id("zulip"))
|
||||
realm = get_realm("zulip")
|
||||
do_deactivate_realm(get_realm("zulip"))
|
||||
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
|
@ -519,7 +519,7 @@ class DeactivatedRealmTest(ZulipTestCase):
|
|||
authenticated_json_view views fail in a deactivated realm
|
||||
|
||||
"""
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
email = "hamlet@zulip.com"
|
||||
test_password = "abcd1234"
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
|
@ -537,7 +537,7 @@ class DeactivatedRealmTest(ZulipTestCase):
|
|||
logging in fails in a deactivated realm
|
||||
|
||||
"""
|
||||
do_deactivate_realm(get_realm_by_string_id("zulip"))
|
||||
do_deactivate_realm(get_realm("zulip"))
|
||||
result = self.login_with_return("hamlet@zulip.com")
|
||||
self.assert_in_response("has been deactivated", result)
|
||||
|
||||
|
@ -547,7 +547,7 @@ class DeactivatedRealmTest(ZulipTestCase):
|
|||
Using a webhook while in a deactivated realm fails
|
||||
|
||||
"""
|
||||
do_deactivate_realm(get_realm_by_string_id("zulip"))
|
||||
do_deactivate_realm(get_realm("zulip"))
|
||||
email = "hamlet@zulip.com"
|
||||
api_key = self.get_api_key(email)
|
||||
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
|
||||
|
|
|
@ -14,7 +14,7 @@ from zerver.lib.test_classes import (
|
|||
|
||||
from zerver.models import (
|
||||
get_display_recipient, get_stream, get_user_profile_by_email,
|
||||
Recipient, get_realm_by_string_id,
|
||||
Recipient, get_realm,
|
||||
)
|
||||
|
||||
from zerver.lib.actions import (
|
||||
|
@ -357,7 +357,7 @@ class TestCommandMTA(TestCase):
|
|||
# type: (mock.Mock) -> None
|
||||
|
||||
sender = "hamlet@zulip.com"
|
||||
stream = get_stream("Denmark", get_realm_by_string_id("zulip"))
|
||||
stream = get_stream("Denmark", get_realm("zulip"))
|
||||
stream_to_address = encode_email_address(stream)
|
||||
|
||||
template_path = os.path.join(MAILS_DIR, "simple.txt")
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.http import HttpRequest, HttpResponse
|
|||
from django.test import TestCase
|
||||
|
||||
from zerver.models import (
|
||||
get_client, get_realm_by_string_id, get_stream, get_user_profile_by_email,
|
||||
get_client, get_realm, get_stream, get_user_profile_by_email,
|
||||
Message, Recipient, UserProfile
|
||||
)
|
||||
|
||||
|
@ -254,7 +254,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
def create_bot(self, email):
|
||||
# type: (str) -> UserProfile
|
||||
return do_create_user(email, '123',
|
||||
get_realm_by_string_id('zulip'), 'Test Bot', 'test',
|
||||
get_realm('zulip'), 'Test Bot', 'test',
|
||||
bot_type=UserProfile.DEFAULT_BOT, bot_owner=self.user_profile)
|
||||
|
||||
def realm_bot_schema(self, field_name, check):
|
||||
|
@ -783,12 +783,12 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
('op', equals('update')),
|
||||
('realm_emoji', check_dict([])),
|
||||
])
|
||||
events = self.do_test(lambda: check_add_realm_emoji(get_realm_by_string_id("zulip"), "my_emoji",
|
||||
events = self.do_test(lambda: check_add_realm_emoji(get_realm("zulip"), "my_emoji",
|
||||
"https://realm.com/my_emoji"))
|
||||
error = schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
events = self.do_test(lambda: do_remove_realm_emoji(get_realm_by_string_id("zulip"), "my_emoji"))
|
||||
events = self.do_test(lambda: do_remove_realm_emoji(get_realm("zulip"), "my_emoji"))
|
||||
error = schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
|
@ -798,12 +798,12 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
('type', equals('realm_filters')),
|
||||
('realm_filters', check_list(None)), # TODO: validate tuples in the list
|
||||
])
|
||||
events = self.do_test(lambda: do_add_realm_filter(get_realm_by_string_id("zulip"), "#(?P<id>[123])",
|
||||
events = self.do_test(lambda: do_add_realm_filter(get_realm("zulip"), "#(?P<id>[123])",
|
||||
"https://realm.com/my_realm_filter/%(id)s"))
|
||||
error = schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
self.do_test(lambda: do_remove_realm_filter(get_realm_by_string_id("zulip"), "#(?P<id>[123])"))
|
||||
self.do_test(lambda: do_remove_realm_filter(get_realm("zulip"), "#(?P<id>[123])"))
|
||||
error = schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
|
@ -890,7 +890,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
|
||||
def test_rename_stream(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
stream = self.make_stream('old_name')
|
||||
new_name = u'stream with a brand new name'
|
||||
self.subscribe_to_stream(self.user_profile.email, stream.name)
|
||||
|
@ -1028,7 +1028,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
error = add_schema_checker('events[1]', events[1])
|
||||
self.assert_on_error(error)
|
||||
|
||||
action = lambda: do_change_stream_description(get_realm_by_string_id('zulip'), 'test_stream', u'new description')
|
||||
action = lambda: do_change_stream_description(get_realm('zulip'), 'test_stream', u'new description')
|
||||
events = self.do_test(action)
|
||||
error = stream_update_schema_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
|
|
@ -4,7 +4,7 @@ from mock import patch, MagicMock
|
|||
from django.test import TestCase
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
from confirmation.models import RealmCreationKey, generate_realm_creation_url
|
||||
from datetime import timedelta
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
|
@ -79,7 +79,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
|
|||
self.assert_in_success_response([u"Let's get started…"], result)
|
||||
|
||||
# Create Realm with generated link
|
||||
self.assertIsNone(get_realm_by_string_id('test'))
|
||||
self.assertIsNone(get_realm('test'))
|
||||
result = self.client_post(generated_link, {'email': email})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertTrue(result["Location"].endswith(
|
||||
|
|
|
@ -31,7 +31,7 @@ from zerver.lib.test_classes import (
|
|||
from zerver.models import (
|
||||
MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH,
|
||||
Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment, RealmAlias,
|
||||
get_realm_by_string_id, get_stream, get_user_profile_by_email,
|
||||
get_realm, get_stream, get_user_profile_by_email,
|
||||
Reaction, sew_messages_and_reactions
|
||||
)
|
||||
|
||||
|
@ -127,7 +127,7 @@ class TopicHistoryTest(ZulipTestCase):
|
|||
# out of realm
|
||||
bad_stream = self.make_stream(
|
||||
'mit_stream',
|
||||
realm=get_realm_by_string_id('mit')
|
||||
realm=get_realm('mit')
|
||||
)
|
||||
endpoint = '/json/users/me/%s/topics' % (bad_stream.id,)
|
||||
result = self.client_get(endpoint, dict())
|
||||
|
@ -158,7 +158,7 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
# We need to save the object before we can access
|
||||
# the many-to-many relationship 'realms'
|
||||
dep.save()
|
||||
dep.realms = [get_realm_by_string_id("zulip")]
|
||||
dep.realms = [get_realm("zulip")]
|
||||
dep.save()
|
||||
|
||||
def create_user(self, email):
|
||||
|
@ -383,7 +383,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
"""
|
||||
Check that messages sent to a stream reach all subscribers to that stream.
|
||||
"""
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
subscribers = self.users_subscribed_to_stream(stream_name, realm)
|
||||
old_subscriber_messages = []
|
||||
for subscriber in subscribers:
|
||||
|
@ -508,7 +508,7 @@ class StreamMessagesTest(ZulipTestCase):
|
|||
|
||||
# Subscribe everyone to a stream with non-ASCII characters.
|
||||
non_ascii_stream_name = u"hümbüǵ"
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
stream = self.make_stream(non_ascii_stream_name)
|
||||
for user_profile in UserProfile.objects.filter(realm=realm):
|
||||
self.subscribe_to_stream(user_profile.email, stream.name)
|
||||
|
|
|
@ -12,7 +12,7 @@ from sqlalchemy.sql import compiler # type: ignore
|
|||
|
||||
from zerver.models import (
|
||||
Realm, Recipient, Stream, Subscription, UserProfile, Attachment,
|
||||
get_display_recipient, get_recipient, get_realm_by_string_id, get_stream, get_user_profile_by_email,
|
||||
get_display_recipient, get_recipient, get_realm, get_stream, get_user_profile_by_email,
|
||||
Reaction
|
||||
)
|
||||
from zerver.lib.message import (
|
||||
|
@ -70,7 +70,7 @@ def mute_stream(realm, user_profile, stream_name):
|
|||
class NarrowBuilderTest(ZulipTestCase):
|
||||
def setUp(self):
|
||||
# type: () -> None
|
||||
self.realm = get_realm_by_string_id('zulip')
|
||||
self.realm = get_realm('zulip')
|
||||
self.user_profile = get_user_profile_by_email("hamlet@zulip.com")
|
||||
self.builder = NarrowBuilder(self.user_profile, column('id'))
|
||||
self.raw_query = select([column("id")], None, "zerver_message")
|
||||
|
@ -333,7 +333,7 @@ class BuildNarrowFilterTest(TestCase):
|
|||
class IncludeHistoryTest(ZulipTestCase):
|
||||
def test_ok_to_include_history(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.make_stream('public_stream', realm=realm)
|
||||
|
||||
# Negated stream searches should not include history.
|
||||
|
@ -1006,7 +1006,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
doing.
|
||||
"""
|
||||
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.make_stream('web stuff')
|
||||
user_profile = get_user_profile_by_email("hamlet@zulip.com")
|
||||
user_profile.muted_topics = ujson.dumps([['Scotland', 'golf'], ['web stuff', 'css'], ['bogus', 'bogus']])
|
||||
|
@ -1042,7 +1042,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
|
||||
def test_exclude_muting_conditions(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.make_stream('web stuff')
|
||||
user_profile = get_user_profile_by_email("hamlet@zulip.com")
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
|
||||
from zerver.lib.actions import get_realm_by_string_id, check_add_realm_emoji
|
||||
from zerver.lib.actions import get_realm, check_add_realm_emoji
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import RealmEmoji
|
||||
import ujson
|
||||
|
@ -11,7 +11,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
def test_list(self):
|
||||
# type: () -> None
|
||||
self.login("iago@zulip.com")
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
|
||||
result = self.client_get("/json/realm/emoji")
|
||||
self.assert_json_success(result)
|
||||
|
@ -22,7 +22,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
def test_list_no_author(self):
|
||||
# type: () -> None
|
||||
self.login("iago@zulip.com")
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
RealmEmoji.objects.create(realm=realm, name='my_emojy', img_url='https://example.com/my_emoji')
|
||||
result = self.client_get("/json/realm/emoji")
|
||||
self.assert_json_success(result)
|
||||
|
@ -33,7 +33,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
def test_list_admins_only(self):
|
||||
# type: () -> None
|
||||
self.login('othello@zulip.com')
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.add_emoji_by_admins_only = True
|
||||
realm.save()
|
||||
check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
|
||||
|
@ -62,7 +62,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
self.assertEqual(
|
||||
content["emoji"]['my_emoji']['author']['email'], email)
|
||||
|
||||
realm_emoji = RealmEmoji.objects.get(realm=get_realm_by_string_id('zulip'))
|
||||
realm_emoji = RealmEmoji.objects.get(realm=get_realm('zulip'))
|
||||
self.assertEqual(
|
||||
str(realm_emoji),
|
||||
'<RealmEmoji(zulip.com): my_emoji https://example.com/my_emoji>'
|
||||
|
@ -78,7 +78,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
def test_upload_admins_only(self):
|
||||
# type: () -> None
|
||||
self.login('othello@zulip.com')
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.add_emoji_by_admins_only = True
|
||||
realm.save()
|
||||
data = {"name": "my_emoji", "url": "https://example.com/my_emoji"}
|
||||
|
@ -88,7 +88,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
def test_delete(self):
|
||||
# type: () -> None
|
||||
self.login("iago@zulip.com")
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
|
||||
result = self.client_delete("/json/realm/emoji/my_emoji")
|
||||
self.assert_json_success(result)
|
||||
|
@ -101,7 +101,7 @@ class RealmEmojiTest(ZulipTestCase):
|
|||
def test_delete_admins_only(self):
|
||||
# type: () -> None
|
||||
self.login('othello@zulip.com')
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.add_emoji_by_admins_only = True
|
||||
realm.save()
|
||||
check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
|
||||
from zerver.lib.actions import get_realm_by_string_id, do_add_realm_filter
|
||||
from zerver.lib.actions import get_realm, do_add_realm_filter
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import RealmFilter
|
||||
import ujson
|
||||
|
@ -12,7 +12,7 @@ class RealmFilterTest(ZulipTestCase):
|
|||
def test_list(self):
|
||||
# type: () -> None
|
||||
self.login("iago@zulip.com")
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
do_add_realm_filter(
|
||||
realm,
|
||||
"#(?P<id>[123])",
|
||||
|
@ -58,7 +58,7 @@ class RealmFilterTest(ZulipTestCase):
|
|||
def test_delete(self):
|
||||
# type: () -> None
|
||||
self.login("iago@zulip.com")
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
filter_id = do_add_realm_filter(
|
||||
realm,
|
||||
"#(?P<id>[123])",
|
||||
|
|
|
@ -16,7 +16,7 @@ from zerver.forms import HomepageForm
|
|||
from zerver.views import do_change_password
|
||||
from zerver.views.invite import get_invitee_emails_set
|
||||
from zerver.models import (
|
||||
get_realm_by_string_id, get_prereg_user_by_email, get_user_profile_by_email,
|
||||
get_realm, get_prereg_user_by_email, get_user_profile_by_email,
|
||||
PreregistrationUser, Realm, RealmAlias, Recipient,
|
||||
Referral, ScheduledJob, UserProfile, UserMessage,
|
||||
Stream, Subscription, ScheduledJob
|
||||
|
@ -150,7 +150,7 @@ class AddNewUserHistoryTest(ZulipTestCase):
|
|||
"Denmark": {"description": "A Scandinavian country", "invite_only": False},
|
||||
"Verona": {"description": "A city in Italy", "invite_only": False}
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
set_default_streams(get_realm_by_string_id("zulip"), stream_dict)
|
||||
set_default_streams(get_realm("zulip"), stream_dict)
|
||||
with patch("zerver.lib.actions.add_new_user_history"):
|
||||
self.register("test", "test")
|
||||
user_profile = get_user_profile_by_email("test@zulip.com")
|
||||
|
@ -250,7 +250,7 @@ class LoginTest(ZulipTestCase):
|
|||
|
||||
def test_register(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
stream_dict = {"stream_"+str(i): {"description": "stream_%s_description" % i, "invite_only": False}
|
||||
for i in range(40)} # type: Dict[Text, Dict[Text, Any]]
|
||||
for stream_name in stream_dict.keys():
|
||||
|
@ -271,7 +271,7 @@ class LoginTest(ZulipTestCase):
|
|||
If you try to register for a deactivated realm, you get a clear error
|
||||
page.
|
||||
"""
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
realm.deactivated = True
|
||||
realm.save(update_fields=["deactivated"])
|
||||
|
||||
|
@ -286,7 +286,7 @@ class LoginTest(ZulipTestCase):
|
|||
"""
|
||||
If you try to log in to a deactivated realm, you get a clear error page.
|
||||
"""
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
realm.deactivated = True
|
||||
realm.save(update_fields=["deactivated"])
|
||||
|
||||
|
@ -518,7 +518,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
|||
In a realm with `restricted_to_domain = True`, you can't invite people
|
||||
with a different domain from that of the realm or your e-mail address.
|
||||
"""
|
||||
zulip_realm = get_realm_by_string_id("zulip")
|
||||
zulip_realm = get_realm("zulip")
|
||||
zulip_realm.restricted_to_domain = True
|
||||
zulip_realm.save()
|
||||
|
||||
|
@ -535,7 +535,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
|||
In a realm with `restricted_to_domain = False`, you can invite people
|
||||
with a different domain from that of the realm or your e-mail address.
|
||||
"""
|
||||
zulip_realm = get_realm_by_string_id("zulip")
|
||||
zulip_realm = get_realm("zulip")
|
||||
zulip_realm.restricted_to_domain = False
|
||||
zulip_realm.save()
|
||||
|
||||
|
@ -736,7 +736,7 @@ class RealmCreationTest(ZulipTestCase):
|
|||
string_id = "zuliptest"
|
||||
domain = 'test.com'
|
||||
email = "user1@test.com"
|
||||
realm = get_realm_by_string_id('test')
|
||||
realm = get_realm('test')
|
||||
|
||||
# Make sure the realm does not exist
|
||||
self.assertIsNone(realm)
|
||||
|
@ -760,7 +760,7 @@ class RealmCreationTest(ZulipTestCase):
|
|||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
# Make sure the realm is created
|
||||
realm = get_realm_by_string_id(string_id)
|
||||
realm = get_realm(string_id)
|
||||
self.assertIsNotNone(realm)
|
||||
self.assertEqual(realm.string_id, string_id)
|
||||
self.assertEqual(get_user_profile_by_email(email).realm, realm)
|
||||
|
@ -782,7 +782,7 @@ class RealmCreationTest(ZulipTestCase):
|
|||
realm_name = "Test"
|
||||
|
||||
# Make sure the realm does not exist
|
||||
self.assertIsNone(get_realm_by_string_id('test'))
|
||||
self.assertIsNone(get_realm('test'))
|
||||
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=True), self.settings(OPEN_REALM_CREATION=True):
|
||||
# Create new realm with the email
|
||||
|
@ -806,7 +806,7 @@ class RealmCreationTest(ZulipTestCase):
|
|||
self.assertEqual(result.status_code, 302)
|
||||
|
||||
# Make sure the realm is created
|
||||
realm = get_realm_by_string_id(string_id)
|
||||
realm = get_realm(string_id)
|
||||
self.assertIsNotNone(realm)
|
||||
self.assertEqual(realm.string_id, string_id)
|
||||
self.assertEqual(get_user_profile_by_email(email).realm, realm)
|
||||
|
@ -866,7 +866,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
username = "newguy"
|
||||
email = "newguy@zulip.com"
|
||||
password = "newpassword"
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
domain = realm.domain
|
||||
do_set_realm_default_language(realm, "de")
|
||||
|
||||
|
@ -899,12 +899,12 @@ class UserSignUpTest(ZulipTestCase):
|
|||
subdomain = "zulip"
|
||||
realm_name = "Zulip"
|
||||
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.restricted_to_domain = False
|
||||
realm.invite_required = False
|
||||
realm.save()
|
||||
|
||||
realm = get_realm_by_string_id('mit')
|
||||
realm = get_realm('mit')
|
||||
do_deactivate_realm(realm)
|
||||
realm.save()
|
||||
|
||||
|
@ -946,7 +946,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
subdomain = "zulip"
|
||||
realm_name = "Zulip"
|
||||
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.restricted_to_domain = False
|
||||
realm.invite_required = False
|
||||
realm.save()
|
||||
|
@ -983,7 +983,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
|
||||
def test_failed_signup_due_to_restricted_domain(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS = True):
|
||||
request = HostRequestMock(host = realm.host)
|
||||
request.session = {} # type: ignore
|
||||
|
@ -992,7 +992,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
|
||||
def test_failed_signup_due_to_invite_required(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.invite_required = True
|
||||
realm.save()
|
||||
request = HostRequestMock(host = realm.host)
|
||||
|
|
|
@ -38,7 +38,7 @@ from zerver.lib.actions import (
|
|||
do_add_default_stream, do_change_is_admin, do_set_realm_waiting_period_threshold,
|
||||
do_create_realm, do_remove_default_stream, do_set_realm_create_stream_by_admins_only,
|
||||
gather_subscriptions_helper, bulk_add_subscriptions, bulk_remove_subscriptions,
|
||||
gather_subscriptions, get_default_streams_for_realm, get_realm_by_string_id, get_stream,
|
||||
gather_subscriptions, get_default_streams_for_realm, get_realm, get_stream,
|
||||
get_user_profile_by_email, set_default_streams, get_subscription,
|
||||
create_streams_if_needed, active_user_ids
|
||||
)
|
||||
|
@ -59,7 +59,7 @@ class TestCreateStreams(ZulipTestCase):
|
|||
# type: () -> None
|
||||
stream_names = [u'new1', u'new2', u'new3']
|
||||
stream_descriptions = [u'des1', u'des2', u'des3']
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
|
||||
new_streams, existing_streams = create_streams_if_needed(
|
||||
realm,
|
||||
|
@ -98,7 +98,7 @@ class TestCreateStreams(ZulipTestCase):
|
|||
class RecipientTest(ZulipTestCase):
|
||||
def test_recipient(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
stream = get_stream('Verona', realm)
|
||||
recipient = Recipient.objects.get(
|
||||
type_id=stream.id,
|
||||
|
@ -411,7 +411,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(deletion_events, [])
|
||||
|
||||
with self.assertRaises(Stream.DoesNotExist):
|
||||
Stream.objects.get(realm=get_realm_by_string_id("zulip"), name=active_name)
|
||||
Stream.objects.get(realm=get_realm("zulip"), name=active_name)
|
||||
|
||||
# A deleted stream's name is changed, is deactivated, is invite-only,
|
||||
# and has no subscribers.
|
||||
|
@ -688,7 +688,7 @@ class DefaultStreamTest(ZulipTestCase):
|
|||
|
||||
def test_add_and_remove_default_stream(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
orig_stream_names = self.get_default_stream_names(realm)
|
||||
do_add_default_stream(realm, 'Added Stream')
|
||||
new_stream_names = self.get_default_stream_names(realm)
|
||||
|
@ -1407,7 +1407,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
# type: () -> None
|
||||
email1 = 'cordelia@zulip.com'
|
||||
email2 = 'iago@zulip.com'
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
streams_to_sub = ['multi_user_stream']
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
|
@ -1604,7 +1604,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
|
||||
def test_bulk_subscribe_MIT(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id("mit")
|
||||
realm = get_realm("mit")
|
||||
streams = ["stream_%s" % i for i in range(40)]
|
||||
for stream_name in streams:
|
||||
self.make_stream(stream_name, realm=realm)
|
||||
|
@ -2109,7 +2109,7 @@ class GetSubscribersTest(ZulipTestCase):
|
|||
"""
|
||||
Check never_subscribed streams are fetched correctly and not include invite_only streams.
|
||||
"""
|
||||
realm = get_realm_by_string_id("zulip")
|
||||
realm = get_realm("zulip")
|
||||
streams = ["stream_%s" % i for i in range(10)]
|
||||
for stream_name in streams:
|
||||
self.make_stream(stream_name, realm=realm)
|
||||
|
|
|
@ -22,7 +22,7 @@ from zerver.forms import WRONG_SUBDOMAIN_ERROR
|
|||
|
||||
from zerver.models import UserProfile, Recipient, \
|
||||
Realm, RealmAlias, UserActivity, \
|
||||
get_user_profile_by_email, get_realm_by_string_id, get_realm_by_email_domain, \
|
||||
get_user_profile_by_email, get_realm, get_realm_by_email_domain, \
|
||||
get_client, get_stream, Message, get_unique_open_realm, \
|
||||
completely_open, GetRealmByDomainException
|
||||
|
||||
|
@ -114,15 +114,15 @@ class RealmTest(ZulipTestCase):
|
|||
cache, and we start by populating the cache for Hamlet, and we end
|
||||
by checking the cache to ensure that the new value is there."""
|
||||
get_user_profile_by_email('hamlet@zulip.com')
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
new_name = 'Zed You Elle Eye Pea'
|
||||
do_set_realm_name(realm, new_name)
|
||||
self.assertEqual(get_realm_by_string_id(realm.string_id).name, new_name)
|
||||
self.assertEqual(get_realm(realm.string_id).name, new_name)
|
||||
self.assert_user_profile_cache_gets_new_name('hamlet@zulip.com', new_name)
|
||||
|
||||
def test_do_set_realm_name_events(self):
|
||||
# type: () -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
new_name = 'Puliz'
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events):
|
||||
|
@ -146,7 +146,7 @@ class RealmTest(ZulipTestCase):
|
|||
|
||||
def set_up_db(attr, value):
|
||||
# type: (str, Any) -> None
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
setattr(realm, attr, value)
|
||||
realm.save()
|
||||
|
||||
|
@ -155,7 +155,7 @@ class RealmTest(ZulipTestCase):
|
|||
params = {k: ujson.dumps(v) for k, v in kwarg.items()}
|
||||
result = self.client_patch('/json/realm', params)
|
||||
self.assert_json_success(result)
|
||||
return get_realm_by_string_id('zulip') # refresh data
|
||||
return get_realm('zulip') # refresh data
|
||||
|
||||
# name
|
||||
realm = update_with_api(name=new_name)
|
||||
|
@ -231,7 +231,7 @@ class RealmTest(ZulipTestCase):
|
|||
realm appears to be deactivated. You can make this test fail
|
||||
by disabling cache.flush_realm()."""
|
||||
get_user_profile_by_email('hamlet@zulip.com')
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
do_deactivate_realm(realm)
|
||||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
self.assertTrue(user.realm.deactivated)
|
||||
|
@ -239,7 +239,7 @@ class RealmTest(ZulipTestCase):
|
|||
def test_do_set_realm_default_language(self):
|
||||
# type: () -> None
|
||||
new_lang = "de"
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.assertNotEqual(realm.default_language, new_lang)
|
||||
# we need an admin user.
|
||||
email = 'iago@zulip.com'
|
||||
|
@ -248,7 +248,7 @@ class RealmTest(ZulipTestCase):
|
|||
req = dict(default_language=ujson.dumps(new_lang))
|
||||
result = self.client_patch('/json/realm', req)
|
||||
self.assert_json_success(result)
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.assertEqual(realm.default_language, new_lang)
|
||||
|
||||
# Test setting zh_CN, we set zh_HANS instead of zh_CN in db
|
||||
|
@ -257,7 +257,7 @@ class RealmTest(ZulipTestCase):
|
|||
req = dict(default_language=ujson.dumps(chinese))
|
||||
result = self.client_patch('/json/realm', req)
|
||||
self.assert_json_success(result)
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.assertEqual(realm.default_language, simplified_chinese)
|
||||
|
||||
# Test to make sure that when invalid languages are passed
|
||||
|
@ -267,7 +267,7 @@ class RealmTest(ZulipTestCase):
|
|||
req = dict(default_language=ujson.dumps(invalid_lang))
|
||||
result = self.client_patch('/json/realm', req)
|
||||
self.assert_json_error(result, "Invalid language '%s'" % (invalid_lang,))
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
self.assertNotEqual(realm.default_language, invalid_lang)
|
||||
|
||||
|
||||
|
@ -511,7 +511,7 @@ class AdminCreateUserTest(ZulipTestCase):
|
|||
self.assert_json_error(result,
|
||||
"Email 'romeo@not-zulip.com' does not belong to domain 'zulip.com'")
|
||||
|
||||
RealmAlias.objects.create(realm=get_realm_by_string_id('zulip'), domain='zulip.net')
|
||||
RealmAlias.objects.create(realm=get_realm('zulip'), domain='zulip.net')
|
||||
|
||||
# HAPPY PATH STARTS HERE
|
||||
valid_params = dict(
|
||||
|
@ -2045,7 +2045,7 @@ class HomeTest(ZulipTestCase):
|
|||
def test_notifications_stream(self):
|
||||
# type: () -> None
|
||||
email = 'hamlet@zulip.com'
|
||||
realm = get_realm_by_string_id('zulip')
|
||||
realm = get_realm('zulip')
|
||||
realm.notifications_stream = get_stream('Denmark', realm)
|
||||
realm.save()
|
||||
self.login(email)
|
||||
|
@ -2288,7 +2288,7 @@ class TestMissedMessages(ZulipTestCase):
|
|||
class TestOpenRealms(ZulipTestCase):
|
||||
def test_open_realm_logic(self):
|
||||
# type: () -> None
|
||||
mit_realm = get_realm_by_string_id("mit")
|
||||
mit_realm = get_realm("mit")
|
||||
self.assertEqual(get_unique_open_realm(), None)
|
||||
mit_realm.restricted_to_domain = False
|
||||
mit_realm.save()
|
||||
|
|
|
@ -21,7 +21,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, Huddle, \
|
|||
PreregistrationUser, get_client, UserActivity, \
|
||||
get_stream, UserPresence, get_recipient, name_changes_disabled, email_to_username, \
|
||||
completely_open, get_unique_open_realm, email_allowed_for_realm, \
|
||||
get_realm_by_string_id, get_realm_by_email_domain, list_of_domains_for_realm
|
||||
get_realm, get_realm_by_email_domain, list_of_domains_for_realm
|
||||
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
|
||||
do_activate_user, do_create_user, do_create_realm, set_default_streams, \
|
||||
update_user_presence, do_events_register, \
|
||||
|
@ -114,7 +114,7 @@ def accounts_register(request):
|
|||
# For creating a new realm, there is no existing realm or domain
|
||||
realm = None
|
||||
elif settings.REALMS_HAVE_SUBDOMAINS:
|
||||
realm = get_realm_by_string_id(get_subdomain(request))
|
||||
realm = get_realm(get_subdomain(request))
|
||||
else:
|
||||
realm = get_realm_by_email_domain(email)
|
||||
|
||||
|
@ -303,14 +303,14 @@ def create_preregistration_user(email, request, realm_creation=False):
|
|||
# The user is trying to sign up for a completely open realm,
|
||||
# so create them a PreregistrationUser for that realm
|
||||
return PreregistrationUser.objects.create(email=email,
|
||||
realm=get_realm_by_string_id(realm_str),
|
||||
realm=get_realm(realm_str),
|
||||
realm_creation=realm_creation)
|
||||
|
||||
return PreregistrationUser.objects.create(email=email, realm_creation=realm_creation)
|
||||
|
||||
def accounts_home_with_realm_str(request, realm_str):
|
||||
# type: (HttpRequest, str) -> HttpResponse
|
||||
if not settings.REALMS_HAVE_SUBDOMAINS and completely_open(get_realm_by_string_id(realm_str)):
|
||||
if not settings.REALMS_HAVE_SUBDOMAINS and completely_open(get_realm(realm_str)):
|
||||
# You can sign up for a completely open realm through a
|
||||
# special registration path that contains the domain in the
|
||||
# URL. We store this information in the session rather than
|
||||
|
@ -385,7 +385,7 @@ def get_realm_from_request(request):
|
|||
realm_str = get_subdomain(request)
|
||||
else:
|
||||
realm_str = request.session.get("realm_str")
|
||||
return get_realm_by_string_id(realm_str)
|
||||
return get_realm(realm_str)
|
||||
|
||||
def accounts_home(request):
|
||||
# type: (HttpRequest) -> HttpResponse
|
||||
|
|
|
@ -42,7 +42,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, \
|
|||
Realm, RealmAlias, Recipient, UserMessage, bulk_get_recipients, get_recipient, \
|
||||
get_user_profile_by_email, get_stream, \
|
||||
parse_usermessage_flags, \
|
||||
email_to_domain, get_realm_by_string_id, get_active_streams, \
|
||||
email_to_domain, get_realm, get_active_streams, \
|
||||
bulk_get_streams, get_user_profile_by_id
|
||||
|
||||
from sqlalchemy import func
|
||||
|
@ -813,7 +813,7 @@ def send_message_backend(request, user_profile,
|
|||
# The email gateway bot needs to be able to send messages in
|
||||
# any realm.
|
||||
return json_error(_("User not authorized for this query"))
|
||||
realm = get_realm_by_string_id(realm_str)
|
||||
realm = get_realm(realm_str)
|
||||
if not realm:
|
||||
return json_error(_("Unknown realm %s") % (realm_str,))
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from typing import Any
|
|||
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import get_realm
|
||||
from zerver.lib.create_user import random_api_key
|
||||
from zerver.management.commands.create_realm import Command as CreateRealm
|
||||
|
||||
|
@ -40,7 +40,7 @@ class Command(BaseCommand):
|
|||
CreateRealm().handle(*args, **options)
|
||||
print() # Newline
|
||||
|
||||
realm = get_realm_by_string_id(options["string_id"])
|
||||
realm = get_realm(options["string_id"])
|
||||
if realm is None:
|
||||
print("\033[1;31mRealm does not exist!\033[0m\n", file=sys.stderr)
|
||||
exit(2)
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.conf import settings
|
|||
from zerver.lib.bulk_create import bulk_create_realms, \
|
||||
bulk_create_streams, bulk_create_users, bulk_create_huddles, \
|
||||
bulk_create_clients
|
||||
from zerver.models import DefaultStream, get_stream, get_realm_by_string_id
|
||||
from zerver.models import DefaultStream, get_stream, get_realm
|
||||
from zilencer.models import Deployment
|
||||
|
||||
import random
|
||||
|
@ -171,7 +171,7 @@ class Command(BaseCommand):
|
|||
subscriptions_to_add.append(s)
|
||||
Subscription.objects.bulk_create(subscriptions_to_add)
|
||||
else:
|
||||
zulip_realm = get_realm_by_string_id("zulip")
|
||||
zulip_realm = get_realm("zulip")
|
||||
recipient_streams = [klass.type_id for klass in
|
||||
Recipient.objects.filter(type=Recipient.STREAM)]
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from zerver.lib.actions import internal_send_message
|
|||
from zerver.lib.redis_utils import get_redis_client
|
||||
from zerver.lib.response import json_success, json_error, json_response
|
||||
from zerver.lib.validator import check_dict
|
||||
from zerver.models import get_realm_by_string_id, get_user_profile_by_email, \
|
||||
from zerver.models import get_realm, get_user_profile_by_email, \
|
||||
get_realm_by_email_domain, UserProfile, Realm
|
||||
from .error_notify import notify_server_error, notify_browser_error
|
||||
|
||||
|
@ -49,7 +49,7 @@ def get_ticket_number():
|
|||
def submit_feedback(request, deployment, message=REQ(validator=check_dict([]))):
|
||||
# type: (HttpRequest, Deployment, Dict[str, Text]) -> HttpResponse
|
||||
domainish = message["sender_domain"]
|
||||
if get_realm_by_string_id("zulip") not in deployment.realms.all():
|
||||
if get_realm("zulip") not in deployment.realms.all():
|
||||
domainish += u" via " + deployment.name
|
||||
subject = "%s" % (message["sender_email"],)
|
||||
|
||||
|
|
Loading…
Reference in New Issue