support revoking tokens from token page

This commit is contained in:
Min RK
2018-04-16 11:07:40 +02:00
parent 32fe3cf61d
commit 33cb62c2ee
3 changed files with 20 additions and 3 deletions

View File

@@ -132,9 +132,9 @@ define(['jquery', 'utils'], function ($, utils) {
); );
}; };
JHAPI.prototype.delete_token = function (user, token_id, options) { JHAPI.prototype.revoke_token = function (user, token_id, options) {
options = options || {}; options = options || {};
options = update(options, {type: 'POST'}); options = update(options, {type: 'DELETE'});
this.api_request( this.api_request(
utils.url_path_join('users', user, 'tokens', token_id), utils.url_path_join('users', user, 'tokens', token_id),
options options

View File

@@ -32,5 +32,22 @@ require(["jquery", "jhapi", "moment"], function($, JHAPI, moment) {
); );
return false; return false;
}); });
function get_token_row(element) {
while (!element.hasClass("token-row")) {
element = element.parent();
}
return element;
}
$(".revoke-token-btn").click(function() {
var el = $(this);
var row = get_token_row(el);
el.attr("disabled", true);
api.revoke_token(user, row.data('token-id'), {
success: function(reply) {
row.remove();
},
}); });
});
}); });

View File

@@ -71,7 +71,7 @@
{{ token.created.isoformat() + 'Z' }} {{ token.created.isoformat() + 'Z' }}
</td> </td>
<td class="col-sm-1 text-center"> <td class="col-sm-1 text-center">
<a role="button" class="delete-token-btn btn btn-xs btn-danger">revoke</a> <a role="button" class="revoke-token-btn btn btn-xs btn-danger">revoke</a>
</td> </td>
{% endblock token_row %} {% endblock token_row %}
</tr> </tr>