[AE-11486] move lock and favorite (#8089)

* [ci:force] move lock and favorite

* fix
This commit is contained in:
Eugenio Romano
2023-01-04 15:24:42 +01:00
committed by GitHub
parent f7fdc5c92a
commit b9e0221ca2
42 changed files with 92 additions and 102 deletions

View File

@@ -23,7 +23,7 @@ import { EMPTY, of } from 'rxjs';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { NodeAspectService } from './node-aspect.service';
import { DialogAspectListService } from './dialog-aspect-list.service';
import { CardViewContentUpdateService } from '../../services/card-view-content-update.service';
import { CardViewContentUpdateService } from '../../common/services/card-view-content-update.service';
describe('NodeAspectService', () => {

View File

@@ -18,7 +18,7 @@
import { Injectable } from '@angular/core';
import { NodesApiService } from '@alfresco/adf-core';
import { DialogAspectListService } from './dialog-aspect-list.service';
import { CardViewContentUpdateService } from '../../services/card-view-content-update.service';
import { CardViewContentUpdateService } from '../../common/services/card-view-content-update.service';
@Injectable({
providedIn: 'root'

View File

@@ -15,5 +15,6 @@
* limitations under the License.
*/
export * from './card-view-content-update.service';
export * from './sites.service';
export * from './services/favorites-api.service';
export * from './services/card-view-content-update.service';
export * from './services/sites.service';

View File

@@ -19,7 +19,7 @@ import { UpdateNotification, CardViewBaseItemModel, CardViewUpdateService } from
import { MinimalNode } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { BaseCardViewContentUpdate } from '../interfaces/base-card-view-content-update.interface';
import { BaseCardViewContentUpdate } from '../../interfaces/base-card-view-content-update.interface';
@Injectable({
providedIn: 'root'

View File

@@ -0,0 +1,92 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { FavoritesApi, NodePaging, FavoritePaging } from '@alfresco/js-api';
import { Observable, from, of } from 'rxjs';
import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class FavoritesApiService {
_favoritesApi: FavoritesApi;
get favoritesApi(): FavoritesApi {
this._favoritesApi = this._favoritesApi ?? new FavoritesApi(this.apiService.getInstance());
return this._favoritesApi;
}
static remapEntry({ entry }: any): any {
entry.properties = {
'cm:title': entry.title,
'cm:description': entry.description
};
return { entry };
}
constructor(
private apiService: AlfrescoApiService,
private preferences: UserPreferencesService
) {
}
remapFavoritesData(data: FavoritePaging = {}): NodePaging {
const pagination = (data?.list?.pagination || {});
const entries: any[] = this
.remapFavoriteEntries(data?.list?.entries || []);
return {
list: { entries, pagination }
};
}
remapFavoriteEntries(entries: any[]) {
return entries
.map(({ entry: { target } }: any) => ({
entry: target.file || target.folder
}))
.filter(({ entry }) => (!!entry))
.map(FavoritesApiService.remapEntry);
}
/**
* Gets the favorites for a user.
*
* @param personId ID of the user
* @param options Options supported by JS-API
* @returns List of favorites
*/
getFavorites(personId: string, options?: any): Observable<NodePaging> {
const defaultOptions = {
maxItems: this.preferences.paginationSize,
skipCount: 0,
where: '(EXISTS(target/file) OR EXISTS(target/folder))',
include: ['properties', 'allowableOperations']
};
const queryOptions = Object.assign(defaultOptions, options);
const promise = this.favoritesApi
.listFavorites(personId, queryOptions)
.then(this.remapFavoritesData);
return from(promise).pipe(
catchError((err) => of(err))
);
}
}

View File

@@ -29,7 +29,7 @@ import { throwError, of } from 'rxjs';
import { ContentTestingModule } from '../../../testing/content.testing.module';
import { mockGroupProperties } from './mock-data';
import { TranslateModule } from '@ngx-translate/core';
import { CardViewContentUpdateService } from '../../../services/card-view-content-update.service';
import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
describe('ContentMetadataComponent', () => {
let component: ContentMetadataComponent;

View File

@@ -30,7 +30,7 @@ import {
import { ContentMetadataService } from '../../services/content-metadata.service';
import { CardViewGroup, PresetConfig } from '../../interfaces/content-metadata.interfaces';
import { takeUntil, debounceTime, catchError, map } from 'rxjs/operators';
import { CardViewContentUpdateService } from '../../../services/card-view-content-update.service';
import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
const DEFAULT_SEPARATOR = ', ';

View File

@@ -25,7 +25,7 @@ import { Subject, of } from 'rxjs';
import { ContentTestingModule } from '../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { NodeAction } from '../document-list/models/node-action.enum';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
const fakeNodeEntry = {
entry: {

View File

@@ -27,7 +27,7 @@ import { ContentNodeSelectorComponentData } from './content-node-selector.compon
import { NodeAction } from '../document-list/models/node-action.enum';
import { NodeLockDialogComponent } from '../dialogs/node-lock.dialog';
import { switchMap } from 'rxjs/operators';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
@Injectable({
providedIn: 'root'

View File

@@ -39,7 +39,7 @@ import { NodeEntryEvent, ShareDataRow } from '../document-list';
import { TranslateModule } from '@ngx-translate/core';
import { SearchQueryBuilderService } from '../search';
import { mockQueryBody } from '../mock/search-query.mock';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
const fakeResultSetPaging: ResultSetPaging = {
list: {

View File

@@ -52,7 +52,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { SearchQueryBuilderService } from '../search';
import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
import { mockContentModelTextProperty } from '../mock/content-model.mock';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
const fakeResultSetPaging: ResultSetPaging = {
list: {

View File

@@ -52,7 +52,7 @@ import { SEARCH_QUERY_SERVICE_TOKEN } from '../search/search-query-service.token
import { SearchQueryBuilderService } from '../search/services/search-query-builder.service';
import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
import { NodeEntryEvent } from '../document-list/components/node.event';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
export type ValidationFunction = (entry: Node) => boolean;

View File

@@ -30,7 +30,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { UploadModule } from '../upload';
import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component';
import { NodeAction } from '../document-list/models/node-action.enum';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
describe('ContentNodeSelectorComponent', () => {
let component: ContentNodeSelectorComponent;

View File

@@ -25,7 +25,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { of, throwError } from 'rxjs';
import { delay } from 'rxjs/operators';
import { SiteEntry } from '@alfresco/js-api';
import { SitesService } from '../../services/sites.service';
import { SitesService } from '../../common/services/sites.service';
describe('LibraryDialogComponent', () => {
let fixture: ComponentFixture<LibraryDialogComponent>;

View File

@@ -35,7 +35,7 @@ import { MatDialogRef } from '@angular/material/dialog';
import { QueriesApi, SiteBodyCreate, SiteEntry, SitePaging } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { debounceTime, finalize, mergeMap, takeUntil } from 'rxjs/operators';
import { SitesService } from '../../services/sites.service';
import { SitesService } from '../../common/services/sites.service';
@Component({
selector: 'adf-library-dialog',

View File

@@ -22,7 +22,7 @@ import { of, throwError, Subject } from 'rxjs';
import { TranslateModule } from '@ngx-translate/core';
import { AlfrescoApiService, CoreModule, CoreTestingModule } from '@alfresco/adf-core';
import { ContentDirectiveModule } from './content-directive.module';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
describe('LibraryMembershipDirective', () => {
let alfrescoApiService: AlfrescoApiService;

View File

@@ -28,7 +28,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryMembershipToggleEvent } from '../interfaces/library-membership-toggle-event.interface';
import { LibraryMembershipErrorEvent} from '../interfaces/library-membership-error-event.interface';
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
@Directive({
selector: '[adf-library-membership]',

View File

@@ -45,7 +45,6 @@ import {
RequestPaginationModel,
AlfrescoApiService,
UserPreferenceValues,
LockService,
DataRow,
DataTableService,
NodesApiService
@@ -63,6 +62,7 @@ import { NavigableComponentInterface } from '../../breadcrumb/navigable-componen
import { FilterSearch } from './../../search/models/filter-search.interface';
import { RowFilter } from '../data/row-filter.model';
import { DocumentListService } from '../services/document-list.service';
import { LockService } from '../services/lock.service';
import { DocumentLoaderNode } from '../models/document-folder.model';
import { takeUntil } from 'rxjs/operators';
import { ADF_DOCUMENT_PARENT_COMPONENT } from './document-list.token';

View File

@@ -38,6 +38,7 @@ export * from './services/document-actions.service';
export * from './services/document-list.service';
export * from './services/node-actions.service';
export * from './services/custom-resources.service';
export * from './services/lock.service';
// models
export * from './models/content-action.model';

View File

@@ -0,0 +1,168 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { LockService } from './lock.service';
import { CoreTestingModule, setupTestBed, AlfrescoApiService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
import moment from 'moment';
import { TranslateModule } from '@ngx-translate/core';
describe('PeopleProcessService', () => {
let service: LockService;
let apiService: AlfrescoApiService;
const fakeNodeUnlocked: Node = { name: 'unlocked', isLocked: false, isFile: true } as Node;
const fakeFolderNode: Node = { name: 'unlocked', isLocked: false, isFile: false, isFolder: true } as Node;
const fakeNodeNoProperty: Node = { name: 'unlocked', isLocked: true, isFile: true, properties: {} } as Node;
setupTestBed({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
]
});
beforeEach(() => {
service = TestBed.inject(LockService);
apiService = TestBed.inject(AlfrescoApiService);
});
it('should return false when no lock is configured', () => {
expect(service.isLocked(fakeNodeUnlocked)).toBeFalsy();
});
it('should return false when isLocked is true but property `cm:lockType` is not present', () => {
expect(service.isLocked(fakeNodeNoProperty)).toBeFalsy();
});
it('should return false when a node folder', () => {
expect(service.isLocked(fakeFolderNode)).toBeFalsy();
});
describe('When the lock is readonly', () => {
const nodeReadonly: Node = {
name: 'readonly-lock-node',
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'READ_ONLY_LOCK',
'cm:lockLifetime': 'PERSISTENT'
}
} as Node;
const nodeReadOnlyWithExpiredDate: Node = {
name: 'readonly-lock-node',
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract(4, 'days')
}
} as Node;
const nodeReadOnlyWithActiveExpiration: Node = {
name: 'readonly-lock-node',
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add(4, 'days')
}
} as Node;
it('should return true when readonly lock is active', () => {
expect(service.isLocked(nodeReadonly)).toBeTruthy();
});
it('should return false when readonly lock is expired', () => {
expect(service.isLocked(nodeReadOnlyWithExpiredDate)).toBeFalsy();
});
it('should return true when readonly lock is active and expiration date is active', () => {
expect(service.isLocked(nodeReadOnlyWithActiveExpiration)).toBeTruthy();
});
});
describe('When only the lock owner is allowed', () => {
const nodeOwnerAllowedLock: Node = {
name: 'readonly-lock-node',
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' }
}
} as Node;
const nodeOwnerAllowedLockWithExpiredDate: Node = {
name: 'readonly-lock-node',
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract(4, 'days')
}
} as Node;
const nodeOwnerAllowedLockWithActiveExpiration: Node = {
name: 'readonly-lock-node',
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add(4, 'days')
}
} as Node;
it('should return false when the user is the lock owner', () => {
spyOn(apiService.getInstance(), 'getEcmUsername').and.returnValue('lock-owner-user');
expect(service.isLocked(nodeOwnerAllowedLock)).toBeFalsy();
});
it('should return true when the user is not the lock owner', () => {
spyOn(apiService.getInstance(), 'getEcmUsername').and.returnValue('banana-user');
expect(service.isLocked(nodeOwnerAllowedLock)).toBeTruthy();
});
it('should return false when the user is not the lock owner but the lock is expired', () => {
spyOn(apiService.getInstance(), 'getEcmUsername').and.returnValue('banana-user');
expect(service.isLocked(nodeOwnerAllowedLockWithExpiredDate)).toBeFalsy();
});
it('should return true when is not the lock owner and the expiration date is valid', () => {
spyOn(apiService.getInstance(), 'getEcmUsername').and.returnValue('banana-user');
expect(service.isLocked(nodeOwnerAllowedLockWithActiveExpiration)).toBeTruthy();
});
});
});

View File

@@ -0,0 +1,72 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
import moment, { Moment } from 'moment';
@Injectable({
providedIn: 'root'
})
export class LockService {
constructor(private alfrescoApiService: AlfrescoApiService) {
}
isLocked(node: Node): boolean {
let isLocked = false;
if (this.hasLockConfigured(node)) {
if (this.isReadOnlyLock(node)) {
isLocked = !this.isLockExpired(node);
} else if (this.isLockOwnerAllowed(node)) {
isLocked = this.alfrescoApiService.getInstance().getEcmUsername() !== node.properties['cm:lockOwner'].id;
if (this.isLockExpired(node)) {
isLocked = false;
}
}
}
return isLocked;
}
private hasLockConfigured(node: Node): boolean {
return node.isFile && node.isLocked && node.properties['cm:lockType'];
}
private isReadOnlyLock(node: Node): boolean {
return node.properties['cm:lockType'] === 'READ_ONLY_LOCK' && node.properties['cm:lockLifetime'] === 'PERSISTENT';
}
private isLockOwnerAllowed(node: Node): boolean {
return node.properties['cm:lockType'] === 'WRITE_LOCK' && node.properties['cm:lockLifetime'] === 'PERSISTENT';
}
private getLockExpiryTime(node: Node): Moment | undefined {
if (node.properties['cm:expiryDate']) {
return moment(node.properties['cm:expiryDate'], 'yyyy-MM-ddThh:mm:ssZ');
}
return undefined;
}
private isLockExpired(node: Node): boolean {
const expiryLockTime = this.getLockExpiryTime(node);
if (expiryLockTime) {
return moment().isAfter(expiryLockTime);
}
return false;
}
}

View File

@@ -29,7 +29,7 @@ import { getFakeSitePaging,
} from '../mock';
import { ContentTestingModule } from '../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
const customSiteList = {
list: {

View File

@@ -21,7 +21,7 @@ import { SitePaging, SiteEntry } from '@alfresco/js-api';
import { MatSelectChange } from '@angular/material/select';
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {TranslateService} from '@ngx-translate/core';
import { SitesService } from '../services/sites.service';
import { SitesService } from '../common/services/sites.service';
/* eslint-disable no-shadow */
/* eslint-disable @typescript-eslint/naming-convention */

View File

@@ -40,6 +40,6 @@ export * from './lib/new-version-uploader';
export * from './lib/interfaces/index';
export * from './lib/version-compatibility/index';
export * from './lib/pipes/index';
export * from './lib/services/index';
export * from './lib/common/index';
export * from './lib/content.module';