1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00
This commit is contained in:
Torsten Dittmann 2022-05-06 10:49:37 +02:00
parent af9150def9
commit 809767401e
8 changed files with 149 additions and 220 deletions

View file

@ -152,7 +152,7 @@ App::get('/console/settings')
->setParam('body', $page);
});
App::get('/console/webhooks')
App::get('/console/webhooks')
->groups(['web', 'console'])
->label('permission', 'public')
->label('scope', 'console')
@ -169,18 +169,41 @@ App::get('/console/settings')
->setParam('body', $page);
});
App::get('/console/webhooks/webhook')
App::get('/console/webhooks/webhook')
->groups(['web', 'console'])
->label('permission', 'public')
->label('scope', 'console')
->param('id', '', new UID(), 'Bucket unique ID.')
->param('id', '', new UID(), 'Webhook unique ID.')
->inject('layout')
->action(function ($id, $layout) {
/** @var Appwrite\Utopia\View $layout */
$page = new View(__DIR__.'/../../views/console/webhooks/webhook.phtml');
$page->setParam('events', Config::getParam('events', []));
$page
->setParam('events', Config::getParam('events', []))
->setParam('new', false)
;
$layout
->setParam('title', APP_NAME.' - Webhooks')
->setParam('body', $page);
});
App::get('/console/webhooks/webhook/new')
->groups(['web', 'console'])
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
$page = new View(__DIR__.'/../../views/console/webhooks/webhook.phtml');
$page
->setParam('events', Config::getParam('events', []))
->setParam('new', true)
;
$layout
->setParam('title', APP_NAME.' - Webhooks')

View file

