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

[ACS-5279] improved plugin handling #3332

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions projects/aca-content/ms-office/src/aos-extension.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ import { NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { AosEffects } from './effects/aos.effects';
import { TranslationService } from '@alfresco/adf-core';
import { AlfrescoOfficeExtensionService } from '@alfresco/aca-shared';
import { canOpenWithOffice } from '@alfresco/aca-shared/rules';

@NgModule({
imports: [EffectsModule.forFeature([AosEffects])],
providers: [provideExtensionConfig(['aos.plugin.json'])]
})
export class AosExtensionModule {
constructor(extensions: ExtensionService, translation: TranslationService, aosService: AlfrescoOfficeExtensionService) {
constructor(extensions: ExtensionService, translation: TranslationService) {
translation.addTranslationFolder('ms-office', 'assets/ms-office');
extensions.setEvaluators({
'aos.canOpenWithOffice': (context) => aosService.isAosPluginEnabled() && canOpenWithOffice(context)
'aos.canOpenWithOffice': canOpenWithOffice
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { CommonModule } from '@angular/common';
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { AppExtensionService } from '@alfresco/aca-shared';
import { ContentServiceExtensionService } from '../services/content-service-extension.service';

export function setupExtensions(service: AppExtensionService): () => void {
return () => service.load();
Expand All @@ -44,7 +43,7 @@ export class CoreExtensionsModule {
{
provide: APP_INITIALIZER,
useFactory: setupExtensions,
deps: [AppExtensionService, ContentServiceExtensionService],
deps: [AppExtensionService],
multi: true
}
]
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class NodeTemplateService {
private currentTemplateConfig: TemplateDialogConfig = null;
private rootNode: ResultNode;

_searchApi: SearchApi;
private _searchApi: SearchApi;
get searchApi(): SearchApi {
this._searchApi = this._searchApi ?? new SearchApi(this.alfrescoApiService.getInstance());
return this._searchApi;
Expand Down
37 changes: 20 additions & 17 deletions projects/aca-shared/rules/src/app.rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,26 +549,14 @@ describe('app.evaluators', () => {
});
});

describe('isContentServiceEnabled', () => {
it('should return true when local storage has contentService set to true', () => {
localStorage.setItem('contentService', 'true');
expect(app.isContentServiceEnabled()).toBe(true);
});

it('should return false when local storage has contentService set to false', () => {
localStorage.setItem('contentService', 'false');
expect(app.isContentServiceEnabled()).toBe(false);
});

it('should return true when contentService is not defined in local storage', () => {
localStorage.clear();
expect(app.isContentServiceEnabled()).toBe(true);
});
});

describe('canOpenWithOffice', () => {
const appConfig = {
get: (key: string) => key
};

it('should return [false] if using SSO', () => {
const context: any = {
appConfig,
auth: {
isOauth: () => true
}
Expand All @@ -579,6 +567,7 @@ describe('app.evaluators', () => {

it('should return [false] if no selection present', () => {
const context: any = {
appConfig,
selection: null
};

Expand All @@ -587,6 +576,7 @@ describe('app.evaluators', () => {

it('should return [false] if no file selected', () => {
const context: any = {
appConfig,
selection: {
file: null
}
Expand All @@ -597,6 +587,7 @@ describe('app.evaluators', () => {

it('should return [false] if selected file has no entry', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: null
Expand All @@ -609,6 +600,7 @@ describe('app.evaluators', () => {

it('should return [false] if selected file has no properties', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -623,6 +615,7 @@ describe('app.evaluators', () => {

it('should return [false] if selected file is locked', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -638,6 +631,7 @@ describe('app.evaluators', () => {

it('should return [false] if selected file has no extension', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -654,6 +648,7 @@ describe('app.evaluators', () => {

it('should return [false] if extension is not supported', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -670,6 +665,7 @@ describe('app.evaluators', () => {

it('should return [false] if selected file has write lock', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -688,6 +684,7 @@ describe('app.evaluators', () => {

it('should return [false] if selected file has read-only lock', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -706,6 +703,7 @@ describe('app.evaluators', () => {

it('should return [false] if current user is not lock owner', () => {
const context: any = {
appConfig,
profile: {
id: 'user1'
},
Expand All @@ -730,6 +728,7 @@ describe('app.evaluators', () => {

it('should return [false] if current user is lock owner', () => {
const context: any = {
appConfig,
profile: {
id: 'user1'
},
Expand All @@ -754,6 +753,7 @@ describe('app.evaluators', () => {

it('should return [false] if permissions check is false', () => {
const context: any = {
appConfig,
selection: {
file: {
entry: {
Expand All @@ -773,6 +773,9 @@ describe('app.evaluators', () => {

it('should return [true] if all checks succeed', () => {
const context: any = {
appConfig: {
get: () => true
},
selection: {
file: {
entry: {
Expand Down
30 changes: 20 additions & 10 deletions projects/aca-shared/rules/src/app.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export interface AcaRuleContext extends RuleContext {
* Checks if the content plugin is enabled.
* JSON ref: `app.isContentServiceEnabled`
*/
export const isContentServiceEnabled = (): boolean => localStorage && localStorage.getItem('contentService') !== 'false';
export const isContentServiceEnabled = (context: AcaRuleContext): boolean => {
const flag = context.appConfig.get<boolean | string>('plugins.contentService');
return flag === true || flag === 'true';
};

/**
* Checks if Search is supported for active view
Expand All @@ -101,10 +104,10 @@ export const isSearchSupported = (context: RuleContext): boolean =>
* Checks if upload action is supported for the given context
* JSON ref: `app.isUploadSupported`
*
* @param content Rule execution context
* @param context Rule execution context
*/
export const isUploadSupported = (context: RuleContext): boolean =>
[isContentServiceEnabled(), navigation.isPersonalFiles(context) || navigation.isLibraryContent(context), canUpload(context)].every(Boolean);
export const isUploadSupported = (context: AcaRuleContext): boolean =>
[isContentServiceEnabled(context), navigation.isPersonalFiles(context) || navigation.isLibraryContent(context), canUpload(context)].every(Boolean);
/**
* Checks if user can copy selected node.
* JSON ref: `app.canCopyNode`
Expand Down Expand Up @@ -240,8 +243,8 @@ export const hasSelection = (context: RuleContext): boolean => !context.selectio
* Checks if user can create a new folder with current path.
* JSON ref: `app.navigation.folder.canCreate`
*/
export function canCreateFolder(context: RuleContext): boolean {
if (isContentServiceEnabled() && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) {
export function canCreateFolder(context: AcaRuleContext): boolean {
if (isContentServiceEnabled(context) && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) {
const { currentFolder } = context.navigation;

if (currentFolder) {
Expand All @@ -257,14 +260,15 @@ export function canCreateFolder(context: RuleContext): boolean {
*
* @param context Rule execution context
*/
export const canCreateLibrary = (context: RuleContext): boolean => [isContentServiceEnabled(), navigation.isLibraries(context)].every(Boolean);
export const canCreateLibrary = (context: AcaRuleContext): boolean =>
[isContentServiceEnabled(context), navigation.isLibraries(context)].every(Boolean);

/**
* Checks if user can upload content to current folder.
* JSON ref: `app.navigation.folder.canUpload`
*/
export function canUpload(context: RuleContext): boolean {
if (isContentServiceEnabled() && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) {
export function canUpload(context: AcaRuleContext): boolean {
if (isContentServiceEnabled(context) && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) {
const { currentFolder } = context.navigation;

if (currentFolder) {
Expand Down Expand Up @@ -578,7 +582,13 @@ export const showInfoSelectionButton = (context: RuleContext): boolean => naviga
*
* @param context Rule execution context
*/
export function canOpenWithOffice(context: RuleContext): boolean {
export function canOpenWithOffice(context: AcaRuleContext): boolean {
const flag = `${context.appConfig.get<boolean | string>('plugins.aosPlugin', false)}`;

if (flag !== 'true') {
return false;
}

if (context.navigation && context.navigation.url && context.navigation.url.startsWith('/trashcan')) {
return false;
}
Expand Down
Loading