status-lib/status/permissions.nim

46 lines
1.4 KiB
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
import json
import sets
import chronicles
import ./statusgo_backend/permissions as status_permissions
import ./types/permission
2021-09-08 18:05:39 +00:00
import ../eventemitter
logScope:
topics = "permissions-model"
type
PermissionsModel* = ref object
events*: EventEmitter
proc newPermissionsModel*(events: EventEmitter): PermissionsModel =
result = PermissionsModel()
result.events = events
proc init*(self: PermissionsModel) =
discard
proc getDapps*(self: PermissionsModel): seq[Dapp] =
return status_permissions.getDapps()
2021-09-08 18:05:39 +00:00
proc getPermissions*(self: PermissionsModel, dapp: string): HashSet[Permission] =
return status_permissions.getPermissions(dapp)
2021-09-08 18:05:39 +00:00
proc revoke*(self: PermissionsModel, permission: Permission) =
status_permissions.revoke(permission)
2021-09-08 18:05:39 +00:00
proc hasPermission*(self: PermissionsModel, dapp: string, permission: Permission): bool =
return self.getPermissions(dapp).contains(permission)
2021-09-08 18:05:39 +00:00
proc addPermission*(self: PermissionsModel, dapp: string, permission: Permission) =
status_permissions.addPermission(dapp, permission)
2021-09-08 18:05:39 +00:00
proc revokePermission*(self: PermissionsModel, dapp: string, permission: Permission) =
status_permissions.revokePermission(dapp, permission)
2021-09-08 18:05:39 +00:00
proc clearPermissions*(self: PermissionsModel, dapp: string) =
status_permissions.clearPermissions(dapp)
2021-09-08 18:05:39 +00:00
proc clearPermissions*(self: PermissionsModel) =
for dapps in status_permissions.getDapps():
status_permissions.clearPermissions(dapps.name)