@dasch-swiss/dsp-js
Version:
TypeScript client library for DSP-API
188 lines • 8.87 kB
JavaScript
import { catchError, map } from 'rxjs';
import { GroupsResponse } from '../../../models/admin/groups-response';
import { ProjectsResponse } from '../../../models/admin/projects-response';
import { UserResponse } from '../../../models/admin/user-response';
import { UsersResponse } from '../../../models/admin/users-response';
import { ApiResponseData } from '../../../models/api-response-data';
import { Endpoint } from '../../endpoint';
/**
* An endpoint for working with Knora users.
* @deprecated Use open API docs instead
* @category Endpoint Admin
*/
export class UsersEndpointAdmin extends Endpoint {
/**
* Returns a list of all users.
*/
getUsers() {
return this.httpGet('').pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UsersResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Gets a user by a property.
*
* @param property The name of the property by which the user is identified.
* @param value The value of the property by which the user is identified.
*/
getUser(property, value) {
return this.httpGet(`/${encodeURIComponent(property)}/${encodeURIComponent(value)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Gets a user by IRI.
*
* @param iri The IRI of the user.
*/
getUserByIri(iri) {
return this.getUser('iri', iri);
}
/**
* Gets a user by email address.
*
* @param email The email address of the user.
*/
getUserByEmail(email) {
return this.getUser('email', email);
}
/**
* Gets a user by username.
*
* @param username The username of the user.
*/
getUserByUsername(username) {
return this.getUser('username', username);
}
/**
* Gets a user's group memberships.
*
* @param iri The user's IRI.
*/
getUserGroupMemberships(iri) {
return this.httpGet(`/iri/${encodeURIComponent(iri)}/group-memberships`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, GroupsResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Gets a user's project memberships.
*
* @param iri The IRI of the user.
*/
getUserProjectMemberships(iri) {
return this.httpGet(`/iri/${encodeURIComponent(iri)}/project-memberships`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, ProjectsResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Gets a user's project admin memberships.
*
* @param iri The user's IRI.
*/
getUserProjectAdminMemberships(iri) {
return this.httpGet(`/iri/${encodeURIComponent(iri)}/project-admin-memberships`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, ProjectsResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Creates a user.
*
* @param user The user to be created.
*/
createUser(user) {
return this.httpPost('', this.jsonConvert.serializeObject(user)).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Updates an existing user's basic information.
*
* @param iri The IRI of the user to be updated.
* @param userInfo The user information to be updated.
*/
updateUserBasicInformation(iri, userInfo) {
return this.httpPut(`/iri/${encodeURIComponent(iri)}/BasicUserInformation`, this.jsonConvert.serializeObject(userInfo)).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Updates a user's status.
*
* @param iri The user's IRI.
* @param status The user's new status.
*/
updateUserStatus(iri, status) {
return this.httpPut(`/iri/${encodeURIComponent(iri)}/Status`, { status }).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Updates a user's password.
*
* @param iri The IRI of the user to be updated.
* @param requesterPassword The requesting user's current password.
* @param newPassword The specified user's new password.
*/
updateUserPassword(iri, requesterPassword, newPassword) {
return this.httpPut(`/iri/${encodeURIComponent(iri)}/Password`, {
requesterPassword,
newPassword,
}).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Adds a user to a group.
*
* @param userIri The IRI of the user.
* @param groupIri The IRI of the group.
*/
addUserToGroupMembership(userIri, groupIri) {
return this.httpPost(`/iri/${encodeURIComponent(userIri)}/group-memberships/${encodeURIComponent(groupIri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Removes a user from a project.
*
* @param userIri The IRI of the user.
* @param groupIri The IRI of the group.
*/
removeUserFromGroupMembership(userIri, groupIri) {
return this.httpDelete(`/iri/${encodeURIComponent(userIri)}/group-memberships/${encodeURIComponent(groupIri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Adds a user to a project.
*
* @param userIri The user's IRI.
* @param projectIri The project's IRI.
*/
addUserToProjectMembership(userIri, projectIri) {
return this.httpPost(`/iri/${encodeURIComponent(userIri)}/project-memberships/${encodeURIComponent(projectIri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Removes a user from a project.
*
* @param userIri The user's IRI.
* @param projectIri The project's IRI.
*/
removeUserFromProjectMembership(userIri, projectIri) {
return this.httpDelete(`/iri/${encodeURIComponent(userIri)}/project-memberships/${encodeURIComponent(projectIri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Makes a user a project administrator.
*
* @param userIri The IRI of the user.
* @param projectIri The IRI of the project.
*/
addUserToProjectAdminMembership(userIri, projectIri) {
return this.httpPost(`/iri/${encodeURIComponent(userIri)}/project-admin-memberships/${encodeURIComponent(projectIri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Removes a user's project administrator status.
*
* @param userIri The IRI of the user.
* @param projectIri The IRI of the project.
*/
removeUserFromProjectAdminMembership(userIri, projectIri) {
return this.httpDelete(`/iri/${encodeURIComponent(userIri)}/project-admin-memberships/${encodeURIComponent(projectIri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Updates a user's SystemAdmin membership.
*
* @param iri The IRI of the user to be updated.
* @param systemAdmin True if the user should be a system admin
*/
updateUserSystemAdminMembership(iri, systemAdmin) {
return this.httpPut(`/iri/${encodeURIComponent(iri)}/SystemAdmin`, { systemAdmin }).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
/**
* Deletes a user. This method does not actually delete a user, but sets the status to false.
*
* @param iri The IRI of the user to be deleted.
*/
deleteUser(iri) {
return this.httpDelete(`/iri/${encodeURIComponent(iri)}`).pipe(map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, UserResponse, this.jsonConvert)), catchError(error => this.handleError(error)));
}
}
//# sourceMappingURL=users-endpoint-admin.js.map