Skip to content

Commit 7c686f2

Browse files
author
Yuan Huang
committed
feat: support global token in projects list query
1 parent e5ef97d commit 7c686f2

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

src/api/handlers/projects/projects.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ def get(self):
4949
'''
5050
Returns user's projects
5151
'''
52-
projects = g.db.execute_many_dict("""
53-
SELECT p.id, p.name, p.type, p.public, co.role AS userrole
54-
FROM project p
55-
INNER JOIN collaborator co
56-
ON co.project_id = p.id
57-
AND %s = co.user_id
58-
ORDER BY p.name
59-
""", [g.token['user']['id']])
52+
# Global tokens can see all projects
53+
if g.token and g.token.get('type') == 'global':
54+
projects = g.db.execute_many_dict("""
55+
SELECT p.id, p.name, p.type, p.public
56+
FROM project p
57+
ORDER BY p.name
58+
""")
59+
else:
60+
projects = g.db.execute_many_dict("""
61+
SELECT p.id, p.name, p.type, p.public, co.role AS userrole
62+
FROM project p
63+
INNER JOIN collaborator co
64+
ON co.project_id = p.id
65+
AND %s = co.user_id
66+
ORDER BY p.name
67+
""", [g.token['user']['id']])
6068

6169
return projects
6270

0 commit comments

Comments
 (0)