Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4801,8 +4801,9 @@ async def restrict_chat_member(
"""
Use this method to restrict a user in a supergroup. The bot must be an administrator in
the supergroup for this to work and must have the appropriate admin rights. Pass
:obj:`True` for all boolean parameters in :class:`telegram.ChatPermissions` to lift
restrictions from a user.
:obj:`True` for all boolean parameters to lift restrictions from a user.

.. seealso:: :meth:`telegram.ChatPermissions.all_permissions`

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
Expand Down
22 changes: 22 additions & 0 deletions telegram/_chatpermissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,25 @@ def __init__(
self.can_invite_users,
self.can_pin_messages,
)

@classmethod
def all_permissions(cls) -> 'ChatPermissions':
"""
This method returns an :class:`ChatPermissions` instance with all attributes
set to :obj:`True`. This is e.g. useful when unrestricting a chat member with
:meth:`telegram.Bot.restrict_chat_member`.

.. versionadded:: 20.0

"""
return cls(True, True, True, True, True, True, True, True)

@classmethod
def no_permissions(cls) -> 'ChatPermissions':
"""
This method returns an :class:`ChatPermissions` instance
with all attributes set to :obj:`False`.

.. versionadded:: 20.0
"""
return cls(False, False, False, False, False, False, False, False)
24 changes: 24 additions & 0 deletions tests/test_chatpermissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,27 @@ def test_equality(self):

assert a != d
assert hash(a) != hash(d)

def test_all_permissions(self):
f = ChatPermissions()
t = ChatPermissions.all_permissions()
# if the dirs are the same, the attributes will all be there
assert dir(f) == dir(t)
# now we just need to check that all attributes are True. _id_attrs returns all values,
# if a new one is added without defaulting to True, this will fail
for key in t.__slots__:
assert t[key] is True
# and as a finisher, make sure the default is different.
assert f != t

def test_no_permissions(self):
f = ChatPermissions()
t = ChatPermissions.no_permissions()
# if the dirs are the same, the attributes will all be there
assert dir(f) == dir(t)
# now we just need to check that all attributes are True. _id_attrs returns all values,
# if a new one is added without defaulting to True, this will fail
for key in t.__slots__:
assert t[key] is False
# and as a finisher, make sure the default is different.
assert f != t