Skip to content

Commit

Permalink
Fix error when showing authorized user applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
ferbncode authored and gentlecat committed Jun 26, 2017
1 parent 0d68de9 commit 1512d18
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
22 changes: 14 additions & 8 deletions critiquebrainz/db/oauth_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ def list_tokens(*, client_id=None, refresh_token=None, access_token=None, limit=
"expires": (datetime),
"user_id": (uuid),
"scopes": (str),
"client_name": (str),
"client_website": (str),
}
"""
filters = []
filter_data = {}

if client_id is not None:
filters.append("client_id = :client_id")
filters.append("oauth_token.client_id = :client_id")
filter_data["client_id"] = client_id
if refresh_token is not None:
filters.append("refresh_token = :refresh_token")
Expand All @@ -88,14 +90,18 @@ def list_tokens(*, client_id=None, refresh_token=None, access_token=None, limit=

with db.engine.connect() as connection:
results = connection.execute(sqlalchemy.text("""
SELECT id,
client_id,
access_token,
refresh_token,
expires,
user_id,
scopes
SELECT oauth_token.id,
oauth_token.client_id,
oauth_token.access_token,
oauth_token.refresh_token,
oauth_token.expires,
oauth_token.user_id,
oauth_token.scopes,
oauth_client.name AS client_name,
oauth_client.website AS client_website
FROM oauth_token
JOIN oauth_client
ON oauth_token.client_id = oauth_client.client_id
{where_clause}
LIMIT :limit
OFFSET :offset
Expand Down
18 changes: 12 additions & 6 deletions critiquebrainz/db/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,23 @@ def tokens(user_id):
"refresh_token": (str),
"expires": (datetime),
"scopes": (str)
"client_name": (str),
"client_website": (str),
}
"""
with db.engine.connect() as connection:
result = connection.execute(sqlalchemy.text("""
SELECT id,
client_id,
access_token,
refresh_token,
expires,
scopes
SELECT oauth_token.id,
oauth_token.client_id,
oauth_token.access_token,
oauth_token.refresh_token,
oauth_token.expires,
oauth_token.scopes,
oauth_client.name AS client_name,
oauth_client.website AS client_website
FROM oauth_token
JOIN oauth_client
ON oauth_token.client_id = oauth_client.client_id
WHERE user_id = :user_id
"""), {
"user_id": user_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ <h3>{{ _('Authorized applications') }}</h3>
<tbody>
{% for token in tokens %}
<tr>
<td><b>{{ token.client.name }}</b></td>
<td>{{ token.client.website }}</td>
<td><b>{{ token.client_name }}</b></td>
<td>{{ token.client_website }}</td>
<td>
{% if token.scopes %}
<ul>
Expand All @@ -76,7 +76,7 @@ <h3>{{ _('Authorized applications') }}</h3>
{% endif %}
</td>
<td>
<a class="btn btn-danger btn-xs" href="{{ url_for('profile_applications.token_delete', client_id=token.client.client_id) }}">{{ _('Revoke access') }}</a>
<a class="btn btn-danger btn-xs" href="{{ url_for('profile_applications.token_delete', client_id=token.client_id) }}">{{ _('Revoke access') }}</a>
</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit 1512d18

Please sign in to comment.