Skip to content

Commit

Permalink
feat: descriptor groups. close #578
Browse files Browse the repository at this point in the history
  • Loading branch information
MortenHofft committed Aug 19, 2024
1 parent 99ed546 commit 66dac2e
Show file tree
Hide file tree
Showing 14 changed files with 4,888 additions and 4,095 deletions.
8 changes: 8 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"addNewContact": "Add a new contact",
"addDataset": "Add a dataset",
"addNetwork": "Add a network",
"addDescriptorGroup": "Add a descriptor group",
"editFormInstructions": "Multi value fields position, email, phone, homepage and address are indicated by * and use the semicolon as the delimiter.",
"type": "Type",
"select.type": "Select a type",
Expand Down Expand Up @@ -106,7 +107,9 @@
"provide.userName": "Please input your username!",
"provide.password": "Please input your Password!",
"provide.comment": "Please provide a comment (include affiliation)",
"beenUpdated.descriptorGroup": "Descriptor group has been updated",
"description": "Description",
"fileCsvTsv": "File (.csv or. tsv)",
"phone": "Phone",
"homepage": "Homepage",
"organization": "Organization",
Expand Down Expand Up @@ -147,6 +150,7 @@
"institution": "Institution",
"tags": "Tags",
"machineTags": "Machine Tags",
"collectionDescriptorGroups": "Descriptor groups",
"comments": "Comments",
"commentAndAffiliation": "Comment, affiliation and additional update suggestion",
"publishedDataset": "Published Dataset",
Expand Down Expand Up @@ -1407,6 +1411,7 @@
"beenDeleted.defaultValue": "Default value has been deleted",
"beenDeleted.constituentDataset": "Constituent dataset has been deleted",
"beenDeleted.datasetFromNetwork": "Dataset has been deleted from network",
"beenDeleted.descriptorGroup": "Descriptor group has been deleted",
"beenSaved.contact": "Contact has been saved",
"beenSaved.comment": "Comment has been saved",
"beenSaved.endpoint": "Endpoint has been saved",
Expand All @@ -1423,6 +1428,7 @@
"beenCreated.institution.title": "Institution has been created successfully!",
"beenCreated.person.title": "Person has been created successfully!",
"beenAdded.constituentDataset": "Constituent dataset has been added!",
"beenAdded.descriptorGroup": "Descriptor group has been added!",
"beenAdded.datasetToNetwork": "Dataset has been added to the network",
"beenAdded.vocabulary.label": "Label has been added",
"beenAdded.concept.label": "Label has been added",
Expand Down Expand Up @@ -1550,6 +1556,7 @@
"forQuery": " for '{query}'",
"ok": "OK",
"close": "Close",
"about": "About",
"viewOnGBIF": "View on GBIF.org",
"noInformation": "No information",
"button.showMore": "Show more",
Expand Down Expand Up @@ -1935,6 +1942,7 @@
"delete.confirmation.fromNetwork": "Are you sure to delete dataset from this network?",
"delete.confirmation.generic": "Are you sure to abort and finish this entry?",
"delete.confirmation.deleteDatasetRelation": "Removing the dataset disassociates it with this network and doesn't delete it. It may be added again in the future. Are you sure you wish to remove this dataset from the network?",
"delete.confirmation.deleteCollectionDescriptionGroup": "Do you want to remove the collection descriptor group and the associated file?",
"delete.organization": "Delete this organization",
"delete.dataset": "Delete this dataset",
"delete.installation": "Delete this installation",
Expand Down
4,110 changes: 2,095 additions & 2,015 deletions public/_translations/ar-mock.json

Large diffs are not rendered by default.

