[ADF-3745] Added docs for new core services (#4126)

This commit is contained in:
Andy Stark
2019-01-10 01:40:07 +00:00
committed by Eugenio Romano
parent 5690a64842
commit 78411fc365
9 changed files with 206 additions and 17 deletions

View File

@@ -31,24 +31,49 @@ export class DownloadZipService {
private logService: LogService) {
}
/**
* Creates a new download.
* @param payload Object containing the node IDs of the items to add to the ZIP file
* @returns Status object for the download
*/
createDownload(payload: DownloadBodyCreate): Observable<DownloadEntry> {
return from(this.apiService.getInstance().core.downloadsApi.createDownload(payload)).pipe(
catchError((err) => this.handleError(err))
);
}
/**
* Gets a content URL for the given node.
* @param nodeId Node to get URL for.
* @param attachment Toggles whether to retrieve content as an attachment for download
* @returns URL string
*/
getContentUrl(nodeId: string, attachment?: boolean): string {
return this.apiService.getInstance().content.getContentUrl(nodeId, attachment);
}
/**
* Gets a Node via its node ID.
* @param nodeId ID of the target node
* @returns Details of the node
*/
getNode(nodeId: string): Observable<NodeEntry> {
return from(this.apiService.getInstance().core.nodesApi.getNode(nodeId));
}
/**
* Gets status information for a download node.
* @param downloadId ID of the download node
* @returns Status object for the download
*/
getDownload(downloadId: string): Observable<DownloadEntry> {
return from(this.apiService.getInstance().core.downloadsApi.getDownload(downloadId));
}
/**
* Cancels a download.
* @param downloadId ID of the target download node
*/
cancelDownload(downloadId: string) {
this.apiService.getInstance().core.downloadsApi.cancelDownload(downloadId);
}

View File

@@ -24,6 +24,11 @@ export class JwtHelperService {
constructor() {}
/**
* Decodes a JSON web token into a JS object.
* @param token Token in encoded form
* @returns Decoded token data object
*/
decodeToken(token): Object {
let parts = token.split('.');

View File

@@ -42,6 +42,10 @@ export class IdentityUserService {
private apiService: AlfrescoApiService,
private appConfigService: AppConfigService) {}
/**
* Gets the name and other basic details of the current user.
* @returns User details
*/
getCurrentUserInfo(): IdentityUserModel {
const familyName = this.getValueFromToken<string>(IdentityUserService.FAMILY_NAME);
const givenName = this.getValueFromToken<string>(IdentityUserService.GIVEN_NAME);
@@ -51,6 +55,11 @@ export class IdentityUserService {
return new IdentityUserModel(user);
}
/**
* Gets a named value from the user access token.
* @param key Key name of the field to retrieve
* @returns Value associated with the key
*/
getValueFromToken<T>(key: string): T {
let value;
const token = localStorage.getItem(IdentityUserService.USER_ACCESS_TOKEN);
@@ -61,6 +70,10 @@ export class IdentityUserService {
return <T> value;
}
/**
* Gets details for all users.
* @returns Array of user info objects
*/
getUsers(): Observable<IdentityUserModel[]> {
const url = this.buildUserUrl();
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
@@ -77,6 +90,11 @@ export class IdentityUserService {
);
}
/**
* Gets a list of roles for a user.
* @param userId ID of the user
* @returns Array of role info objects
*/
getUserRoles(userId: string): Observable<IdentityRoleModel[]> {
const url = this.buildRolesUrl(userId);
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
@@ -93,6 +111,11 @@ export class IdentityUserService {
);
}
/**
* Gets an array of users (including the current user) who have any of the roles in the supplied list.
* @param roleNames List of role names to look for
* @returns Array of user info objects
*/
async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) {
@@ -109,6 +132,11 @@ export class IdentityUserService {
return filteredUsers;
}
/**
* Gets an array of users (not including the current user) who have any of the roles in the supplied list.
* @param roleNames List of role names to look for
* @returns Array of user info objects
*/
async getUsersByRolesWithoutCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) {