Skip to content

Commit

Permalink
[ACA-2239] initial localisation support for AOS extension (Alfresco#988)
Browse files Browse the repository at this point in the history
* setup i18n for aos extension

* translate action names, generic icon

* unit tests and bug fixes

* use AOS testing with CI
  • Loading branch information
DenysVuika authored and dhrn committed Apr 30, 2019
1 parent 83a384a commit 19bc615
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 20 deletions.
14 changes: 12 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions projects/adf-office-services-ext/assets/aos.plugin.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand Down
5 changes: 5 additions & 0 deletions projects/adf-office-services-ext/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"AOS": {
"ACTION_TITLE": "Edit in Microsoft Office™"
}
}
7 changes: 6 additions & 1 deletion projects/adf-office-services-ext/ngi.json
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion projects/adf-office-services-ext/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
208 changes: 208 additions & 0 deletions projects/adf-office-services-ext/src/lib/evaluators.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
14 changes: 7 additions & 7 deletions projects/adf-office-services-ext/src/lib/evaluators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions projects/adf-office-services-ext/src/lib/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 19bc615

Please sign in to comment.