Share via


Permission class

Use to read, replace, or delete a given Permission by id.

See Permissions to create, upsert, query, or read all Permissions.

Properties

id
url

Returns a reference URL to the resource. Used for linking in Permissions.

user

Methods

delete(RequestOptions)

Delete the given Permission.

Example

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const user = database.user("<user-id>");

await user.permission("<permission-id>").delete();
read(RequestOptions)

Read the PermissionDefinition of the given Permission.

Example

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const user = database.user("<user-id>");

const { resource: permission } = await user.permission("<permission-id>").read();
replace(PermissionDefinition, RequestOptions)

Replace the given Permission with the specified PermissionDefinition.

Example

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const user = database.user("<user-id>");
const { resource: permission } = await user.permission("<permission-id>").read();
permission.resource = "<new-resource-url>";

await user.permission("<permission-id>").replace(permission);

Property Details

id

id: string

Property Value

string

url

Returns a reference URL to the resource. Used for linking in Permissions.

string url

Property Value

string

user

user: User

Property Value

Method Details

delete(RequestOptions)

Delete the given Permission.

Example

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const user = database.user("<user-id>");

await user.permission("<permission-id>").delete();
function delete(options?: RequestOptions): Promise<PermissionResponse>

Parameters

options
RequestOptions

Returns

read(RequestOptions)

Read the PermissionDefinition of the given Permission.

Example

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const user = database.user("<user-id>");

const { resource: permission } = await user.permission("<permission-id>").read();
function read(options?: RequestOptions): Promise<PermissionResponse>

Parameters

options
RequestOptions

Returns

replace(PermissionDefinition, RequestOptions)

Replace the given Permission with the specified PermissionDefinition.

Example

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const user = database.user("<user-id>");
const { resource: permission } = await user.permission("<permission-id>").read();
permission.resource = "<new-resource-url>";

await user.permission("<permission-id>").replace(permission);
function replace(body: PermissionDefinition, options?: RequestOptions): Promise<PermissionResponse>

Parameters

options
RequestOptions

Returns