mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
users: Move add_service to zerver.lib.users so it is reusable.
This commit is contained in:
@@ -20,7 +20,6 @@ from django.http import HttpRequest
|
||||
from two_factor.models import PhoneDevice
|
||||
from zerver.lib.initial_password import initial_password
|
||||
from zerver.lib.utils import is_remote_server
|
||||
from zerver.views.users import add_service
|
||||
|
||||
from zerver.lib.actions import (
|
||||
check_send_message, create_stream_if_needed, bulk_add_subscriptions,
|
||||
|
||||
@@ -41,6 +41,15 @@ def check_valid_bot_config(service_name: str, config_data: Dict[str, str]) -> No
|
||||
# error message.
|
||||
raise JsonableError(_("Invalid configuration data!"))
|
||||
|
||||
# Adds an outgoing webhook or embedded bot service.
|
||||
def add_service(name: str, user_profile: UserProfile, base_url: Optional[str]=None,
|
||||
interface: Optional[int]=None, token: Optional[str]=None) -> None:
|
||||
Service.objects.create(name=name,
|
||||
user_profile=user_profile,
|
||||
base_url=base_url,
|
||||
interface=interface,
|
||||
token=token)
|
||||
|
||||
def check_bot_creation_policy(user_profile: UserProfile, bot_type: int) -> None:
|
||||
# Realm administrators can always add bot
|
||||
if user_profile.is_realm_admin:
|
||||
|
||||
@@ -118,7 +118,6 @@ from zerver.lib.validator import (
|
||||
from zerver.lib.upload import upload_backend, attachment_url_to_path_id
|
||||
|
||||
from zerver.views.events_register import _default_all_public_streams, _default_narrow
|
||||
from zerver.views.users import add_service
|
||||
|
||||
from zerver.tornado.event_queue import (
|
||||
allocate_client_descriptor,
|
||||
|
||||
@@ -30,7 +30,7 @@ from zerver.lib.upload import upload_avatar_image
|
||||
from zerver.lib.validator import check_bool, check_string, check_int, check_url, check_dict
|
||||
from zerver.lib.users import check_valid_bot_type, check_bot_creation_policy, \
|
||||
check_full_name, check_short_name, check_valid_interface_type, check_valid_bot_config, \
|
||||
access_bot_by_id
|
||||
access_bot_by_id, add_service
|
||||
from zerver.lib.utils import generate_random_token
|
||||
from zerver.models import UserProfile, Stream, Message, email_allowed_for_realm, \
|
||||
get_user_profile_by_id, get_user, Service, get_user_including_cross_realm, \
|
||||
@@ -242,15 +242,6 @@ def regenerate_bot_api_key(request: HttpRequest, user_profile: UserProfile, bot_
|
||||
)
|
||||
return json_success(json_result)
|
||||
|
||||
# Adds an outgoing webhook or embedded bot service.
|
||||
def add_service(name: str, user_profile: UserProfile, base_url: str=None,
|
||||
interface: int=None, token: str=None) -> None:
|
||||
Service.objects.create(name=name,
|
||||
user_profile=user_profile,
|
||||
base_url=base_url,
|
||||
interface=interface,
|
||||
token=token)
|
||||
|
||||
@require_non_guest_human_user
|
||||
@has_request_variables
|
||||
def add_bot_backend(
|
||||
|
||||
Reference in New Issue
Block a user