2022-07-07 05:19:05 +08:00
|
|
|
<script>
|
|
|
|
import { slide } from "svelte/transition";
|
|
|
|
import { Collection } from "pocketbase";
|
2023-02-19 01:33:42 +08:00
|
|
|
import CommonHelper from "@/utils/CommonHelper";
|
2022-10-30 16:28:14 +08:00
|
|
|
import RuleField from "@/components/collections/RuleField.svelte";
|
2022-07-07 05:19:05 +08:00
|
|
|
|
|
|
|
export let collection = new Collection();
|
|
|
|
|
2023-02-19 01:33:42 +08:00
|
|
|
$: fields = CommonHelper.getAllCollectionIdentifiers(collection);
|
|
|
|
|
2022-07-07 05:19:05 +08:00
|
|
|
let showFiltersInfo = false;
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="block m-b-base">
|
2023-01-08 04:25:56 +08:00
|
|
|
<div class="flex txt-sm txt-hint m-b-5">
|
2022-07-07 05:19:05 +08:00
|
|
|
<p>
|
|
|
|
All rules follow the
|
2022-10-30 16:28:14 +08:00
|
|
|
<a href={import.meta.env.PB_RULES_SYNTAX_DOCS} target="_blank" rel="noopener noreferrer">
|
2022-07-07 05:19:05 +08:00
|
|
|
PocketBase filter syntax and operators
|
|
|
|
</a>.
|
|
|
|
</p>
|
2022-11-18 00:59:25 +08:00
|
|
|
<button
|
|
|
|
type="button"
|
2022-07-07 05:19:05 +08:00
|
|
|
class="expand-handle txt-sm txt-bold txt-nowrap link-hint"
|
|
|
|
on:click={() => (showFiltersInfo = !showFiltersInfo)}
|
|
|
|
>
|
|
|
|
{showFiltersInfo ? "Hide available fields" : "Show available fields"}
|
2022-11-18 00:59:25 +08:00
|
|
|
</button>
|
2022-07-07 05:19:05 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if showFiltersInfo}
|
|
|
|
<div transition:slide|local={{ duration: 150 }}>
|
|
|
|
<div class="alert alert-warning m-0">
|
|
|
|
<div class="content">
|
|
|
|
<p class="m-b-0">The following record fields are available:</p>
|
|
|
|
<div class="inline-flex flex-gap-5">
|
2023-02-19 01:33:42 +08:00
|
|
|
{#each fields as name}
|
|
|
|
<code>{name}</code>
|
2022-07-07 05:19:05 +08:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class="m-t-10 m-b-5" />
|
|
|
|
|
|
|
|
<p class="m-b-0">
|
|
|
|
The request fields could be accessed with the special <em>@request</em> filter:
|
|
|
|
</p>
|
|
|
|
<div class="inline-flex flex-gap-5">
|
|
|
|
<code>@request.method</code>
|
|
|
|
<code>@request.query.*</code>
|
|
|
|
<code>@request.data.*</code>
|
2022-10-30 16:28:14 +08:00
|
|
|
<code>@request.auth.*</code>
|
2022-07-07 05:19:05 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class="m-t-10 m-b-5" />
|
|
|
|
|
|
|
|
<p class="m-b-0">
|
|
|
|
You could also add constraints and query other collections using the <em
|
|
|
|
>@collection</em
|
|
|
|
> filter:
|
|
|
|
</p>
|
|
|
|
<div class="inline-flex flex-gap-5">
|
|
|
|
<code>@collection.ANY_COLLECTION_NAME.*</code>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class="m-t-10 m-b-5" />
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Example rule:
|
|
|
|
<br />
|
2022-10-30 16:28:14 +08:00
|
|
|
<code>@request.auth.id != "" && created > "2022-01-01 00:00:00"</code>
|
2022-07-07 05:19:05 +08:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
|
2022-10-30 16:28:14 +08:00
|
|
|
<RuleField label="List/Search action" formKey="listRule" {collection} bind:rule={collection.listRule} />
|
|
|
|
|
|
|
|
<hr class="m-t-sm m-b-sm" />
|
|
|
|
<RuleField label="View action" formKey="viewRule" {collection} bind:rule={collection.viewRule} />
|
|
|
|
|
2023-02-19 01:33:42 +08:00
|
|
|
{#if !collection?.isView}
|
|
|
|
<hr class="m-t-sm m-b-sm" />
|
|
|
|
<RuleField label="Create action" formKey="createRule" {collection} bind:rule={collection.createRule} />
|
2022-10-30 16:28:14 +08:00
|
|
|
|
2023-02-19 01:33:42 +08:00
|
|
|
<hr class="m-t-sm m-b-sm" />
|
|
|
|
<RuleField label="Update action" formKey="updateRule" {collection} bind:rule={collection.updateRule} />
|
2022-10-30 16:28:14 +08:00
|
|
|
|
2023-02-19 01:33:42 +08:00
|
|
|
<hr class="m-t-sm m-b-sm" />
|
|
|
|
<RuleField label="Delete action" formKey="deleteRule" {collection} bind:rule={collection.deleteRule} />
|
|
|
|
{/if}
|
2022-10-30 16:28:14 +08:00
|
|
|
|
|
|
|
{#if collection?.isAuth}
|
|
|
|
<hr class="m-t-sm m-b-sm" />
|
|
|
|
<RuleField
|
|
|
|
label="Manage action"
|
|
|
|
formKey="options.manageRule"
|
|
|
|
{collection}
|
|
|
|
bind:rule={collection.options.manageRule}
|
|
|
|
>
|
|
|
|
<svelte:fragment>
|
|
|
|
<p>
|
|
|
|
This API rule gives admin-like permissions to allow fully managing the auth record(s), eg.
|
|
|
|
changing the password without requiring to enter the old one, directly updating the verified
|
|
|
|
state or email, etc.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
This rule is executed in addition to the <code>create</code> and <code>update</code> API rules.
|
|
|
|
</p>
|
|
|
|
</svelte:fragment>
|
|
|
|
</RuleField>
|
2022-07-07 05:19:05 +08:00
|
|
|
{/if}
|