mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AE-11486] move lock and favorite (#8089)
* [ci:force] move lock and favorite * fix
This commit is contained in:
@@ -21,7 +21,7 @@ import { ObjectUtils } from '../common/utils/object-utils';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { map, distinctUntilChanged, take } from 'rxjs/operators';
|
||||
import { ExtensionConfig, ExtensionService, mergeObjects } from '@alfresco/adf-extensions';
|
||||
import { OpenidConfiguration } from '../services/openid-configuration.interface';
|
||||
import { OpenidConfiguration } from '../auth/interfaces/openid-configuration.interface';
|
||||
|
||||
/* spellchecker: disable */
|
||||
// eslint-disable-next-line no-shadow
|
||||
|
@@ -15,39 +15,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './authentication-interceptor/auth-bearer.interceptor';
|
||||
|
||||
export * from './mock/authentication.service.mock';
|
||||
export * from './mock/identity-group.mock';
|
||||
export * from './mock/identity-group.service.mock';
|
||||
export * from './mock/identity-user.mock';
|
||||
export * from './mock/identity-user.service.mock';
|
||||
export * from './mock/jwt-helper.service.spec';
|
||||
export * from './mock/oauth2.service.mock';
|
||||
|
||||
export * from './guard/auth-guard-base';
|
||||
export * from './guard/auth-guard.service';
|
||||
export * from './guard/auth-guard-ecm.service';
|
||||
export * from './guard/auth-guard-bpm.service';
|
||||
export * from './guard/auth-guard-sso-role.service';
|
||||
|
||||
export * from './services/authentication.service';
|
||||
export * from './services/identity-group.interface';
|
||||
export * from './services/identity-role.service';
|
||||
|
||||
export * from './services/identity-user.service';
|
||||
export * from './services/jwt-helper.service';
|
||||
export * from './services/oauth2.service';
|
||||
|
||||
export * from './services/identity-user.service.interface';
|
||||
export * from './services/openid-configuration.interface';
|
||||
|
||||
export * from './models/oauth-config.model';
|
||||
export * from './models/redirection.model';
|
||||
|
||||
export * from './models/identity-group.model';
|
||||
export * from './models/identity-user.model';
|
||||
export * from './models/identity-role.model';
|
||||
|
||||
export * from './interface/authentication.interface';
|
||||
|
||||
export * from './public-api';
|
||||
|
52
lib/core/src/lib/auth/public-api.ts
Normal file
52
lib/core/src/lib/auth/public-api.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export * from './authentication-interceptor/auth-bearer.interceptor';
|
||||
|
||||
export * from './mock/authentication.service.mock';
|
||||
export * from './mock/identity-group.mock';
|
||||
export * from './mock/identity-group.service.mock';
|
||||
export * from './mock/identity-user.mock';
|
||||
export * from './mock/identity-user.service.mock';
|
||||
export * from './mock/jwt-helper.service.spec';
|
||||
export * from './mock/oauth2.service.mock';
|
||||
|
||||
export * from './guard/auth-guard-base';
|
||||
export * from './guard/auth-guard.service';
|
||||
export * from './guard/auth-guard-ecm.service';
|
||||
export * from './guard/auth-guard-bpm.service';
|
||||
export * from './guard/auth-guard-sso-role.service';
|
||||
|
||||
export * from './services/authentication.service';
|
||||
export * from './services/identity-group.interface';
|
||||
export * from './services/identity-role.service';
|
||||
|
||||
export * from './services/identity-user.service';
|
||||
export * from './services/jwt-helper.service';
|
||||
export * from './services/oauth2.service';
|
||||
|
||||
export * from './services/identity-user.service.interface';
|
||||
|
||||
export * from './models/oauth-config.model';
|
||||
export * from './models/redirection.model';
|
||||
|
||||
export * from './models/identity-group.model';
|
||||
export * from './models/identity-user.model';
|
||||
export * from './models/identity-role.model';
|
||||
|
||||
export * from './interfaces/openid-configuration.interface';
|
||||
|
@@ -21,7 +21,7 @@ import { AppConfigService, AppConfigValues } from '../app-config/app-config.serv
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
import { OauthConfigModel } from '../auth/models/oauth-config.model';
|
||||
import { StorageService } from '../common/services/storage.service';
|
||||
import { OpenidConfiguration } from './openid-configuration.interface';
|
||||
import { OpenidConfiguration } from '../auth/interfaces/openid-configuration.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@@ -1,93 +0,0 @@
|
||||
/*!
|
||||
* @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 } from './alfresco-api.service';
|
||||
import { UserPreferencesService } from '../common/services/user-preferences.service';
|
||||
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))
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,170 +0,0 @@
|
||||
/*!
|
||||
* @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 } from '../testing/core.testing.module';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,72 +0,0 @@
|
||||
/*!
|
||||
* @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-api.service';
|
||||
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;
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export interface OpenidConfiguration {
|
||||
authorization_endpoint: string;
|
||||
token_endpoint: string;
|
||||
userinfo_endpoint: string;
|
||||
end_session_endpoint: string;
|
||||
check_session_iframe: string;
|
||||
revocation_endpoint: string;
|
||||
introspection_endpoint: string;
|
||||
}
|
@@ -26,7 +26,6 @@ export * from './upload.service';
|
||||
export * from './dynamic-component-mapper.service';
|
||||
export * from './highlight-transform.service';
|
||||
export * from './deleted-nodes-api.service';
|
||||
export * from './favorites-api.service';
|
||||
export * from './nodes-api.service';
|
||||
export * from './people-content.service';
|
||||
export * from './people-process.service';
|
||||
@@ -37,7 +36,6 @@ export * from './comment-content.service';
|
||||
export * from './login-dialog.service';
|
||||
export * from './external-alfresco-api.service';
|
||||
export * from './download-zip.service';
|
||||
export * from './lock.service';
|
||||
export * from './automation.service';
|
||||
export * from './automation.service';
|
||||
export * from './download.service';
|
||||
|
Reference in New Issue
Block a user