Skip to content

Commit

Permalink
permissions, some docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Aug 10, 2023
1 parent d9a50e9 commit 0410436
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 19 deletions.
22 changes: 8 additions & 14 deletions debug/launch/graph.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { Logger, LogLevel } from "@pnp/logging";
import { graphSetup } from "./setup.js";
import "@pnp/graph/sites";
import "@pnp/graph/users";
import "@pnp/graph/files";
import "@pnp/graph/operations";

declare var process: { exit(code?: number): void };

export async function Example(settings: any) {

const graph = graphSetup(settings);
const graph = graphSetup(settings);

const site = await graph.sites.getByUrl("318studios.sharepoint.com", "/sites/dev")
const users = await graph.users();

const ops = await site.operations();

Logger.log({
data: users,
level: LogLevel.Info,
message: "List of Users Data",
});

Logger.log({
data: ops,
level: LogLevel.Info,
message: "List of Users Data",
});

process.exit(0);
process.exit(0);
}
4 changes: 2 additions & 2 deletions debug/launch/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ITestingSettings } from "../../test/load-settings.js";
// add your debugging imports here and prior to submitting a PR git checkout debug/debug.ts
// will allow you to keep all your debugging files locally
// comment out the example
// import { Example } from "./sp.js";
import { Example } from "./graph.js";
import { Example } from "./sp.js";
// import { Example } from "./graph.js";

// setup the connection to SharePoint using the settings file, you can
// override any of the values as you want here, just be sure not to commit
Expand Down
79 changes: 79 additions & 0 deletions docs/graph/permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# @pnp/graph/permissions

Allows you to manipulate the permissions of various entities.

[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md)

## site permissions

[![Official Docs](https://img.shields.io/badge/Official_Graph_Docs-social.svg)](https://learn.microsoft.com/en-us/graph/api/resources/permission?view=graph-rest-1.0)

Allows you to manage application permissions for sites.

### list site permissions

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/sites";
import "@pnp/graph/permissions";

const graph = graphfi(...);

const permissions = await graph.sites.getById("{site id}").permissions();
```

### get a site permission

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/sites";
import "@pnp/graph/permissions";

const graph = graphfi(...);

const permissions = await graph.sites.getById("{site id}").permissions.getById("{permission id}")();
```

### add a site permission

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/sites";
import "@pnp/graph/permissions";

const graph = graphfi(...);

const permissions = await graph.sites.getById("{site id}").permissions.add({
roles: ["fullcontrol"],
grantedToIdentities: [{
id: "89ea5c94-7736-4e25-95ad-3fa95f62b66e",
displayName: "Contoso Time Manager App",
}],
});
```

### update a site permission

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/sites";
import "@pnp/graph/permissions";

const graph = graphfi(...);

const permissions = await graph.sites.getById("{site id}").permissions.getById("{permission id}").update({
roles: ["read"],
});
```

### delete a site permission

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/sites";
import "@pnp/graph/permissions";

const graph = graphfi(...);

const permissions = await graph.sites.getById("{site id}").permissions.getById("{permission id}").delete();
```
2 changes: 1 addition & 1 deletion docs/graph/shares.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const shareInfo = await graph.shares.getById(shareLink)();

## Access a Share's driveItem resource

You can also access the full functionality of the driveItem via a share. Find [more details on the capabilities of driveItem here](./onedrive.md).
You can also access the full functionality of the driveItem via a share. Find [more details on the capabilities of driveItem here](./files.md).

```TS
import { graphfi } from "@pnp/graph";
Expand Down
2 changes: 1 addition & 1 deletion docs/graph/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ See [Messages](./messages.md)

## User OneDrive

See [OneDrive](./onedrive.md)
See [Files](./files.md)
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nav:
- 'In NodeJS': 'concepts/auth-nodejs.md'
- 'Batching': 'concepts/batching.md'
- 'Batching & Caching': 'concepts/batching-caching.md'
- 'Calling Other Endpoints': 'concepts/calling-other-endpoints'
- 'Calling Other Endpoints': 'concepts/calling-other-endpoints.md'
- 'Custom Bundling': 'concepts/custom-bundle.md'
- 'Error-Handling': 'concepts/error-handling.md'
- 'Project Config/Services Setup': 'concepts/project-preset.md'
Expand Down Expand Up @@ -56,6 +56,7 @@ nav:
- messages: 'graph/messages.md'
- outlook: 'graph/outlook.md'
- operations: 'graph/operations.md'
- permissions: 'graph/permissions.md'
- photos: 'graph/photos.md'
- planner: 'graph/planner.md'
- search: 'graph/search.md'
Expand Down
8 changes: 8 additions & 0 deletions packages/graph/permissions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "./site.js";

export {
IPermission,
IPermissions,
Permission,
Permissions,
} from "./types.js";
14 changes: 14 additions & 0 deletions packages/graph/permissions/site.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { addProp } from "@pnp/queryable";
import { _Site } from "../sites/types.js";
import { IPermissions, Permissions } from "./types.js";

declare module "../sites/types" {
interface _Site {
readonly permissions: IPermissions;
}
interface ISite {
readonly permissions: IPermissions;
}
}

addProp(_Site, "permissions", Permissions);
29 changes: 29 additions & 0 deletions packages/graph/permissions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { body } from "@pnp/queryable";
import { IDeleteable, IGetById, IUpdateable, defaultPath, deleteable, getById, updateable } from "../decorators.js";
import { graphInvokableFactory, _GraphCollection, _GraphInstance } from "../graphqueryable.js";
import { Permission as IPermissionType } from "@microsoft/microsoft-graph-types";
import { graphPost } from "../ops.js";

/**
* Permission
*/
@deleteable()
@updateable()
export class _Permission extends _GraphInstance<IPermissionType> {}
export interface IPermission extends _Permission, IUpdateable<Partial<IPermissionType>>, IDeleteable { }
export const Permission = graphInvokableFactory<IPermission>(_Permission);

/**
* Permissions
*/
@defaultPath("permissions")
@getById(Permission)
export class _Permissions extends _GraphCollection<IPermissionType[]> {

public add(permissions: Pick<IPermissionType, "roles"| "grantedToIdentities"| "expirationDateTime">): Promise<IPermissionType> {

return graphPost(this, body(permissions));
}
}
export interface IPermissions extends _Permissions, IGetById<IPermission> { }
export const Permissions = graphInvokableFactory<IPermissions>(_Permissions);

0 comments on commit 0410436

Please sign in to comment.