edit permissions

This commit is contained in:
alexweininger 2021-04-22 01:19:22 -07:00
parent 799da899ae
commit 3f7bf3dc8b
12 changed files with 151 additions and 37 deletions

View file

@ -12,17 +12,21 @@ From [appwrite.io](https://appwrite.io)
## Features
### View database documents right inside VS Code.
![Database feature](./media/features/database/scr2.png)
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
### Manage database collection permissions and rules.
For example if there is an image subfolder under your extension project workspace:
![Database feature](./media/features/database/scr1.png)
### Create and view users, user preferences, and more.
![Users feature](./media/features/users/scr1.png)
### Quickly and easily check the health of all the Appwrite services.
### Check the health of all the Appwrite services.
![Health feature](./media/features/health/scr1.png)
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements
This extension does not provide features for setting up or installing Appwrite. Only managing and interacting with Appwrite once it's running.
@ -35,20 +39,30 @@ For example:
This extension contributes the following settings:
* `myExtension.enable`: enable/disable this extension
* `myExtension.thing`: set to `blah` to do something
* `appwrite.projects`: List of Appwrite project configurations. To set up a project configuration, run the `Connect to Appwrite` command. Search commands by hitting <kbd>F1</kbd>, then search `Connect to Appwrite`.
After connecting to an Appwrite project, your `appwrite.projects` setting will contain:
```json
{
"endpoint": "https://[Domain]/v1",
"projectId": "[Project ID]",
"secret": "API key with all scopes",
"nickname": "My project"
}
```
We plan on adding better multi-project support in the future.
## Known Issues
Calling out known issues can help limit users opening duplicate issues against your extension.
## Release Notes
Users appreciate release notes as you update your extension.
If you find issues, or want to suggest features, please file them in the issues section of the repository.
### 1.0.0
Initial release of the Appwrite extension for VS Code
Initial release of the Appwrite extension for VS Code.
The initial release only includes features for Database, Users, and Health Appwrite APIs. However support for Storage and Functions APIs is on the way.
-----------------------------------------------------------------------------------------------------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View file

@ -25,15 +25,8 @@
"commands": [
{
"command": "vscode-appwrite.Connect",
"title": "Connect to Appwrite"
},
{
"command": "vscode-appwrite.AddProject",
"title": "Add an Appwrite project"
},
{
"command": "vscode-appwrite.SelectProject",
"title": "Select an Appwrite project"
"title": "Connect to Appwrite",
"category": ""
},
{
"command": "vscode-appwrite.CreateUser",
@ -232,8 +225,7 @@
"view/item/context": [
{
"command": "vscode-appwrite.viewUserPrefs",
"when": "viewItem == users.prefs",
"group": "inline"
"when": "viewItem == user"
},
{
"command": "vscode-appwrite.DeleteUser",
@ -318,6 +310,78 @@
"when": "viewItem =~ /^(permission)$/",
"group": "inline"
}
],
"commandPalette": [
{
"command": "vscode-appwrite.Connect"
},
{
"command": "vscode-appwrite.CreateUser"
},
{
"command": "vscode-appwrite.DeleteUser",
"when": "viewItem == user"
},
{
"command": "vscode-appwrite.GetUserLogs",
"when": "viewItem == user"
},
{
"command": "vscode-appwrite.openUserInConsole",
"when": "viewItem == user"
},
{
"command": "vscode-appwrite.viewUserPrefs",
"when": "viewItem == user"
},
{
"command": "vscode-appwrite.copyUserId",
"when": "viewItem == user.id"
},
{
"command": "vscode-appwrite.copyUserEmail",
"when": "viewItem == user.email"
},
{
"command": "vscode-appwrite.viewDocumentAsJson",
"when": "viewItem == document"
},
{
"command": "vscode-appwrite.viewCollectionAsJson",
"when": "viewItem == collection"
},
{
"command": "vscode-appwrite.refreshCollection",
"when": "viewItem == collection"
},
{
"command": "vscode-appwrite.createRule",
"when": "viewItem == collection.rules"
},
{
"command": "vscode-appwrite.removeRule",
"when": "viewItem == rule"
},
{
"command": "vscode-appwrite.deleteDocument",
"when": "viewItem == document"
},
{
"command": "vscode-appwrite.deleteCollection",
"when": "viewItem == collection"
},
{
"command": "vscode-appwrite.createPermission",
"when": "viewItem == collection.permissions"
},
{
"command": "vscode-appwrite.deletePermission",
"when": "viewItem =~ /^(permission)$/"
},
{
"command": "vscode-appwrite.editPermission",
"when": "viewItem =~ /^(permission)$/"
}
]
},
"viewsContainers": {

View file

@ -11,7 +11,6 @@ export class Users {
this.users = new sdk.Users(client);
}
public async createNewUser(context: CreateUserContext): Promise<void> {
ext.outputChannel?.appendLog("Creating new user" + JSON.stringify(context));
await AppwriteCall<User, void>(this.users.create(context.email, context.password, context.name), (user) => {
window.showInformationMessage(`Created user with id: ${user.$id}`);
});

View file

@ -1,8 +1,8 @@
import { window } from "vscode";
import { databaseClient } from '../../client';
import { CollapsableTreeItem } from '../../tree/CollapsableTreeItem';
import { PermissionsTreeItem } from "../../tree/database/settings/PermissionsTreeItem";
import { PermissionTreeItem } from "../../tree/database/settings/PermissionTreeItem";
import { databaseClient } from '../../../client';
import { CollapsableTreeItem } from '../../../tree/CollapsableTreeItem';
import { PermissionsTreeItem } from "../../../tree/database/settings/PermissionsTreeItem";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export type CreatePermissionWizardContext = {
kind: "read" | "write";

View file

@ -1,5 +1,5 @@
import { databaseClient } from "../../client";
import { PermissionTreeItem } from "../../tree/database/settings/PermissionTreeItem";
import { databaseClient } from "../../../client";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export async function deletePermission(treeItem: PermissionTreeItem): Promise<void> {
const collection = treeItem.parent.parent.collection;

View file

@ -0,0 +1,29 @@
import { window } from 'vscode';
import { databaseClient } from '../../../client';
import { PermissionTreeItem } from '../../../tree/database/settings/PermissionTreeItem';
export async function editPermission(treeItem: PermissionTreeItem): Promise<void> {
const editedPermission = await window.showInputBox({
value: treeItem.permission,
});
if (editedPermission === undefined) {
return;
}
const collection = treeItem.parent.parent.collection;
const kind = treeItem.kind;
let read = Array.from(collection.$permissions.read);
let write = Array.from(collection.$permissions.write);
if (kind === "read") {
read = read.filter((item) => item !== treeItem.permission);
read.push(editedPermission);
} else {
write = write.filter((item) => item !== treeItem.permission);
write.push(editedPermission);
}
await databaseClient.updatePermissions(collection, read, write);
}

View file

@ -3,11 +3,11 @@ import { AppwriteTree, ext } from "../extensionVariables";
import { refreshTree } from "../utils/refreshTree";
import { connectAppwrite } from "./connectAppwrite";
import { createCollection } from "./database/createCollection";
import { createPermission } from './database/createPermission';
import { createPermission } from './database/permissions/createPermission';
import { createRule } from "./database/createRule";
import { deleteCollection } from "./database/deleteCollection";
import { deleteDocument } from "./database/deleteDocument";
import { deletePermission } from './database/deletePermission';
import { deletePermission } from './database/permissions/deletePermission';
import { viewDocumentAsJson } from "./database/openDocument";
import { refreshCollection } from "./database/refreshCollection";
import { refreshCollectionsList } from "./database/refreshCollectionsList";
@ -23,6 +23,7 @@ import { getUserLogs } from "./users/getUserLogs";
import { openUserInConsole } from "./users/openUserInConsole";
import { refreshUsersList } from "./users/refreshUsersList";
import { viewUserPrefs } from "./users/viewUserPrefs";
import { editPermission } from './database/permissions/editPermission';
class CommandRegistrar {
constructor(private readonly context: ExtensionContext) {}
@ -56,7 +57,6 @@ export function registerCommands(context: ExtensionContext): void {
registerCommand("OpenDatabaseDocumentation", () => openDocumentation('database'));
registerCommand("GetUserLogs", getUserLogs);
registerCommand("viewDocumentAsJson", viewDocumentAsJson);
registerCommand("AddProject", addProject);
registerCommand("viewCollectionAsJson", viewCollectionAsJson);
registerCommand("createRule", createRule);
registerCommand("removeRule", removeRule);
@ -69,4 +69,5 @@ export function registerCommands(context: ExtensionContext): void {
registerCommand("deletePermission", deletePermission, 'database');
registerCommand("refreshHealth", () => {}, 'health');
registerCommand("openHealthDocumentation", () => openDocumentation('health'));
registerCommand("editPermission", editPermission, 'database');
}

View file

@ -1,11 +1,13 @@
import { UserPrefsTreeItem } from "../../tree/users/properties/UserPrefsTreeItem";
import { UserTreeItem } from '../../tree/users/UserTreeItem';
import { openReadOnlyJson } from "../../ui/openReadonlyContent";
export async function viewUserPrefs(item: UserPrefsTreeItem) {
const prefs = item.parent.user.prefs;
export async function viewUserPrefs(item: UserPrefsTreeItem | UserTreeItem) {
const userItem = item instanceof UserPrefsTreeItem ? item.parent : item;
const prefs = userItem.user.prefs;
await openReadOnlyJson(
{ label: `prefs`, fullId: `${item.parent.user.$id}.prefs` },
{ label: `prefs`, fullId: `${userItem.user.$id}.prefs` },
prefs
);
}

View file

@ -6,6 +6,11 @@ export class UserPrefsTreeItem extends UserPropertyTreeItemBase {
constructor(parent: UserTreeItem) {
super(parent, 'View preferences');
this.command = {
command: 'vscode-appwrite.viewUserPrefs',
title: 'View user preferences',
arguments: [this]
};
}
iconPath = new ThemeIcon("json");