From 15179c80c40990aa8dc8d9531ac9d77bed9a24a7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 27 2020 10:40:53 +0000 Subject: [PATCH 1/5] Move the html to show info about API token to a macro This way it can be shared between the project's settings page and the user's settings page Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/_api_token.html b/pagure/templates/_api_token.html new file mode 100644 index 0000000..69daaa3 --- /dev/null +++ b/pagure/templates/_api_token.html @@ -0,0 +1,93 @@ +{% macro render_api_token(token, repo, username, form) -%} +
+
+
+ + + {{ token.description or '' }} + +
+
+ + + {{token.acls_list_pretty|length}} ACLs + + + +
+ + + {% if token.expired %} + + + Expired on {{ token.expiration.date() }} + + + {% else %} + + + Active until {{ token.expiration.date() }} + + + {% endif %} + {% if not token.expired %} + {% if repo %} +
+ {% else %} + + {% endif %} + + {{ form.csrf_token }} +
+ {% endif %} + {% if repo %} +
+ {% endif %} + + {{ form.csrf_token }} +
+
+
+{%- endmacro %} + diff --git a/pagure/templates/settings_api_keys.html b/pagure/templates/settings_api_keys.html index b9e73d5..6c68b77 100644 --- a/pagure/templates/settings_api_keys.html +++ b/pagure/templates/settings_api_keys.html @@ -1,3 +1,4 @@ +{% from "_api_token.html" import render_api_token %}

@@ -45,89 +46,7 @@ {% if repo.tokens %} {% for token in repo.tokens %} {% if token.user.username == g.fas_user.username %} -
-
-
- - - {{ token.description or '' }} - -
-
- - - {{token.acls_list_pretty|length}} ACLs - - - -
- - - {% if token.expired %} - - - Expired on {{ token.expiration.date() }} - - - {% else %} - - - Active until {{ token.expiration.date() }} - - - {% endif %} - {% if not token.expired %} -
- - {{ form.csrf_token }} -
- {% else %} -
- - {{ form.csrf_token }} -
- {% endif %} -
-
+ {{ render_api_token(token, repo, username, form) }} {% endif %} {% endfor %} {% endif %} diff --git a/pagure/templates/user_settings.html b/pagure/templates/user_settings.html index ed65201..e4d082c 100644 --- a/pagure/templates/user_settings.html +++ b/pagure/templates/user_settings.html @@ -1,6 +1,7 @@ {% extends "master.html" %} {% from "_formhelper.html" import render_bootstrap_field %} {% from "_projectstring.html" import projectstring, projecticon %} +{% from "_api_token.html" import render_api_token %} {% block title %}{{ user.user }}'s settings{% endblock %} {% set tag = "users"%} @@ -122,15 +123,25 @@

+

@@ -151,51 +162,7 @@ {% if user.tokens %} {% for token in user.tokens %} {% if not token.project %} -

-
-
- - - {{ token.description or '' }} - -
-
- - {% for acl in token.acls_list %} - {% if acl == 'create_project' %} - - {% elif acl == 'fork_project' %} - - {% elif acl == 'modify_project' %} - - {% endif %} - {% endfor %} - -
- - {% if token.expired %} - - Expired on {{ token.expiration.date() }} - - {% else %} - - Active until {{ token.expiration.date() }} - - {% endif %} - {% if not token.expired %} -
- - {{ form.csrf_token }} -
- {% endif %} -
-
+ {{ render_api_token(token, repo, username, form) }} {% endif %} {% endfor %} {% endif %} @@ -366,6 +333,17 @@ $(".ssh_key_btn").click(function() { $(".ssh_key_block").toggle(); }); + + $('#show_old_keys').click(function(e) { + var _el = $('.expired_api_keys') + if (_el.css('display') == 'none'){ + _el.css('display', 'flex'); + $('#show_old_keys').text('Hide old API keys'); + } else { + $('#show_old_keys').text('Show old API keys'); + _el.hide(); + } + }); }); {% endblock %} From 538d43cf443aea811cb80a3138cb914fa6586c69 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 27 2020 11:22:22 +0000 Subject: [PATCH 2/5] Add an endpoint to review user API token This is similar to the code used to renew project's API token but this time for user's API token. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/_api_token.html b/pagure/templates/_api_token.html index 69daaa3..cbb65c0 100644 --- a/pagure/templates/_api_token.html +++ b/pagure/templates/_api_token.html @@ -80,6 +80,9 @@ namespace=repo.namespace, token_id=token.id) }}" method="post" class="icon"> + {% else %} +
{% endif %}