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