From 0af96d238d27f3499e7c65e53ce7f2c5e10a629b Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Thu, 18 Jun 2020 18:05:09 -0500 Subject: [PATCH] Add permissionsToJson --- src/permission.nim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/permission.nim b/src/permission.nim index c0fca24..d00ab1d 100644 --- a/src/permission.nim +++ b/src/permission.nim @@ -80,4 +80,17 @@ proc addDenyPermission*(perms: Permissions, perm: Permission): Permissions = if ((perms.allowPerms and uint(perm)) == uint(perm)): perms.allowPerms = perms.allowPerms and (not uint(perm)) - perms.denyPerms = perms.denyPerms or uint(perm) \ No newline at end of file + perms.denyPerms = perms.denyPerms or uint(perm) + +proc permissionsToJson*(perms: Permissions): JsonNode = + ## Convert `Permissions` to json. + let json = %* { + "id": perms.roleUserID, + "allow": perms.allowPerms, + "deny": perms.denyPerms + } + + if (perms.permissionType == PermissionType.permTypeMember): + json.add("type", %"member") + else: + json.add("type", %"role") \ No newline at end of file