def handle(self, *args, **options): # type: (*Any, **str) -> None realm = get_realm(options["string_id"]) if options["op"] == "show": print("Aliases for %s:" % (realm.domain,)) for alias in get_realm_aliases(realm): print(alias["domain"]) sys.exit(0) domain = options['alias'].strip().lower() try: validate_domain(domain) except ValidationError as e: print(e.messages[0]) sys.exit(1) if options["op"] == "add": if not can_add_alias(domain): print("A Realm already exists for this domain, cannot add it as an alias for another realm!") sys.exit(1) RealmAlias.objects.create(realm=realm, domain=domain) sys.exit(0) elif options["op"] == "remove": RealmAlias.objects.get(realm=realm, domain=domain).delete() sys.exit(0) else: self.print_help("./manage.py", "realm_alias") sys.exit(1)
def handle(self, *args, **options): # type: (*Any, **str) -> None realm = get_realm(options["string_id"]) if options["op"] == "show": print("Aliases for %s:" % (realm.domain, )) for alias in get_realm_aliases(realm): print(alias["domain"]) sys.exit(0) domain = options['alias'].strip().lower() try: validate_domain(domain) except ValidationError as e: print(e.messages[0]) sys.exit(1) if options["op"] == "add": if not can_add_alias(domain): print( "A Realm already exists for this domain, cannot add it as an alias for another realm!" ) sys.exit(1) RealmAlias.objects.create(realm=realm, domain=domain) sys.exit(0) elif options["op"] == "remove": RealmAlias.objects.get(realm=realm, domain=domain).delete() sys.exit(0) else: self.print_help("./manage.py", "realm_alias") sys.exit(1)
def handle(self, *args, **options): # type: (*Any, **str) -> None realm = get_realm(options["string_id"]) if options["op"] == "show": print("Aliases for %s:" % (realm.string_id, )) for alias in get_realm_aliases(realm): if alias["allow_subdomains"]: print(alias["domain"] + " (subdomains allowed)") else: print(alias["domain"] + " (subdomains not allowed)") sys.exit(0) domain = options['alias'].strip().lower() try: validate_domain(domain) except ValidationError as e: print(e.messages[0]) sys.exit(1) if options["op"] == "add": try: if not can_add_alias(domain): print( _("The domain %(domain)s belongs to another organization." ) % {'domain': domain}) sys.exit(1) RealmAlias.objects.create( realm=realm, domain=domain, allow_subdomains=options["allow_subdomains"]) sys.exit(0) except IntegrityError: print( _("The domain %(domain)s is already a part of your organization." ) % {'domain': domain}) sys.exit(1) elif options["op"] == "remove": try: RealmAlias.objects.get(realm=realm, domain=domain).delete() sys.exit(0) except RealmAlias.DoesNotExist: print("No such entry found!") sys.exit(1) else: self.print_help("./manage.py", "realm_alias") sys.exit(1)
def fetch_initial_state_data(user_profile, event_types, queue_id, include_subscribers=True): # type: (UserProfile, Optional[Iterable[str]], str, bool) -> Dict[str, Any] state = {'queue_id': queue_id} # type: Dict[str, Any] if event_types is None: want = lambda msg_type: True else: want = set(event_types).__contains__ if want('alert_words'): state['alert_words'] = user_alert_words(user_profile) if want('attachments'): state['attachments'] = user_attachments(user_profile) if want('message'): # The client should use get_old_messages() to fetch messages # starting with the max_message_id. They will get messages # newer than that ID via get_events() messages = Message.objects.filter( usermessage__user_profile=user_profile).order_by('-id')[:1] if messages: state['max_message_id'] = messages[0].id else: state['max_message_id'] = -1 if want('muted_topics'): state['muted_topics'] = ujson.loads(user_profile.muted_topics) if want('pointer'): state['pointer'] = user_profile.pointer if want('presence'): state['presences'] = get_status_dict(user_profile) if want('realm'): state['realm_name'] = user_profile.realm.name state['realm_description'] = user_profile.realm.description state[ 'realm_restricted_to_domain'] = user_profile.realm.restricted_to_domain state['realm_invite_required'] = user_profile.realm.invite_required state[ 'realm_invite_by_admins_only'] = user_profile.realm.invite_by_admins_only state[ 'realm_authentication_methods'] = user_profile.realm.authentication_methods_dict( ) state[ 'realm_create_stream_by_admins_only'] = user_profile.realm.create_stream_by_admins_only state[ 'realm_add_emoji_by_admins_only'] = user_profile.realm.add_emoji_by_admins_only state[ 'realm_allow_message_editing'] = user_profile.realm.allow_message_editing state[ 'realm_message_content_edit_limit_seconds'] = user_profile.realm.message_content_edit_limit_seconds state['realm_default_language'] = user_profile.realm.default_language state[ 'realm_waiting_period_threshold'] = user_profile.realm.waiting_period_threshold state['realm_icon_url'] = realm_icon_url(user_profile.realm) state['realm_icon_source'] = user_profile.realm.icon_source state[ 'realm_name_changes_disabled'] = user_profile.realm.name_changes_disabled state[ 'realm_email_changes_disabled'] = user_profile.realm.email_changes_disabled state['max_icon_file_size'] = settings.MAX_ICON_FILE_SIZE state['realm_bot_domain'] = user_profile.realm.get_bot_domain() if want('realm_domains'): state['realm_domains'] = get_realm_aliases(user_profile.realm) if want('realm_emoji'): state['realm_emoji'] = user_profile.realm.get_emoji() if want('realm_filters'): state['realm_filters'] = realm_filters_for_realm(user_profile.realm_id) if want('realm_user'): state['realm_users'] = get_realm_user_dicts(user_profile) if want('realm_bot'): state['realm_bots'] = get_owned_bot_dicts(user_profile) if want('referral'): state['referrals'] = { 'granted': user_profile.invites_granted, 'used': user_profile.invites_used } if want('subscription'): subscriptions, unsubscribed, never_subscribed = gather_subscriptions_helper( user_profile, include_subscribers=include_subscribers) state['subscriptions'] = subscriptions state['unsubscribed'] = unsubscribed state['never_subscribed'] = never_subscribed if want('update_message_flags'): # There's no initial data for message flag updates, client will # get any updates during a session from get_events() pass if want('stream'): state['streams'] = do_get_streams(user_profile) if want('default_streams'): state['realm_default_streams'] = streams_to_dicts_sorted( get_default_streams_for_realm(user_profile.realm)) if want('update_display_settings'): state['twenty_four_hour_time'] = user_profile.twenty_four_hour_time state['left_side_userlist'] = user_profile.left_side_userlist state['emoji_alt_code'] = user_profile.emoji_alt_code default_language = user_profile.default_language state['default_language'] = default_language if want('update_global_notifications'): state[ 'enable_stream_desktop_notifications'] = user_profile.enable_stream_desktop_notifications state['enable_stream_sounds'] = user_profile.enable_stream_sounds state[ 'enable_desktop_notifications'] = user_profile.enable_desktop_notifications state['enable_sounds'] = user_profile.enable_sounds state[ 'enable_offline_email_notifications'] = user_profile.enable_offline_email_notifications state[ 'enable_offline_push_notifications'] = user_profile.enable_offline_push_notifications state[ 'enable_online_push_notifications'] = user_profile.enable_online_push_notifications state['enable_digest_emails'] = user_profile.enable_digest_emails if want('zulip_version'): state['zulip_version'] = ZULIP_VERSION return state
def list_aliases(request, user_profile): # type: (HttpRequest, UserProfile) -> (HttpResponse) aliases = get_realm_aliases(user_profile.realm) return json_success({'domains': aliases})
def fetch_initial_state_data(user_profile, event_types, queue_id, include_subscribers=True): # type: (UserProfile, Optional[Iterable[str]], str, bool) -> Dict[str, Any] state = {'queue_id': queue_id} # type: Dict[str, Any] if event_types is None: want = lambda msg_type: True else: want = set(event_types).__contains__ if want('alert_words'): state['alert_words'] = user_alert_words(user_profile) if want('attachments'): state['attachments'] = user_attachments(user_profile) if want('message'): # The client should use get_old_messages() to fetch messages # starting with the max_message_id. They will get messages # newer than that ID via get_events() messages = Message.objects.filter(usermessage__user_profile=user_profile).order_by('-id')[:1] if messages: state['max_message_id'] = messages[0].id else: state['max_message_id'] = -1 if want('muted_topics'): state['muted_topics'] = ujson.loads(user_profile.muted_topics) if want('pointer'): state['pointer'] = user_profile.pointer if want('presence'): state['presences'] = get_status_dict(user_profile) if want('realm'): state['realm_name'] = user_profile.realm.name state['realm_restricted_to_domain'] = user_profile.realm.restricted_to_domain state['realm_invite_required'] = user_profile.realm.invite_required state['realm_invite_by_admins_only'] = user_profile.realm.invite_by_admins_only state['realm_authentication_methods'] = user_profile.realm.authentication_methods_dict() state['realm_create_stream_by_admins_only'] = user_profile.realm.create_stream_by_admins_only state['realm_add_emoji_by_admins_only'] = user_profile.realm.add_emoji_by_admins_only state['realm_allow_message_editing'] = user_profile.realm.allow_message_editing state['realm_message_content_edit_limit_seconds'] = user_profile.realm.message_content_edit_limit_seconds state['realm_default_language'] = user_profile.realm.default_language state['realm_waiting_period_threshold'] = user_profile.realm.waiting_period_threshold state['realm_icon_url'] = realm_icon_url(user_profile.realm) state['realm_icon_source'] = user_profile.realm.icon_source state['realm_name_changes_disabled'] = user_profile.realm.name_changes_disabled state['realm_email_changes_disabled'] = user_profile.realm.email_changes_disabled state['max_icon_file_size'] = settings.MAX_ICON_FILE_SIZE state['realm_bot_domain'] = user_profile.realm.get_bot_domain() if want('realm_domains'): state['realm_domains'] = get_realm_aliases(user_profile.realm) if want('realm_emoji'): state['realm_emoji'] = user_profile.realm.get_emoji() if want('realm_filters'): state['realm_filters'] = realm_filters_for_realm(user_profile.realm_id) if want('realm_user'): state['realm_users'] = get_realm_user_dicts(user_profile) if want('realm_bot'): state['realm_bots'] = get_owned_bot_dicts(user_profile) if want('referral'): state['referrals'] = {'granted': user_profile.invites_granted, 'used': user_profile.invites_used} if want('subscription'): subscriptions, unsubscribed, never_subscribed = gather_subscriptions_helper( user_profile, include_subscribers=include_subscribers) state['subscriptions'] = subscriptions state['unsubscribed'] = unsubscribed state['never_subscribed'] = never_subscribed if want('update_message_flags'): # There's no initial data for message flag updates, client will # get any updates during a session from get_events() pass if want('stream'): state['streams'] = do_get_streams(user_profile) if want('default_streams'): state['realm_default_streams'] = streams_to_dicts_sorted(get_default_streams_for_realm(user_profile.realm)) if want('update_display_settings'): state['twenty_four_hour_time'] = user_profile.twenty_four_hour_time state['left_side_userlist'] = user_profile.left_side_userlist state['emoji_alt_code'] = user_profile.emoji_alt_code default_language = user_profile.default_language state['default_language'] = default_language if want('update_global_notifications'): state['enable_stream_desktop_notifications'] = user_profile.enable_stream_desktop_notifications state['enable_stream_sounds'] = user_profile.enable_stream_sounds state['enable_desktop_notifications'] = user_profile.enable_desktop_notifications state['enable_sounds'] = user_profile.enable_sounds state['enable_offline_email_notifications'] = user_profile.enable_offline_email_notifications state['enable_offline_push_notifications'] = user_profile.enable_offline_push_notifications state['enable_online_push_notifications'] = user_profile.enable_online_push_notifications state['enable_digest_emails'] = user_profile.enable_digest_emails if want('zulip_version'): state['zulip_version'] = ZULIP_VERSION return state
def list_aliases(request, user_profile): # type: (HttpRequest, UserProfile) -> (HttpResponse) aliases = get_realm_aliases(user_profile.realm) return json_success({'domains': aliases})