Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 4.x][Fixes #935] Share permissions form not showing for users in groups with manage permission #1047

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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