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

[ACA-2259] Edit in Microsoft Office - check update permissions #1015

Merged
merged 10 commits into from
Mar 14, 2019
47 changes: 47 additions & 0 deletions projects/adf-office-services-ext/src/lib/evaluators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,50 @@ describe('evaluators', () => {
expect(canOpenWithOffice(context)).toBeFalsy();
});

it('should return [false] if permissions check is false', () => {
const context: any = {
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {}
}
}
},
permissions: {
check: () => false
}
};

expect(canOpenWithOffice(context)).toBeFalsy();
});

it('should check the [update] permission when selected file has allowableOperationsOnTarget', () => {
let checkOnTarget = '';
const context: any = {
selection: {
file: {
entry: {
name: 'document.docx',
isLocked: false,
properties: {},
allowableOperationsOnTarget: {}
}
}
},
permissions: {
check: (source: any, permissions: string[], options?: any) => {
checkOnTarget = options && options.target;
return true;
}
}
};

expect(canOpenWithOffice(context)).toBeTruthy();
expect(checkOnTarget).toEqual('allowableOperationsOnTarget');
});

it('should return [true] if all checks succeed', () => {
const context: any = {
selection: {
Expand All @@ -199,6 +243,9 @@ describe('evaluators', () => {
properties: {}
}
}
},
permissions: {
check: () => true
}
};

Expand Down
8 changes: 7 additions & 1 deletion projects/adf-office-services-ext/src/lib/evaluators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ export function canOpenWithOffice(
return false;
}

return true;
if (file.entry.hasOwnProperty('allowableOperationsOnTarget')) {
return context.permissions.check(file, ['update'], {
DenysVuika marked this conversation as resolved.
Show resolved Hide resolved
target: 'allowableOperationsOnTarget'
});
}

return context.permissions.check(file, ['update']);
}