4,096 changes: 2,088 additions & 2,008 deletions public/_translations/en-mock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions public/_translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"addNewContact": "Add a new contact",
"addDataset": "Add a dataset",
"addNetwork": "Add a network",
"addDescriptorGroup": "Add a descriptor group",
"editFormInstructions": "Multi value fields position, email, phone, homepage and address are indicated by * and use the semicolon as the delimiter.",
"type": "Type",
"select.type": "Select a type",
Expand Down Expand Up @@ -106,7 +107,9 @@
"provide.userName": "Please input your username!",
"provide.password": "Please input your Password!",
"provide.comment": "Please provide a comment (include affiliation)",
"beenUpdated.descriptorGroup": "Descriptor group has been updated",
"description": "Description",
"fileCsvTsv": "File (.csv or. tsv)",
"phone": "Phone",
"homepage": "Homepage",
"organization": "Organization",
Expand Down Expand Up @@ -147,6 +150,7 @@
"institution": "Institution",
"tags": "Tags",
"machineTags": "Machine Tags",
"collectionDescriptorGroups": "Descriptor groups",
"comments": "Comments",
"commentAndAffiliation": "Comment, affiliation and additional update suggestion",
"publishedDataset": "Published Dataset",
Expand Down Expand Up @@ -1407,6 +1411,7 @@
"beenDeleted.defaultValue": "Default value has been deleted",
"beenDeleted.constituentDataset": "Constituent dataset has been deleted",
"beenDeleted.datasetFromNetwork": "Dataset has been deleted from network",
"beenDeleted.descriptorGroup": "Descriptor group has been deleted",
"beenSaved.contact": "Contact has been saved",
"beenSaved.comment": "Comment has been saved",
"beenSaved.endpoint": "Endpoint has been saved",
Expand All @@ -1423,6 +1428,7 @@
"beenCreated.institution.title": "Institution has been created successfully!",
"beenCreated.person.title": "Person has been created successfully!",
"beenAdded.constituentDataset": "Constituent dataset has been added!",
"beenAdded.descriptorGroup": "Descriptor group has been added!",
"beenAdded.datasetToNetwork": "Dataset has been added to the network",
"beenAdded.vocabulary.label": "Label has been added",
"beenAdded.concept.label": "Label has been added",
Expand Down Expand Up @@ -1550,6 +1556,7 @@
"forQuery": " for '{query}'",
"ok": "OK",
"close": "Close",
"about": "About",
"viewOnGBIF": "View on GBIF.org",
"noInformation": "No information",
"button.showMore": "Show more",
Expand Down Expand Up @@ -1935,6 +1942,7 @@
"delete.confirmation.fromNetwork": "Are you sure to delete dataset from this network?",
"delete.confirmation.generic": "Are you sure to abort and finish this entry?",
"delete.confirmation.deleteDatasetRelation": "Removing the dataset disassociates it with this network and doesn't delete it. It may be added again in the future. Are you sure you wish to remove this dataset from the network?",
"delete.confirmation.deleteCollectionDescriptionGroup": "Do you want to remove the collection descriptor group and the associated file?",
"delete.organization": "Delete this organization",
"delete.dataset": "Delete this dataset",
"delete.installation": "Delete this installation",
Expand Down
47 changes: 46 additions & 1 deletion src/api/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ export const suggestMergeCollection = ({ entityKey, mergeTargetKey, proposerEmai
}

export const getCollectionOverview = async key => {
const collection = (await getCollection(key)).data;

const [{ data: collection }, { data: descriptorGroups }] = await Promise.all([
getCollection(key),
getDescriptorGroup(key, { limit: 200 })
]);


const pendingSuggestions = (await collectionSuggestionSearch({ entityKey: key, status: 'PENDING' })).data;
let institution;
if (collection.institutionKey) {
Expand All @@ -128,10 +134,49 @@ export const getCollectionOverview = async key => {
return {
...collection,
institution,
descriptorGroups,
pendingSuggestions
}
};

export const getDescriptorGroup = (key, query) => {
return axiosWithCrendetials_cancelable.get(`/grscicoll/collection/${key}/descriptorGroup?${qs.stringify(query)}`);
};

export const deleteDescriptorGroup = (key, descriptorGroupKey) => {
return axiosInstanceWithCredentials.delete(`/grscicoll/collection/${key}/descriptorGroup/${descriptorGroupKey}`);
};

export const updateDescriptorGroup = (key, descriptorGroupData) => {
const formData = new FormData();
formData.append('descriptorsFile', descriptorGroupData.selectedFile);
formData.append('title', descriptorGroupData.title);
formData.append('description', descriptorGroupData.description);
formData.append('format', descriptorGroupData.format);

return axiosInstanceWithCredentials.put(`/grscicoll/collection/${key}/descriptorGroup/${descriptorGroupData.key}`,
formData, {
headers: {
'Content-Type': 'multipart/form-data'
},
});
};

export const createDescriptorGroup = (key, descriptorGroupData) => {
const formData = new FormData();
formData.append('descriptorsFile', descriptorGroupData.selectedFile);
formData.append('title', descriptorGroupData.title);
formData.append('description', descriptorGroupData.description);
formData.append('format', descriptorGroupData.format);

return axiosInstanceWithCredentials.post(`/grscicoll/collection/${key}/descriptorGroup`,
formData, {
headers: {
'Content-Type': 'multipart/form-data'
},
});
};

export const deleteContact = (key, contactKey) => {
return axiosInstanceWithCredentials.delete(`/grscicoll/collection/${key}/contactPerson/${contactKey}`);
};
Expand Down
98 changes: 52 additions & 46 deletions src/api/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import qs from 'qs';
import axiosInstanceWithCredentials from './util/axiosInstanceWithCredentials';
// import axiosWithCrendetials_cancelable from './util/axiosCancelWithCredentials';

function composeUrl({resource, key, subType, subKey, query = {}}) {
function composeUrl({ resource, key, subType, subKey, query = {} }) {
query.checkPermissionsOnly = true;
let str = `/${resource}`;
if (typeof key !== 'undefined') {
Expand All @@ -18,130 +18,136 @@ function composeUrl({resource, key, subType, subKey, query = {}}) {
return str;
}

const mayPost = ({resource, key, subType, subKey, query, body = {}}) => {
const url = composeUrl({resource, key, subType, subKey, query});
return axiosInstanceWithCredentials.post(url, {...body})
.then(() => true).catch(err => false);
const mayPost = ({ resource, key, subType, subKey, query, body = {}, headers = {} }) => {
const url = composeUrl({ resource, key, subType, subKey, query });
return axiosInstanceWithCredentials.post(url, { ...body }, {
headers: {
...headers
}
}).then(() => true).catch(err => false);
};

const mayPut = ({resource, key, subType, subKey}) => {
const url = composeUrl({resource, key, subType, subKey});
return axiosInstanceWithCredentials.put(url, {})
.then(() => true).catch(err => false);
const mayPut = ({ resource, key, subType, subKey, headers = {} }) => {
const url = composeUrl({ resource, key, subType, subKey });
return axiosInstanceWithCredentials.put(url, {}, {
headers: {
...headers
}
}).then(() => true).catch(err => false);
};

const mayDelete = ({resource, key, subType, subKey}) => {
const url = composeUrl({resource, key, subType, subKey});
const mayDelete = ({ resource, key, subType, subKey }) => {
const url = composeUrl({ resource, key, subType, subKey });
return axiosInstanceWithCredentials.delete(url)
.then(() => true).catch(err => false);
};

const mayGet = ({resource, key, subType, subKey}) => {
const url = composeUrl({resource, key, subType, subKey});
const mayGet = ({ resource, key, subType, subKey }) => {
const url = composeUrl({ resource, key, subType, subKey });
return axiosInstanceWithCredentials.get(url)
.then(() => true).catch(err => false);
};

export const checkPermissions = ({method, resource, key, subType, subKey}) => {
if (method === 'post') return mayPost({resource, key, subType, subKey});
if (method === 'put') return mayPut({resource, key, subType, subKey});
if (method === 'delete') return mayDelete({resource, key, subType, subKey});
return mayGet({resource, key, subType, subKey});
export const checkPermissions = ({ method, resource, key, subType, subKey, headers, body }) => {
if (method === 'post') return mayPost({ resource, key, subType, subKey, headers, body });
if (method === 'put') return mayPut({ resource, key, subType, subKey, headers, body });
if (method === 'delete') return mayDelete({ resource, key, subType, subKey });
return mayGet({ resource, key, subType, subKey });
};

export const canCreate = (resource, key, subType, subKey, query, body) => {
return mayPost({resource, key, subType, subKey, query, body});
return mayPost({ resource, key, subType, subKey, query, body });
}
export const canUpdate = (resource, key, subType, subKey) => {
return mayPut({resource, key, subType, subKey});
return mayPut({ resource, key, subType, subKey });
}
export const canDelete = (resource, key, subType, subKey) => {
return mayDelete({resource, key, subType, subKey});
return mayDelete({ resource, key, subType, subKey });
}
export const canGet = (resource, key, subType, subKey) => {
return mayGet({resource, key, subType, subKey});
return mayGet({ resource, key, subType, subKey });
}

//contacts
export const canCreateContact = (resource, key) => {
return mayPost({resource, key, subType: 'contact'});
return mayPost({ resource, key, subType: 'contact' });
}
export const canUpdateContact = (resource, key, subKey) => {
return mayPut({resource, key, subType: 'contact', subKey});
return mayPut({ resource, key, subType: 'contact', subKey });
}
export const canDeleteContact = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'contact', subKey});
return mayDelete({ resource, key, subType: 'contact', subKey });
}
export const canGetContact = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'contact', subKey});
return mayDelete({ resource, key, subType: 'contact', subKey });
}

//endpoints
export const canCreateEndpoint = (resource, key) => {
return mayPost({resource, key, subType: 'endpoint'});
return mayPost({ resource, key, subType: 'endpoint' });
}
export const canUpdateEndpoint = (resource, key, subKey) => {
return mayPut({resource, key, subType: 'endpoint', subKey});
return mayPut({ resource, key, subType: 'endpoint', subKey });
}
export const canDeleteEndpoint = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'endpoint', subKey});
return mayDelete({ resource, key, subType: 'endpoint', subKey });
}
export const canGetEndpoint = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'endpoint', subKey});
return mayDelete({ resource, key, subType: 'endpoint', subKey });
}

