From f3c673d6ea14ca719769ddf9ca6ebfb9f49cb1ba Mon Sep 17 00:00:00 2001 From: Rob Thijssen Date: Thu, 23 Apr 2015 17:21:32 +0100 Subject: [PATCH 1/2] dont show orange revoke tokens button if there are no revokable tokens fix for https://github.com/mozilla/build-relengapi/issues/198 --- relengapi/blueprints/tokenauth/static/tokens.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/relengapi/blueprints/tokenauth/static/tokens.js b/relengapi/blueprints/tokenauth/static/tokens.js index ea3f3df0..536c84c1 100644 --- a/relengapi/blueprints/tokenauth/static/tokens.js +++ b/relengapi/blueprints/tokenauth/static/tokens.js @@ -13,8 +13,7 @@ angular.module('tokens').controller('TokenController', // permissions -- this is just used to decide which pages to show. $scope.can_view = false; $scope.can_issue = false; - $scope.can_revoke = false; - angular.forEach(['view', 'issue', 'revoke'], function (action) { + angular.forEach(['view', 'issue'], function (action) { var re = new RegExp("^base\.tokens\.[^.]*\." + action + "(?:\.my|\.all)?"); angular.forEach(initial_data.user.permissions, function (perm) { if (perm.name.match(re)) { @@ -29,6 +28,20 @@ angular.module('tokens').controller('TokenController', }); }; + $scope.can_revoke = false; + // 'can_revoke' := 'can_the_current_user_revoke_any_of_the_active_tokens' + if ($scope.can('base.tokens.usr.revoke.all')) { + $scope.can_revoke = true; + } else { + if ($scope.can('base.tokens.usr.revoke.my')) { + angular.forEach(initial_data.tokens, function (token) { + if (token.user == initial_data.user.authenticated_email) { + $scope.can_revoke = true; + } + }); + } + } + $scope.canRevokeToken = function(token) { if (token.typ == 'usr') { if ($scope.can('base.tokens.usr.revoke.all')) { From 267cb57942923a072df027397a445f6fdbcedc18 Mon Sep 17 00:00:00 2001 From: Rob Thijssen Date: Thu, 23 Apr 2015 22:35:21 +0100 Subject: [PATCH 2/2] handle prm tokens and scenarios where no tokens exist --- .../blueprints/tokenauth/static/tokens.js | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/relengapi/blueprints/tokenauth/static/tokens.js b/relengapi/blueprints/tokenauth/static/tokens.js index 536c84c1..d4a84497 100644 --- a/relengapi/blueprints/tokenauth/static/tokens.js +++ b/relengapi/blueprints/tokenauth/static/tokens.js @@ -27,18 +27,32 @@ angular.module('tokens').controller('TokenController', return perm.name == query_perm; }); }; + $scope.any = function(token_typ) { + return initial_data.tokens.some(function(token) { + return token.typ == token_typ; + }); + }; - $scope.can_revoke = false; // 'can_revoke' := 'can_the_current_user_revoke_any_of_the_active_tokens' - if ($scope.can('base.tokens.usr.revoke.all')) { + $scope.can_revoke = false; + + // 'prm' tokens exist & user can revoke + if ($scope.any('prm') && $scope.can('base.tokens.prm.revoke')) { $scope.can_revoke = true; - } else { - if ($scope.can('base.tokens.usr.revoke.my')) { - angular.forEach(initial_data.tokens, function (token) { - if (token.user == initial_data.user.authenticated_email) { - $scope.can_revoke = true; - } - }); + } + + // 'usr' tokens exist & user can revoke + if ($scope.any('usr')) { + if ($scope.can('base.tokens.usr.revoke.all')) { + $scope.can_revoke = true; + } else { + if ($scope.can('base.tokens.usr.revoke.my')) { + angular.forEach(initial_data.tokens, function (token) { + if (token.user == initial_data.user.authenticated_email) { + $scope.can_revoke = true; + } + }); + } } }