2021-09-08 18:05:39 +00:00
|
|
|
import json
|
|
|
|
import sets
|
|
|
|
import chronicles
|
2021-10-01 16:53:38 +00:00
|
|
|
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] =
|
2021-10-01 16:53:38 +00:00
|
|
|
return status_permissions.getDapps()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getPermissions*(self: PermissionsModel, dapp: string): HashSet[Permission] =
|
2021-10-01 16:53:38 +00:00
|
|
|
return status_permissions.getPermissions(dapp)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc revoke*(self: PermissionsModel, permission: Permission) =
|
2021-10-01 16:53:38 +00:00
|
|
|
status_permissions.revoke(permission)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc hasPermission*(self: PermissionsModel, dapp: string, permission: Permission): bool =
|
2021-10-01 16:53:38 +00:00
|
|
|
return self.getPermissions(dapp).contains(permission)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc addPermission*(self: PermissionsModel, dapp: string, permission: Permission) =
|
2021-10-01 16:53:38 +00:00
|
|
|
status_permissions.addPermission(dapp, permission)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc revokePermission*(self: PermissionsModel, dapp: string, permission: Permission) =
|
2021-10-01 16:53:38 +00:00
|
|
|
status_permissions.revokePermission(dapp, permission)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc clearPermissions*(self: PermissionsModel, dapp: string) =
|
2021-10-01 16:53:38 +00:00
|
|
|
status_permissions.clearPermissions(dapp)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc clearPermissions*(self: PermissionsModel) =
|
2021-10-01 16:53:38 +00:00
|
|
|
for dapps in status_permissions.getDapps():
|
|
|
|
status_permissions.clearPermissions(dapps.name)
|