//identifier
export const canCreateIdentifier = (resource, key) => {
return mayPost({resource, key, subType: 'identifier'});
return mayPost({ resource, key, subType: 'identifier' });
}
export const canUpdateIdentifier = (resource, key, subKey) => {
return mayPut({resource, key, subType: 'identifier', subKey});
return mayPut({ resource, key, subType: 'identifier', subKey });
}
export const canDeleteIdentifier = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'identifier', subKey});
return mayDelete({ resource, key, subType: 'identifier', subKey });
}
export const canGetIdentifier = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'identifier', subKey});
return mayDelete({ resource, key, subType: 'identifier', subKey });
}

//tags
export const canCreateTag = (resource, key) => {
return mayPost({resource, key, subType: 'tag'});
return mayPost({ resource, key, subType: 'tag' });
}
export const canUpdateTag = (resource, key, subKey) => {
return mayPut({resource, key, subType: 'tag', subKey});
return mayPut({ resource, key, subType: 'tag', subKey });
}
export const canDeleteTag = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'tag', subKey});
return mayDelete({ resource, key, subType: 'tag', subKey });
}
export const canGetTag = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'tag', subKey});
return mayDelete({ resource, key, subType: 'tag', subKey });
}

//machineTags
export const canCreateMachineTag = (resource, key) => {
return mayPost({resource, key, subType: 'machineTag'});
return mayPost({ resource, key, subType: 'machineTag' });
}
export const canUpdateMachineTag = (resource, key, subKey) => {
return mayPut({resource, key, subType: 'machineTag', subKey});
return mayPut({ resource, key, subType: 'machineTag', subKey });
}
export const canDeleteMachineTag = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'machineTag', subKey});
return mayDelete({ resource, key, subType: 'machineTag', subKey });
}
export const canGetMachineTag = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'machineTag', subKey});
return mayDelete({ resource, key, subType: 'machineTag', subKey });
}

//comments
export const canCreateComment = (resource, key) => {
return mayPost({resource, key, subType: 'comment'});
return mayPost({ resource, key, subType: 'comment' });
}
export const canUpdateComment = (resource, key, subKey) => {
return mayPut({resource, key, subType: 'comment', subKey});
return mayPut({ resource, key, subType: 'comment', subKey });
}
export const canDeleteComment = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'comment', subKey});
return mayDelete({ resource, key, subType: 'comment', subKey });
}
export const canGetComment = (resource, key, subKey) => {
return mayDelete({resource, key, subType: 'comment', subKey});
return mayDelete({ resource, key, subType: 'comment', subKey });
}
2 changes: 1 addition & 1 deletion src/components/Collection/collection.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,6 @@ CollectionActions.propTypes = {
onChange: PropTypes.func.isRequired
};

const mapContextToProps = ({ user, addSuccess }) => ({ user, addSuccess });
const mapContextToProps = ({ user, addSuccess, addError }) => ({ user, addSuccess, addError });

export default withContext(mapContextToProps)(injectIntl(injectSheet(styles)(CollectionActions)));
Loading

0 comments on commit 66dac2e

Please sign in to comment.