mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACA-1639] use alfresco-js-api-node for sitesApi (#553)
This commit is contained in:
committed by
Denys Vuika
parent
54f879f5e6
commit
b009f85246
@@ -57,11 +57,11 @@ describe('File Libraries', () => {
|
|||||||
.all([
|
.all([
|
||||||
apis.admin.people.createUser(username),
|
apis.admin.people.createUser(username),
|
||||||
apis.admin.sites.createSite(sitePublic, SITE_VISIBILITY.PUBLIC),
|
apis.admin.sites.createSite(sitePublic, SITE_VISIBILITY.PUBLIC),
|
||||||
apis.admin.sites.createSite(siteModerated, SITE_VISIBILITY.MODERATED, { description: siteDescription }),
|
apis.admin.sites.createSite(siteModerated, SITE_VISIBILITY.MODERATED, siteDescription),
|
||||||
apis.admin.sites.createSite(sitePrivate, SITE_VISIBILITY.PRIVATE, { description: '' }),
|
apis.admin.sites.createSite(sitePrivate, SITE_VISIBILITY.PRIVATE, null),
|
||||||
apis.admin.sites.createSite(adminSite, SITE_VISIBILITY.PUBLIC),
|
apis.admin.sites.createSite(adminSite, SITE_VISIBILITY.PUBLIC),
|
||||||
apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC, { id: siteId1 }),
|
apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC, null, siteId1),
|
||||||
apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC, { id: siteId2 })
|
apis.admin.sites.createSite(siteName, SITE_VISIBILITY.PUBLIC, null, siteId2)
|
||||||
])
|
])
|
||||||
.then(() => apis.admin.sites.addSiteMember(sitePublic, username, SITE_ROLES.SITE_CONSUMER))
|
.then(() => apis.admin.sites.addSiteMember(sitePublic, username, SITE_ROLES.SITE_CONSUMER))
|
||||||
.then(() => apis.admin.sites.addSiteMember(siteModerated, username, SITE_ROLES.SITE_MANAGER))
|
.then(() => apis.admin.sites.addSiteMember(siteModerated, username, SITE_ROLES.SITE_MANAGER))
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Alfresco Example Content Application
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { SITE_VISIBILITY } from '../../../../configs';
|
|
||||||
|
|
||||||
export class Site {
|
|
||||||
title?: string;
|
|
||||||
visibility?: string = SITE_VISIBILITY.PUBLIC;
|
|
||||||
id?: string;
|
|
||||||
description?: string;
|
|
||||||
|
|
||||||
constructor(title: string, visibility: string, details: Site) {
|
|
||||||
this.title = title;
|
|
||||||
this.visibility = visibility;
|
|
||||||
this.id = title;
|
|
||||||
this.description = `${title} description`;
|
|
||||||
|
|
||||||
Object.assign(this, details);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -23,102 +23,78 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { RepoApi } from '../repo-api';
|
import { RepoApiNew } from '../repo-api-new';
|
||||||
import { Site } from './sites-api-models';
|
import { SiteBody, SiteMemberRoleBody, SiteMemberBody } from 'alfresco-js-api-node';
|
||||||
|
import { SITE_VISIBILITY } from '../../../../configs';
|
||||||
|
|
||||||
export class SitesApi extends RepoApi {
|
export class SitesApi extends RepoApiNew {
|
||||||
getSite(id: string): Promise<any> {
|
|
||||||
return this
|
constructor(username?, password?) {
|
||||||
.get(`/sites/${id}`)
|
super(username, password);
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSiteContainers(siteId: string): Promise<any> {
|
async getSite(siteId: string) {
|
||||||
return this
|
await this.apiAuth();
|
||||||
.get(`/sites/${siteId}/containers`)
|
return await this.alfrescoJsApi.core.sitesApi.getSite(siteId);
|
||||||
.then(resp => resp.data.list.entries)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDocLibId(siteId: string) {
|
async getDocLibId(siteId: string) {
|
||||||
return this.getSiteContainers(siteId)
|
await this.apiAuth();
|
||||||
.then(resp => resp[0].entry.id)
|
return (await this.alfrescoJsApi.core.sitesApi.getSiteContainers(siteId)).list.entries[0].entry.id;
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSite(id: string, details?: Site): Promise<any> {
|
async createSite(title: string, visibility?: string, description?: string, siteId?: string) {
|
||||||
if (details.id) {
|
const site = <SiteBody>{
|
||||||
delete details.id;
|
title,
|
||||||
}
|
visibility: visibility || SITE_VISIBILITY.PUBLIC,
|
||||||
|
description: description,
|
||||||
return this
|
id: siteId || title
|
||||||
.put(`/sites/${id}`, { data: details })
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
|
||||||
|
|
||||||
createOrUpdateSite(title: string, visibility: string, details?: Site): Promise<any> {
|
|
||||||
const site: Site = new Site(title, visibility, details);
|
|
||||||
const onSuccess = (response) => response;
|
|
||||||
const onError = (response) => {
|
|
||||||
return (response.statusCode === 409)
|
|
||||||
? Promise.resolve(this.updateSite(site.id, site))
|
|
||||||
: Promise.reject(response);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this
|
await this.apiAuth();
|
||||||
.post(`/sites`, { data: site })
|
return await this.alfrescoJsApi.core.sitesApi.createSite(site);
|
||||||
.then(onSuccess, onError)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createSite(title: string, visibility: string, details?: Site): Promise<any> {
|
async createSites(titles: string[], visibility: string) {
|
||||||
const site: Site = new Site(title, visibility, details);
|
return await titles.reduce(async (previous: any, current: any) => {
|
||||||
return this
|
await previous;
|
||||||
.post(`/sites`, { data: site })
|
return await this.createSite(current, visibility);
|
||||||
.catch(this.handleError);
|
}, Promise.resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
createSites(titles: string[], visibility: string): Promise<any[]> {
|
async deleteSite(siteId: string, permanent: boolean = true) {
|
||||||
return titles.reduce((previous, current) => (
|
await this.apiAuth();
|
||||||
previous.then(() => this.createSite(current, visibility))
|
return this.alfrescoJsApi.core.sitesApi.deleteSite(siteId, { permanent });
|
||||||
), Promise.resolve());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSite(id: string, permanent: boolean = true): Promise<any> {
|
async deleteSites(siteIds: string[], permanent: boolean = true) {
|
||||||
return this
|
return await siteIds.reduce(async (previous, current) => {
|
||||||
.delete(`/sites/${id}?permanent=${permanent}`)
|
await previous;
|
||||||
.catch(this.handleError);
|
return await this.deleteSite(current);
|
||||||
|
}, Promise.resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSites(ids: string[], permanent: boolean = true): Promise<any[]> {
|
async updateSiteMember(siteId: string, userId: string, role: string) {
|
||||||
return ids.reduce((previous, current) => (
|
const siteRole = <SiteMemberRoleBody>{
|
||||||
previous.then(() => this.deleteSite(current))
|
role: role
|
||||||
), Promise.resolve());
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSiteMember(siteId: string, userId: string, role: string): Promise<any> {
|
|
||||||
return this
|
|
||||||
.put(`/sites/${siteId}/members/${userId}`, { data: { role } })
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
|
||||||
|
|
||||||
addSiteMember(siteId: string, userId: string, role: string): Promise<any> {
|
|
||||||
const onSuccess = (response) => response;
|
|
||||||
const onError = (response) => {
|
|
||||||
return (response.statusCode === 409)
|
|
||||||
? Promise.resolve(this.updateSiteMember(siteId, userId, role))
|
|
||||||
: Promise.reject(response);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this
|
await this.apiAuth();
|
||||||
.post(`/sites/${siteId}/members`, { data: { role, id: userId } })
|
return await this.alfrescoJsApi.core.sitesApi.updateSiteMember(siteId, userId, siteRole);
|
||||||
.then(onSuccess, onError)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSiteMember(siteId: string, userId: string): Promise<any> {
|
async addSiteMember(siteId: string, userId: string, role: string) {
|
||||||
return this
|
const memberBody = <SiteMemberBody>{
|
||||||
.delete(`/sites/${siteId}/members/${userId}`)
|
id: userId,
|
||||||
.catch(this.handleError);
|
role: role
|
||||||
|
};
|
||||||
|
|
||||||
|
await this.apiAuth();
|
||||||
|
return await this.alfrescoJsApi.core.sitesApi.addSiteMember(siteId, memberBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteSiteMember(siteId: string, userId: string) {
|
||||||
|
await this.apiAuth();
|
||||||
|
return await this.alfrescoJsApi.core.sitesApi.removeSiteMember(siteId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ export class RepoClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get sites() {
|
get sites() {
|
||||||
return new SitesApi(this.auth, this.config);
|
return new SitesApi(this.auth.username, this.auth.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
get favorites() {
|
get favorites() {
|
||||||
|
Reference in New Issue
Block a user