UNPKG

@knora/api

Version:

JavaScript library that handles API requests to Knora

220 lines 12.6 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var operators_1 = require("rxjs/operators"); var api_response_data_1 = require("../../../models/api-response-data"); var endpoint_1 = require("../../endpoint"); var groups_response_1 = require("../../../models/admin/groups-response"); var projects_response_1 = require("../../../models/admin/projects-response"); var user_response_1 = require("../../../models/admin/user-response"); var users_response_1 = require("../../../models/admin/users-response"); /** * An endpoint for working with Knora users. */ var UsersEndpoint = /** @class */ (function (_super) { __extends(UsersEndpoint, _super); function UsersEndpoint() { return _super !== null && _super.apply(this, arguments) || this; } /** * Returns a list of all users. */ UsersEndpoint.prototype.getUsers = function () { var _this = this; return this.httpGet("").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, users_response_1.UsersResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _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. */ UsersEndpoint.prototype.getUser = function (property, value) { var _this = this; return this.httpGet("/" + encodeURIComponent(property) + "/" + encodeURIComponent(value)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Gets a user by IRI. * * @param iri The IRI of the user. */ UsersEndpoint.prototype.getUserByIri = function (iri) { return this.getUser("iri", iri); }; /** * Gets a user by email address. * * @param email The email address of the user. */ UsersEndpoint.prototype.getUserByEmail = function (email) { return this.getUser("email", email); }; /** * Gets a user by username. * * @param username The username of the user. */ UsersEndpoint.prototype.getUserByUsername = function (username) { return this.getUser("username", username); }; /** * Gets a user's group memberships. * * @param iri The user's IRI. */ UsersEndpoint.prototype.getUserGroupMemberships = function (iri) { var _this = this; return this.httpGet("/iri/" + encodeURIComponent(iri) + "/group-memberships").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, groups_response_1.GroupsResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Gets a user's project memberships. * * @param iri The IRI of the user. */ UsersEndpoint.prototype.getUserProjectMemberships = function (iri) { var _this = this; return this.httpGet("/iri/" + encodeURIComponent(iri) + "/project-memberships").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, projects_response_1.ProjectsResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Gets a user's project admin memberships. * * @param iri The user's IRI. */ UsersEndpoint.prototype.getUserProjectAdminMemberships = function (iri) { var _this = this; return this.httpGet("/iri/" + encodeURIComponent(iri) + "/project-admin-memberships").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, projects_response_1.ProjectsResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Creates a user. * * @param user The user to be created. */ UsersEndpoint.prototype.createUser = function (user) { var _this = this; return this.httpPost("", this.jsonConvert.serializeObject(user)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _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. */ UsersEndpoint.prototype.updateUserBasicInformation = function (iri, userInfo) { var _this = this; return this.httpPut("/iri/" + encodeURIComponent(iri) + "/BasicUserInformation", this.jsonConvert.serializeObject(userInfo)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Updates a user's status. * * @param iri The user's IRI. * @param status The user's new status. */ UsersEndpoint.prototype.updateUserStatus = function (iri, status) { var _this = this; return this.httpPut("/iri/" + encodeURIComponent(iri) + "/Status", { status: status }).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _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. */ UsersEndpoint.prototype.updateUserPassword = function (iri, requesterPassword, newPassword) { var _this = this; return this.httpPut("/iri/" + encodeURIComponent(iri) + "/Password", { requesterPassword: requesterPassword, newPassword: newPassword }).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Adds a user to a group. * * @param userIri The IRI of the user. * @param groupIri The IRI of the group. */ UsersEndpoint.prototype.addUserToGroupMembership = function (userIri, groupIri) { var _this = this; return this.httpPost("/iri/" + encodeURIComponent(userIri) + "/group-memberships/" + encodeURIComponent(groupIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Removes a user from a project. * * @param userIri The IRI of the user. * @param groupIri The IRI of the group. */ UsersEndpoint.prototype.removeUserFromGroupMembership = function (userIri, groupIri) { var _this = this; return this.httpDelete("/iri/" + encodeURIComponent(userIri) + "/group-memberships/" + encodeURIComponent(groupIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Adds a user to a project. * * @param userIri The user's IRI. * @param projectIri The project's IRI. */ UsersEndpoint.prototype.addUserToProjectMembership = function (userIri, projectIri) { var _this = this; return this.httpPost("/iri/" + encodeURIComponent(userIri) + "/project-memberships/" + encodeURIComponent(projectIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Removes a user from a project. * * @param userIri The user's IRI. * @param projectIri The project's IRI. */ UsersEndpoint.prototype.removeUserFromProjectMembership = function (userIri, projectIri) { var _this = this; return this.httpDelete("/iri/" + encodeURIComponent(userIri) + "/project-memberships/" + encodeURIComponent(projectIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Makes a user a project administrator. * * @param userIri The IRI of the user. * @param projectIri The IRI of the project. */ UsersEndpoint.prototype.addUserToProjectAdminMembership = function (userIri, projectIri) { var _this = this; return this.httpPost("/iri/" + encodeURIComponent(userIri) + "/project-admin-memberships/" + encodeURIComponent(projectIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Removes a user's project administrator status. * * @param userIri The IRI of the user. * @param projectIri The IRI of the project. */ UsersEndpoint.prototype.removeUserFromProjectAdminMembership = function (userIri, projectIri) { var _this = this; return this.httpDelete("/iri/" + encodeURIComponent(userIri) + "/project-admin-memberships/" + encodeURIComponent(projectIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Updates a user's SystemAdmin membership. * * @param user The user to be updated. */ UsersEndpoint.prototype.updateUserSystemAdminMembership = function (user) { var _this = this; return this.httpPut("/iri/" + encodeURIComponent(user.id) + "/SystemAdmin", { systemAdmin: user.systemAdmin }).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _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. */ UsersEndpoint.prototype.deleteUser = function (iri) { var _this = this; return this.httpDelete("/iri/" + encodeURIComponent(iri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, user_response_1.UserResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; return UsersEndpoint; }(endpoint_1.Endpoint)); exports.UsersEndpoint = UsersEndpoint; //# sourceMappingURL=users-endpoint.js.map