File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ export async function validateSpaceSettings(originalSpace: any) {
29
29
delete space . hibernated ;
30
30
delete space . id ;
31
31
32
+ if ( space . parent && space . parent === originalSpace . id ) {
33
+ return Promise . reject ( 'space cannot be its own parent' ) ;
34
+ }
35
+
36
+ if (
37
+ space . children &&
38
+ Array . isArray ( space . children ) &&
39
+ space . children . includes ( originalSpace . id )
40
+ ) {
41
+ return Promise . reject ( 'space cannot be its own child' ) ;
42
+ }
43
+
32
44
const schemaIsValid : any = snapshot . utils . validateSchema ( snapshot . schemas . space , space , {
33
45
spaceType,
34
46
snapshotEnv : SNAPSHOT_ENV
@@ -73,6 +85,7 @@ export async function verify(body): Promise<any> {
73
85
try {
74
86
await validateSpaceSettings ( {
75
87
...msg . payload ,
88
+ id : msg . space ,
76
89
deleted : space ?. deleted ,
77
90
turbo : space ?. turbo
78
91
} ) ;
Original file line number Diff line number Diff line change @@ -134,6 +134,29 @@ describe('writer/settings', () => {
134
134
verify ( editedInput ( { validation : { name : 'any' } , strategies : [ { name : 'ticket' } ] } ) )
135
135
) . rejects . toContain ( 'space with ticket requires voting validation' ) ;
136
136
} ) ;
137
+
138
+ it ( 'rejects if space tries to set itself as parent' , async ( ) => {
139
+ return expect ( verify ( editedInput ( { parent : 'fabien.eth' } ) ) ) . rejects . toContain (
140
+ 'space cannot be its own parent'
141
+ ) ;
142
+ } ) ;
143
+
144
+ it ( 'rejects if space tries to include itself in children array' , async ( ) => {
145
+ return expect (
146
+ verify ( editedInput ( { children : [ 'other-space.eth' , 'fabien.eth' , 'another-space.eth' ] } ) )
147
+ ) . rejects . toContain ( 'space cannot be its own child' ) ;
148
+ } ) ;
149
+
150
+ it ( 'accepts valid parent that is not the space itself' , async ( ) => {
151
+ return expect ( verify ( editedInput ( { parent : 'parent-space.eth' } ) ) ) . resolves . toBeUndefined ( ) ;
152
+ } ) ;
153
+
154
+ it ( 'accepts valid children array that does not include the space itself' , async ( ) => {
155
+ return expect (
156
+ verify ( editedInput ( { children : [ 'child1.eth' , 'child2.eth' ] } ) )
157
+ ) . resolves . toBeUndefined ( ) ;
158
+ } ) ;
159
+
137
160
it . todo ( 'rejects if the submitter does not have permission' ) ;
138
161
it . todo ( 'rejects if the submitter does not have permission to change admin' ) ;
139
162
const maxStrategiesForNormalSpace = LIMITS [ 'space.default.strategies_limit' ] ;
You can’t perform that action at this time.
0 commit comments