Get create permission working
This commit is contained in:
parent
e8d51b651f
commit
ca934ac162
5 changed files with 166 additions and 14 deletions
|
@ -589,22 +589,28 @@ def create_organization_prototype_permission(orgname):
|
|||
abort(404)
|
||||
|
||||
details = request.get_json()
|
||||
activating_user = details['activating_user']['name']
|
||||
activating_username = details['activating_user']['name']
|
||||
|
||||
delegate = details['delegate']
|
||||
delegate_kind = delegate['kind']
|
||||
delegate_name = delegate['name']
|
||||
|
||||
delegate_user = delegate_name if delegate_kind == 'user' else None
|
||||
delegate_team = delegate_name if delegate_kind == 'team' else None
|
||||
delegate_username = delegate_name if delegate_kind == 'user' else None
|
||||
delegate_teamname = delegate_name if delegate_kind == 'team' else None
|
||||
|
||||
role_name = details['role']
|
||||
activating_user = model.get_user(activating_username)
|
||||
delegate_user = model.get_user(delegate_username) if delegate_username else None
|
||||
delegate_team = model.get_organization_team(orgname, delegate_teamname) if delegate_teamname else None
|
||||
|
||||
if not activating_user:
|
||||
abort(404)
|
||||
|
||||
if not delegate_user and not delegate_team:
|
||||
abort(400)
|
||||
|
||||
role_name = details['role']
|
||||
prototype = model.add_prototype_permission(org, role_name, activating_user, delegate_user, delegate_team)
|
||||
return jsonify(protoype_view(prototype))
|
||||
return jsonify(prototype_view(prototype))
|
||||
|
||||
abort(403)
|
||||
|
||||
|
|
|
@ -73,10 +73,24 @@
|
|||
top: 70px;
|
||||
}
|
||||
|
||||
.entity-search-element {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.entity-search-element .entity-icon {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
.entity-search-element input {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.entity-search-element.persistent input {
|
||||
padding-left: 28px;
|
||||
}
|
||||
|
||||
.entity-search-element .twitter-typeahead {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
<span class="entity-search-element"><input class="entity-search-control form-control">
|
||||
<span class="entity-search-element" ng-class="isPersistent ? 'persistent' : ''"><input class="entity-search-control form-control">
|
||||
<span class="entity-icon" ng-show="isPersistent">
|
||||
<i class="fa fa-user" ng-show="currentEntity.kind == 'user' && !currentEntity.is_robot" title="User"
|
||||
bs-tooltip="tooltip.title" data-container="body"></i>
|
||||
<i class="fa fa-wrench" ng-show="currentEntity.kind == 'user' && currentEntity.is_robot" title="Robot Account"
|
||||
bs-tooltip="tooltip.title" data-container="body"></i>
|
||||
<i class="fa fa-group" ng-show="currentEntity.kind == 'team'" title="Team"
|
||||
bs-tooltip="tooltip.title" data-container="body"></i>
|
||||
</span>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="entityDropdownMenu" data-toggle="dropdown"
|
||||
ng-click="lazyLoad()">
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</div>
|
||||
|
||||
<div class="side-controls">
|
||||
<button class="btn btn-success">
|
||||
<button class="btn btn-success" ng-click="showAddDialog()">
|
||||
<i class="fa fa-plus"></i>
|
||||
New Default Permission
|
||||
</button>
|
||||
|
@ -55,5 +55,50 @@
|
|||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Modal message dialog -->
|
||||
<div class="modal fade" id="addPermissionDialogModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">Create Default Permission</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Activating User/Robot:</td>
|
||||
<td>
|
||||
<span class="entity-search" namespace="organization.name" input-title="'Activating User/Robot'"
|
||||
is-organization="true" include-teams="false" current-entity="activatingForNew" is-persistent="true"
|
||||
clear-now="clearCounter">
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Delegated User/Team:</td>
|
||||
<td>
|
||||
<span class="entity-search" namespace="organization.name" input-title="'Delegated User/Robot'"
|
||||
is-organization="true" include-teams="true" current-entity="delegateForNew" is-persistent="true"
|
||||
clear-now="clearCounter">
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Permission:</td>
|
||||
<td>
|
||||
<span class="role-group" current-role="newRole" role-changed="setRoleForNew(role)" roles="roles"></span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button ype="button" class="btn btn-primary" ng-disabled="!activatingForNew || !delegateForNew" ng-click="createPrototype()">
|
||||
Create Permission
|
||||
</button>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1491,6 +1491,9 @@ quayApp.directive('prototypeManager', function () {
|
|||
},
|
||||
controller: function($scope, $element, ApiService) {
|
||||
$scope.loading = false;
|
||||
$scope.activatingForNew = null;
|
||||
$scope.delegateForNew = null;
|
||||
$scope.clearCounter = 0;
|
||||
|
||||
$scope.roles = [
|
||||
{ 'id': 'read', 'title': 'Read', 'kind': 'success' },
|
||||
|
@ -1525,6 +1528,50 @@ quayApp.directive('prototypeManager', function () {
|
|||
});
|
||||
};
|
||||
|
||||
$scope.setRoleForNew = function(role) {
|
||||
$scope.newRole = role;
|
||||
};
|
||||
|
||||
$scope.showAddDialog = function() {
|
||||
$scope.activatingForNew = null;
|
||||
$scope.delegateForNew = null;
|
||||
$scope.newRole = 'read';
|
||||
$scope.clearCounter++;
|
||||
$('#addPermissionDialogModal').modal({});
|
||||
};
|
||||
|
||||
$scope.createPrototype = function() {
|
||||
$scope.loading = true;
|
||||
|
||||
var params = {
|
||||
'orgname': $scope.organization.name
|
||||
};
|
||||
|
||||
var data = {
|
||||
'activating_user': $scope.activatingForNew,
|
||||
'delegate': $scope.delegateForNew,
|
||||
'role': $scope.newRole
|
||||
};
|
||||
|
||||
ApiService.createOrganizationPrototypePermission(data, params).then(function(resp) {
|
||||
$scope.prototypes.push(resp);
|
||||
$scope.loading = false;
|
||||
$('#addPermissionDialogModal').modal('hide');
|
||||
}, function(resp) {
|
||||
$('#addPermissionDialogModal').modal('hide');
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The permission could not be created',
|
||||
"title": "Cannot create permission",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deletePrototype = function(prototype) {
|
||||
$scope.loading = true;
|
||||
|
||||
|
@ -1546,7 +1593,7 @@ quayApp.directive('prototypeManager', function () {
|
|||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1841,7 +1888,10 @@ quayApp.directive('entitySearch', function () {
|
|||
'inputTitle': '=inputTitle',
|
||||
'entitySelected': '=entitySelected',
|
||||
'includeTeams': '=includeTeams',
|
||||
'isOrganization': '=isOrganization'
|
||||
'isOrganization': '=isOrganization',
|
||||
'isPersistent': '=isPersistent',
|
||||
'currentEntity': '=currentEntity',
|
||||
'clearNow': '=clearNow'
|
||||
},
|
||||
controller: function($scope, $element, Restangular, UserService, ApiService) {
|
||||
$scope.lazyLoading = true;
|
||||
|
@ -1915,10 +1965,27 @@ quayApp.directive('entitySearch', function () {
|
|||
entity['is_org_member'] = true;
|
||||
}
|
||||
|
||||
$scope.entitySelected(entity);
|
||||
$scope.setEntityInternal(entity);
|
||||
};
|
||||
|
||||
if (!$scope.entitySelected) { return; }
|
||||
$scope.clearEntityInternal = function() {
|
||||
$scope.currentEntity = null;
|
||||
if ($scope.entitySelected) {
|
||||
$scope.entitySelected(null);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.setEntityInternal = function(entity) {
|
||||
$(input).typeahead('setQuery', $scope.isPersistent ? entity.name : '');
|
||||
|
||||
if ($scope.isPersistent) {
|
||||
$scope.currentEntity = entity;
|
||||
}
|
||||
|
||||
if ($scope.entitySelected) {
|
||||
$scope.entitySelected(entity);
|
||||
}
|
||||
};
|
||||
|
||||
number++;
|
||||
|
||||
|
@ -1969,13 +2036,25 @@ quayApp.directive('entitySearch', function () {
|
|||
},
|
||||
});
|
||||
|
||||
$(input).on('typeahead:selected', function(e, datum) {
|
||||
$(input).typeahead('setQuery', '');
|
||||
$(input).on('input', function(e) {
|
||||
$scope.$apply(function() {
|
||||
$scope.entitySelected(datum.entity);
|
||||
if ($scope.isPersistent) {
|
||||
$scope.clearEntityInternal();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(input).on('typeahead:selected', function(e, datum) {
|
||||
$scope.$apply(function() {
|
||||
$scope.setEntityInternal(datum.entity);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$watch('clearNow', function() {
|
||||
$(input).typeahead('setQuery', '');
|
||||
$scope.clearEntityInternal();
|
||||
});
|
||||
|
||||
$scope.$watch('inputTitle', function(title) {
|
||||
input.setAttribute('placeholder', title);
|
||||
});
|
||||
|
|
Reference in a new issue