Skip to content

Commit e98f59c

Browse files
author
Anatoly Rugalev
authored
Updated permissions REST API (#64)
1 parent 2e53f05 commit e98f59c

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

stream_chat/async_chat/client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,15 @@ async def get_permission(self, name):
406406
407407
:param name: Name of the permission
408408
"""
409-
return await self.get(f"custom_permission/{name}")
409+
return await self.get(f"permissions/{name}")
410410

411411
async def create_permission(self, permission):
412412
"""
413413
Create a custom permission
414414
415415
:param permission: Definition of the permission
416416
"""
417-
return await self.post("custom_permission", data=permission)
417+
return await self.post("permissions", data=permission)
418418

419419
async def update_permission(self, name, permission):
420420
"""
@@ -423,43 +423,43 @@ async def update_permission(self, name, permission):
423423
:param name: Name of the permission
424424
:param permission: New definition of the permission
425425
"""
426-
return await self.post(f"custom_permission/{name}", data=permission)
426+
return await self.put(f"permissions/{name}", data=permission)
427427

428428
async def delete_permission(self, name):
429429
"""
430430
Delete a custom permission
431431
432432
:param name: Name of the permission
433433
"""
434-
return await self.delete(f"custom_permission/{name}")
434+
return await self.delete(f"permissions/{name}")
435435

436436
async def list_permissions(self):
437437
"""
438-
List custom permissions of the app
438+
List all permissions of the app
439439
"""
440-
return await self.get("custom_permission")
440+
return await self.get("permissions")
441441

442442
async def create_role(self, name):
443443
"""
444444
Create a custom role
445445
446446
:param name: Name of the role
447447
"""
448-
return await self.post("custom_role", data={"name": name})
448+
return await self.post("roles", data={"name": name})
449449

450450
async def delete_role(self, name):
451451
"""
452452
Delete a custom role
453453
454454
:param name: Name of the role
455455
"""
456-
return await self.delete(f"custom_role/{name}")
456+
return await self.delete(f"roles/{name}")
457457

458458
async def list_roles(self):
459459
"""
460-
List custom roles of the app
460+
List all roles of the app
461461
"""
462-
return await self.get("custom_role")
462+
return await self.get("roles")
463463

464464
async def create_segment(self, segment):
465465
"""

stream_chat/base/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def delete_permission(self, name):
402402
@abc.abstractmethod
403403
def list_permissions(self):
404404
"""
405-
List custom permissions of the app
405+
List all permissions of the app
406406
"""
407407
pass
408408

@@ -427,7 +427,7 @@ def delete_role(self, name):
427427
@abc.abstractmethod
428428
def list_roles(self):
429429
"""
430-
List custom roles of the app
430+
List all roles of the app
431431
"""
432432
pass
433433

stream_chat/tests/test_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def wait():
390390

391391
custom = {
392392
"name": name,
393-
"resource": "DeleteChannel",
393+
"action": "DeleteChannel",
394394
"owner": False,
395395
"same_team": True,
396396
}
@@ -401,7 +401,7 @@ def wait():
401401
assert response["permission"]["name"] == name
402402
assert response["permission"]["custom"]
403403
assert not response["permission"]["owner"]
404-
assert response["permission"]["resource"] == custom["resource"]
404+
assert response["permission"]["action"] == custom["action"]
405405

406406
custom["owner"] = True
407407
client.update_permission(name, custom)
@@ -411,15 +411,15 @@ def wait():
411411
assert response["permission"]["name"] == name
412412
assert response["permission"]["custom"]
413413
assert response["permission"]["owner"]
414-
assert response["permission"]["resource"] == custom["resource"]
414+
assert response["permission"]["action"] == custom["action"]
415415

416416
response = client.list_permissions()
417-
assert len(response["permissions"]) == 1
417+
original_len = len(response["permissions"])
418418
assert response["permissions"][0]["name"] == name
419419
client.delete_permission(name)
420420
wait()
421421
response = client.list_permissions()
422-
assert len(response["permissions"]) == 0
422+
assert len(response["permissions"]) == original_len - 1
423423

424424
client.create_role(role)
425425
wait()

0 commit comments

Comments
 (0)