Skip to content

Commit a41d353

Browse files
author
Anatoly Rugalev
authored
Permissions API follow-up changes (#67)
1 parent e98f59c commit a41d353

File tree

4 files changed

+51
-49
lines changed

4 files changed

+51
-49
lines changed

stream_chat/async_chat/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ async def check_sqs(self, sqs_key=None, sqs_secret=None, sqs_url=None):
400400
data = {"sqs_key": sqs_key, "sqs_secret": sqs_secret, "sqs_url": sqs_url}
401401
return await self.post("check_sqs", data=data)
402402

403-
async def get_permission(self, name):
403+
async def get_permission(self, id):
404404
"""
405405
Get the definition for a permission
406406
407-
:param name: Name of the permission
407+
:param id: ID of the permission
408408
"""
409-
return await self.get(f"permissions/{name}")
409+
return await self.get(f"permissions/{id}")
410410

411411
async def create_permission(self, permission):
412412
"""
@@ -416,22 +416,22 @@ async def create_permission(self, permission):
416416
"""
417417
return await self.post("permissions", data=permission)
418418

419-
async def update_permission(self, name, permission):
419+
async def update_permission(self, id, permission):
420420
"""
421421
Update a custom permission
422422
423-
:param name: Name of the permission
423+
:param id: ID of the permission
424424
:param permission: New definition of the permission
425425
"""
426-
return await self.put(f"permissions/{name}", data=permission)
426+
return await self.put(f"permissions/{id}", data=permission)
427427

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

436436
async def list_permissions(self):
437437
"""

stream_chat/client.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,66 +388,66 @@ def check_sqs(self, sqs_key=None, sqs_secret=None, sqs_url=None):
388388
data = {"sqs_key": sqs_key, "sqs_secret": sqs_secret, "sqs_url": sqs_url}
389389
return self.post("check_sqs", data=data)
390390

391-
def get_permission(self, name):
391+
def get_permission(self, id):
392392
"""
393393
Get the definition for a permission
394394
395-
:param name: Name of the permission
395+
:param id: ID of the permission
396396
"""
397-
return self.get(f"custom_permission/{name}")
397+
return self.get(f"permissions/{id}")
398398

399399
def create_permission(self, permission):
400400
"""
401401
Create a custom permission
402402
403403
:param permission: Definition of the permission
404404
"""
405-
return self.post("custom_permission", data=permission)
405+
return self.post("permissions", data=permission)
406406

407-
def update_permission(self, name, permission):
407+
def update_permission(self, id, permission):
408408
"""
409409
Update a custom permission
410410
411-
:param name: Name of the permission
411+
:param id: ID of the permission
412412
:param permission: New definition of the permission
413413
"""
414-
return self.post(f"custom_permission/{name}", data=permission)
414+
return self.put(f"permissions/{id}", data=permission)
415415

416-
def delete_permission(self, name):
416+
def delete_permission(self, id):
417417
"""
418418
Delete a custom permission
419419
420-
:param name: Name of the permission
420+
:param id: ID of the permission
421421
"""
422-
return self.delete(f"custom_permission/{name}")
422+
return self.delete(f"permissions/{id}")
423423

424424
def list_permissions(self):
425425
"""
426426
List custom permissions of the app
427427
"""
428-
return self.get("custom_permission")
428+
return self.get("permissions")
429429

430430
def create_role(self, name):
431431
"""
432432
Create a custom role
433433
434434
:param name: Name of the role
435435
"""
436-
return self.post("custom_role", data={"name": name})
436+
return self.post("roles", data={"name": name})
437437

438438
def delete_role(self, name):
439439
"""
440440
Delete a custom role
441441
442442
:param name: Name of the role
443443
"""
444-
return self.delete(f"custom_role/{name}")
444+
return self.delete(f"roles/{name}")
445445

446446
def list_roles(self):
447447
"""
448-
List custom roles of the app
448+
List all roles of the app
449449
"""
450-
return self.get("custom_role")
450+
return self.get("roles")
451451

452452
def create_segment(self, segment):
453453
"""

stream_chat/tests/async_chat/test_client.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -450,50 +450,51 @@ async def test_check_sqs(self, client):
450450
@pytest.mark.asyncio
451451
@pytest.mark.skip(reason="slow and flaky due to waits")
452452
async def test_custom_permission_and_roles(self, client):
453-
name, role = "Something restricted", "god"
453+
id, role = "my-custom-permission", "god"
454454

455455
def wait():
456456
time.sleep(3)
457457

458458
with suppress(Exception):
459-
await client.delete_permission(name)
459+
await client.delete_permission(id)
460460
wait()
461461
with suppress(Exception):
462462
await client.delete_role(role)
463463
wait()
464464

465465
custom = {
466-
"name": name,
467-
"resource": "DeleteChannel",
466+
"id": id,
467+
"name": "My Custom Permission",
468+
"action": "DeleteChannel",
468469
"owner": False,
469470
"same_team": True,
470471
}
471472

472473
await client.create_permission(custom)
473474
wait()
474-
response = await client.get_permission(name)
475-
assert response["permission"]["name"] == name
475+
response = await client.get_permission(id)
476+
assert response["permission"]["id"] == id
476477
assert response["permission"]["custom"]
477478
assert not response["permission"]["owner"]
478-
assert response["permission"]["resource"] == custom["resource"]
479+
assert response["permission"]["action"] == custom["action"]
479480

480481
custom["owner"] = True
481-
await client.update_permission(name, custom)
482+
await client.update_permission(id, custom)
482483

483484
wait()
484-
response = await client.get_permission(name)
485-
assert response["permission"]["name"] == name
485+
response = await client.get_permission(id)
486+
assert response["permission"]["id"] == id
486487
assert response["permission"]["custom"]
487488
assert response["permission"]["owner"]
488-
assert response["permission"]["resource"] == custom["resource"]
489+
assert response["permission"]["action"] == custom["action"]
489490

490491
response = await client.list_permissions()
491-
assert len(response["permissions"]) == 1
492-
assert response["permissions"][0]["name"] == name
493-
await client.delete_permission(name)
492+
original_len = len(response["permissions"])
493+
assert response["permissions"][0]["id"] == id
494+
await client.delete_permission(id)
494495
wait()
495496
response = await client.list_permissions()
496-
assert len(response["permissions"]) == 0
497+
assert len(response["permissions"]) == original_len - 1
497498

498499
await client.create_role(role)
499500
wait()

stream_chat/tests/test_client.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,47 +376,48 @@ def test_check_sqs(self, client):
376376

377377
@pytest.mark.skip(reason="slow and flaky due to waits")
378378
def test_custom_permission_and_roles(self, client):
379-
name, role = "Something restricted", "god"
379+
id, role = "my-custom-permission", "god"
380380

381381
def wait():
382382
time.sleep(3)
383383

384384
with suppress(Exception):
385-
client.delete_permission(name)
385+
client.delete_permission(id)
386386
wait()
387387
with suppress(Exception):
388388
client.delete_role(role)
389389
wait()
390390

391391
custom = {
392-
"name": name,
392+
"id": id,
393+
"name": "My Custom Permission",
393394
"action": "DeleteChannel",
394395
"owner": False,
395396
"same_team": True,
396397
}
397398

398399
client.create_permission(custom)
399400
wait()
400-
response = client.get_permission(name)
401-
assert response["permission"]["name"] == name
401+
response = client.get_permission(id)
402+
assert response["permission"]["id"] == id
402403
assert response["permission"]["custom"]
403404
assert not response["permission"]["owner"]
404405
assert response["permission"]["action"] == custom["action"]
405406

406407
custom["owner"] = True
407-
client.update_permission(name, custom)
408+
client.update_permission(id, custom)
408409

409410
wait()
410-
response = client.get_permission(name)
411-
assert response["permission"]["name"] == name
411+
response = client.get_permission(id)
412+
assert response["permission"]["id"] == id
412413
assert response["permission"]["custom"]
413414
assert response["permission"]["owner"]
414415
assert response["permission"]["action"] == custom["action"]
415416

416417
response = client.list_permissions()
417418
original_len = len(response["permissions"])
418-
assert response["permissions"][0]["name"] == name
419-
client.delete_permission(name)
419+
assert response["permissions"][0]["id"] == id
420+
client.delete_permission(id)
420421
wait()
421422
response = client.list_permissions()
422423
assert len(response["permissions"]) == original_len - 1

0 commit comments

Comments
 (0)