Skip to content

Commit

Permalink
fix: REST API is now returning flattened user permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Jan 11, 2024
1 parent 18a2aa3 commit cb2d814
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 53 deletions.
6 changes: 2 additions & 4 deletions src/taxonomy/TaxonomyListPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ const taxonomies = [{
description: 'This is a description',
showSystemBadge: false,
tagsCount: 0,
userPermissions: {
canChange: true,
canDelete: true,
},
canChange: true,
canDelete: true,
}];
const organizationsListUrl = 'http://localhost:18010/organizations';
const organizations = ['Org 1', 'Org 2'];
Expand Down
24 changes: 8 additions & 16 deletions src/taxonomy/__mocks__/taxonomyListMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ module.exports = {
allowFreeText: false,
systemDefined: true,
visibleToAuthors: false,
userPermissions: {
canChange: false,
canDelete: false,
},
canChange: false,
canDelete: false,
},
{
id: -1,
Expand All @@ -30,10 +28,8 @@ module.exports = {
allowFreeText: false,
systemDefined: true,
visibleToAuthors: true,
userPermissions: {
canChange: false,
canDelete: false,
},
canChange: false,
canDelete: false,
},
{
id: 1,
Expand All @@ -44,10 +40,8 @@ module.exports = {
allowFreeText: false,
systemDefined: false,
visibleToAuthors: true,
userPermissions: {
canChange: true,
canDelete: true,
},
canChange: true,
canDelete: true,
},
{
id: 2,
Expand All @@ -58,10 +52,8 @@ module.exports = {
allowFreeText: false,
systemDefined: false,
visibleToAuthors: true,
userPermissions: {
canChange: true,
canDelete: true,
},
canChange: true,
canDelete: true,
},
],
};
9 changes: 2 additions & 7 deletions src/taxonomy/data/types.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// @ts-check

/**
* @typedef {Object} UserPermissions
* @property {boolean} canChange
* @property {boolean} canDelete
**/

/**
* @typedef {Object} TaxonomyData
* @property {number} id
Expand All @@ -18,7 +12,8 @@
* @property {boolean} visibleToAuthors
* @property {number} tagsCount
* @property {string[]} orgs
* @property {UserPermissions} userPermissions
* @property {boolean} canChange
* @property {boolean} canDelete
*/

/**
Expand Down
12 changes: 4 additions & 8 deletions src/taxonomy/taxonomy-card/TaxonomyCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ const data = {
id: taxonomyId,
name: 'Taxonomy 1',
description: 'This is a description',
userPermissions: {
canChange: true,
canDelete: true,
},
canChange: true,
canDelete: true,
};

const queryClient = new QueryClient();
Expand All @@ -44,10 +42,8 @@ TaxonomyCardComponent.propTypes = {
systemDefined: PropTypes.bool,
orgsCount: PropTypes.number,
onDeleteTaxonomy: PropTypes.func,
userPermissions: PropTypes.shape({
canChange: PropTypes.bool,
canDelete: PropTypes.bool,
}),
canChange: PropTypes.bool,
canDelete: PropTypes.bool,
}).isRequired,
};

Expand Down
6 changes: 2 additions & 4 deletions src/taxonomy/taxonomy-card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ TaxonomyCard.propTypes = {
systemDefined: PropTypes.bool,
orgsCount: PropTypes.number,
tagsCount: PropTypes.number,
userPermissions: PropTypes.shape({
canChange: PropTypes.bool.isRequired,
canDelete: PropTypes.bool.isRequired,
}).isRequired,
canChange: PropTypes.bool,
canDelete: PropTypes.bool,
}).isRequired,
};

Expand Down
7 changes: 2 additions & 5 deletions src/taxonomy/taxonomy-detail/TaxonomyDetailPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ describe('<TaxonomyDetailPage />', async () => {
name: 'Test taxonomy',
description: 'This is a description',
systemDefined: true,
userPermissions: {
canChange: true,
canDelete: true,
},
canChange: true,
canDelete: true,
},
});
const { getByTestId, queryByTestId } = render(<RootWrapper />);
Expand Down Expand Up @@ -148,7 +146,6 @@ describe('<TaxonomyDetailPage />', async () => {
name: 'Test taxonomy',
description: 'This is a description',
systemDefined: false,
userPermissions: {},
},
});
const { queryByText } = render(<RootWrapper />);
Expand Down
10 changes: 4 additions & 6 deletions src/taxonomy/taxonomy-menu/TaxonomyMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const TaxonomyMenu = ({
import: {
title: intl.formatMessage(messages.importMenu),
action: () => importTaxonomyTags(taxonomy.id, intl),
show: taxonomy.userPermissions.canChange,
show: taxonomy.canChange,
},
export: {
title: intl.formatMessage(messages.exportMenu),
Expand All @@ -69,7 +69,7 @@ const TaxonomyMenu = ({
delete: {
title: intl.formatMessage(messages.deleteMenu),
action: deleteDialogOpen,
show: taxonomy.userPermissions.canDelete,
show: taxonomy.canDelete,
},
};

Expand Down Expand Up @@ -136,10 +136,8 @@ TaxonomyMenu.propTypes = {
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
tagsCount: PropTypes.number.isRequired,
userPermissions: PropTypes.shape({
canChange: PropTypes.bool.isRequired,
canDelete: PropTypes.bool.isRequired,
}).isRequired,
canChange: PropTypes.bool,
canDelete: PropTypes.bool,
}).isRequired,
iconMenu: PropTypes.bool,
};
Expand Down
5 changes: 2 additions & 3 deletions src/taxonomy/taxonomy-menu/TaxonomyMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ const TaxonomyMenuComponent = ({
id: taxonomyId,
name: taxonomyName,
tagsCount: 0,
userPermissions: {
canChange, canDelete,
},
canChange,
canDelete,
}}
iconMenu={iconMenu}
/>
Expand Down

0 comments on commit cb2d814

Please sign in to comment.