Skip to content

Commit

Permalink
[Fixes #935] Share permissions form not showing for users in groups w…
Browse files Browse the repository at this point in the history
…ith manage permission (#1047)
  • Loading branch information
DavidQuartz authored Jun 23, 2022
1 parent c4d227e commit f6d094c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
getGeonodeResourceFromDashboard,
getResourceThumbnail,
updatingThumbnailResource,
isThumbnailChanged
isThumbnailChanged,
canEditPermissions
} from '../resource';

const testState = {
Expand All @@ -25,6 +26,9 @@ const testState = {
thumbnailChanged: true,
thumbnail_url: 'thumbnail.jpeg',
updatingThumbnail: true
},
compactPermissions: {
groups: [{name: 'test-group', permissions: 'manage'}]
}
},
geostory: {
Expand All @@ -36,6 +40,13 @@ const testState = {
originalData: {
widgets: [{widgetType: 'map', name: 'test widget', map: {extraParams: {pk: 1}}}, {widgetType: 'map', name: 'test widget 2', map: {pk: 1}}]
}
},
security: {
user: {
info: {
groups: ['test-group']
}
}
}
};

Expand Down Expand Up @@ -65,4 +76,8 @@ describe('resource selector', () => {
it('should get resource thumbnail updating status', () => {
expect(updatingThumbnailResource(testState)).toBeTruthy();
});

it('should get permissions from users in groups with manage rights', () => {
expect(canEditPermissions(testState)).toBeTruthy();
});
});
6 changes: 5 additions & 1 deletion geonode_mapstore_client/client/js/selectors/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ export const getPermissionsPayload = (state) => {
export const canEditPermissions = (state) => {
const compactPermissions = getCompactPermissions(state);
const users = compactPermissions.users || [];
const groups = compactPermissions.groups || [];
const organizations = compactPermissions.organizations || [];
const user = state?.security?.user;
const { permissions } = user && users.find(({ id }) => id === user.pk) || {};
return ['owner', 'manage'].includes(permissions);
const { permissions: allowedGroups } = user && groups.find((group) => user.info.groups.includes(group.name)) || {};
const { permissions: allowedOrganizations } = user && organizations.find((organization) => user.info.groups.includes(organization.name)) || {};
return ['owner', 'manage'].includes(permissions) || ['manage'].includes(allowedGroups) || ['manage'].includes(allowedOrganizations);
};

export const getSelectedLayerPermissions = (state) => {
Expand Down

0 comments on commit f6d094c

Please sign in to comment.