Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
Use scopes when creating new API keys (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly authored Oct 14, 2018
1 parent ca4ef74 commit e0f5a2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
24 changes: 4 additions & 20 deletions app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ angular.module('alerta')

$scope.perms = [];
$scope.perm = '';
$scope.scope = '';
$scope.match = '';

$scope.createPerm = function(scope, match) {
Expand Down Expand Up @@ -1292,31 +1293,14 @@ angular.module('alerta')
function($scope, $route, $timeout, $auth, config, Keys) {

$scope.keys = [];
$scope.type = {
name: 'read-only',
scopes: ['read']
};
$scope.scope = ''
$scope.text = '';

$scope.types = [{
name: 'admin',
scopes: ['read', 'write', 'admin']
},
{
name: 'read-write',
scopes: ['read', 'write']
},
{
name: 'read-only',
scopes: ['read']
}
];

$scope.createKey = function(type, customer, text) {
$scope.createKey = function(scope, customer, text) {
var login = $auth.getPayload().preferred_username || $auth.getPayload().login;
Keys.save({}, {
user: login,
scopes: type.scopes,
scopes: scope.split(' '),
customer: customer,
text: text
}, function(data) {
Expand Down
19 changes: 8 additions & 11 deletions app/partials/keys.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,18 @@
</table>

<div>
<form name="form" class="form-inline css-form" novalidate>
<div class="row">
<div class="form-group col-md-5 col-sm-4 col-xs-4">
<input type="text" class="form-control" id="text" placeholder="Application requiring API Key" ng-model="text" name="text" required />
<div class="form-group row">
<div class="col-xs-2">
<input type="text" class="form-control" id="text" placeholder="Application" ng-model="text" name="text" required />
</div>
<div class="form-group col-md-2 col-sm-2 col-xs-2">
<input type="text" class="form-control" id="customer" placeholder="Customer (optional)" ng-model="customer" name="customer" />
<div class="col-xs-4">
<input class="form-control" id="input-scopes" placeholder="Scopes eg. admin write read:alerts admin:keys" ng-model="scope" name="scope" required />
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<select class="form-control input-md" ng-options="key as key.name for key in types track by key.name" ng-model="type"></select>
</select>
<div class="col-xs-2">
<input type="text" class="form-control" id="customer" placeholder="Customer (optional)" ng-model="customer" name="customer" />
</div>
<button ng-disabled="!hasPermission('write:keys')" type="button" class="btn btn-primary" ng-click="createKey(type, customer, text)">Create new API Key</button>
<button ng-disabled="!hasPermission('write:keys')" type="button" class="btn btn-primary" ng-click="createKey(scope, customer, text)">Create new API Key</button>
</div>
</form>
</div>

</div>
Expand Down

0 comments on commit e0f5a2f

Please sign in to comment.