mirror of https://github.com/zulip/zulip.git
ruff: Fix RSE102 Unnecessary parentheses on raised exception.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
3099487bc3
commit
da3cf5ea7a
|
@ -240,10 +240,10 @@ def validate_key(creation_key: Optional[str]) -> Optional["RealmCreationKey"]:
|
|||
try:
|
||||
key_record = RealmCreationKey.objects.get(creation_key=creation_key)
|
||||
except RealmCreationKey.DoesNotExist:
|
||||
raise RealmCreationKey.InvalidError()
|
||||
raise RealmCreationKey.InvalidError
|
||||
time_elapsed = timezone_now() - key_record.date_created
|
||||
if time_elapsed.total_seconds() > settings.REALM_CREATION_LINK_VALIDITY_DAYS * 24 * 3600:
|
||||
raise RealmCreationKey.InvalidError()
|
||||
raise RealmCreationKey.InvalidError
|
||||
return key_record
|
||||
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ def check_spare_licenses_available_for_adding_new_users(
|
|||
if plan.licenses() < get_seat_count(
|
||||
realm, extra_non_guests_count=extra_non_guests_count, extra_guests_count=extra_guests_count
|
||||
):
|
||||
raise LicenseLimitError()
|
||||
raise LicenseLimitError
|
||||
|
||||
|
||||
def check_spare_licenses_available_for_registering_new_user(
|
||||
|
|
|
@ -636,7 +636,7 @@ def ensure_realm_does_not_have_active_plan(realm: Realm) -> None:
|
|||
"Upgrade of %s failed because of existing active plan.",
|
||||
realm.string_id,
|
||||
)
|
||||
raise UpgradeWithExistingPlanError()
|
||||
raise UpgradeWithExistingPlanError
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
|
|
|
@ -82,7 +82,7 @@ def get_ses_arn(session: boto3.session.Session, args: argparse.Namespace) -> str
|
|||
return settings["ComplaintTopic"]
|
||||
elif args.deliveries:
|
||||
return settings["DeliveryTopic"]
|
||||
raise AssertionError() # Unreachable
|
||||
raise AssertionError # Unreachable
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
|
|
@ -71,7 +71,7 @@ def get_realm_from_request(request: HttpRequest) -> Optional[Realm]:
|
|||
def get_valid_realm_from_request(request: HttpRequest) -> Realm:
|
||||
realm = get_realm_from_request(request)
|
||||
if realm is None:
|
||||
raise InvalidSubdomainError()
|
||||
raise InvalidSubdomainError
|
||||
return realm
|
||||
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ def require_realm_owner(
|
|||
**kwargs: ParamT.kwargs,
|
||||
) -> HttpResponse:
|
||||
if not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
return func(request, user_profile, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
@ -157,7 +157,7 @@ def require_realm_admin(
|
|||
**kwargs: ParamT.kwargs,
|
||||
) -> HttpResponse:
|
||||
if not user_profile.is_realm_admin:
|
||||
raise OrganizationAdministratorRequiredError()
|
||||
raise OrganizationAdministratorRequiredError
|
||||
return func(request, user_profile, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
@ -175,7 +175,7 @@ def require_organization_member(
|
|||
**kwargs: ParamT.kwargs,
|
||||
) -> HttpResponse:
|
||||
if user_profile.role > UserProfile.ROLE_MEMBER:
|
||||
raise OrganizationMemberRequiredError()
|
||||
raise OrganizationMemberRequiredError
|
||||
return func(request, user_profile, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
@ -257,9 +257,9 @@ def validate_api_key(
|
|||
|
||||
def validate_account_and_subdomain(request: HttpRequest, user_profile: UserProfile) -> None:
|
||||
if user_profile.realm.deactivated:
|
||||
raise RealmDeactivatedError()
|
||||
raise RealmDeactivatedError
|
||||
if not user_profile.is_active:
|
||||
raise UserDeactivatedError()
|
||||
raise UserDeactivatedError
|
||||
|
||||
# Either the subdomain matches, or we're accessing Tornado from
|
||||
# and to localhost (aka spoofing a request as the user).
|
||||
|
@ -281,17 +281,17 @@ def access_user_by_api_key(
|
|||
request: HttpRequest, api_key: str, email: Optional[str] = None
|
||||
) -> UserProfile:
|
||||
if not has_api_key_format(api_key):
|
||||
raise InvalidAPIKeyFormatError()
|
||||
raise InvalidAPIKeyFormatError
|
||||
|
||||
try:
|
||||
user_profile = get_user_profile_by_api_key(api_key)
|
||||
except UserProfile.DoesNotExist:
|
||||
raise InvalidAPIKeyError()
|
||||
raise InvalidAPIKeyError
|
||||
if email is not None and email.lower() != user_profile.delivery_email.lower():
|
||||
# This covers the case that the API key is correct, but for a
|
||||
# different user. We may end up wanting to relaxing this
|
||||
# constraint or give a different error message in the future.
|
||||
raise InvalidAPIKeyError()
|
||||
raise InvalidAPIKeyError
|
||||
|
||||
validate_account_and_subdomain(request, user_profile)
|
||||
|
||||
|
@ -866,7 +866,7 @@ def authenticated_json_view(
|
|||
**kwargs: ParamT.kwargs,
|
||||
) -> HttpResponse:
|
||||
if not request.user.is_authenticated:
|
||||
raise UnauthorizedError()
|
||||
raise UnauthorizedError
|
||||
|
||||
user_profile = request.user
|
||||
if not skip_rate_limiting:
|
||||
|
@ -913,7 +913,7 @@ def internal_notify_view(
|
|||
request: HttpRequest, /, *args: ParamT.args, **kwargs: ParamT.kwargs
|
||||
) -> HttpResponse:
|
||||
if not authenticate_notify(request):
|
||||
raise AccessDeniedError()
|
||||
raise AccessDeniedError
|
||||
request_notes = RequestNotes.get_notes(request)
|
||||
is_tornado_request = request_notes.tornado_handler_id is not None
|
||||
# These next 2 are not security checks; they are internal
|
||||
|
|
|
@ -647,7 +647,7 @@ def apply_events(
|
|||
) -> None:
|
||||
for event in events:
|
||||
if event["type"] == "restart":
|
||||
raise RestartEventError()
|
||||
raise RestartEventError
|
||||
if fetch_event_types is not None and event["type"] not in fetch_event_types:
|
||||
# TODO: continuing here is not, most precisely, correct.
|
||||
# In theory, an event of one type, e.g. `realm_user`,
|
||||
|
|
|
@ -50,7 +50,7 @@ class InvalidPlatformError(Exception):
|
|||
@cache_with_key(lambda platform: f"download_link:{platform}", timeout=60 * 30)
|
||||
def get_latest_github_release_download_link_for_platform(platform: str) -> str:
|
||||
if platform not in PLATFORM_TO_SETUP_FILE:
|
||||
raise InvalidPlatformError()
|
||||
raise InvalidPlatformError
|
||||
|
||||
latest_version = get_latest_github_release_version_for_repo("zulip-desktop")
|
||||
if latest_version:
|
||||
|
|
|
@ -2639,7 +2639,7 @@ def do_convert(
|
|||
logging_message_id,
|
||||
)
|
||||
|
||||
raise MarkdownRenderingError()
|
||||
raise MarkdownRenderingError
|
||||
finally:
|
||||
# These next three lines are slightly paranoid, since
|
||||
# we always set these right before actually using the
|
||||
|
|
|
@ -210,7 +210,7 @@ class ZulipBaseHandler:
|
|||
"""Returns a formatted text.
|
||||
Subclasses should override this method.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def generic_handler(
|
||||
|
|
|
@ -766,21 +766,21 @@ def access_web_public_message(
|
|||
# message with the provided ID exists on the server if the client
|
||||
# shouldn't have access to it.
|
||||
if not realm.web_public_streams_enabled():
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
try:
|
||||
message = Message.objects.select_related().get(id=message_id)
|
||||
except Message.DoesNotExist:
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
if not message.is_stream_message():
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
queryset = get_web_public_streams_queryset(realm)
|
||||
try:
|
||||
stream = queryset.get(id=message.recipient.type_id)
|
||||
except Stream.DoesNotExist:
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
# These should all have been enforced by the code in
|
||||
# get_web_public_streams_queryset
|
||||
|
|
|
@ -480,7 +480,7 @@ class RedisRateLimiterBackend(RateLimiterBackend):
|
|||
break
|
||||
except redis.WatchError: # nocoverage # Ideally we'd have a test for this.
|
||||
if count > 10:
|
||||
raise RateLimiterLockingError()
|
||||
raise RateLimiterLockingError
|
||||
count += 1
|
||||
|
||||
continue
|
||||
|
|
|
@ -192,7 +192,7 @@ def rest_dispatch(request: HttpRequest, /, **kwargs: object) -> HttpResponse:
|
|||
else:
|
||||
# Otherwise, throw an authentication error; our middleware
|
||||
# will generate the appropriate HTTP response.
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
if request.method in ["DELETE", "PATCH", "PUT"]:
|
||||
# process_as_post needs to be the outer decorator, because
|
||||
|
|
|
@ -318,7 +318,7 @@ def check_stream_access_for_delete_or_update(
|
|||
if sub is None and stream.invite_only:
|
||||
raise JsonableError(error)
|
||||
|
||||
raise OrganizationAdministratorRequiredError()
|
||||
raise OrganizationAdministratorRequiredError
|
||||
|
||||
|
||||
def access_stream_for_delete_or_update(
|
||||
|
@ -739,7 +739,7 @@ def list_to_streams(
|
|||
|
||||
if message_retention_days_not_none:
|
||||
if not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
user_profile.realm.ensure_not_on_limited_plan()
|
||||
|
||||
|
|
|
@ -181,10 +181,10 @@ def resize_emoji(
|
|||
|
||||
class ZulipUploadBackend:
|
||||
def get_public_upload_root_url(self) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def generate_message_upload_path(self, realm_id: str, uploaded_file_name: str) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def upload_message_file(
|
||||
self,
|
||||
|
@ -195,7 +195,7 @@ class ZulipUploadBackend:
|
|||
user_profile: UserProfile,
|
||||
target_realm: Optional[Realm] = None,
|
||||
) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def upload_avatar_image(
|
||||
self,
|
||||
|
@ -204,44 +204,44 @@ class ZulipUploadBackend:
|
|||
target_user_profile: UserProfile,
|
||||
content_type: Optional[str] = None,
|
||||
) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def delete_avatar_image(self, user: UserProfile) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def delete_message_image(self, path_id: str) -> bool:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def get_avatar_url(self, hash_key: str, medium: bool = False) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def copy_avatar(self, source_profile: UserProfile, target_profile: UserProfile) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def ensure_avatar_image(self, user_profile: UserProfile, is_medium: bool = False) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def upload_realm_icon_image(self, icon_file: IO[bytes], user_profile: UserProfile) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def get_realm_icon_url(self, realm_id: int, version: int) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def upload_realm_logo_image(
|
||||
self, logo_file: IO[bytes], user_profile: UserProfile, night: bool
|
||||
) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def get_realm_logo_url(self, realm_id: int, version: int, night: bool) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def upload_emoji_image(
|
||||
self, emoji_file: IO[bytes], emoji_file_name: str, user_profile: UserProfile
|
||||
) -> bool:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def get_emoji_url(self, emoji_file_name: str, realm_id: int, still: bool = False) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def upload_export_tarball(
|
||||
self,
|
||||
|
@ -249,13 +249,13 @@ class ZulipUploadBackend:
|
|||
tarball_path: str,
|
||||
percent_callback: Optional[Callable[[Any], None]] = None,
|
||||
) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def delete_export_tarball(self, export_path: str) -> Optional[str]:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def get_export_tarball_url(self, realm: Realm, export_path: str) -> str:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def realm_avatar_and_logo_path(self, realm: Realm) -> str:
|
||||
return os.path.join(str(realm.id), "realm")
|
||||
|
|
|
@ -17,4 +17,4 @@ class BaseParser:
|
|||
self._soup = BeautifulSoup(html_source, "lxml", from_encoding=charset)
|
||||
|
||||
def extract_data(self) -> UrlEmbedData:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -145,12 +145,12 @@ def check_bot_creation_policy(user_profile: UserProfile, bot_type: int) -> None:
|
|||
if user_profile.realm.bot_creation_policy == Realm.BOT_CREATION_EVERYONE:
|
||||
return
|
||||
if user_profile.realm.bot_creation_policy == Realm.BOT_CREATION_ADMINS_ONLY:
|
||||
raise OrganizationAdministratorRequiredError()
|
||||
raise OrganizationAdministratorRequiredError
|
||||
if (
|
||||
user_profile.realm.bot_creation_policy == Realm.BOT_CREATION_LIMIT_GENERIC_BOTS
|
||||
and bot_type == UserProfile.DEFAULT_BOT
|
||||
):
|
||||
raise OrganizationAdministratorRequiredError()
|
||||
raise OrganizationAdministratorRequiredError
|
||||
|
||||
|
||||
def check_valid_bot_type(user_profile: UserProfile, bot_type: int) -> None:
|
||||
|
@ -255,7 +255,7 @@ def access_bot_by_id(user_profile: UserProfile, user_id: int) -> UserProfile:
|
|||
# default, because it can be abused to send spam. Requiring an
|
||||
# owner is intended to ensure organizational responsibility
|
||||
# for use of this permission.
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
return target
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class Uploader:
|
|||
self.new_path_template = "{realm_id}/emoji/images/{emoji_file_name}"
|
||||
|
||||
def copy_files(self, src_path: str, dst_path: str) -> None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def ensure_emoji_images(self, realm_id: int, old_filename: str, new_filename: str) -> None:
|
||||
# Copy original image file.
|
||||
|
|
|
@ -3733,7 +3733,7 @@ def maybe_get_user_profile_by_api_key(api_key: str) -> Optional[UserProfile]:
|
|||
def get_user_profile_by_api_key(api_key: str) -> UserProfile:
|
||||
user_profile = maybe_get_user_profile_by_api_key(api_key)
|
||||
if user_profile is None:
|
||||
raise UserProfile.DoesNotExist()
|
||||
raise UserProfile.DoesNotExist
|
||||
|
||||
return user_profile
|
||||
|
||||
|
@ -3790,7 +3790,7 @@ def get_active_user(email: str, realm: Realm) -> UserProfile:
|
|||
See get_user docstring for important usage notes."""
|
||||
user_profile = get_user(email, realm)
|
||||
if not user_profile.is_active:
|
||||
raise UserProfile.DoesNotExist()
|
||||
raise UserProfile.DoesNotExist
|
||||
return user_profile
|
||||
|
||||
|
||||
|
@ -3801,7 +3801,7 @@ def get_user_profile_by_id_in_realm(uid: int, realm: Realm) -> UserProfile:
|
|||
def get_active_user_profile_by_id_in_realm(uid: int, realm: Realm) -> UserProfile:
|
||||
user_profile = get_user_profile_by_id_in_realm(uid, realm)
|
||||
if not user_profile.is_active:
|
||||
raise UserProfile.DoesNotExist()
|
||||
raise UserProfile.DoesNotExist
|
||||
return user_profile
|
||||
|
||||
|
||||
|
@ -3839,7 +3839,7 @@ def get_user_by_id_in_realm_including_cross_realm(
|
|||
if is_cross_realm_bot_email(user_profile.delivery_email):
|
||||
return user_profile
|
||||
|
||||
raise UserProfile.DoesNotExist()
|
||||
raise UserProfile.DoesNotExist
|
||||
|
||||
|
||||
@cache_with_key(realm_user_dicts_cache_key, timeout=3600 * 24 * 7)
|
||||
|
|
|
@ -56,7 +56,7 @@ class VersionTest(ZulipTestCase):
|
|||
self.assertIsNone(version_lt(ver1, ver2), msg=msg)
|
||||
self.assertIsNone(version_lt(ver2, ver1), msg=msg)
|
||||
else:
|
||||
raise AssertionError() # nocoverage
|
||||
raise AssertionError # nocoverage
|
||||
|
||||
mobile_os_data = [
|
||||
case.split(None, 1)
|
||||
|
@ -115,7 +115,7 @@ class CompatibilityTest(ZulipTestCase):
|
|||
elif expected == "old":
|
||||
self.assert_json_error(result, "Client is too old")
|
||||
else:
|
||||
raise AssertionError() # nocoverage
|
||||
raise AssertionError # nocoverage
|
||||
|
||||
@mock.patch("zerver.lib.compatibility.DESKTOP_MINIMUM_VERSION", "5.0.0")
|
||||
@mock.patch("zerver.lib.compatibility.DESKTOP_WARNING_VERSION", "5.2.0")
|
||||
|
|
|
@ -170,7 +170,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
|
|||
kwargs["tos_version"] = None
|
||||
kwargs["timezone"] = timezone_now()
|
||||
create_user_profile(**kwargs).save()
|
||||
raise IntegrityError()
|
||||
raise IntegrityError
|
||||
|
||||
with mock.patch("zerver.actions.message_send.create_user", side_effect=create_user) as m:
|
||||
mirror_fred_user = create_mirror_user_if_needed(
|
||||
|
|
|
@ -45,7 +45,7 @@ def timeout_error(final_url: Any, **request_kwargs: Any) -> Any:
|
|||
|
||||
|
||||
def connection_error(final_url: Any, **request_kwargs: Any) -> Any:
|
||||
raise requests.exceptions.ConnectionError()
|
||||
raise requests.exceptions.ConnectionError
|
||||
|
||||
|
||||
class DoRestCallTests(ZulipTestCase):
|
||||
|
|
|
@ -92,7 +92,7 @@ class RateLimiterBackendBase(ZulipTestCase, ABC):
|
|||
"""
|
||||
This depends on the algorithm used in the backend, and should be defined by the test class.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError
|
||||
|
||||
def test_hit_ratelimits(self) -> None:
|
||||
obj = self.create_object("test", [(2, 3)])
|
||||
|
|
|
@ -479,7 +479,7 @@ def get_email_and_realm_from_jwt_authentication_request(
|
|||
) -> Tuple[str, Realm]:
|
||||
realm = get_realm_from_request(request)
|
||||
if realm is None:
|
||||
raise InvalidSubdomainError()
|
||||
raise InvalidSubdomainError
|
||||
|
||||
try:
|
||||
key = settings.JWT_AUTH_KEYS[realm.subdomain]["key"]
|
||||
|
@ -922,7 +922,7 @@ def get_api_key_fetch_authenticate_failure(return_data: Dict[str, bool]) -> Json
|
|||
if return_data.get("password_reset_needed"):
|
||||
return PasswordResetRequiredError()
|
||||
if return_data.get("invalid_subdomain"):
|
||||
raise InvalidSubdomainError()
|
||||
raise InvalidSubdomainError
|
||||
|
||||
return AuthenticationFailedError()
|
||||
|
||||
|
@ -976,7 +976,7 @@ def api_fetch_api_key(
|
|||
|
||||
realm = get_realm_from_request(request)
|
||||
if realm is None:
|
||||
raise InvalidSubdomainError()
|
||||
raise InvalidSubdomainError
|
||||
|
||||
if not ldap_auth_enabled(realm=realm):
|
||||
# In case we don't authenticate against LDAP, check for a valid
|
||||
|
|
|
@ -117,20 +117,20 @@ def api_dev_fetch_api_key(request: HttpRequest, username: str = REQ()) -> HttpRe
|
|||
validate_login_email(username)
|
||||
realm = get_realm_from_request(request)
|
||||
if realm is None:
|
||||
raise InvalidSubdomainError()
|
||||
raise InvalidSubdomainError
|
||||
return_data: Dict[str, bool] = {}
|
||||
user_profile = authenticate(dev_auth_username=username, realm=realm, return_data=return_data)
|
||||
if return_data.get("inactive_realm"):
|
||||
raise RealmDeactivatedError()
|
||||
raise RealmDeactivatedError
|
||||
if return_data.get("inactive_user"):
|
||||
raise UserDeactivatedError()
|
||||
raise UserDeactivatedError
|
||||
if return_data.get("invalid_subdomain"):
|
||||
raise InvalidSubdomainError()
|
||||
raise InvalidSubdomainError
|
||||
if user_profile is None:
|
||||
# Since we're not actually checking passwords, this condition
|
||||
# is when one's attempting to send an email address that
|
||||
# doesn't have an account, i.e. it's definitely invalid username.
|
||||
raise AuthenticationFailedError()
|
||||
raise AuthenticationFailedError
|
||||
assert isinstance(user_profile, UserProfile)
|
||||
|
||||
do_login(request, user_profile)
|
||||
|
|
|
@ -98,7 +98,7 @@ def events_register_backend(
|
|||
user_profile = None
|
||||
realm = get_valid_realm_from_request(request)
|
||||
if not realm.allow_web_public_streams_access():
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
# These parameters must be false for anonymous requests.
|
||||
if client_gravatar:
|
||||
|
|
|
@ -34,7 +34,7 @@ def check_if_owner_required(invited_as: int, user_profile: UserProfile) -> None:
|
|||
invited_as == PreregistrationUser.INVITE_AS["REALM_OWNER"]
|
||||
and not user_profile.is_realm_owner
|
||||
):
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
|
||||
@require_member_or_admin
|
||||
|
|
|
@ -117,12 +117,12 @@ def get_messages_backend(
|
|||
# that we are not leaking any secure data (private messages and
|
||||
# non-web-public stream messages) via this path.
|
||||
if not realm.allow_web_public_streams_access():
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
if not is_web_public_narrow(narrow):
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
assert narrow is not None
|
||||
if not is_spectator_compatible(narrow):
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
# We use None to indicate unauthenticated requests as it's more
|
||||
# readable than using AnonymousUser, and the lack of Django
|
||||
|
|
|
@ -155,7 +155,7 @@ def update_realm(
|
|||
raise JsonableError(_("Invalid language '{}'").format(default_language))
|
||||
if authentication_methods is not None:
|
||||
if not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
if True not in list(authentication_methods.values()):
|
||||
raise JsonableError(_("At least one authentication method must be enabled."))
|
||||
if video_chat_provider is not None and video_chat_provider not in {
|
||||
|
@ -170,7 +170,7 @@ def update_realm(
|
|||
message_retention_days: Optional[int] = None
|
||||
if message_retention_days_raw is not None:
|
||||
if not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
realm.ensure_not_on_limited_plan()
|
||||
message_retention_days = parse_message_retention_days(
|
||||
message_retention_days_raw, Realm.MESSAGE_RETENTION_SPECIAL_VALUES_MAP
|
||||
|
@ -180,15 +180,15 @@ def update_realm(
|
|||
if (
|
||||
invite_to_realm_policy is not None or invite_required is not None
|
||||
) and not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
if (
|
||||
emails_restricted_to_domains is not None or disallow_disposable_email_addresses is not None
|
||||
) and not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
if waiting_period_threshold is not None and not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
if enable_spectator_access:
|
||||
realm.ensure_not_on_limited_plan()
|
||||
|
@ -307,7 +307,7 @@ def update_realm(
|
|||
|
||||
if string_id is not None:
|
||||
if not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
|
||||
if realm.demo_organization_scheduled_deletion_date is None:
|
||||
raise JsonableError(_("Must be a demo organization."))
|
||||
|
|
|
@ -346,7 +346,7 @@ def update_stream_backend(
|
|||
|
||||
if message_retention_days is not None:
|
||||
if not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
user_profile.realm.ensure_not_on_limited_plan()
|
||||
new_message_retention_days_value = parse_message_retention_days(
|
||||
message_retention_days, Stream.MESSAGE_RETENTION_SPECIAL_VALUES_MAP
|
||||
|
|
|
@ -79,7 +79,7 @@ def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpRes
|
|||
|
||||
if not user_profile.is_active:
|
||||
# TODO: Make this into a user-facing error, not JSON
|
||||
raise UserDeactivatedError()
|
||||
raise UserDeactivatedError
|
||||
|
||||
if user_profile.realm.email_changes_disabled and not user_profile.is_realm_admin:
|
||||
raise JsonableError(_("Email address changes are disabled in this organization."))
|
||||
|
|
|
@ -117,7 +117,7 @@ def deactivate_user_backend(
|
|||
) -> HttpResponse:
|
||||
target = access_user_by_id(user_profile, user_id, for_admin=True)
|
||||
if target.is_realm_owner and not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
if check_last_owner(target):
|
||||
raise JsonableError(_("Cannot deactivate the only organization owner"))
|
||||
if deactivation_notification_comment is not None:
|
||||
|
@ -231,9 +231,9 @@ def update_user_backend(
|
|||
#
|
||||
# Logic replicated in patch_bot_backend.
|
||||
if UserProfile.ROLE_REALM_OWNER in [role, target.role] and not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
elif not user_profile.is_realm_admin:
|
||||
raise OrganizationAdministratorRequiredError()
|
||||
raise OrganizationAdministratorRequiredError
|
||||
|
||||
if target.role == UserProfile.ROLE_REALM_OWNER and check_last_owner(target):
|
||||
raise JsonableError(
|
||||
|
@ -285,14 +285,14 @@ def avatar(
|
|||
# enabled in the organization.
|
||||
realm = get_valid_realm_from_request(request)
|
||||
if not realm.allow_web_public_streams_access():
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
# We only allow the ID format for accessing a user's avatar
|
||||
# for spectators. This is mainly for defense in depth, since
|
||||
# email_address_visibility should mean spectators only
|
||||
# interact with fake email addresses anyway.
|
||||
if is_email:
|
||||
raise MissingAuthenticationError()
|
||||
raise MissingAuthenticationError
|
||||
|
||||
if settings.RATE_LIMITING:
|
||||
unique_avatar_key = f"{realm.id}/{email_or_id}/{medium}"
|
||||
|
@ -367,9 +367,9 @@ def patch_bot_backend(
|
|||
if role is not None and bot.role != role:
|
||||
# Logic duplicated from update_user_backend.
|
||||
if UserProfile.ROLE_REALM_OWNER in [role, bot.role] and not user_profile.is_realm_owner:
|
||||
raise OrganizationOwnerRequiredError()
|
||||
raise OrganizationOwnerRequiredError
|
||||
elif not user_profile.is_realm_admin:
|
||||
raise OrganizationAdministratorRequiredError()
|
||||
raise OrganizationAdministratorRequiredError
|
||||
|
||||
do_change_user_role(bot, role, acting_user=user_profile)
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ def api_jira_webhook(
|
|||
return json_success(request)
|
||||
|
||||
if event is None:
|
||||
raise AnomalousWebhookPayloadError()
|
||||
raise AnomalousWebhookPayloadError
|
||||
|
||||
if event is not None:
|
||||
content_func = JIRA_CONTENT_FUNCTION_MAPPER.get(event)
|
||||
|
|
|
@ -98,7 +98,7 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]:
|
|||
blacklist
|
||||
)
|
||||
if not previous_attributes: # nocoverage
|
||||
raise SuppressedEventError()
|
||||
raise SuppressedEventError
|
||||
return "".join(
|
||||
"\n* "
|
||||
+ attribute.replace("_", " ").capitalize()
|
||||
|
@ -119,18 +119,18 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]:
|
|||
if resource == "account":
|
||||
if event == "updated":
|
||||
if "previous_attributes" not in payload["data"]:
|
||||
raise SuppressedEventError()
|
||||
raise SuppressedEventError
|
||||
topic = "account updates"
|
||||
body = update_string()
|
||||
else:
|
||||
# Part of Stripe Connect
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category == "application_fee": # nocoverage
|
||||
# Part of Stripe Connect
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category == "balance": # nocoverage
|
||||
# Not that interesting to most businesses, I think
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category == "charge":
|
||||
if resource == "charge":
|
||||
if not topic: # only in legacy fixtures
|
||||
|
@ -160,10 +160,10 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]:
|
|||
)
|
||||
if category == "checkout_beta": # nocoverage
|
||||
# Not sure what this is
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category == "coupon": # nocoverage
|
||||
# Not something that likely happens programmatically
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category == "customer":
|
||||
if resource == "customer":
|
||||
# Running into the 60 character topic limit.
|
||||
|
@ -260,10 +260,10 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]:
|
|||
)
|
||||
if category.startswith("issuing"): # nocoverage
|
||||
# Not implemented
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category.startswith("order"): # nocoverage
|
||||
# Not implemented
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
if category in [
|
||||
"payment_intent",
|
||||
"payout",
|
||||
|
@ -282,7 +282,7 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]:
|
|||
# Not implemented. In theory doing something like
|
||||
# body = default_body()
|
||||
# may not be hard for some of these
|
||||
raise NotImplementedEventTypeError()
|
||||
raise NotImplementedEventTypeError
|
||||
|
||||
if body is None:
|
||||
raise UnsupportedWebhookEventTypeError(event_type)
|
||||
|
|
|
@ -78,7 +78,7 @@ def validate_remote_server(
|
|||
raise InvalidZulipServerKeyError(role)
|
||||
|
||||
if remote_server.deactivated:
|
||||
raise RemoteServerDeactivatedError()
|
||||
raise RemoteServerDeactivatedError
|
||||
|
||||
if get_subdomain(request) != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN:
|
||||
raise JsonableError(_("Invalid subdomain for push notifications bouncer"))
|
||||
|
|
|
@ -14,7 +14,7 @@ def get_remote_server_by_uuid(uuid: str) -> "RemoteZulipServer":
|
|||
try:
|
||||
return RemoteZulipServer.objects.get(uuid=uuid)
|
||||
except ValidationError:
|
||||
raise RemoteZulipServer.DoesNotExist()
|
||||
raise RemoteZulipServer.DoesNotExist
|
||||
|
||||
|
||||
class RemoteZulipServer(models.Model):
|
||||
|
|
Loading…
Reference in New Issue