models: Add new helper can_move_messages_between_streams.

This commit adds new helper can_move_messages_between_streams
which will be used to check whether a user is allowed to move
messages from one stream to another according to value of
'move_messages_between_streams_policy'.
This commit is contained in:
sahil839 2021-04-08 23:03:22 +05:30 committed by Tim Abbott
parent 2dc99aa90f
commit 4ac3fabadd
2 changed files with 11 additions and 0 deletions

View File

@ -1554,6 +1554,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
"create_stream_policy", "create_stream_policy",
"invite_to_stream_policy", "invite_to_stream_policy",
"invite_to_realm_policy", "invite_to_realm_policy",
"move_messages_between_streams_policy",
]: ]:
raise AssertionError("Invalid policy") raise AssertionError("Invalid policy")
@ -1588,6 +1589,9 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
def can_invite_others_to_realm(self) -> bool: def can_invite_others_to_realm(self) -> bool:
return self.has_permission("invite_to_realm_policy") return self.has_permission("invite_to_realm_policy")
def can_move_messages_between_streams(self) -> bool:
return self.has_permission("move_messages_between_streams_policy")
def can_access_public_streams(self) -> bool: def can_access_public_streams(self) -> bool:
return not (self.is_guest or self.realm.is_zephyr_mirror_realm) return not (self.is_guest or self.realm.is_zephyr_mirror_realm)

View File

@ -1539,6 +1539,13 @@ class EditMessageTest(ZulipTestCase):
to_invite_only=False, to_invite_only=False,
) )
def test_can_move_messages_between_streams(self) -> None:
def validation_func(user_profile: UserProfile) -> bool:
user_profile.refresh_from_db()
return user_profile.can_move_messages_between_streams()
self.check_has_permission_policies("move_messages_between_streams_policy", validation_func)
class DeleteMessageTest(ZulipTestCase): class DeleteMessageTest(ZulipTestCase):
def test_delete_message_invalid_request_format(self) -> None: def test_delete_message_invalid_request_format(self) -> None: