Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Plugin permissions component #1890

Merged
merged 19 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/components/PluginPermissions.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
import { createMarkdownProcessor } from '@astrojs/markdown-remark';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';

interface Props {
plugin: string;
}

const { plugin } = Astro.props;

async function importMDX(plugin: string): Promise<string> {
const base = fileURLToPath(import.meta.url);
const dirname = path.dirname(base);

const mdPath = path.join(
dirname,
'../../packages/plugins-workspace/plugins',
plugin,
'permissions/autogenerated',
'reference.md'
);

try {
const content = await fs.readFile(mdPath, 'utf-8');
return content;
} catch (err) {
console.error(`Error reading file ${mdPath}: ${err}`);
throw err;
}
}
const md = await createMarkdownProcessor();

const pageContent: string = await importMDX(plugin);
const content = await md.render(pageContent);
---

<Fragment set:html={content.code} />
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ permissions are used.

In the case of official maintained plugins you can find a
rendered description in the documentation
(eg. [fs default](/plugin/file-system/#default-permissions)).
(eg. [fs default](/plugin/file-system/#permissions)).

In case you are figuring this out for a community plugin you
need to check out the source code of the plugin.
Expand Down Expand Up @@ -147,7 +147,7 @@ permissions are used.
The `fs` plugin has autogenerated permissions which will disable
or enable individual commands and allow or disable global scopes.

These can be found in the [documentation](/plugin/file-system/#command-permissions)
These can be found in the [documentation](/plugin/file-system/#permissions)
or in the source code of the plugin (`fs/permissions/autogenerated`).

Let us assume we want to enable writing to a text file `test.txt`
Expand Down
10 changes: 2 additions & 8 deletions src/content/docs/plugin/autostart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sidebar:
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="autostart" />

Expand Down Expand Up @@ -145,11 +146,4 @@ See [Permissions Overview](/security/permissions/) for more information.
}
```

| Permission | Description |
| ---------------------------- | ---------------------------------------------------------------- |
| `autostart:allow-disable` | Enables the disable command without any pre-configured scope. |
| `autostart:deny-disable` | Denies the disable command without any pre-configured scope. |
| `autostart:allow-enable` | Enables the enable command without any pre-configured scope. |
| `autostart:deny-enable` | Denies the enable command without any pre-configured scope. |
| `autostart:allow-is-enabled` | Enables the is_enabled command without any pre-configured scope. |
| `autostart:deny-is-enabled` | Denies the is_enabled command without any pre-configured scope. |
<PluginPermissions plugin="autostart" />
16 changes: 2 additions & 14 deletions src/content/docs/plugin/barcode-scanner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sidebar:
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="barcode-scanner" />

Expand Down Expand Up @@ -105,17 +106,4 @@ See [Permissions Overview](/security/permissions/) for more information.
}
```

| Permission | Description |
| ------------------------------------------- | ------------------------------------------------------------------------- |
| `barcode-scanner:allow-cancel` | Enables the cancel command without any pre-configured scope. |
| `barcode-scanner:deny-cancel` | Denies the cancel command without any pre-configured scope. |
| `barcode-scanner:allow-check-permissions` | Enables the check_permissions command without any pre-configured scope. |
| `barcode-scanner:deny-check-permissions` | Denies the check_permissions command without any pre-configured scope. |
| `barcode-scanner:allow-open-app-settings` | Enables the open_app_settings command without any pre-configured scope. |
| `barcode-scanner:deny-open-app-settings` | Denies the open_app_settings command without any pre-configured scope. |
| `barcode-scanner:allow-request-permissions` | Enables the request_permissions command without any pre-configured scope. |
| `barcode-scanner:deny-request-permissions` | Denies the request_permissions command without any pre-configured scope. |
| `barcode-scanner:allow-scan` | Enables the scan command without any pre-configured scope. |
| `barcode-scanner:deny-scan` | Denies the scan command without any pre-configured scope. |
| `barcode-scanner:allow-vibrate` | Enables the vibrate command without any pre-configured scope. |
| `barcode-scanner:deny-vibrate` | Denies the vibrate command without any pre-configured scope. |
<PluginPermissions plugin="barcode-scanner" />
3 changes: 3 additions & 0 deletions src/content/docs/plugin/biometric.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sidebar:

import Stub from '@components/Stub.astro';
import PluginLinks from '@components/PluginLinks.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="biometric" />

Expand All @@ -17,3 +18,5 @@ import PluginLinks from '@components/PluginLinks.astro';
Based on https://github.com/tauri-apps/plugins-workspace/tree/plugins/biometric

</Stub>

<PluginPermissions plugin="biometric" />
7 changes: 2 additions & 5 deletions src/content/docs/plugin/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sidebar:
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="cli" />

Expand Down Expand Up @@ -284,8 +285,4 @@ See [Permissions Overview](/security/permissions/) for more information.
}
```

| Permission | Description |
| ----------------------- | ----------------------------------------------------------------- |
| `cli:default` | Allows reading the CLI matches. |
| `cli:allow-cli-matches` | Enables the cli_matches command without any pre-configured scope. |
| `cli:deny-cli-matches` | Denies the cli_matches command without any pre-configured scope. |
<PluginPermissions plugin="cli" />
3 changes: 3 additions & 0 deletions src/content/docs/plugin/clipboard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Stub from '@components/Stub.astro';
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="clipboard-manager" />

Expand Down Expand Up @@ -111,3 +112,5 @@ println!("{:?}", content.unwrap());

</TabItem>
</Tabs>

<PluginPermissions plugin="clipboard-manager" />
7 changes: 2 additions & 5 deletions src/content/docs/plugin/deep-linking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sidebar:
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="deep-link" />

Expand Down Expand Up @@ -227,8 +228,4 @@ See [Permissions Overview](/security/permissions/) for more information.
}
```

| Permission | Description |
| ----------------------------- | ----------------------------------------------------------------- |
| `deep-link:default` | Allows reading the opened deep link via the get_current command. |
| `deep-link:allow-get-current` | Enables the get_current command without any pre-configured scope. |
| `deep-link:deny-get-current` | Denies the get_current command without any pre-configured scope. |
<PluginPermissions plugin="deep-link" />
3 changes: 3 additions & 0 deletions src/content/docs/plugin/dialog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tableOfContents:
import PluginLinks from '@components/PluginLinks.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin="dialog" />

Expand Down Expand Up @@ -304,3 +305,5 @@ app.dialog()
// return a file_path `Option`, or `None` if the user closes the dialog
});
```

<PluginPermissions plugin="dialog" />
Loading
Loading