mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACS-5279] improved plugin handling (#3332)
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -579,6 +567,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if no selection present', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: null
|
||||
};
|
||||
|
||||
@@ -587,6 +576,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if no file selected', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: null
|
||||
}
|
||||
@@ -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
|
||||
@@ -609,6 +600,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if selected file has no properties', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
@@ -623,6 +615,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if selected file is locked', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
@@ -638,6 +631,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if selected file has no extension', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
@@ -654,6 +648,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if extension is not supported', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
@@ -670,6 +665,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if selected file has write lock', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
@@ -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: {
|
||||
@@ -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'
|
||||
},
|
||||
@@ -730,6 +728,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if current user is lock owner', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
profile: {
|
||||
id: 'user1'
|
||||
},
|
||||
@@ -754,6 +753,7 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [false] if permissions check is false', () => {
|
||||
const context: any = {
|
||||
appConfig,
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
@@ -773,6 +773,9 @@ describe('app.evaluators', () => {
|
||||
|
||||
it('should return [true] if all checks succeed', () => {
|
||||
const context: any = {
|
||||
appConfig: {
|
||||
get: () => true
|
||||
},
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
|
@@ -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
|
||||
@@ -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`
|
||||
@@ -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) {
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user