Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1513 -> Production: check top level folder permissions #1517

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading