Skip to content

Commit 8f2a55d

Browse files
authored
#1977: Move group setting to management panel (#2024)
1 parent 131ee15 commit 8f2a55d

File tree

20 files changed

+170
-13
lines changed

20 files changed

+170
-13
lines changed
Submodule MapStore2 updated 187 files

geonode_mapstore_client/client/js/api/geonode/v2/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,13 @@ export const getUsers = ({
382382
q,
383383
page = 1,
384384
pageSize = 20,
385+
config,
385386
...params
386387
} = {}) => {
387388
return axios.get(
388389
getEndpointUrl(USERS),
389390
{
391+
...config,
390392
params: {
391393
...params,
392394
...(q && {
@@ -411,11 +413,13 @@ export const getGroups = ({
411413
q,
412414
page = 1,
413415
pageSize = 20,
416+
config,
414417
...params
415418
} = {}) => {
416419
return axios.get(
417420
getEndpointUrl(GROUPS),
418421
{
422+
...config,
419423
params: {
420424
...params,
421425
...(q && {

geonode_mapstore_client/client/js/epics/__tests__/gnsave-test.js

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { SET_EDIT_PERMISSION } from '@mapstore/framework/actions/styleeditor';
3333
import { configureMap } from '@mapstore/framework/actions/config';
3434

3535
import { selectNode, addLayer } from '@mapstore/framework/actions/layers';
36+
import { START_ASYNC_PROCESS } from '@js/actions/resourceservice';
3637

3738

3839
let mockAxios;
@@ -49,13 +50,101 @@ describe('gnsave epics', () => {
4950
setTimeout(done);
5051
});
5152
it('should create new map with success (gnSaveContent)', (done) => {
53+
const NUM_ACTIONS = 5;
54+
const metadata = {
55+
title: 'Title',
56+
description: 'Description',
57+
thumbnail: 'thumbnail.jpeg'
58+
};
59+
mockAxios.onPost().reply(() => [200, { map: {} }]);
60+
mockAxios.onPut().reply(() => [200, { output: {} }]);
61+
testEpic(
62+
gnSaveContent,
63+
NUM_ACTIONS,
64+
saveContent(undefined, metadata, false),
65+
(actions) => {
66+
try {
67+
expect(actions.map(({ type }) => type))
68+
.toEqual([
69+
SAVING_RESOURCE,
70+
SAVE_SUCCESS,
71+
SET_RESOURCE,
72+
UPDATE_SINGLE_RESOURCE,
73+
START_ASYNC_PROCESS
74+
]);
75+
} catch (e) {
76+
done(e);
77+
}
78+
done();
79+
},
80+
{
81+
gnresource: {
82+
data: {
83+
resource_type: "map"
84+
},
85+
isCompactPermissionsChanged: true,
86+
compactPermissions: {
87+
users: [],
88+
organizations: [],
89+
groups: []
90+
}
91+
}
92+
}
93+
);
94+
});
95+
it('should update existing map with success (gnSaveContent)', (done) => {
96+
const NUM_ACTIONS = 5;
97+
const id = 1;
98+
const metadata = {
99+
title: 'Title',
100+
description: 'Description',
101+
thumbnail: 'thumbnail.jpeg'
102+
};
103+
mockAxios.onPatch().reply(() => [200, {}]);
104+
mockAxios.onPut().reply(() => [200, { output: {} }]);
105+
testEpic(
106+
gnSaveContent,
107+
NUM_ACTIONS,
108+
saveContent(id, metadata, false, false),
109+
(actions) => {
110+
try {
111+
expect(actions.map(({ type }) => type))
112+
.toEqual([
113+
SAVING_RESOURCE,
114+
SAVE_SUCCESS,
115+
SET_RESOURCE,
116+
UPDATE_SINGLE_RESOURCE,
117+
START_ASYNC_PROCESS
118+
]);
119+
} catch (e) {
120+
done(e);
121+
}
122+
done();
123+
},
124+
{
125+
gnresource: {
126+
data: {
127+
resource_type: "map"
128+
},
129+
isCompactPermissionsChanged: true,
130+
compactPermissions: {
131+
users: [],
132+
organizations: [],
133+
groups: []
134+
}
135+
}
136+
}
137+
);
138+
});
139+
it('should skip permission update when permission is unchanged', (done) => {
52140
const NUM_ACTIONS = 4;
53141
const metadata = {
54142
title: 'Title',
55143
description: 'Description',
56144
thumbnail: 'thumbnail.jpeg'
57145
};
58146
mockAxios.onPost().reply(() => [200, { map: {} }]);
147+
mockAxios.onPut().reply(() => [200, { output: {} }]);
59148
testEpic(
60149
gnSaveContent,
61150
NUM_ACTIONS,
@@ -110,7 +199,15 @@ describe('gnsave epics', () => {
110199
},
111200
{
112201
gnresource: {
113-
type: "map"
202+
data: {
203+
resource_type: "map"
204+
},
205+
isCompactPermissionsChanged: false,
206+
compactPermissions: {
207+
users: [],
208+
organizations: [],
209+
groups: []
210+
}
114211
}
115212
}
116213
);
@@ -170,7 +267,7 @@ describe('gnsave epics', () => {
170267
'thumbnail_url': 'thumbnail.jpeg'
171268
};
172269
mockAxios.onGet(new RegExp(`resources/${pk}`))
173-
.reply(200, resource);
270+
.reply(200, {resource});
174271
testEpic(
175272
gnSaveDirectContent,
176273
NUM_ACTIONS,

geonode_mapstore_client/client/js/epics/gnsave.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ export const gnSaveContent = (action$, store) =>
204204
const extent = getExtentPayload(state, contentType);
205205
const body = {
206206
'title': action.metadata.name,
207-
...(RESOURCE_MANAGEMENT_PROPERTIES_KEYS.reduce((acc, key) => {
207+
...([...RESOURCE_MANAGEMENT_PROPERTIES_KEYS, 'group'].reduce((acc, key) => {
208208
if (currentResource?.[key] !== undefined) {
209-
acc[key] = !!currentResource[key];
209+
const value = typeof currentResource[key] === 'boolean' ? !!currentResource[key] : currentResource[key];
210+
acc[key] = value;
210211
}
211212
return acc;
212213
}, {})),
@@ -312,6 +313,8 @@ export const gnSaveDirectContent = (action$, store) =>
312313
const resourceId = mapInfo?.id || getResourceId(state);
313314
const { geoLimits } = getPermissionsPayload(state);
314315

316+
// resource information should be saved in a synchronous manner
317+
// i.e update resource data followed by permissions
315318
return Observable.defer(() => axios.all([
316319
getResourceByPk(resourceId),
317320
...(geoLimits

geonode_mapstore_client/client/js/plugins/ResourceDetails/components/DetailsSettings.jsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React, { forwardRef } from 'react';
2-
import { Checkbox } from 'react-bootstrap';
2+
import { Checkbox, FormGroup, ControlLabel } from 'react-bootstrap';
3+
34
import Message from '@mapstore/framework/components/I18N/Message';
45
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
5-
import { canAccessPermissions, canManageResourceSettings, RESOURCE_MANAGEMENT_PROPERTIES } from '@js/utils/ResourceUtils';
66
import FlexBox from '@mapstore/framework/components/layout/FlexBox';
77
import Text from '@mapstore/framework/components/layout/Text';
8+
import SelectInfiniteScroll from '@mapstore/framework/plugins/ResourcesCatalog/components/SelectInfiniteScroll';
9+
import { getGroups } from '@js/api/geonode/v2';
10+
import { canAccessPermissions, canManageResourceSettings, RESOURCE_MANAGEMENT_PROPERTIES } from '@js/utils/ResourceUtils';
811
import DetailsPermissions from '@js/plugins/ResourceDetails/containers/Permissions';
912

1013
const MessageTooltip = tooltip(forwardRef(({children, msgId, ...props}, ref) => {
@@ -20,6 +23,30 @@ const MessageTooltip = tooltip(forwardRef(({children, msgId, ...props}, ref) =>
2023
function DetailsSettings({ resource, onChange }) {
2124
return (
2225
<FlexBox column gap="md" className="gn-details-settings _padding-tb-md">
26+
<FlexBox.Fill gap="xs" className="_padding-b-xs">
27+
<FormGroup>
28+
<ControlLabel><Message msgId={"gnviewer.group"} /></ControlLabel>
29+
<SelectInfiniteScroll
30+
clearable
31+
disabled={!(resource?.perms || []).includes('change_resourcebase')}
32+
value={{ label: resource?.group?.name, value: resource?.group }}
33+
placeholder={"gnviewer.groupPlaceholder"}
34+
onChange={(selected) => onChange({ group: selected?.value ?? null})}
35+
loadOptions={({ q, ...params }) => getGroups({q, ...params})
36+
.then((response) => {
37+
return {
38+
...response,
39+
results: (response?.groups ?? [])
40+
.map((item) => ({...item, selectOption: {
41+
value: item.group,
42+
label: item.group.name
43+
}}))
44+
};
45+
})
46+
}
47+
/>
48+
</FormGroup>
49+
</FlexBox.Fill>
2350
{canAccessPermissions(resource) && <DetailsPermissions resource={resource} />}
2451
{canManageResourceSettings(resource) && (
2552
<FlexBox column gap="xs">

geonode_mapstore_client/client/js/selectors/resource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export const getResourceDirtyState = (state) => {
334334
return null;
335335
}
336336
const resourceType = state?.gnresource?.type;
337-
let metadataKeys = ['title', 'abstract', 'data', 'extent', ...RESOURCE_MANAGEMENT_PROPERTIES_KEYS];
337+
let metadataKeys = ['title', 'abstract', 'data', 'extent', 'group', ...RESOURCE_MANAGEMENT_PROPERTIES_KEYS];
338338
if (resourceType === ResourceTypes.DATASET) {
339339
metadataKeys = metadataKeys.concat('timeseries');
340340
}

geonode_mapstore_client/client/js/utils/ResourceUtils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
import uuid from 'uuid';
1010
import url from 'url';
11-
import isEmpty from 'lodash/isEmpty';
12-
import omit from 'lodash/omit';
11+
import { isEmpty, uniqBy, omit, orderBy, isString, isObject } from 'lodash';
12+
13+
import { isImageServerUrl } from '@mapstore/framework/utils/ArcGISUtils';
1314
import { getConfigProp, convertFromLegacy, normalizeConfig } from '@mapstore/framework/utils/ConfigUtils';
15+
import { excludeGoogleBackground, extractTileMatrixFromSources, ServerTypes } from '@mapstore/framework/utils/LayersUtils';
16+
1417
import { getGeoNodeLocalConfig, parseDevHostname } from '@js/utils/APIUtils';
1518
import { ProcessTypes, ProcessStatus } from '@js/utils/ResourceServiceUtils';
16-
import { uniqBy, orderBy, isString, isObject } from 'lodash';
17-
import { excludeGoogleBackground, extractTileMatrixFromSources, ServerTypes } from '@mapstore/framework/utils/LayersUtils';
1819
import { determineResourceType } from '@js/utils/FileUtils';
19-
import { isImageServerUrl } from '@mapstore/framework/utils/ArcGISUtils';
2020

2121
/**
2222
* @module utils/ResourceUtils

geonode_mapstore_client/static/mapstore/gn-translations/data.de-DE.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@
202202
"filterBy": "Filtern...",
203203
"addPermissionsEntry": "Benutzer / Gruppen hinzufügen",
204204
"groups": "Gruppen",
205+
"group": "Gruppe",
206+
"groupPlaceholder": "Gruppe auswählen",
205207
"users": "Benutzer",
206208
"nonePermission": "Keiner",
207209
"viewPermission": "Ansicht",

geonode_mapstore_client/static/mapstore/gn-translations/data.en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@
201201
"data": "Data",
202202
"filterBy": "Filter...",
203203
"addPermissionsEntry": "Add Users / Groups",
204+
"group": "Group",
205+
"groupPlaceholder": "Select group",
204206
"groups": "Groups",
205207
"users": "Users",
206208
"nonePermission": "None",

geonode_mapstore_client/static/mapstore/gn-translations/data.es-ES.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@
202202
"filterBy": "Filtro ...",
203203
"addPermissionsEntry": "Agregar usuarios / grupos",
204204
"groups": "Grupos",
205+
"group": "Grupo",
206+
"groupPlaceholder": "Seleccionar grupo",
205207
"users": "Usuarios",
206208
"nonePermission": "Ninguno",
207209
"viewPermission": "Ver",

0 commit comments

Comments
 (0)