[ACA-1634] update peopleApi to use alfresco-ja-api-node in e2e (#558)

* update peopleApi to use alfresco-ja-api-node in e2e

* small code improvement
This commit is contained in:
Adina Parpalita
2018-08-09 20:51:45 +03:00
committed by Denys Vuika
parent b8cc5422f4
commit 8c76d92f47
29 changed files with 76 additions and 80 deletions

View File

@@ -23,21 +23,31 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
export class Person {
id?: string;
export interface PersonModel {
username?: string;
password?: string;
firstName?: string;
lastName?: string;
email?: string;
enabled?: boolean;
properties?: any;
}
constructor(username: string, password: string, details: Person) {
this.id = username;
this.password = password || username;
this.firstName = username;
this.lastName = username;
this.email = `${username}@alfresco.com`;
export class Person {
id: string;
password: string;
firstName: string;
lastName: string;
email: string;
enabled: boolean;
properties: any;
Object.assign(this, details);
constructor(user: PersonModel) {
this.id = user.username;
this.password = user.password || user.username;
this.firstName = user.firstName || user.username;
this.lastName = user.lastName || user.username;
this.email = user.email || `${user.username}@alfresco.com`;
this.enabled = user.enabled || true;
}
}

View File

@@ -23,48 +23,36 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Person } from './people-api-models';
import { PersonModel, Person } from './people-api-models';
import { RepoApiNew } from '../repo-api-new';
export class PeopleApi extends RepoApi {
getUser(username: string) {
return this
.get(`/people/${username}`)
.catch(this.handleError);
export class PeopleApi extends RepoApiNew {
constructor(username?, password?) {
super(username, password);
}
updateUser(username: string, details?: Person): Promise<any> {
if (details.id) {
delete details.id;
}
return this
.put(`/people/${username}`, { data: details })
.catch(this.handleError);
async createUser(user: PersonModel) {
const person = new Person(user);
await this.apiAuth();
return await this.alfrescoJsApi.core.peopleApi.addPerson(person);
}
createUser(username: string, password?: string, details?: Person): Promise<any> {
const person: Person = new Person(username, password, details);
const onSuccess = (response) => response;
const onError = (response) => {
return (response.statusCode === 409)
? Promise.resolve(this.updateUser(username, person))
: Promise.reject(response);
};
return this
.post(`/people`, { data: person })
.then(onSuccess, onError)
.catch(this.handleError);
async getUser(username: string) {
await this.apiAuth();
return await this.alfrescoJsApi.core.peopleApi.getPerson(username);
}
disableUser(username: string): Promise<any> {
return this.put(`/people/${username}`, { data: { enabled: false } })
.catch(this.handleError);
async updateUser(username: string, userDetails?: PersonModel) {
await this.apiAuth();
return this.alfrescoJsApi.core.peopleApi.updatePerson(username, userDetails);
}
changePassword(username: string, newPassword: string) {
return this.put(`/people/${username}`, { data: { password: newPassword } })
.catch(this.handleError);
async disableUser(username: string) {
return await this.updateUser(username, { enabled: false });
}
async changePassword(username: string, newPassword: string) {
return await this.updateUser(username, { password: newPassword });
}
}

View File

@@ -46,7 +46,7 @@ export class RepoClient {
}
get people () {
return new PeopleApi(this.auth, this.config);
return new PeopleApi(this.auth.username, this.auth.password);
}
get nodes() {