[ACA-2239] initial localisation support for AOS extension (#988)

* setup i18n for aos extension

* translate action names, generic icon

* unit tests and bug fixes

* use AOS testing with CI
This commit is contained in:
Denys Vuika
2019-03-05 12:50:16 +00:00
committed by GitHub
parent 31a0dae59e
commit 0b60514a01
10 changed files with 268 additions and 20 deletions

View File

@@ -51,12 +51,22 @@
"output": "./assets" "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", "input": "node_modules/@alfresco/adf-office-services-ext/assets",
"output": "./assets/plugins" "output": "./assets/plugins"
}, },
{ {
"glob": "**/*.json", "glob": "aos.plugin.json",
"input": "projects/adf-office-services-ext/assets", "input": "projects/adf-office-services-ext/assets",
"output": "./assets/plugins" "output": "./assets/plugins"
} }

View File

@@ -12,7 +12,7 @@
"build": "npm run build.extensions && npm run build.app -- --prod", "build": "npm run build.extensions && npm run build.app -- --prod",
"build.e2e": "npm run build.extensions && npm run build.app -- --prod --configuration=e2e", "build.e2e": "npm run build.extensions && npm run build.app -- --prod --configuration=e2e",
"test": "ng test app --code-coverage", "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", "lint": "ng lint && npm run spellcheck && npm run format:check",
"wd:update": "webdriver-manager update --gecko=false", "wd:update": "webdriver-manager update --gecko=false",
"e2e": "npm run wd:update && protractor --baseUrl=http://localhost:4000", "e2e": "npm run wd:update && protractor --baseUrl=http://localhost:4000",

View File

@@ -1,7 +1,7 @@
{ {
"$schema": "../../../extension.schema.json", "$schema": "../../../extension.schema.json",
"$id": "9a635542-d87a-4558-ae64-ffa199d1a364", "$id": "9a635542-d87a-4558-ae64-ffa199d1a364",
"$version": "1.0.0", "$version": "0.0.6",
"$name": "keensoft.aos.plugin", "$name": "keensoft.aos.plugin",
"$description": "Extension that provides Office Edit Online Action", "$description": "Extension that provides Office Edit Online Action",
"$vendor": "Keensoft", "$vendor": "Keensoft",
@@ -24,8 +24,8 @@
{ {
"id": "aos.toolbar.openWith.office", "id": "aos.toolbar.openWith.office",
"order": 90, "order": 90,
"icon": "adf:application/msword", "icon": "edit",
"title": "Edit in Microsoft Office™", "title": "AOS.ACTION_TITLE",
"actions": { "actions": {
"click": "aos.openWith.office" "click": "aos.openWith.office"
}, },
@@ -40,8 +40,8 @@
{ {
"id": "aos.context.openWith.office", "id": "aos.context.openWith.office",
"order": 90, "order": 90,
"icon": "adf:application/msword", "icon": "edit",
"title": "Edit in Microsoft Office™", "title": "AOS.ACTION_TITLE",
"actions": { "actions": {
"click": "aos.openWith.office" "click": "aos.openWith.office"
}, },
@@ -58,8 +58,8 @@
{ {
"id": "aos.viewer.openWith.office", "id": "aos.viewer.openWith.office",
"order": 1, "order": 1,
"icon": "adf:application/msword", "icon": "edit",
"title": "Microsoft Office™", "title": "AOS.ACTION_TITLE",
"actions": { "actions": {
"click": "aos.openWith.office" "click": "aos.openWith.office"
}, },

View File

@@ -0,0 +1,5 @@
{
"AOS": {
"ACTION_TITLE": "Edit in Microsoft Office™"
}
}

View File

@@ -1,7 +1,12 @@
{ {
"assets": [ "assets": [
{ {
"glob": "**/*.json", "glob": "**/*",
"input": "./assets",
"output": "./assets/adf-office-services-ext"
},
{
"glob": "aos.plugin.json",
"input": "./assets", "input": "./assets",
"output": "./assets/plugins" "output": "./assets/plugins"
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "@alfresco/adf-office-services-ext", "name": "@alfresco/adf-office-services-ext",
"version": "0.0.5", "version": "0.0.6",
"license": "Apache-2.0", "license": "Apache-2.0",
"author": { "author": {
"name": "Keensoft", "name": "Keensoft",

View File

@@ -6,13 +6,18 @@ import { AosEditOnlineService } from './aos-extension.service';
import { AosEffects } from './effects/aos.effects'; import { AosEffects } from './effects/aos.effects';
import { canOpenWithOffice } from './evaluators'; import { canOpenWithOffice } from './evaluators';
import { TranslationService } from '@alfresco/adf-core';
@NgModule({ @NgModule({
imports: [EffectsModule.forFeature([AosEffects])], imports: [EffectsModule.forFeature([AosEffects])],
providers: [AosEditOnlineService] providers: [AosEditOnlineService]
}) })
export class AosExtensionModule { export class AosExtensionModule {
constructor(extensions: ExtensionService) { constructor(extensions: ExtensionService, translation: TranslationService) {
translation.addTranslationFolder(
'adf-office-services-ext',
'assets/adf-office-services-ext'
);
extensions.setEvaluators({ extensions.setEvaluators({
'aos.canOpenWithOffice': canOpenWithOffice 'aos.canOpenWithOffice': canOpenWithOffice
}); });

View File

@@ -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();
});
});
});

View File

@@ -12,7 +12,11 @@ export function canOpenWithOffice(
return false; return false;
} }
const file = context.selection.file; if (!context || !context.selection) {
return false;
}
const { file } = context.selection;
if (!file || !file.entry || !file.entry.properties) { if (!file || !file.entry || !file.entry.properties) {
return false; return false;
@@ -43,12 +47,8 @@ export function canOpenWithOffice(
file.entry.properties['cm:lockType'] === 'WRITE_LOCK' || file.entry.properties['cm:lockType'] === 'WRITE_LOCK' ||
file.entry.properties['cm:lockType'] === 'READ_ONLY_LOCK' file.entry.properties['cm:lockType'] === 'READ_ONLY_LOCK'
) { ) {
return false; const lockOwner = file.entry.properties['cm:lockOwner'];
} return lockOwner && lockOwner.id === context.profile.id;
const lockOwner = file.entry.properties['cm:lockOwner'];
if (lockOwner && lockOwner.id !== context.profile.id) {
return false;
} }
return true; return true;

View File

@@ -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);
});
});