![](/img/trans.png)
[英]How to broadcast an event to an specific user with Pyramid and socketio
[英]How to give permission specific user python pyramid?
在python金字塔框架中,我可以在對象級別給予權限但是我如何在對象級別給予權限。我有組管理員和主持人但在主持人組中,一個用戶將給予額外的刪除權限,在管理員組中,一個用戶將獲得比管理員更少的角色。
Websauna框架有一個例子來做到這一點:
https://websauna.org/docs/narrative/crud/standalone.html#creating-crud-resources
復制粘貼答案以滿足Stackoverflow overzealous版主的深層願望:
class ContractResource(Resource):
"""Map one TokenContract SQLAlchemy model instance to editable CRUD resource."""
# __acl__ can be callable or property.
# @reify caches the results after the first call
@reify
def __acl__(self) -> List[tuple]:
# Give the user principal delete access as the owner
# The returned list overrides __acl__ from the parent level
# (ContractCRUD in our case)
# See websauna.system.auth.principals for details
contract = self.get_object() # type: TokenContract
if contract.owner:
owner_principal = "user:{}".format(contract.owner.id)
return [(Allow, owner_principal, "delete")]
else:
return []
def get_title(self):
token_contract = self.get_object()
return "Smart contract {}".format(bin_to_eth_address(token_contract.contract_address))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.