diff --git a/angular.json b/angular.json index e7700381c..a2dafd68d 100644 --- a/angular.json +++ b/angular.json @@ -51,12 +51,22 @@ "output": "./assets" }, { - "glob": "**/*.json", + "glob": "**/*", + "input": "node_modules/@alfresco/adf-office-services-ext/assets", + "output": "./assets/adf-office-services-ext" + }, + { + "glob": "**/*", + "input": "projects/adf-office-services-ext/assets", + "output": "./assets/adf-office-services-ext" + }, + { + "glob": "aos.plugin.json", "input": "node_modules/@alfresco/adf-office-services-ext/assets", "output": "./assets/plugins" }, { - "glob": "**/*.json", + "glob": "aos.plugin.json", "input": "projects/adf-office-services-ext/assets", "output": "./assets/plugins" } diff --git a/package.json b/package.json index 45875c995..ab7e44d1d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "build": "npm run build.extensions && npm run build.app -- --prod", "build.e2e": "npm run build.extensions && npm run build.app -- --prod --configuration=e2e", "test": "ng test app --code-coverage", - "test:ci": "npm run build.extensions && ng test app --code-coverage --watch=false", + "test:ci": "npm run build.extensions && ng test adf-office-services-ext --watch=false && ng test app --code-coverage --watch=false", "lint": "ng lint && npm run spellcheck && npm run format:check", "wd:update": "webdriver-manager update --gecko=false", "e2e": "npm run wd:update && protractor --baseUrl=http://localhost:4000", diff --git a/projects/adf-office-services-ext/assets/aos.plugin.json b/projects/adf-office-services-ext/assets/aos.plugin.json index f7093dbd3..3a903057c 100644 --- a/projects/adf-office-services-ext/assets/aos.plugin.json +++ b/projects/adf-office-services-ext/assets/aos.plugin.json @@ -1,7 +1,7 @@ { "$schema": "../../../extension.schema.json", "$id": "9a635542-d87a-4558-ae64-ffa199d1a364", - "$version": "1.0.0", + "$version": "0.0.6", "$name": "keensoft.aos.plugin", "$description": "Extension that provides Office Edit Online Action", "$vendor": "Keensoft", @@ -24,8 +24,8 @@ { "id": "aos.toolbar.openWith.office", "order": 90, - "icon": "adf:application/msword", - "title": "Edit in Microsoft Office™", + "icon": "edit", + "title": "AOS.ACTION_TITLE", "actions": { "click": "aos.openWith.office" }, @@ -40,8 +40,8 @@ { "id": "aos.context.openWith.office", "order": 90, - "icon": "adf:application/msword", - "title": "Edit in Microsoft Office™", + "icon": "edit", + "title": "AOS.ACTION_TITLE", "actions": { "click": "aos.openWith.office" }, @@ -58,8 +58,8 @@ { "id": "aos.viewer.openWith.office", "order": 1, - "icon": "adf:application/msword", - "title": "Microsoft Office™", + "icon": "edit", + "title": "AOS.ACTION_TITLE", "actions": { "click": "aos.openWith.office" }, diff --git a/projects/adf-office-services-ext/assets/i18n/en.json b/projects/adf-office-services-ext/assets/i18n/en.json new file mode 100644 index 000000000..9d146cb18 --- /dev/null +++ b/projects/adf-office-services-ext/assets/i18n/en.json @@ -0,0 +1,5 @@ +{ + "AOS": { + "ACTION_TITLE": "Edit in Microsoft Office™" + } +} diff --git a/projects/adf-office-services-ext/ngi.json b/projects/adf-office-services-ext/ngi.json index 471c8fb4d..edb04a010 100644 --- a/projects/adf-office-services-ext/ngi.json +++ b/projects/adf-office-services-ext/ngi.json @@ -1,7 +1,12 @@ { "assets": [ { - "glob": "**/*.json", + "glob": "**/*", + "input": "./assets", + "output": "./assets/adf-office-services-ext" + }, + { + "glob": "aos.plugin.json", "input": "./assets", "output": "./assets/plugins" } diff --git a/projects/adf-office-services-ext/package.json b/projects/adf-office-services-ext/package.json index 3270785f3..849fd06b6 100644 --- a/projects/adf-office-services-ext/package.json +++ b/projects/adf-office-services-ext/package.json @@ -1,6 +1,6 @@ { "name": "@alfresco/adf-office-services-ext", - "version": "0.0.5", + "version": "0.0.6", "license": "Apache-2.0", "author": { "name": "Keensoft", diff --git a/projects/adf-office-services-ext/src/lib/aos-extension.module.ts b/projects/adf-office-services-ext/src/lib/aos-extension.module.ts index 9f6065730..baafa69c4 100644 --- a/projects/adf-office-services-ext/src/lib/aos-extension.module.ts +++ b/projects/adf-office-services-ext/src/lib/aos-extension.module.ts @@ -6,13 +6,18 @@ import { AosEditOnlineService } from './aos-extension.service'; import { AosEffects } from './effects/aos.effects'; import { canOpenWithOffice } from './evaluators'; +import { TranslationService } from '@alfresco/adf-core'; @NgModule({ imports: [EffectsModule.forFeature([AosEffects])], providers: [AosEditOnlineService] }) export class AosExtensionModule { - constructor(extensions: ExtensionService) { + constructor(extensions: ExtensionService, translation: TranslationService) { + translation.addTranslationFolder( + 'adf-office-services-ext', + 'assets/adf-office-services-ext' + ); extensions.setEvaluators({ 'aos.canOpenWithOffice': canOpenWithOffice }); diff --git a/projects/adf-office-services-ext/src/lib/evaluators.spec.ts b/projects/adf-office-services-ext/src/lib/evaluators.spec.ts new file mode 100644 index 000000000..a16e1b40e --- /dev/null +++ b/projects/adf-office-services-ext/src/lib/evaluators.spec.ts @@ -0,0 +1,208 @@ +import { canOpenWithOffice } from './evaluators'; + +describe('evaluators', () => { + describe('canOpenWithOffice', () => { + it('should return [false] if using SSO', () => { + const context: any = { + auth: { + isOauth() { + return true; + } + } + }; + + expect(canOpenWithOffice(context, null)).toBeFalsy(); + }); + + it('should return [false] if no selection present', () => { + const context: any = { + selection: null + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if no file selected', () => { + const context: any = { + selection: { + file: null + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if selected file has no entry', () => { + const context: any = { + selection: { + file: { + entry: null + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if selected file has no properties', () => { + const context: any = { + selection: { + file: { + entry: { + properties: null + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if selected file is locked', () => { + const context: any = { + selection: { + file: { + entry: { + isLocked: true, + properties: {} + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if selected file has no extension', () => { + const context: any = { + selection: { + file: { + entry: { + name: 'readme', + isLocked: false, + properties: {} + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if extension is not supported', () => { + const context: any = { + selection: { + file: { + entry: { + name: 'run.exe', + isLocked: false, + properties: {} + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if selected file has write lock', () => { + const context: any = { + selection: { + file: { + entry: { + name: 'document.docx', + isLocked: false, + properties: { + 'cm:lockType': 'WRITE_LOCK' + } + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if selected file has read-only lock', () => { + const context: any = { + selection: { + file: { + entry: { + name: 'document.docx', + isLocked: false, + properties: { + 'cm:lockType': 'READ_ONLY_LOCK' + } + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [false] if current user is not lock owner', () => { + const context: any = { + profile: { + id: 'user1' + }, + selection: { + file: { + entry: { + name: 'document.docx', + isLocked: false, + properties: { + 'cm:lockType': 'READ_ONLY_LOCK', + 'cm:lockOwner': { + id: 'user2' + } + } + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeFalsy(); + }); + + it('should return [true] if current user is lock owner', () => { + const context: any = { + profile: { + id: 'user1' + }, + selection: { + file: { + entry: { + name: 'document.docx', + isLocked: false, + properties: { + 'cm:lockType': 'READ_ONLY_LOCK', + 'cm:lockOwner': { + id: 'user1' + } + } + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeTruthy(); + }); + + it('should return [true] if all checks succeed', () => { + const context: any = { + selection: { + file: { + entry: { + name: 'document.docx', + isLocked: false, + properties: {} + } + } + } + }; + + expect(canOpenWithOffice(context)).toBeTruthy(); + }); + }); +}); diff --git a/projects/adf-office-services-ext/src/lib/evaluators.ts b/projects/adf-office-services-ext/src/lib/evaluators.ts index e63abdc74..eb1f5c62b 100644 --- a/projects/adf-office-services-ext/src/lib/evaluators.ts +++ b/projects/adf-office-services-ext/src/lib/evaluators.ts @@ -12,7 +12,11 @@ export function canOpenWithOffice( return false; } - const file = context.selection.file; + if (!context || !context.selection) { + return false; + } + + const { file } = context.selection; if (!file || !file.entry || !file.entry.properties) { return false; @@ -43,12 +47,8 @@ export function canOpenWithOffice( file.entry.properties['cm:lockType'] === 'WRITE_LOCK' || file.entry.properties['cm:lockType'] === 'READ_ONLY_LOCK' ) { - return false; - } - - const lockOwner = file.entry.properties['cm:lockOwner']; - if (lockOwner && lockOwner.id !== context.profile.id) { - return false; + const lockOwner = file.entry.properties['cm:lockOwner']; + return lockOwner && lockOwner.id === context.profile.id; } return true; diff --git a/projects/adf-office-services-ext/src/lib/utils.spec.ts b/projects/adf-office-services-ext/src/lib/utils.spec.ts new file mode 100644 index 000000000..cd0a905f7 --- /dev/null +++ b/projects/adf-office-services-ext/src/lib/utils.spec.ts @@ -0,0 +1,15 @@ +import { getFileExtension } from './utils'; + +describe('utils', () => { + it('should return no extension when input is null', () => { + expect(getFileExtension(null)).toBe(null); + }); + + it('should extract file extension', () => { + expect(getFileExtension('test.docx')).toBe('docx'); + }); + + it('should not extract file extension', () => { + expect(getFileExtension('unknown')).toBe(null); + }); +});