Skip to content

Commit 4a9144d

Browse files
committed
Export token type as well and export external ids as json
1 parent c22ee61 commit 4a9144d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

project/access/management/commands/exporttokens.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import json
23
import sqlite3
34

45
from access.utils import all_tokens
@@ -16,14 +17,14 @@ def handle(self, *args, **options):
1617
self.connection = sqlite3.connect(options['filepath'], detect_types=sqlite3.PARSE_DECLTYPES)
1718
self.cursor = self.connection.cursor()
1819

19-
self.cursor.execute("CREATE TABLE valid_tokens (value TEXT UNIQUE, acl INTEGER, external_ids TEXT);")
20-
self.cursor.execute("CREATE TABLE revoked_tokens (value TEXT UNIQUE);")
20+
self.cursor.execute("CREATE TABLE valid_tokens (value TEXT UNIQUE, type INTEGER, acl INTEGER, external_ids TEXT);")
21+
self.cursor.execute("CREATE TABLE revoked_tokens (value TEXT UNIQUE, type INTEGER);")
2122
self.connection.commit()
2223
# TODO: add TokenType filtering
2324
for t in all_tokens():
2425
if t.revoked:
25-
self.cursor.execute("INSERT INTO revoked_tokens VALUES (?);", t.value)
26+
self.cursor.execute("INSERT INTO revoked_tokens VALUES (?,?);", (t.value, t.ttype.pk))
2627
else:
2728
acl = t.acl
28-
self.cursor.execute("INSERT INTO valid_tokens VALUES (?,?,?);", (t.value, acl['bits'], ','.join(acl['externals'])))
29+
self.cursor.execute("INSERT INTO valid_tokens VALUES (?,?,?,?);", (t.value, t.ttype.pk, acl['bits'], json.dumps(acl['externals'])))
2930
self.connection.commit()

0 commit comments

Comments
 (0)