realm owner: Add ability to change realm owner status of user.

This commit adds some basic checks while adding or removing
realm owner status of a user and adds code to change owner
status of a user using update_user_backend.

This also adds restriction on removing owner status of the
last owner of realm. This restriction was previously on
revoking admin status, but as we have added a more privileged
role of realm owner, we now have this restriction on owner
instead of admin.

We need to apply that restriction both in the role change code path
and the deactivate code path.
This commit is contained in:
sahil839
2020-05-17 00:36:43 +05:30
committed by Tim Abbott
parent 2c8c641556
commit 6d667dbe53
5 changed files with 195 additions and 48 deletions

View File

@@ -158,11 +158,11 @@ class StreamWithIDDoesNotExistError(JsonableError):
class CannotDeactivateLastUserError(JsonableError):
code = ErrorCode.CANNOT_DEACTIVATE_LAST_USER
data_fields = ['is_last_admin', 'entity']
data_fields = ['is_last_owner', '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")
def __init__(self, is_last_owner: bool) -> None:
self.is_last_owner = is_last_owner
self.entity = _("organization owner") if is_last_owner else _("user")
@staticmethod
def msg_format() -> str: