settings: Improve error message when deactivating the last user.

This PR was originally started by Rishi Gupta (see #10383).
This commit is contained in:
Rishi Gupta
2018-08-20 23:14:46 -07:00
committed by Tim Abbott
parent 7fb674cc58
commit dd0126ff1b
5 changed files with 41 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ class ErrorCode(AbstractEnum):
BAD_IMAGE = ()
REALM_UPLOAD_QUOTA = ()
BAD_NARROW = ()
CANNOT_DEACTIVATE_LAST_USER = ()
MISSING_HTTP_EVENT_HEADER = ()
STREAM_DOES_NOT_EXIST = ()
UNAUTHORIZED_PRINCIPAL = ()
@@ -139,6 +140,18 @@ class StreamDoesNotExistError(JsonableError):
def msg_format() -> str:
return _("Stream '{stream}' does not exist")
class CannotDeactivateLastUserError(JsonableError):
code = ErrorCode.CANNOT_DEACTIVATE_LAST_USER
data_fields = ['is_last_admin', 'entity']
def __init__(self, is_last_admin: bool) -> None:
self.is_last_admin = is_last_admin
self.entity = _("organization administrator") if is_last_admin else _("user")
@staticmethod
def msg_format() -> str:
return _("Cannot deactivate the only {entity}.")
class RateLimited(PermissionDenied):
def __init__(self, msg: str="") -> None:
super().__init__(msg)