UNPKG

@dasch-swiss/dsp-js

Version:

JavaScript library that handles API requests to Knora

188 lines 12.4 kB
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { catchError, map } from "rxjs/operators"; import { AdministrativePermissionResponse } from "../../../models/admin/administrative-permission-response"; import { AdministrativePermissionsResponse } from "../../../models/admin/administrative-permissions-response"; import { DefaultObjectAccessPermissionResponse } from "../../../models/admin/default-object-access-permission-response"; import { DefaultObjectAccessPermissionsResponse } from "../../../models/admin/default-object-access-permissions-response"; import { DeletePermissionResponse } from "../../../models/admin/delete-permission-response"; import { ProjectPermissionsResponse } from "../../../models/admin/project-permissions-response"; import { ApiResponseData } from "../../../models/api-response-data"; import { Endpoint } from "../../endpoint"; /** * An endpoint for working with Knora permissions. * @deprecated Use open API docs instead * @category Endpoint Admin */ var PermissionsEndpointAdmin = /** @class */ (function (_super) { __extends(PermissionsEndpointAdmin, _super); function PermissionsEndpointAdmin() { return _super !== null && _super.apply(this, arguments) || this; } /** * Gets the permissions for a project. * * @param projectIri The project IRI. */ PermissionsEndpointAdmin.prototype.getProjectPermissions = function (projectIri) { var _this = this; return this.httpGet("/" + encodeURIComponent(projectIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, ProjectPermissionsResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Gets the administrative permissions for a project. * * @param projectIri The project IRI. */ PermissionsEndpointAdmin.prototype.getAdministrativePermissions = function (projectIri) { var _this = this; return this.httpGet("/ap/" + encodeURIComponent(projectIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, AdministrativePermissionsResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Gets the administrative permission for a project and group. * * @param projectIri The project IRI. * @param groupIri The group IRI. */ PermissionsEndpointAdmin.prototype.getAdministrativePermission = function (projectIri, groupIri) { var _this = this; return this.httpGet("/ap/" + encodeURIComponent(projectIri) + "/" + encodeURIComponent(groupIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, AdministrativePermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Creates an administrative permission. * * @param administrativePermission the administrative permission to be created. */ PermissionsEndpointAdmin.prototype.createAdministrativePermission = function (administrativePermission) { var _this = this; if (!administrativePermission.forGroup || !administrativePermission.forProject) { throw new Error("Group and project are required when creating a new administrative permission."); } if (administrativePermission.hasPermissions.length === 0) { throw new Error("At least one permission is expected."); } return this.httpPost("/ap", this.jsonConvert.serializeObject(administrativePermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, AdministrativePermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates an existing administrative permission. * * @param permissionIri the Iri of the permission to be updated. * @param administrativePermission the new permission settings. */ PermissionsEndpointAdmin.prototype.updateAdministrativePermission = function (permissionIri, administrativePermission) { var _this = this; return this.httpPut("/" + encodeURIComponent(permissionIri) + "/hasPermissions", this.jsonConvert.serializeObject(administrativePermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, AdministrativePermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates an existing administrative permission's group. * * @param permissionIri the Iri of the permission to be updated. * @param updateAdministrativePermissionGroup the new group setting. */ PermissionsEndpointAdmin.prototype.updateAdministrativePermissionGroup = function (permissionIri, updateAdministrativePermissionGroup) { var _this = this; return this.httpPut("/" + encodeURIComponent(permissionIri) + "/group", this.jsonConvert.serializeObject(updateAdministrativePermissionGroup)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, AdministrativePermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Gets all default object access permissions for a project. * * @param projectIri The project IRI. */ PermissionsEndpointAdmin.prototype.getDefaultObjectAccessPermissions = function (projectIri) { var _this = this; return this.httpGet("/doap/" + encodeURIComponent(projectIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DefaultObjectAccessPermissionsResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Creates a default object access permission. * * @param defaultObjectAccessPermission the permission to be created. */ PermissionsEndpointAdmin.prototype.createDefaultObjectAccessPermission = function (defaultObjectAccessPermission) { var _this = this; // A default object access permission must // always reference a project if (!defaultObjectAccessPermission.forProject) { throw new Error("Project is required when creating a new default object access permission."); } if (defaultObjectAccessPermission.hasPermissions.length === 0) { throw new Error("At least one permission is expected."); } /* A default object access permission can only reference either a group, a resource class, a property, or a combination of resource class and property. */ if ((defaultObjectAccessPermission.forGroup && !defaultObjectAccessPermission.forResourceClass && !defaultObjectAccessPermission.forProperty || !defaultObjectAccessPermission.forGroup && defaultObjectAccessPermission.forResourceClass && !defaultObjectAccessPermission.forProperty || !defaultObjectAccessPermission.forGroup && !defaultObjectAccessPermission.forResourceClass && defaultObjectAccessPermission.forProperty) || !defaultObjectAccessPermission.forGroup && defaultObjectAccessPermission.forResourceClass && defaultObjectAccessPermission.forProperty) { return this.httpPost("/doap", this.jsonConvert.serializeObject(defaultObjectAccessPermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DefaultObjectAccessPermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); } else { throw new Error("Invalid combination of properties for creation of new default object access permission."); } }; /** * Updates an existing default object access permission. * * @param permissionIri the Iri of the permission to be updated. * @param defaultObjectAccessPermission the new permission settings. */ PermissionsEndpointAdmin.prototype.updateDefaultObjectAccessPermission = function (permissionIri, defaultObjectAccessPermission) { var _this = this; return this.httpPut("/" + encodeURIComponent(permissionIri) + "/hasPermissions", this.jsonConvert.serializeObject(defaultObjectAccessPermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DefaultObjectAccessPermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates an existing default object access permission's group. * * @param permissionIri the Iri of the permission to be updated. * @param administrativePermission the new permission settings. */ PermissionsEndpointAdmin.prototype.updateDefaultObjectAccessPermissionGroup = function (permissionIri, administrativePermission) { var _this = this; return this.httpPut("/" + encodeURIComponent(permissionIri) + "/group", this.jsonConvert.serializeObject(administrativePermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DefaultObjectAccessPermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates an existing default object access permission's resource class. * * @param permissionIri the Iri of the permission to be updated. * @param administrativePermission the new permission settings. */ PermissionsEndpointAdmin.prototype.updateDefaultObjectAccessPermissionResourceClass = function (permissionIri, administrativePermission) { var _this = this; return this.httpPut("/" + encodeURIComponent(permissionIri) + "/resourceClass", this.jsonConvert.serializeObject(administrativePermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DefaultObjectAccessPermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Updates an existing default object access permission's property. * * @param permissionIri the Iri of the permission to be updated. * @param administrativePermission the new permission settings. */ PermissionsEndpointAdmin.prototype.updateDefaultObjectAccessPermissionProperty = function (permissionIri, administrativePermission) { var _this = this; return this.httpPut("/" + encodeURIComponent(permissionIri) + "/property", this.jsonConvert.serializeObject(administrativePermission)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DefaultObjectAccessPermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; /** * Deletes a permission. * * @param permissionIri the IRI of the permission to be deleted. */ PermissionsEndpointAdmin.prototype.deletePermission = function (permissionIri) { var _this = this; return this.httpDelete("/" + encodeURIComponent(permissionIri)).pipe(map(function (ajaxResponse) { return ApiResponseData.fromAjaxResponse(ajaxResponse, DeletePermissionResponse, _this.jsonConvert); }), catchError(function (error) { return _this.handleError(error); })); }; return PermissionsEndpointAdmin; }(Endpoint)); export { PermissionsEndpointAdmin }; //# sourceMappingURL=permissions-endpoint-admin.js.map