[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

@@ -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"
},

View File

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

View File

@@ -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"
}

View File

@@ -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",

View File

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

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

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