-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2932 from juliemturner/version-4
Graph Files Updates - Still a couple failing tests
- Loading branch information
Showing
15 changed files
with
782 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,92 @@ | ||
import { Logger, LogLevel } from "@pnp/logging"; | ||
import { graphSetup } from "./setup.js"; | ||
import "@pnp/graph/users"; | ||
import "@pnp/graph/groups"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/files"; | ||
import { IDriveItemAdd, IDriveItemAddFolder } from "@pnp/graph/files"; | ||
import * as fs from "fs"; | ||
import { IResumableUploadOptions } from "@pnp/graph/files"; | ||
import { graphPut } from "@pnp/graph"; | ||
import { InjectHeaders } from "@pnp/queryable/index.js"; | ||
import { DriveItemUploadableProperties } from "@microsoft/microsoft-graph-types"; | ||
import { ISensitivityLabel } from "@pnp/graph/files"; | ||
|
||
declare var process: { exit(code?: number): void }; | ||
|
||
export async function Example(settings: any) { | ||
const userId = "julie@sympjulie.onmicrosoft.com"; | ||
const graph = graphSetup(settings); | ||
|
||
const graph = graphSetup(settings); | ||
const folderInfo: IDriveItemAddFolder = { | ||
name: "Sub Folder", | ||
conflictBehavior: "replace", | ||
}; | ||
|
||
const users = await graph.users(); | ||
const fileInfo: IDriveItemAdd = { | ||
filename: "Test File.txt", | ||
content: "Contents of test file", | ||
contentType: "text/plain", | ||
conflictBehavior: "replace", | ||
}; | ||
|
||
Logger.log({ | ||
data: users, | ||
level: LogLevel.Info, | ||
message: "List of Users Data", | ||
}); | ||
//const users = await graph.users.getById(userId).drive.root.children.addFolder(folderInfo); | ||
//const folder = await graph.users.getById(userId).drive.getItemByPath("/Test Folder")(); | ||
//const folder = await graph.users.getById(userId).drive.root.getItemByPath("/Test Folder")(); | ||
|
||
process.exit(0); | ||
//const file = await graph.users.getById(userId).drive.root.children.add(fileInfo); | ||
|
||
// const moveItem = { | ||
// parentReference: { | ||
// id: folder.id, | ||
// }, | ||
// name: "Moved File.txt", | ||
// } | ||
// const move = await graph.users.getById(userId).drive.getItemById(file.id).moveItem(moveItem); | ||
//const thumbnails = await graph.users.getById(userId).drive.getItemById(folder.id).thumbnails(); | ||
//const versions = await graph.users.getById(userId).drive.getItemById(folder.id).versions(); | ||
//const users = await graph.sites.getById(settings.testing.graph.id).drive.list(); | ||
|
||
const fileBuff = fs.readFileSync("C:\\Users\\jturner.BMA\\Desktop\\TestDocument.docx"); | ||
|
||
const fileUploadOptions: IResumableUploadOptions<DriveItemUploadableProperties> = { | ||
item: { | ||
name: "TestDocument2.docx", | ||
fileSize: fileBuff.byteLength, | ||
}, | ||
}; | ||
|
||
const label: ISensitivityLabel = { | ||
sensitivityLabelId: "b7a3c3d5-7b6d-4e6c-8e0c-3f5c7b1d0e3d", | ||
assignmentMethod: "standard", | ||
justificationText: "Just because", | ||
}; | ||
|
||
const driveRoot = await graph.sites.getById(settings.testing.graph.id).drive.root(); | ||
const driveItems = await graph.sites.getById(settings.testing.graph.id).drive.root.children(); | ||
const driveItem = await graph.sites.getById(settings.testing.graph.id).drive.getItemById(driveItems[1].id)(); | ||
const retentionLabelStatusUrl = await graph.sites.getById(settings.testing.graph.id).drive.getItemById(driveItems[1].id).assignSensitivityLabel(label); | ||
//const retentionLabel = await graph.users.getById(userId).drive.getItemById(driveItems[0].id).extractSensitivityLabels(); | ||
const uploadSession = await graph.users.getById(userId).drive.getItemById(driveRoot.id).createUploadSession(fileUploadOptions); | ||
const status = await uploadSession.resumableUpload.status(); | ||
|
||
const upload = await uploadSession.resumableUpload.upload(fileBuff.length, fileBuff); | ||
|
||
// Upload a chunk of the file to the upload session | ||
// Using a fragment size that doesn't divide evenly by 320 KiB results in errors committing some files. | ||
const chunkSize = 327680; | ||
let startFrom = 0; | ||
while (startFrom < fileBuff.length) { | ||
const fileChunk = fileBuff.slice(startFrom, startFrom + chunkSize); | ||
const contentLength = `bytes ${startFrom}-${startFrom + chunkSize}/${fileBuff.length}` | ||
const uploadChunk = await uploadSession.resumableUpload.upload(chunkSize, fileChunk, contentLength); | ||
startFrom += chunkSize; | ||
} | ||
Logger.log({ | ||
data: retentionLabelStatusUrl, | ||
level: LogLevel.Info, | ||
message: "List of Users Data", | ||
}); | ||
|
||
process.exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# @pnp/graph/files - Sensitivity and Retention Labels (Premium Endpoint) | ||
|
||
The ability to manage sensitivity and retention labels on drive items in SharePoint. | ||
|
||
More information can be found in the official Graph documentation: | ||
|
||
- [Drives/Files Resource Type](https://learn.microsoft.com/en-us/graph/api/resources/drive?view=graph-rest-1.0) | ||
|
||
## IInvitations | ||
|
||
[![Invokable Banner](https://img.shields.io/badge/Invokable-informational.svg)](../concepts/invokable.md) [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) | ||
|
||
## Assign Sensitivity Label to Drive Item | ||
|
||
Using the assignSensitivityLabel() you can add a sensitivity label to a DriveItem | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/users"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/groups"; | ||
import "@pnp/graph/files"; | ||
import { ISensitivityLabel } from "@pnp/graph/files"; | ||
|
||
const graph = graphfi(...); | ||
|
||
const label: ISensitivityLabel = { | ||
sensitivityLabelId: "b7a3c3d5-7b6d-4e6c-8e0c-3f5c7b1d0e3d", | ||
assignmentMethod: "standard", | ||
justificationText: "Just because", | ||
}; | ||
|
||
// This is a long running operation and returns a url to check the status. | ||
const retentionLabelStatusUrl = await graph.sites.getById({site id}).drive.getItemById({item id}).assignSensitivityLabel(label); | ||
const retentionLabelStatusUrl = await graph.users.getById({user id}).drive.getItemById({item id}).assignSensitivityLabel(label); | ||
const retentionLabelStatusUrl = await graph.group.getById({group id}).drive.getItemById({item id}).assignSensitivityLabel(label); | ||
``` | ||
|
||
## Extract Sensitivity Labels from a Drive Item | ||
|
||
Using extractSensitivityLabels() extract one or more sensitivity labels assigned to a drive item | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/users"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/groups"; | ||
import "@pnp/graph/files"; | ||
|
||
const graph = graphfi(...); | ||
|
||
const sensitivityLabels = await graph.sites.getById({site id}).drive.getItemById({item id}).extractSensitivityLabels(); | ||
const sensitivityLabels = await graph.users.getById({user id}).drive.getItemById({item id}).extractSensitivityLabels(); | ||
const sensitivityLabels = await graph.group.getById({group id}).drive.getItemById({item id}).extractSensitivityLabels(); | ||
``` | ||
|
||
## Retrieve/Update/Delete Retention Label of the Drive Item | ||
|
||
Method for retrieving, updating, and removing the retention label of the drive item. | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/users"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/groups"; | ||
import "@pnp/graph/files"; | ||
|
||
const graph = graphfi(...); | ||
|
||
// Get retention label | ||
const retentionLabel = await graph.sites.getById({site id}).drive.getItemById({item id}).retentionLabel(); | ||
const retentionLabel = await graph.users.getById({user id}).drive.getItemById({item id}).retentionLabel(); | ||
const retentionLabel = await graph.group.getById({group id}).drive.getItemById({item id}).retentionLabel(); | ||
|
||
// Update retention label | ||
const retentionLabel = await graph.sites.getById({site id}).drive.getItemById({item id}).updateRetentionLabel("New Name"); | ||
const retentionLabel = await graph.users.getById({user id}).drive.getItemById({item id}).updateRetentionLabel("New Name"); | ||
const retentionLabel = await graph.group.getById({group id}).drive.getItemById({item id}).updateRetentionLabel("New Name"); | ||
|
||
// Delete retention label | ||
await graph.sites.getById({site id}).drive.getItemById({item id}).removeRetentionLabel(); | ||
await graph.users.getById({user id}).drive.getItemById({item id}).removeRetentionLabel(); | ||
await graph.group.getById({group id}).drive.getItemById({item id}).removeRetentionLabel(); | ||
``` | ||
|
||
## Lock/Unlock Record of the Drive Item | ||
|
||
Method for locking/unlocking a record of the drive item. | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/users"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/groups"; | ||
import "@pnp/graph/files"; | ||
|
||
const graph = graphfi(...); | ||
|
||
// Send 'true' to lock the record, and 'false' to unlock the record. | ||
const retentionLabel = await graph.sites.getById({site id}).drive.getItemById({item id}).recordLocked(true); | ||
const retentionLabel = await graph.users.getById({user id}).drive.getItemById({item id}).recordLocked(true); | ||
const retentionLabel = await graph.group.getById({group id}).drive.getItemById({item id}).recordLocked(true); | ||
``` |
Oops, something went wrong.