Skip to content

Commit 8e96f89

Browse files
vasfvitordreyfus92lucasfernog
authored
feat: Plugin permissions component (tauri-apps#1890)
Co-authored-by: Paul Valladares <[email protected]> Co-authored-by: Lucas Nogueira <[email protected]>
1 parent 779e359 commit 8e96f89

26 files changed

+99
-457
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
import { createMarkdownProcessor } from '@astrojs/markdown-remark';
3+
import fs from 'fs/promises';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
interface Props {
8+
plugin: string;
9+
}
10+
11+
const { plugin } = Astro.props;
12+
13+
async function importMDX(plugin: string): Promise<string> {
14+
const base = fileURLToPath(import.meta.url);
15+
const dirname = path.dirname(base);
16+
17+
const mdPath = path.join(
18+
dirname,
19+
'../../packages/plugins-workspace/plugins',
20+
plugin,
21+
'permissions/autogenerated',
22+
'reference.md'
23+
);
24+
25+
try {
26+
const content = await fs.readFile(mdPath, 'utf-8');
27+
return content;
28+
} catch (err) {
29+
console.error(`Error reading file ${mdPath}: ${err}`);
30+
throw err;
31+
}
32+
}
33+
const md = await createMarkdownProcessor();
34+
35+
const pageContent: string = await importMDX(plugin);
36+
const content = await md.render(pageContent);
37+
---
38+
39+
<Fragment set:html={content.code} />

src/content/docs/learn/Security/using-plugin-permissions.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ permissions are used.
9898

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

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

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

153153
Let us assume we want to enable writing to a text file `test.txt`

src/content/docs/plugin/autostart.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sidebar:
1010
import PluginLinks from '@components/PluginLinks.astro';
1111
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1212
import CommandTabs from '@components/CommandTabs.astro';
13+
import PluginPermissions from '@components/PluginPermissions.astro';
1314

1415
<PluginLinks plugin="autostart" />
1516

@@ -144,11 +145,4 @@ See the [Capabilities Overview](/security/capabilities/) for more information an
144145
}
145146
```
146147

147-
| Permission | Description |
148-
| ---------------------------- | ---------------------------------------------------------------- |
149-
| `autostart:allow-disable` | Enables the disable command without any pre-configured scope. |
150-
| `autostart:deny-disable` | Denies the disable command without any pre-configured scope. |
151-
| `autostart:allow-enable` | Enables the enable command without any pre-configured scope. |
152-
| `autostart:deny-enable` | Denies the enable command without any pre-configured scope. |
153-
| `autostart:allow-is-enabled` | Enables the is_enabled command without any pre-configured scope. |
154-
| `autostart:deny-is-enabled` | Denies the is_enabled command without any pre-configured scope. |
148+
<PluginPermissions plugin="autostart" />

src/content/docs/plugin/barcode-scanner.mdx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sidebar:
1010
import PluginLinks from '@components/PluginLinks.astro';
1111
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1212
import CommandTabs from '@components/CommandTabs.astro';
13+
import PluginPermissions from '@components/PluginPermissions.astro';
1314

1415
<PluginLinks plugin="barcode-scanner" />
1516

@@ -104,17 +105,4 @@ See the [Capabilities Overview](/security/capabilities/) for more information an
104105
}
105106
```
106107