@ -528,7 +528,36 @@ foreach ($events as $name => $event) {
</section>
<section x-data="events" class="margin-bottom-small" data-ls-attrs="x-init=events={{project-function.events}}">
<label>Events</label>
<label class="margin-bottom">Events
<div data-ui-modal x-ref="modal" class="modal box close width-small height-small" data-button-text="Add Event" data-button-class="pull-end small">
<select x-model="selected" @change="setEvent()">
<option value="" selected>Select event</option>
<?php foreach ($patterns as $event) : ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach; ?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent($refs.modal)">Add Event</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</div>
</label>
<template x-for="(event, index) in events">
<div class="row events responsive thin margin-bottom-small">
<div class="col span-12 margin-bottom-small">
@ -540,32 +569,6 @@ foreach ($events as $name => $event) {
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
<select x-model="selected" @change="setEvent()">
<option value="" selected>Add event</option>
<?php foreach ($patterns as $event): ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach; ?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent()">Add Event</button>
</section>
<label for="schedule">Schedule (CRON Syntax) <span class="tooltip small" data-tooltip="Set a CRON schedule to trigger this function."><i class="icon-info-circled"></i></span></label>

View file

@ -62,117 +62,5 @@ foreach ($events as $name => $event) {
</li>
</ul>
</div>
<div class="clear">
<div data-ui-modal class="modal close box sticky-footer" data-button-text="Add Webhook">
<button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>
<h1>Add Webhook</h1>
<form
data-analytics
data-analytics-activity
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Create Project Webhook"
data-service="projects.createWebhook"
data-scope="console"
data-event="submit"
data-success="alert,trigger,reset"
data-success-param-alert-text="Created webhook successfully"
data-success-param-trigger-events="projects.createWebhook"
data-failure="alert"
data-failure-param-alert-text="Failed to create webhook"
data-failure-param-alert-classname="error">
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
<label for="name">Name</label>
<input type="text" class="full-width" id="name" name="name" required autocomplete="off" maxlength="128" />
<label for="url">POST URL</label>
<input type="url" class="full-width" id="url" name="url" required autocomplete="off" placeholder="https://example.com/callback" />
<section x-data="events" class="margin-bottom-small">
<label>Events</label>
<template x-for="(event, index) in events">
<div class="row events responsive thin margin-bottom-tiny">
<div class="col span-12 margin-bottom-small">
<span class="text" x-text="event"></span>
<span class="action" @click="removeEvent(index)">
<i class="icon-trash"></i>
</span>
</div>
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
<label>Add event</label>
<select x-model="selected" @change="setEvent()">
<option value="" selected>---</option>
<?php foreach ($patterns as $event): ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach;?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent()">Add Event</button>
</section>
<div class="margin-bottom toggle" data-ls-ui-open data-button-aria="Advanced Options">
<i class="icon-plus pull-end margin-top-tiny"></i>
<i class="icon-minus pull-end margin-top-tiny"></i>
<h2 class="margin-bottom">
Advanced Options
<small class="text-size-small">(optional)</small>
</h2>
<label data-ls-attrs="for=security-{{task.$id}}" class="margin-bottom-small">
<div class="margin-bottom-small text-bold">SSL / TLS (Certificate verification)</div>
<input name="security" type="radio" required data-ls-attrs="id=secure-yes" checked="checked" value="1" /> &nbsp; <span>Enabled</span> &nbsp;
<input name="security" type="radio" required data-ls-attrs="id=secure-no" value="0" /> &nbsp; <span>Disabled</span> &nbsp;
</label>
<p class="margin-bottom text-size-small text-fade"><span class="text-red">Warning</span>: Untrusted or self-signed certificates may not be secure.
<a href="https://en.wikipedia.org/wiki/Self-signed_certificate" target="_blank" rel="noopener">Learn more<i class="icon-link-ext"></i></a>
</p>
<label>HTTP Authentication <span class="tooltip" data-tooltip="Use to secure your endpoint from untrusted sources"><i class="icon-question"></i></span> &nbsp;<small>(optional)</small></label>
<div class="row responsive thin">
<div class="col span-6 margin-bottom">
<label for="httpUser">User</label>
<input type="text" class="full-width margin-bottom-no" id="httpUser" name="httpUser" autocomplete="off" />
</div>
<div class="col span-6 margin-bottom">
<label for="httpPass">Password</label>
<input type="password" data-forms-show-secret class="full-width margin-bottom-no" id="httpPass" name="httpPass" autocomplete="off" />
</div>
</div>
</div>
<footer>
<button type="submit">Create</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</footer>
</form>
</div>
</div>
<a data-ls-attrs="href=/console/webhooks/webhook/new?project={{router.params.project}}" class="button">Add Webhook</a>
</div>

View file

@ -1,9 +1,6 @@
<?php
$fileLimit = $this->getParam('fileLimit', 0);
$fileLimitHuman = $this->getParam('fileLimitHuman', 0);
$new = $this->getParam('new', false);
$events = $this->getParam('events', []);
$timeout = $this->getParam('timeout', 900);
$usageStatsEnabled = $this->getParam('usageStatsEnabled', true);
$patterns = [];
foreach ($events as $name => $event) {
@ -40,7 +37,11 @@ foreach ($events as $name => $event) {
<a data-ls-attrs="href=/console/webhooks?project={{router.params.project}}" class="back text-size-small link-return-animation--start"><i class="icon-left-open"></i> Webhooks</a>
<br />
<span data-ls-bind="{{project-webhook.name}}&nbsp;">&nbsp;</span>
<?php if ($new) : ?>
<span>Add Webhook</span>
<? else : ?>
<span data-ls-bind="{{project-webhook.name}}&nbsp;">&nbsp;</span>
<?php endif; ?>
</h1>
</div>
@ -50,24 +51,34 @@ foreach ($events as $name => $event) {
<label>&nbsp;</label>
<div class="box margin-bottom-large">
<form
<form
data-analytics
data-analytics-activity
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Update Project Webhook"
data-service="projects.updateWebhook"
<?php if ($new) : ?>
data-success="alert,trigger,redirect"
data-analytics-label="Create Project Webhook"
data-service="projects.createWebhook"
data-success-param-alert-text="Created webhook successfully"
data-success-param-trigger-events="projects.createWebhook"
data-failure-param-alert-text="Failed to create webhook"
data-success-param-redirect-url="/console/webhooks?project={{router.params.project}}"
<?php else : ?>
data-success="alert,trigger"
data-analytics-label="Update Project Webhook"
data-service="projects.updateWebhook"
data-success-param-alert-text="Updated webhook successfully"
data-success-param-trigger-events="projects.updateWebhook"
data-failure-param-alert-text="Failed to update webhook"
<?php endif; ?>
data-scope="console"
data-event="submit"
data-success="alert,trigger"
data-success-param-alert-text="Updated webhook successfully"
data-success-param-trigger-events="projects.updateWebhook"
data-failure="alert"
data-failure-param-alert-text="Failed to update webhook"
data-failure-param-alert-classname="error">
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
<input type="hidden" name="webhookId" data-ls-bind="{{project-webhook.$id}}" />
<?php if (!$new) : ?><input type="hidden" name="webhookId" data-ls-bind="{{project-webhook.$id}}" /><?php endif; ?>
<label data-ls-attrs="for=name-{{webhook.$id}}">Name</label>
<input type="text" class="full-width" data-ls-attrs="id=name-{{project-webhook.$id}}" name="name" required autocomplete="off" data-ls-bind="{{project-webhook.name}}" maxlength="128" />
@ -76,7 +87,36 @@ foreach ($events as $name => $event) {
<input type="url" class="full-width" data-ls-attrs="id=url-{{project-webhook.$id}}" name="url" required autocomplete="off" placeholder="https://example.com/callback" data-ls-bind="{{project-webhook.url}}" />
<section x-data="events" class="margin-bottom-small" data-ls-attrs="x-init=events={{project-webhook.events}}">
<label>Events</label>
<label class="margin-bottom">Events
<div data-ui-modal x-ref="modal" class="modal box close width-small height-small" data-button-text="Add Event" data-button-class="pull-end small">
<select x-model="selected" @change="setEvent()">
<option value="" selected>Select event</option>
<?php foreach ($patterns as $event) : ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach; ?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent($refs.modal)">Add Event</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</div>
</label>
<template x-for="(event, index) in events">
<div class="row events responsive thin margin-bottom-small">
<div class="col span-12 margin-bottom-small">
@ -88,32 +128,6 @@ foreach ($events as $name => $event) {
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
<select x-model="selected" @change="setEvent()">
<option value="" selected>Add event</option>
<?php foreach ($patterns as $event): ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach; ?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent()">Add Event</button>
</section>
<div class="margin-bottom toggle" data-ls-ui-open data-button-aria="Advanced Options">
@ -151,41 +165,27 @@ foreach ($events as $name => $event) {
</div>
<footer>
<button type="submit">Update</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
<button type="submit">Update</button>
</footer>
</form>
</div>
</div>
<div class="col span-4 sticky-top margin-bottom">
<label>Webhook ID</label>
<div class="input-copy margin-bottom">
<input id="uid" type="text" autocomplete="off" placeholder="" data-ls-bind="{{project-webhook.$id}}" disabled data-forms-copy>
<?php if (!$new) : ?>
<div class="col span-4 sticky-top margin-bottom">
<label>Webhook ID</label>
<div class="input-copy margin-bottom">
<input id="uid" type="text" autocomplete="off" placeholder="" data-ls-bind="{{project-webhook.$id}}" disabled data-forms-copy>
</div>
<form class="margin-bottom" data-analytics data-analytics-activity data-analytics-event="submit" data-analytics-category="console" data-analytics-label="Delete Project Webhook" data-service="projects.deleteWebhook" data-scope="console" data-event="submit" data-confirm="Are you sure you want to delete this webhook?" data-success="alert,redirect" data-success-param-redirect-url="/console/webhooks?project={{router.params.project}}" data-success-param-alert-text="Deleted webhook successfully" data-success-param-trigger-events="projects.deleteWebhook" data-failure="alert" data-failure-param-alert-text="Failed to delete webhook" data-failure-param-alert-classname="error">
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
<input type="hidden" name="webhookId" data-ls-bind="{{project-webhook.$id}}" />
<button class="danger fill">Delete Webhook</button>
</form>
</div>
<form class="margin-bottom"
data-analytics
data-analytics-activity
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Delete Project Webhook"
data-service="projects.deleteWebhook"
data-scope="console"
data-event="submit"
data-confirm="Are you sure you want to delete this webhook?"
data-success="alert,redirect"
data-success-param-redirect-url="/console/webhooks?project={{router.params.project}}"
data-success-param-alert-text="Deleted webhook successfully"
data-success-param-trigger-events="projects.deleteWebhook"
data-failure="alert"
data-failure-param-alert-text="Failed to delete webhook"
data-failure-param-alert-classname="error">
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
<input type="hidden" name="webhookId" data-ls-bind="{{project-webhook.$id}}" />
<button class="danger fill">Delete Webhook</button>
</form>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -156,7 +156,13 @@
}
this.action = action;
},
addEvent() {
addEvent(modal) {
if (modal) {
document.documentElement.classList.remove("modal-open");
modal.classList.add("close");
modal.classList.remove("open");
}
let event = `${this.type}.${this.resource ? this.resource : '*'}`;
if (this.hasSubResource) {

View file

@ -90,6 +90,13 @@ window.ls.router
scope: "console",
project: true
})
.add("/console/webhooks/webhook/new", {
template: function(window) {
return window.location.pathname + window.location.search + '&version=' + APP_ENV.CACHEBUSTER;
},
scope: "console",
project: true
})
.add("/console/keys", {
template: "/console/keys?version=" + APP_ENV.CACHEBUSTER,
scope: "console",