Skip to content

Commit

Permalink
[ACA-4679] Added code changes and env variables to enable DownloadPro…
Browse files Browse the repository at this point in the history
…mpt and FileAutoDownload features on ACA (#3127)

* [ACA-4679] Added docker variables, app.config.json.tpl config and additional code for enabling non-responsive file preview download and file auto download features in ACA

* [ACA-4679] Added defaults for downloadPrompt for viewer and fileAutoDownload features. Updated variable names from 'nonResponsiveDialog' to 'downloadPrompt'

* [ACA-4679] Added unit test cases for FileAutoDownloadService

* [ACA-4679] Updated env variable references from NonResponsiveDialog to DownloadPrompt

* [ACA-4679] Added missing licence header on new files

* [ACA-4679] Added env variable configuration for GithubActions jobs

* [ACA-4679] Added env variable configuration for GithubActions jobs

* [ACA-4679] Removed unneeded env variable configuration for GithubActions jobs

* [ACA-4679] Updated .env file configuration in README.md
  • Loading branch information
swapnil-verma-gl authored Apr 20, 2023
1 parent f86c80d commit 9148ccc
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ env:
APP_CONFIG_OAUTH2_REDIRECT_LOGOUT: /
APP_CONFIG_OAUTH2_REDIRECT_LOGIN: /
APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI: "{protocol}//{hostname}{:port}/assets/silent-refresh.html"
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT: true
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS: true
APP_CONFIG_DOWNLOAD_PROMPT_DELAY: 50
APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY: 30
APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD: true
APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB: 15

jobs:
lint:
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ ENV APP_CONFIG_PLUGIN_FOLDER_RULES=true
ENV APP_CONFIG_PLUGIN_CONTENT_SERVICE=true
ENV APP_CONFIG_ENABLE_MOBILE_APP_SWITCH=true
ENV APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS="12"
ENV APP_CONFIG_ENABLE_DOWNLOAD_PROMPT=true
ENV APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS=true
ENV APP_CONFIG_DOWNLOAD_PROMPT_DELAY=50
ENV APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY=30
ENV APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD=true
ENV APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB=15

COPY docker/default.conf.template /etc/nginx/templates/
COPY docker/docker-entrypoint.d/* /docker-entrypoint.d/
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ APP_CONFIG_OAUTH2_SILENT_LOGIN=true
APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/
APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/
APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI="{protocol}//{hostname}{:port}/assets/silent-refresh.html"

# Download Prompt configurations
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT=true
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS=true
APP_CONFIG_DOWNLOAD_PROMPT_DELAY=<time>
APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY=<time>
APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD=true
APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB=<file-size>

```

Where `<URL>` is the address of the ACS.
Expand Down
8 changes: 8 additions & 0 deletions app/src/app.config.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1184,5 +1184,13 @@
"cm:taggable", "app:inlineeditable", "cm:geographic", "exif:exif",
"audio:audio", "cm:indexControl", "dp:restrictable", "smf:customConfigSmartFolder", "smf:systemConfigSmartFolder"],
"ai": ["ai:products", "ai:dates", "ai:places", "ai:events", "ai:organizations", "ai:people", "ai:things", "ai:quantities", "ai:creativeWorks", "ai:labels", "ai:textLines"]
},
"viewer": {
"enableDownloadPrompt": ${APP_CONFIG_ENABLE_DOWNLOAD_PROMPT},
"enableDownloadPromptReminder": ${APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS},
"downloadPromptDelay": ${APP_CONFIG_DOWNLOAD_PROMPT_DELAY},
"downloadPromptReminderDelay": ${APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY},
"enableFileAutoDownload": ${APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD},
"fileAutoDownloadSizeThresholdInMB": ${APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { AppExtensionService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { AcaFileAutoDownloadService, AppExtensionService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { AppStore } from '@alfresco/aca-shared/store';
import { UploadService } from '@alfresco/adf-content-services';
import { MinimalNodeEntity, MinimalNodeEntryEntity, PathElementEntity, PathInfo } from '@alfresco/js-api';
Expand All @@ -49,9 +49,10 @@ export class FavoritesComponent extends PageComponent implements OnInit {
private contentApi: ContentApiService,
content: ContentManagementService,
private uploadService: UploadService,
private breakpointObserver: BreakpointObserver
private breakpointObserver: BreakpointObserver,
fileAutoDownloadService: AcaFileAutoDownloadService
) {
super(store, extensions, content);
super(store, extensions, content, fileAutoDownloadService);
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Store } from '@ngrx/store';
import { MinimalNodeEntity, MinimalNodeEntryEntity, PathElement, PathElementEntity } from '@alfresco/js-api';
import { ContentManagementService } from '../../services/content-management.service';
import { NodeActionsService } from '../../services/node-actions.service';
import { AppExtensionService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { AcaFileAutoDownloadService, AppExtensionService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { SetCurrentFolderAction, isAdmin, AppStore, UploadFileVersionAction, showLoaderSelector } from '@alfresco/aca-shared/store';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { debounceTime, takeUntil } from 'rxjs/operators';
Expand Down Expand Up @@ -61,9 +61,10 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
private uploadService: UploadService,
content: ContentManagementService,
extensions: AppExtensionService,
private breakpointObserver: BreakpointObserver
private breakpointObserver: BreakpointObserver,
fileAutoDownloadService: AcaFileAutoDownloadService
) {
super(store, extensions, content);
super(store, extensions, content, fileAutoDownloadService);
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { AppStore } from '@alfresco/aca-shared/store';
import { UploadService } from '@alfresco/adf-content-services';
import { debounceTime } from 'rxjs/operators';
import { Router } from '@angular/router';
import { AppExtensionService, PageComponent } from '@alfresco/aca-shared';
import { AcaFileAutoDownloadService, AppExtensionService, PageComponent } from '@alfresco/aca-shared';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';

@Component({
Expand All @@ -48,9 +48,10 @@ export class RecentFilesComponent extends PageComponent implements OnInit {
content: ContentManagementService,
private uploadService: UploadService,
private breakpointObserver: BreakpointObserver,
private router: Router
private router: Router,
fileAutoDownloadService: AcaFileAutoDownloadService
) {
super(store, extensions, content);
super(store, extensions, content, fileAutoDownloadService);
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { BehaviorSubject, Subject } from 'rxjs';
import { NodesApiService } from '@alfresco/adf-content-services';
import { takeUntil } from 'rxjs/operators';
import { Router } from '@angular/router';
import { AcaFileAutoDownloadService } from '@alfresco/aca-shared';

@Component({
selector: 'aca-search-results-row',
Expand All @@ -49,7 +50,12 @@ export class SearchResultsRowComponent implements OnInit, OnDestroy {
name$ = new BehaviorSubject<string>('');
title$ = new BehaviorSubject<string>('');

constructor(private store: Store<any>, private nodesApiService: NodesApiService, private router: Router) {}
constructor(
private store: Store<any>,
private nodesApiService: NodesApiService,
private router: Router,
private fileAutoDownloadService: AcaFileAutoDownloadService
) {}

ngOnInit() {
this.updateValues();
Expand Down Expand Up @@ -93,7 +99,11 @@ export class SearchResultsRowComponent implements OnInit, OnDestroy {

showPreview(event: Event) {
event.stopPropagation();
this.store.dispatch(new ViewNodeAction(this.node.entry.id, { location: this.router.url }));
if (this.fileAutoDownloadService.shouldFileAutoDownload(this.node.entry.content.sizeInBytes)) {
this.fileAutoDownloadService.autoDownloadFile(this.node);
} else {
this.store.dispatch(new ViewNodeAction(this.node.entry.id, { location: this.router.url }));
}
}

navigate(event: Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { ContentManagementService } from '../../../services/content-management.service';
import { TranslationService } from '@alfresco/adf-core';
import { combineLatest, Observable } from 'rxjs';
import { AppExtensionService, PageComponent } from '@alfresco/aca-shared';
import { AcaFileAutoDownloadService, AppExtensionService, PageComponent } from '@alfresco/aca-shared';
import { SearchSortingDefinition } from '@alfresco/adf-content-services/lib/search/models/search-sorting-definition.interface';
import { takeUntil } from 'rxjs/operators';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
Expand Down Expand Up @@ -70,9 +70,10 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
content: ContentManagementService,
private translationService: TranslationService,
private router: Router,
private breakpointObserver: BreakpointObserver
private breakpointObserver: BreakpointObserver,
fileAutoDownloadService: AcaFileAutoDownloadService
) {
super(store, extensions, content);
super(store, extensions, content, fileAutoDownloadService);

queryBuilder.paging = {
skipCount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import { debounceTime } from 'rxjs/operators';
import { UploadService } from '@alfresco/adf-content-services';
import { Router } from '@angular/router';
import { MinimalNodeEntity } from '@alfresco/js-api';
import { AppExtensionService, AppHookService, PageComponent } from '@alfresco/aca-shared';
import { AcaFileAutoDownloadService, AppExtensionService, AppHookService, PageComponent } from '@alfresco/aca-shared';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';

@Component({
templateUrl: './shared-files.component.html'
})
Expand All @@ -48,9 +47,10 @@ export class SharedFilesComponent extends PageComponent implements OnInit {
private appHookService: AppHookService,
private uploadService: UploadService,
private breakpointObserver: BreakpointObserver,
private router: Router
private router: Router,
fileAutoDownloadService: AcaFileAutoDownloadService
) {
super(store, extensions, content);
super(store, extensions, content, fileAutoDownloadService);
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AppStore, ViewNodeAction, getAppSelection } from '@alfresco/aca-shared/
import { Router } from '@angular/router';
import { take } from 'rxjs/operators';
import { SharedLinkEntry } from '@alfresco/js-api';
import { AcaFileAutoDownloadService } from '@alfresco/aca-shared';

@Component({
selector: 'app-view-node',
Expand All @@ -53,22 +54,26 @@ import { SharedLinkEntry } from '@alfresco/js-api';
export class ViewNodeComponent {
@Input() data: { title?: string; menuButton?: boolean; iconButton?: boolean };

constructor(private store: Store<AppStore>, private router: Router) {}
constructor(private store: Store<AppStore>, private router: Router, private fileAutoDownloadService: AcaFileAutoDownloadService) {}

onClick() {
this.store
.select(getAppSelection)
.pipe(take(1))
.subscribe((selection) => {
let id: string;

if (selection.file.entry.nodeType === 'app:filelink') {
id = selection.file.entry.properties['cm:destination'];
if (this.fileAutoDownloadService.shouldFileAutoDownload(selection.file.entry?.content?.sizeInBytes)) {
this.fileAutoDownloadService.autoDownloadFile(selection.file);
} else {
id = (selection.file as SharedLinkEntry).entry.nodeId || (selection.file as any).entry.guid || selection.file.entry.id;
}
let id: string;

this.store.dispatch(new ViewNodeAction(id, { location: this.router.url }));
if (selection.file.entry.nodeType === 'app:filelink') {
id = selection.file.entry.properties['cm:destination'];
} else {
id = (selection.file as SharedLinkEntry).entry.nodeId || (selection.file as any).entry.guid || selection.file.entry.id;
}

this.store.dispatch(new ViewNodeAction(id, { location: this.router.url }));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from '@alfresco/aca-shared/store';
import { AppExtensionService } from '../../services/app.extension.service';
import { isLibrary, isLocked } from '../../utils/node.utils';
import { AcaFileAutoDownloadService } from '../../services/aca-file-auto-download.service';

/* eslint-disable @angular-eslint/directive-class-suffix */
@Directive()
Expand All @@ -71,7 +72,12 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {

protected subscriptions: Subscription[] = [];

protected constructor(protected store: Store<AppStore>, protected extensions: AppExtensionService, protected content: DocumentBasePageService) {}
protected constructor(
protected store: Store<AppStore>,
protected extensions: AppExtensionService,
protected content: DocumentBasePageService,
private fileAutoDownloadService: AcaFileAutoDownloadService = null
) {}

ngOnInit() {
this.extensions
Expand Down Expand Up @@ -133,15 +139,19 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {

showPreview(node: MinimalNodeEntity, extras?: ViewNodeExtras) {
if (node && node.entry) {
let id: string;

if (node.entry.nodeType === 'app:filelink') {
id = node.entry.properties['cm:destination'];
if (this.fileAutoDownloadService?.shouldFileAutoDownload(node.entry?.content?.sizeInBytes)) {
this.fileAutoDownloadService.autoDownloadFile(node);
} else {
id = (node as any).entry.nodeId || (node as any).entry.guid || node.entry.id;
}
let id: string;

this.store.dispatch(new ViewNodeAction(id, extras));
if (node.entry.nodeType === 'app:filelink') {
id = node.entry.properties['cm:destination'];
} else {
id = (node as any).entry.nodeId || (node as any).entry.guid || node.entry.id;
}

this.store.dispatch(new ViewNodeAction(id, extras));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*!
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { TestBed } from '@angular/core/testing';
import { AcaFileAutoDownloadService, initialState, LibTestingModule } from '@alfresco/aca-shared';
import { MatDialog } from '@angular/material/dialog';
import { AppConfigService } from '@alfresco/adf-core';
import { FileAutoDownloadComponent } from '@alfresco/adf-content-services';
import { provideMockStore } from '@ngrx/store/testing';

describe('AcaFileAutoDownloadService', () => {
let service: AcaFileAutoDownloadService;
let appConfig: AppConfigService;

const mockDialogRef = {
open: jasmine.createSpy('open')
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [LibTestingModule],
providers: [provideMockStore({ initialState }), { provide: MatDialog, useValue: mockDialogRef }]
});

service = TestBed.inject(AcaFileAutoDownloadService);
appConfig = TestBed.inject(AppConfigService);
});

it('shouldFileAutoDownload should return true if fileSize exceeds configured threshold and file auto download is enabled', () => {
appConfig.config.viewer = {
enableFileAutoDownload: true,
fileAutoDownloadSizeThresholdInMB: 10
};
const shouldAutDownloadFlag = service.shouldFileAutoDownload(11000000);
expect(shouldAutDownloadFlag).toBe(true);
});

it('shouldFileAutoDownload should return false if fileSize does not exceeds configured threshold and file auto download is enabled', () => {
appConfig.config.viewer = {
enableFileAutoDownload: true,
fileAutoDownloadSizeThresholdInMB: 10
};
const shouldAutDownloadFlag = service.shouldFileAutoDownload(500000);
expect(shouldAutDownloadFlag).toBe(false);
});

it('shouldFileAutoDownload should return false if fileSize exceeds configured threshold but file auto download is disabled', () => {
appConfig.config.viewer = {
enableFileAutoDownload: false,
fileAutoDownloadSizeThresholdInMB: 10
};
const shouldAutDownloadFlag = service.shouldFileAutoDownload(11000000);
expect(shouldAutDownloadFlag).toBe(false);
});

it('autoDownloadFile should open FileAutoDownload dialog when called', () => {
const nodeEntity: any = { entry: { isFile: true } };
service.autoDownloadFile(nodeEntity);
expect(mockDialogRef.open).toHaveBeenCalledWith(FileAutoDownloadComponent, { disableClose: true, data: nodeEntity });
});
});
Loading

0 comments on commit 9148ccc

Please sign in to comment.