Wire up webhooks to the UI.
This commit is contained in:
parent
fe67bc3d25
commit
ecc5f8fba7
7 changed files with 94 additions and 7 deletions
|
@ -212,4 +212,4 @@ class QueueItem(BaseModel):
|
|||
all_models = [User, Repository, Image, AccessToken, Role,
|
||||
RepositoryPermission, Visibility, RepositoryTag,
|
||||
EmailConfirmation, FederatedLogin, LoginService, QueueItem,
|
||||
RepositoryBuild, Team, TeamMember, TeamRole]
|
||||
RepositoryBuild, Team, TeamMember, TeamRole, Webhook]
|
||||
|
|
|
@ -973,3 +973,8 @@ def list_webhooks(namespace_name, repository_name):
|
|||
joined = Webhook.select().join(Repository)
|
||||
return joined.where(Repository.namespace == namespace_name,
|
||||
Repository.name == repository_name)
|
||||
|
||||
|
||||
def delete_webhook(namespace_name, repository_name, public_id):
|
||||
webhook = get_webhook(namespace_name, repository_name, public_id)
|
||||
webhook.delete_instance()
|
||||
|
|
|
@ -841,7 +841,7 @@ def webhook_view(webhook):
|
|||
@api_login_required
|
||||
@parse_repository_name
|
||||
def create_webhook(namespace, repository):
|
||||
permission = ModifyRepositoryPermission(namespace, repository)
|
||||
permission = AdministerRepositoryPermission(namespace, repository)
|
||||
if permission.can():
|
||||
repo = model.get_repository(namespace, repository)
|
||||
webhook = model.create_webhook(repo, request.get_json())
|
||||
|
@ -849,6 +849,7 @@ def create_webhook(namespace, repository):
|
|||
repo_string = '%s/%s' % (namespace, repository)
|
||||
resp.headers['Location'] = url_for('get_webhook', repository=repo_string,
|
||||
public_id=webhook.public_id)
|
||||
return resp
|
||||
|
||||
abort(403) # Permissions denied
|
||||
|
||||
|
@ -858,7 +859,7 @@ def create_webhook(namespace, repository):
|
|||
@api_login_required
|
||||
@parse_repository_name
|
||||
def get_webhook(namespace, repository, public_id):
|
||||
permission = ModifyRepositoryPermission(namespace, repository)
|
||||
permission = AdministerRepositoryPermission(namespace, repository)
|
||||
if permission.can():
|
||||
webhook = model.get_webhook(namespace, repository, public_id)
|
||||
return jsonify(webhook_view(webhook))
|
||||
|
@ -870,7 +871,7 @@ def get_webhook(namespace, repository, public_id):
|
|||
@api_login_required
|
||||
@parse_repository_name
|
||||
def list_webhooks(namespace, repository):
|
||||
permission = ModifyRepositoryPermission(namespace, repository)
|
||||
permission = AdministerRepositoryPermission(namespace, repository)
|
||||
if permission.can():
|
||||
webhooks = model.list_webhooks(namespace, repository)
|
||||
return jsonify({
|
||||
|
@ -880,6 +881,19 @@ def list_webhooks(namespace, repository):
|
|||
abort(403) # Permission denied
|
||||
|
||||
|
||||
@app.route('/api/repository/<path:repository>/webhook/<public_id>',
|
||||
methods=['DELETE'])
|
||||
@api_login_required
|
||||
@parse_repository_name
|
||||
def delete_webhook(namespace, repository, public_id):
|
||||
permission = AdministerRepositoryPermission(namespace, repository)
|
||||
if permission.can():
|
||||
model.delete_webhook(namespace, repository, public_id)
|
||||
return make_response('No Content', 204)
|
||||
|
||||
abort(403) # Permission denied
|
||||
|
||||
|
||||
@app.route('/api/filedrop/', methods=['POST'])
|
||||
@api_login_required
|
||||
def get_filedrop_url():
|
||||
|
|
|
@ -524,11 +524,13 @@
|
|||
font-size: .4em;
|
||||
}
|
||||
|
||||
form input.ng-invalid.ng-dirty {
|
||||
form input.ng-invalid.ng-dirty,
|
||||
*[ng-form] input.ng-invalid.ng-dirty {
|
||||
background-color: #FDD7D9;
|
||||
}
|
||||
|
||||
form input.ng-valid.ng-dirty {
|
||||
form input.ng-valid.ng-dirty,
|
||||
*[ng-form] input.ng-valid.ng-dirty {
|
||||
background-color: #DDFFEE;
|
||||
}
|
||||
|
||||
|
|
|
@ -559,7 +559,7 @@ function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) {
|
|||
});
|
||||
};
|
||||
|
||||
$scope.roles = [
|
||||
$scope.roles = [
|
||||
{ 'id': 'read', 'title': 'Read', 'kind': 'success' },
|
||||
{ 'id': 'write', 'title': 'Write', 'kind': 'success' },
|
||||
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary' }
|
||||
|
@ -700,6 +700,31 @@ function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) {
|
|||
$scope.loading = false;
|
||||
});
|
||||
|
||||
$scope.webhooksLoading = true;
|
||||
$scope.loadWebhooks = function() {
|
||||
$scope.webhooksLoading = true;
|
||||
var fetchWebhooks = Restangular.one('repository/' + namespace + '/' + name + '/webhook/');
|
||||
fetchWebhooks.get().then(function(resp) {
|
||||
$scope.webhooks = resp.webhooks;
|
||||
$scope.webhooksLoading = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createWebhook = function() {
|
||||
var newWebhook = Restangular.one('repository/' + namespace + '/' + name + '/webhook/');
|
||||
newWebhook.customPOST($scope.newWebhook).then(function(resp) {
|
||||
$scope.webhooks.push(resp);
|
||||
$scope.newWebhook.url = '';
|
||||
$scope.newWebhookForm.$setPristine();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteWebhook = function(webhook) {
|
||||
var deleteWebhookReq = Restangular.one('repository/' + namespace + '/' + name + '/webhook/' + webhook.public_id);
|
||||
deleteWebhookReq.customDELETE().then(function(resp) {
|
||||
$scope.webhooks.splice($scope.webhooks.indexOf(webhook), 1);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function UserAdminCtrl($scope, $timeout, $location, Restangular, PlanService, UserService, KeyService, $routeParams) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<div class="col-md-2">
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="active"><a href="javascript:void(0)" data-toggle="tab" data-target="#permissions">Permissions</a></li>
|
||||
<li><a href="javascript:void(0)" data-toggle="tab" data-target="#webhook" ng-click="loadWebhooks()">Webhooks</a></li>
|
||||
<li><a href="javascript:void(0)" data-toggle="tab" data-target="#publicprivate">Public/Private</a></li>
|
||||
<li><a href="javascript:void(0)" data-toggle="tab" data-target="#delete">Delete</a></li>
|
||||
</ul>
|
||||
|
@ -148,6 +149,46 @@
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Webhook tab -->
|
||||
<div id="webhook" class="tab-pane">
|
||||
<div ng-show="webhooksLoading">
|
||||
Loading webhooks: <i class="fa fa-spinner fa-spin fa-2x" style="vertical-align: middle; margin-left: 4px"></i>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default" ng-show="!webhooksLoading">
|
||||
<div class="panel-body">
|
||||
<table class="permissions" ng-form="newWebhookForm">
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="width: 500px;">Webhook URL</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr ng-repeat="webhook in webhooks">
|
||||
<td>{{ webhook.parameters.url }}</td>
|
||||
<td>
|
||||
<span class="delete-ui" tabindex="0">
|
||||
<span class="delete-ui-button" ng-click="deleteWebhook(webhook)"><button class="btn btn-danger">Delete</button></span>
|
||||
<i class="fa fa-times" bs-tooltip="tooltip.title" data-placement="right" title="Delete Webhook"></i>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="url" class="form-control" placeholder="New webhook url..." ng-model="newWebhook.url" required>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-primary" type="submit" ng-click="createWebhook()">Create</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Public/private tab -->
|
||||
<div id="publicprivate" class="tab-pane">
|
||||
<!-- Public/Private -->
|
||||
|
|
Binary file not shown.
Reference in a new issue