@@ -27,6 +27,22 @@ export const USER_ROLES = {
2727 SUBMITTER : 'Submitter' ,
2828} ;
2929
30+ /* This is the internal implementation of addGroup(..) function.
31+ * It does exactly what is described there, but mutates its "groups" argument.
32+ */
33+ function addGroupPrivate ( groups , srcGroup ) {
34+ const group = _ . clone ( srcGroup ) ;
35+ if ( group . subGroups ) {
36+ if ( group . subGroups . length ) {
37+ group . subGroupIds = group . subGroups . map ( g => g . id ) ;
38+ group . subGroups . forEach ( g => addGroupPrivate ( groups , g ) ) ;
39+ }
40+ delete group . subGroups ;
41+ }
42+ groups [ group . id ] = group ; // eslint-disable-line no-param-reassign
43+ return groups ;
44+ }
45+
3046/**
3147 * This function merges "srcGroup" into "groups" (without mutation of original
3248 * objects) and returns the result.
@@ -45,15 +61,7 @@ export const USER_ROLES = {
4561 * overwrite corresponding data from "groups".
4662 */
4763export function addGroup ( groups , srcGroup ) {
48- const group = _ . clone ( srcGroup ) ;
49- if ( group . subGroups ) {
50- if ( group . subGroups . length ) {
51- group . subGroupIds = group . subGroups . map ( g => g . id ) ;
52- group . subGroups . forEach ( g => addGroup ( groups , g ) ) ;
53- }
54- delete group . subGroups ;
55- }
56- return { ...groups , [ group . id ] : group } ;
64+ return addGroupPrivate ( _ . clone ( groups ) , srcGroup ) ;
5765}
5866
5967/**
0 commit comments