Skip to content

Commit

Permalink
check top level folder permissions
Browse files Browse the repository at this point in the history
Use the full url of a file to find the top-level folder with permission data

closes #1513
  • Loading branch information
TangoYankee committed Apr 19, 2024
1 parent a744df0 commit 2ff1f42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
48 changes: 19 additions & 29 deletions server/src/document/document.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function hyphenateGUID(unhyphenatedGUID) {
].join("");
}

//
// Note that <folder_name> has this format:
// <dcp_name>_<RECORDID>
//
// where dcp_name is usually the dcp_name property on the entity (e.g. package, artifact, or projectaction)
Expand All @@ -58,7 +58,9 @@ function hyphenateGUID(unhyphenatedGUID) {
//
// We have assurance of this after sprint 10 EAS enhancements. See
// https://dcp-paperless.visualstudio.com/dcp-paperless-dynamics/_workitems/edit/13366
function getRecordIdFromFolderName(documentName: string) {
function getRecordIdFromFileUrl(url: string) {
const urlSegments = url.split("/");
const documentName = urlSegments[6];
const documentSegments = documentName.split("_");
const strippedRecordId = documentSegments[documentSegments.length - 1];

Expand Down Expand Up @@ -94,16 +96,13 @@ export class DocumentService {
}
// For info on the path param,
// see above documentation for the getRecordIdFromDocumentPath function
public async getPackageDocument(fileId) {
public async getPackageDocument(fileId: string) {
const driveId = this.sharepointService.driveIdMap.dcp_package;
const {
parentReference
} = await this.sharepointService.getSharepointFileParentReference(
const { webUrl } = await this.sharepointService.getSharepointFileUrl(
driveId,
fileId
);
const { name: parentName } = parentReference;
const recordId = getRecordIdFromFolderName(parentName);
const recordId = getRecordIdFromFileUrl(webUrl);

try {
// Only documents belonging to public, submitted packages should be accessible
Expand Down Expand Up @@ -132,7 +131,7 @@ export class DocumentService {

if (!firstPackage) {
throwNoDocumentError(
`Client attempted to retrieve document ${parentName}, but no associated public, submitted packages were found.`
`Client attempted to retrieve document ${fileId}, but no associated public, submitted packages were found.`
);
}

Expand All @@ -150,16 +149,13 @@ export class DocumentService {
);
}

public async getArtifactDocument(fileId) {
public async getArtifactDocument(fileId: string) {
const driveId = this.sharepointService.driveIdMap.dcp_artifact;
const {
parentReference
} = await this.sharepointService.getSharepointFileParentReference(
const { webUrl } = await this.sharepointService.getSharepointFileUrl(
driveId,
fileId
);
const { name: parentName } = parentReference;
const recordId = getRecordIdFromFolderName(parentName);
const recordId = getRecordIdFromFileUrl(webUrl);

try {
const {
Expand All @@ -177,7 +173,7 @@ export class DocumentService {

if (!firstArtifact) {
throwNoDocumentError(
`Client attempted to retrieve document ${parentName}, but no associated public, submitted artifacts were found.`
`Client attempted to retrieve document ${fileId}, but no associated public, submitted artifacts were found.`
);
}

Expand All @@ -197,14 +193,11 @@ export class DocumentService {

public async getProjectactionDocument(fileId: string) {
const driveId = this.sharepointService.driveIdMap.dcp_projectaction;
const {
parentReference
} = await this.sharepointService.getSharepointFileParentReference(
const { webUrl } = await this.sharepointService.getSharepointFileUrl(
driveId,
fileId
);
const { name: parentName } = parentReference;
const recordId = getRecordIdFromFolderName(parentName);
const recordId = getRecordIdFromFileUrl(webUrl);

try {
const {
Expand All @@ -222,7 +215,7 @@ export class DocumentService {

if (!firstProjectaction) {
throwNoDocumentError(
`Client attempted to retrieve document ${parentName}, but no associated inactive project actions were found.`
`Client attempted to retrieve document ${fileId}, but no associated inactive project actions were found.`
);
}

Expand All @@ -241,17 +234,14 @@ export class DocumentService {
);
}

public async getDispositionDocument(fileId) {
public async getDispositionDocument(fileId: string) {
const driveId = this.sharepointService.driveIdMap
.dcp_communityboarddisposition;
const {
parentReference
} = await this.sharepointService.getSharepointFileParentReference(
const { webUrl } = await this.sharepointService.getSharepointFileUrl(
driveId,
fileId
);
const { name: parentName } = parentReference;
const recordId = getRecordIdFromFolderName(parentName);
const recordId = getRecordIdFromFileUrl(webUrl);

try {
const {
Expand All @@ -271,7 +261,7 @@ export class DocumentService {

if (!firstDisposition) {
throwNoDocumentError(
`Client attempted to retrieve document ${parentName}, but no associated public, submitted dispositions were found.`
`Client attempted to retrieve document ${fileId}, but no associated public, submitted dispositions were found.`
);
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/sharepoint/sharepoint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ export class SharepointService {
}
}

async getSharepointFileParentReference(driveId: string, fileId: string) {
async getSharepointFileUrl(driveId: string, fileId: string) {
const { accessToken } = await this.msalProvider.getGraphClientToken();

const url = `${
this.msalProvider.sharePointSiteUrl
}/drives/${driveId}/items/${fileId}?$select=parentReference`;
}/drives/${driveId}/items/${fileId}?$select=webUrl`;
const options = {
method: "GET",
headers: {
Expand Down

0 comments on commit 2ff1f42

Please sign in to comment.