Commit bfcd2416 authored by Matija Obreza's avatar Matija Obreza
Browse files

Services upgraded to match current API

parent 86d79ec7
import { log } from 'utilities/debug';
import { SidPermissions } from 'model/acl/ACL';
import SidPermissions from 'model/acl/SidPermissions';
import PermissionService from 'service/genesys/PermissionService';
export const permissions = (clazz: string, id: number) => (dispatch, getState) => {
......
import AclSid from 'model/acl/AclSid';
export class Permissions {
public create: boolean;
......@@ -30,14 +29,6 @@ export class Permissions {
}
}
export class SidPermissions extends Permissions {
public sid: AclSid | string;
public getClassname(): string {
return 'org.genesys.blocks.security.serialization.SidPermissions';
}
}
export interface IUserPermissions {
_permissions: Permissions;
}
import AclClass from 'model/acl/AclClass';
import AclSid from 'model/acl/AclSid';
import { SidPermissions } from 'model/acl/ACL';
import SidPermissions from 'model/acl/SidPermissions';
/*
* Defined in Swagger as '#/definitions/AclObjectIdentityExt'
......
import AclSid from 'model/acl/AclSid';
/*
* Defined in Swagger as '#/definitions/SidPermissions'
*/
class SidPermissions {
public create: boolean;
public delete: boolean;
public manage: boolean;
public read: boolean;
public sid: string | AclSid;
public write: boolean;
}
export default SidPermissions;
......@@ -72,7 +72,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
{ request.body.requestInfo && <PropertiesItem title="Purpose type">{ t(`request.purposeType.${request.body.requestInfo.purposeType}`) }</PropertiesItem> }
{ request.body.requestInfo && <PropertiesItem title={ t(`request.preacceptSMTA`) }>{ request.body.requestInfo.preacceptSMTA ? 'Yes' : 'No' }</PropertiesItem> }
{ request.body.requestInfo && <PropertiesItem title="Notes">{ request.body.requestInfo.notes }</PropertiesItem> }
<PropertiesItem title="Requested accession ids">{ request.body.accessionRefs.reduce((id, acc) => `${acc}, ${id}`) }</PropertiesItem>
<PropertiesItem title="Requested accession ids">{ request.body.accessionIds.reduce((id, acc) => `${acc}, ${id}`) }</PropertiesItem>
</Properties>
</MainSection>
{ request.body.pid && request.body.pid.type === 'in' &&
......
......@@ -40,7 +40,7 @@ const RequestCard = ({request, classes, index, ...other}: { request: MaterialReq
<b></b>
</span>
}
{ request.body.accessionRefs.length } accessions
{ request.body.accessionIds.length } accessions
</div>
</CardContent>
</Card>
......
import { axiosBackend } from 'utilities/requestUtils';
import ApiInfo from 'model/ApiInfo';
......@@ -19,7 +20,7 @@ class ApiInfoService {
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
......
......@@ -21,6 +21,7 @@ const URL_ENSURE_MENU_ITEM = `/api/v1/cms/ensure-menu-item`;
const URL_GET_GLOBAL_ARTICLE = UrlTemplate.parse(`/api/v1/cms/global-article/{slug}/{language}`);
const URL_GET_LAST_NEWS = `/api/v1/cms/last-news`;
const URL_LIST_ARTICLES = `/api/v1/cms/list`;
const URL_GET_DEFAULT_LOCALE = `/api/v1/cms/locale`;
const URL_GET_MENU = UrlTemplate.parse(`/api/v1/cms/menu/{menuKey}`);
const URL_PROCESS_TEMPLATE = `/api/v1/cms/process-template`;
const URL_UPDATE_ACTIVITY_POST = `/api/v1/cms/update-activity-post`;
......@@ -79,9 +80,9 @@ class CmsService {
* @param language language
* @param slug slug
*/
public static getArticleBySlugAndLang(slug: string, language: string): Promise<Article> {
public static getArticleBySlugAndLang(language: string, slug: string): Promise<Article> {
const apiUrl = URL_GET_ARTICLE_BY_SLUG_AND_LANG.expand({slug, language});
const apiUrl = URL_GET_ARTICLE_BY_SLUG_AND_LANG.expand({language, slug});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -241,6 +242,23 @@ class CmsService {
}).then(({ data }) => data as FilteredPage<Article>);
}
/**
* getDefaultLocale at /api/v1/cms/locale
*
*/
public static getDefaultLocale(): Promise<string> {
const apiUrl = URL_GET_DEFAULT_LOCALE;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as string);
}
/**
* getMenu at /api/v1/cms/menu/{menuKey}
*
......
......@@ -4,14 +4,14 @@ import * as QueryString from 'query-string';
import { axiosBackend } from 'utilities/requestUtils';
import AclObjectIdentity from 'model/acl/AclObjectIdentity';
import { SidPermissions } from 'model/acl/ACL';
import SidPermissions from 'model/acl/SidPermissions';
const URL_AC_SID = `/api/v1/permission/autocomplete`;
const URL_ADD_PERMISSION = UrlTemplate.parse(`/api/v1/permission/permissions/{clazz}/{id}`);
const URL_AC_OAUTH_CLIENT = `/api/v1/permission/autocomplete-oauth-client`;
const URL_AC_ROLE = `/api/v1/permission/autocompleterole`;
const URL_AC_USER = `/api/v1/permission/autocompleteuser`;
const URL_AC_SID = `/api/v1/permission/autocomplete`;
const URL_AC_ROLE = `/api/v1/permission/autocompleterole`;
const URL_PERMISSIONS = UrlTemplate.parse(`/api/v1/permission/permissions/{clazz}/{id}`);
const URL_ADD_PERMISSION = UrlTemplate.parse(`/api/v1/permission/permissions/{clazz}/{id}`);
/*
* Defined in Swagger as 'permission'
......@@ -19,24 +19,23 @@ const URL_ADD_PERMISSION = UrlTemplate.parse(`/api/v1/permission/permissions/{cl
class PermissionService {
/**
* acSid at /api/v1/permission/autocomplete
* addPermission at /api/v1/permission/permissions/{clazz}/{id}
*
* @param term term
* @param clazz clazz
* @param id id
* @param sidPermissions sidPermissions
*/
public static acSid(term: string): Promise<any> {
public static addPermission(clazz: string, id: number, sidPermissions: SidPermissions): Promise<AclObjectIdentity> {
const qs = QueryString.stringify({
term: term || undefined,
}, {});
const apiUrl = URL_AC_SID + (qs ? `?${qs}` : '');
const apiUrl = URL_ADD_PERMISSION.expand({clazz, id});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
const content = { data: sidPermissions };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'GET',
method: 'POST',
...content,
}).then(({ data }) => data as any);
}).then(({ data }) => data as AclObjectIdentity);
}
/**
......@@ -54,7 +53,7 @@ class PermissionService {
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
......@@ -62,21 +61,21 @@ class PermissionService {
}
/**
* acRole at /api/v1/permission/autocompleterole
* acUser at /api/v1/permission/autocompleteuser
*
* @param term term
* @deprecated
*/
public static acRole(term: string): Promise<any> {
public static acUser(term: string): Promise<any> {
const qs = QueryString.stringify({
term: term || undefined,
}, {});
const apiUrl = URL_AC_ROLE + (qs ? `?${qs}` : '');
const apiUrl = URL_AC_USER + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
......@@ -84,21 +83,20 @@ class PermissionService {
}
/**
* acUser at /api/v1/permission/autocompleteuser
* acSid at /api/v1/permission/autocomplete
*
* @param term term
* @deprecated
*/
public static acUser(term: string): Promise<any> {
public static acSid(term: string): Promise<any> {
const qs = QueryString.stringify({
term: term || undefined,
}, {});
const apiUrl = URL_AC_USER + (qs ? `?${qs}` : '');
const apiUrl = URL_AC_SID + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
......@@ -106,40 +104,42 @@ class PermissionService {
}
/**
* permissions at /api/v1/permission/permissions/{clazz}/{id}
* acRole at /api/v1/permission/autocompleterole
*
* @param clazz clazz
* @param id id
* @param term term
* @deprecated
*/
public static permissions(clazz: string, id: number): Promise<AclObjectIdentity> {
public static acRole(term: string): Promise<any> {
const apiUrl = URL_PERMISSIONS.expand({clazz, id});
const qs = QueryString.stringify({
term: term || undefined,
}, {});
const apiUrl = URL_AC_ROLE + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as AclObjectIdentity);
}).then(({ data }) => data as any);
}
/**
* addPermission at /api/v1/permission/permissions/{clazz}/{id}
* permissions at /api/v1/permission/permissions/{clazz}/{id}
*
* @param clazz clazz
* @param id id
* @param sidPermissions sidPermissions
*/
public static addPermission(clazz: string, id: number, sidPermissions: SidPermissions): Promise<AclObjectIdentity> {
public static permissions(clazz: string, id: number): Promise<AclObjectIdentity> {
const apiUrl = URL_ADD_PERMISSION.expand({clazz, id});
const apiUrl = URL_PERMISSIONS.expand({clazz, id});
// console.log(`Fetching from ${apiUrl}`);
const content = { data: sidPermissions };
const content = { /* No content in request body */ };
return axiosBackend({
return axiosBackend.request({
url: apiUrl,
method: 'POST',
method: 'GET',
...content,
}).then(({ data }) => data as AclObjectIdentity);
}
......
import * as UrlTemplate from 'url-template';
// import * as QueryString from 'query-string';
import * as QueryString from 'query-string';
import { axiosBackend } from 'utilities/requestUtils';
import FolderDetails from 'model/repository/FolderDetails';
import ImageGallery from 'model/repository/ImageGallery';
import RepositoryFile from 'model/repository/RepositoryFile';
import RepositoryFolder from 'model/repository/RepositoryFolder';
import ImageGallery from 'model/repository/ImageGallery';
// const URL_DOWNLOAD_FILE = UrlTemplate.parse(`/api/v1/repository/download/{fileUuid}`);
const URL_UPLOAD_FILE = `/api/v1/repository/upload`;
const URL_GET_FILE = UrlTemplate.parse(`/api/v1/repository/file/{fileUuid}`);
const URL_REMOVE_FILE = UrlTemplate.parse(`/api/v1/repository/file/{fileUuid}`);
const URL_UPDATE_FILE = UrlTemplate.parse(`/api/v1/repository/file`);
const URL_UPDATE_FILE = `/api/v1/repository/file`;
const URL_MOVE_AND_RENAME_FILE = UrlTemplate.parse(`/api/v1/repository/file/{fileUuid}/move`);
// Folders
const URL_ENSURE_FOLDER = `/api/v1/repository/folder/**`;
const URL_UPDATE_FOLDER = `/api/v1/repository/folder`;
const URL_GET_FOLDER = `/api/v1/repository/folder`;
const URL_DELETE_FOLDER = `/api/v1/repository/folder`;
const URL_GET_FOLDER = UrlTemplate.parse(`/api/v1/repository/folder/{path}`);
const URL_ENSURE_FOLDER = UrlTemplate.parse(`/api/v1/repository/folder/{path}`);
const URL_DELETE_FOLDER = UrlTemplate.parse(`/api/v1/repository/folder/{path}`);
const URL_RENAME_FOLDER = UrlTemplate.parse(`/api/v1/repository/folder/{folderUuid}/rename`);
// Image galleries
const URL_UPDATE_GALLERY = `/api/v1/repository/gallery`;
const URL_GET_GALLERY = `/api/v1/repository/gallery`;
const URL_CREATE_GALLERY = `/api/v1/repository/gallery`;
const URL_REMOVE_GALLERY = `/api/v1/repository/gallery`;
const URL_GET_GALLERY = UrlTemplate.parse(`/api/v1/repository/gallery/{path}`);
const URL_CREATE_GALLERY = UrlTemplate.parse(`/api/v1/repository/gallery/{path}`);
const URL_REMOVE_GALLERY = UrlTemplate.parse(`/api/v1/repository/gallery/{path}`);
const URL_UPLOAD_FILE = UrlTemplate.parse(`/api/v1/repository/upload/{path}`);
/*
* Defined in Swagger as 'repository'
*/
class FileRepositoryService {
// /**
// * downloadFile at /api/v1/repository/download/{fileUuid}
// *
// * @param authToken Authorization token
// * @param fileUuid fileUuid
// */
// public static downloadFile(fileUuid: string): Promise {
// const apiUrl = URL_DOWNLOAD_FILE.expand({fileUuid});
// // console.log(`Fetching from ${apiUrl}`);
// const content = { /* No content in request body */ };
// return axiosBackend.request({
// url: apiUrl,
// method: 'GET',
// ...content,
// }).then(({ data }) => data as undefined);
// }
/**
* uploadFile at /api/v1/repository/upload/**
*
* @param authToken Authorization token
* @param path Repository path
* @param file The file
*/
public static uploadFile(path: string, file: File): Promise<RepositoryFile> {
const apiUrl = URL_UPLOAD_FILE + path;
const data = new FormData();
data.append('file', file);
return axiosBackend.request({
url: apiUrl,
method: 'POST',
data,
headers: { 'Content-Type': 'multipart/form-data' },
}).then(({ data }) => data as RepositoryFile);
}
/**
* getFile at /api/v1/repository/file/{fileUuid}
*
* @param authToken Authorization token
* @param fileUuid fileUuid
*/
public static getFile(fileUuid: string): Promise<RepositoryFile> {
const apiUrl = URL_GET_FILE.expand({ fileUuid });
const apiUrl = URL_GET_FILE.expand({fileUuid});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -94,12 +49,11 @@ class FileRepositoryService {
/**
* removeFile at /api/v1/repository/file/{fileUuid}
*
* @param authToken Authorization token
* @param fileUuid fileUuid
*/
public static removeFile(fileUuid: string): Promise<RepositoryFile> {
const apiUrl = URL_REMOVE_FILE.expand({ fileUuid });
const apiUrl = URL_REMOVE_FILE.expand({fileUuid});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -111,14 +65,11 @@ class FileRepositoryService {
}
/**
* updateFile at /api/v1/repository/file/{fileUuid},{version}
* updateFile at /api/v1/repository/file
*
* @param authToken Authorization token
* @param fileUuid fileUuid
* @param version version
* @param metadata metadata
*/
public static updateFile(fileUuid: string, version: number, metadata: RepositoryFile): Promise<RepositoryFile> {
public static updateFile(metadata: RepositoryFile): Promise<RepositoryFile> {
const apiUrl = URL_UPDATE_FILE;
// console.log(`Fetching from ${apiUrl}`);
......@@ -134,87 +85,84 @@ class FileRepositoryService {
/**
* moveAndRenameFile at /api/v1/repository/file/{fileUuid}/move
*
* @param authToken Authorization token
* @param fileUuid fileUuid
* @param fullPath fullPath
*/
public static moveAndRenameFile(fileUuid: string, fullPath: string): Promise<RepositoryFile> {
public static moveAndRenameFile(fileUuid: string, fullPath: undefined): Promise<RepositoryFile> {
const apiUrl = URL_MOVE_AND_RENAME_FILE.expand({ fileUuid });
const apiUrl = URL_MOVE_AND_RENAME_FILE.expand({fileUuid});
// console.log(`Fetching from ${apiUrl}`);
const content = { data: fullPath };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
headers: {'Content-Type': 'text/plain'},
...content,
}).then(({ data }) => data as RepositoryFile);
}
/**
* ensureFolder at /api/v1/repository/folder/**
* updateFolder at /api/v1/repository/folder
*
* @param authToken Authorization token
* @param folder folder
*/
public static ensureFolder(path: string): Promise<RepositoryFolder> {
public static updateFolder(folder: RepositoryFolder): Promise<FolderDetails> {
const apiUrl = URL_ENSURE_FOLDER + path;
const apiUrl = URL_UPDATE_FOLDER;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
const content = { data: folder };
return axiosBackend.request({
url: apiUrl,
method: 'PUT',
...content,
}).then(({ data }) => data as RepositoryFolder);
}).then(({ data }) => data as FolderDetails);
}
/**
* updateFolder at /api/v1/repository/folder
* getFolder at /api/v1/repository/folder/{path}
*
* @param authToken Authorization token
* @param folder folder
* @param path URL path
*/
public static updateFolder(folder: RepositoryFolder): Promise<FolderDetails> {
public static getFolder(path: string): Promise<FolderDetails> {
const apiUrl = URL_UPDATE_FOLDER;
const apiUrl = URL_GET_FOLDER.expand({path});
// console.log(`Fetching from ${apiUrl}`);
const content = { data: folder };
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'PUT',
method: 'GET',
...content,
}).then(({ data }) => data as FolderDetails);
}
/**
* getFolder at /api/v1/repository/folder/**
* ensureFolder at /api/v1/repository/folder/{path}
*
* @param authToken Authorization token
* @param path URL path
*/
public static getFolder(path: string = '/'): Promise<FolderDetails> {
public static ensureFolder(path: string): Promise<RepositoryFolder> {
const apiUrl = URL_GET_FOLDER + path;
const apiUrl = URL_ENSURE_FOLDER.expand({path});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'GET',
method: 'PUT',
...content,
}).then(({ data }) => data as FolderDetails);
}).then(({ data }) => data as RepositoryFolder);
}
/**
* deleteFolder at /api/v1/repository/folder/**
* deleteFolder at /api/v1/repository/folder/{path}
*
* @param authToken Authorization token
* @param path URL path
*/
public static deleteFolder(path: string): Promise<RepositoryFolder> {
const apiUrl = URL_DELETE_FOLDER + path;
const apiUrl = URL_DELETE_FOLDER.expand({path});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -228,20 +176,18 @@ class FileRepositoryService {
/**
* renameFolder at /api/v1/repository/folder/{folderUuid}/rename
*
* @param authToken Authorization token
* @param folderUuid folderUuid
* @param fullPath fullPath
*/
public static renameFolder(folderUuid: string, fullPath: string): Promise<FolderDetails> {
public static renameFolder(folderUuid: string, fullPath: undefined): Promise<FolderDetails> {
const apiUrl = URL_RENAME_FOLDER.expand({ folderUuid });
const apiUrl = URL_RENAME_FOLDER.expand({folderUuid});
// console.log(`Fetching from ${apiUrl}`);
const content = { data: fullPath };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
headers: {'Content-Type': 'text/plain'},
...content,
}).then(({ data }) => data as FolderDetails);
}
......@@ -249,7 +195,6 @@ class FileRepositoryService {
/**
* updateGallery at /api/v1/repository/gallery
*
* @param authToken Authorization token
* @param imageGallery imageGallery
*/
public static updateGallery(imageGallery: ImageGallery): Promise<ImageGallery> {
......@@ -266,13 +211,13 @@ class FileRepositoryService {
}
/**
* getGallery at /api/v1/repository/gallery/**
* getGallery at /api/v1/repository/gallery/{path}
*
* @param authToken Authorization token
* @param path URL path
*/
public static getGallery(path: string): Promise<ImageGallery> {
const apiUrl = URL_GET_GALLERY + path;
const apiUrl = URL_GET_GALLERY.expand({path});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -284,33 +229,32 @@ class FileRepositoryService {
}
/**
* createGallery at /api/v1/repository/gallery/**
* createGallery at /api/v1/repository/gallery/{path}
*
* @param authToken Authorization token
* @param imageGallery imageGallery
* @param path URL path
* @param metadata metadata
*/
public static createGallery(path: string, imageGallery: ImageGallery): Promise<ImageGallery> {
public static createGallery(path: string, metadata: ImageGallery): Promise<ImageGallery> {