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-6926] Fix plugins routing #3930

Merged
merged 2 commits into from
Jul 17, 2024
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
8 changes: 1 addition & 7 deletions projects/aca-content/assets/app.extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,13 @@
"order": 100,
"title": "APP.BROWSE.FILE.SIDENAV_LINK.LABEL",
"description": "APP.BROWSE.FILE.SIDENAV_LINK.TOOLTIP",
"rules": {
"visible": "app.isContentServiceEnabled"
},
"children": [
{
"id": "app.navbar.personalFiles",
"order": 100,
"title": "APP.BROWSE.PERSONAL.SIDENAV_LINK.LABEL",
"description": "APP.BROWSE.PERSONAL.SIDENAV_LINK.TOOLTIP",
"route": "personal-files",
"rules": {
"visible": "app.isContentServiceEnabled"
}
"route": "personal-files"
},
{
"id": "app.navbar.libraries.files",
Expand Down
7 changes: 6 additions & 1 deletion projects/aca-content/folder-rules/src/folder-rules.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ import { RuleActionListUiComponent } from './rule-details/actions/rule-action-li
import { RuleActionUiComponent } from './rule-details/actions/rule-action.ui-component';
import { RuleListUiComponent } from './rule-list/rule-list/rule-list.ui-component';
import { RuleSetPickerSmartComponent } from './rule-set-picker/rule-set-picker.smart-component';
import { PluginEnabledGuard } from '@alfresco/aca-shared';

const routes: Routes = [
{
path: 'rules',
component: ManageRulesSmartComponent
component: ManageRulesSmartComponent,
canActivate: [PluginEnabledGuard],
data: {
plugin: 'plugins.folderRules'
}
}
];

Expand Down
85 changes: 85 additions & 0 deletions projects/aca-shared/src/lib/routing/plugin-enabled.guard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*!
* Copyright © 2005-2024 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 { AppConfigService } from '@alfresco/adf-core';
import { TestBed } from '@angular/core/testing';
import { PluginEnabledGuard } from './plugin-enabled.guard';
import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('PluginEnabledGuard', () => {
let service: PluginEnabledGuard;
let getSpy: jasmine.Spy<(key: string, defaultValue?: boolean) => boolean>;
let route: ActivatedRouteSnapshot;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(PluginEnabledGuard);
getSpy = spyOn(TestBed.inject(AppConfigService), 'get');
route = new ActivatedRouteSnapshot();
route.data = {
plugin: 'some plugin'
};
});

describe('canActivate', () => {
it('should call appConfigService.get with correct parameters', () => {
service.canActivate(route);
expect(getSpy).toHaveBeenCalledWith(route.data.plugin, true);
});

it('should return true if appConfigService.get returns true', () => {
getSpy.and.returnValue(true);

expect(service.canActivate(route)).toBeTrue();
});

it('should return false if appConfigService.get returns false', () => {
getSpy.and.returnValue(true);

expect(service.canActivate(route)).toBeTrue();
});

it('should navigate to root if plugin is not enabled', () => {
getSpy.and.returnValue(false);
const routerSpy = spyOn(TestBed.inject(Router), 'navigate');

service.canActivate(route);

expect(routerSpy).toHaveBeenCalledWith(['/']);
});
});

describe('canActivateChild', () => {
it('should call canActivate with the same route and return its result', () => {
spyOn(service, 'canActivate').and.callThrough();
const result = service.canActivateChild(route);

expect(service.canActivate).toHaveBeenCalledWith(route);
expect(result).toBe(service.canActivate(route));
});
});
});
48 changes: 48 additions & 0 deletions projects/aca-shared/src/lib/routing/plugin-enabled.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*!
* Copyright © 2005-2024 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 { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router } from '@angular/router';
import { AppConfigService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class PluginEnabledGuard implements CanActivate, CanActivateChild {
constructor(private appConfigService: AppConfigService, private router: Router) {}

canActivate(route: ActivatedRouteSnapshot): boolean {
const isPluginEnabled = this.appConfigService.get(route.data.plugin, true);

if (!isPluginEnabled) {
this.router.navigate(['/']);
}

return isPluginEnabled;
}

canActivateChild(route: ActivatedRouteSnapshot): boolean {
return this.canActivate(route);
}
}
1 change: 1 addition & 0 deletions projects/aca-shared/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from './lib/models/viewer.rules';
export * from './lib/models/modal-configuration';

export * from './lib/routing/shared.guard';
export * from './lib/routing/plugin-enabled.guard';

export * from './lib/services/app.service';
export * from './lib/services/content-api.service';
Expand Down
Loading