107-
| Permission | Description |
108-
| ------------------------------------------- | ------------------------------------------------------------------------- |
109-
| `barcode-scanner:allow-cancel` | Enables the cancel command without any pre-configured scope. |
110-
| `barcode-scanner:deny-cancel` | Denies the cancel command without any pre-configured scope. |
111-
| `barcode-scanner:allow-check-permissions` | Enables the check_permissions command without any pre-configured scope. |
112-
| `barcode-scanner:deny-check-permissions` | Denies the check_permissions command without any pre-configured scope. |
113-
| `barcode-scanner:allow-open-app-settings` | Enables the open_app_settings command without any pre-configured scope. |
114-
| `barcode-scanner:deny-open-app-settings` | Denies the open_app_settings command without any pre-configured scope. |
115-
| `barcode-scanner:allow-request-permissions` | Enables the request_permissions command without any pre-configured scope. |
116-
| `barcode-scanner:deny-request-permissions` | Denies the request_permissions command without any pre-configured scope. |
117-
| `barcode-scanner:allow-scan` | Enables the scan command without any pre-configured scope. |
118-
| `barcode-scanner:deny-scan` | Denies the scan command without any pre-configured scope. |
119-
| `barcode-scanner:allow-vibrate` | Enables the vibrate command without any pre-configured scope. |
120-
| `barcode-scanner:deny-vibrate` | Denies the vibrate command without any pre-configured scope. |
108+
<PluginPermissions plugin="barcode-scanner" />

src/content/docs/plugin/biometric.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ sidebar:
99

1010
import Stub from '@components/Stub.astro';
1111
import PluginLinks from '@components/PluginLinks.astro';
12+
import PluginPermissions from '@components/PluginPermissions.astro';
1213

1314
<PluginLinks plugin="biometric" />
1415

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

1920
</Stub>
21+
22+
<PluginPermissions plugin="biometric" />

src/content/docs/plugin/cli.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sidebar:
1010
import PluginLinks from '@components/PluginLinks.astro';
1111
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1212
import CommandTabs from '@components/CommandTabs.astro';
13+
import PluginPermissions from '@components/PluginPermissions.astro';
1314

1415
<PluginLinks plugin="cli" />
1516

@@ -283,8 +284,4 @@ See the [Capabilities Overview](/security/capabilities/) for more information an
283284
}
284285
```
285286
286-
| Permission | Description |
287-
| ----------------------- | ----------------------------------------------------------------- |
288-
| `cli:default` | Allows reading the CLI matches. |
289-
| `cli:allow-cli-matches` | Enables the cli_matches command without any pre-configured scope. |
290-
| `cli:deny-cli-matches` | Denies the cli_matches command without any pre-configured scope. |
287+
<PluginPermissions plugin="cli" />

src/content/docs/plugin/clipboard.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Stub from '@components/Stub.astro';
1111
import PluginLinks from '@components/PluginLinks.astro';
1212
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1313
import CommandTabs from '@components/CommandTabs.astro';
14+
import PluginPermissions from '@components/PluginPermissions.astro';
1415

1516
<PluginLinks plugin="clipboard-manager" />
1617

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

112113
</TabItem>
113114
</Tabs>
115+
116+
<PluginPermissions plugin="clipboard-manager" />

src/content/docs/plugin/deep-linking.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sidebar:
1010
import PluginLinks from '@components/PluginLinks.astro';
1111
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1212
import CommandTabs from '@components/CommandTabs.astro';
13+
import PluginPermissions from '@components/PluginPermissions.astro';
1314

1415
<PluginLinks plugin="deep-link" />
1516

@@ -226,8 +227,4 @@ See the [Capabilities Overview](/security/capabilities/) for more information an
226227
}
227228
```
228229

229-
| Permission | Description |
230-
| ----------------------------- | ----------------------------------------------------------------- |
231-
| `deep-link:default` | Allows reading the opened deep link via the get_current command. |
232-
| `deep-link:allow-get-current` | Enables the get_current command without any pre-configured scope. |
233-
| `deep-link:deny-get-current` | Denies the get_current command without any pre-configured scope. |
230+
<PluginPermissions plugin="deep-link" />

src/content/docs/plugin/dialog.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tableOfContents:
99
import PluginLinks from '@components/PluginLinks.astro';
1010
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
1111
import CommandTabs from '@components/CommandTabs.astro';
12+
import PluginPermissions from '@components/PluginPermissions.astro';
1213

1314
<PluginLinks plugin="dialog" />
1415

@@ -304,3 +305,5 @@ app.dialog()
304305
// return a file_path `Option`, or `None` if the user closes the dialog
305306
});
306307
```
308+
309+
<PluginPermissions plugin="dialog" />

0 commit comments

Comments
 (0)