@@ -130,23 +130,11 @@ export class SocketAuxObject {
130
130
}
131
131
132
132
if ( ! groupIsPublic ) {
133
- const [ [ userPlan , personalGroupId ] , groupMemberRole ] =
134
- await Promise . all ( [
135
- dataAbstraction ( ) . hmget ( 'user' , this . userId , [
136
- 'plan' ,
137
- 'personal-group-id' ,
138
- ] ) ,
139
-
140
- dataAbstraction ( ) . hget (
141
- 'group-member' ,
142
- `${ groupId } :${ this . userId } ` ,
143
- 'role' ,
144
- ) ,
145
- ] ) ;
146
-
147
- if ( userPlan !== 'pro' && groupId !== personalGroupId ) {
148
- throw new Error ( 'This requires a Pro plan subscription.' ) ;
149
- }
133
+ const groupMemberRole = await dataAbstraction ( ) . hget (
134
+ 'group-member' ,
135
+ `${ groupId } :${ this . userId } ` ,
136
+ 'role' ,
137
+ ) ;
150
138
151
139
if ( groupMemberRole == null ) {
152
140
throw new Error ( 'User is not a member of the group.' ) ;
@@ -399,13 +387,13 @@ export class SocketAuxObject {
399
387
}
400
388
401
389
private async _handleMessage ( messageBuffer : ArrayBuffer ) {
402
- const [ groupId , sessionInvalidated ] = await Promise . all ( [
403
- dataAbstraction ( ) . hget ( 'page' , this . room . pageId , 'group-id' ) ,
404
-
405
- ... ( this . sessionId != null
406
- ? [ dataAbstraction ( ) . hget ( 'session ' , this . sessionId , 'invalidated' ) ]
407
- : [ ] ) ,
408
- ] ) ;
390
+ const [ sessionInvalidated , userPlan , pageGroupId , pageIsFree ] =
391
+ await Promise . all ( [
392
+ dataAbstraction ( ) . hget ( 'session' , this . sessionId ! , 'invalidated' ) ,
393
+ dataAbstraction ( ) . hget ( 'user' , this . userId ! , 'plan' ) ,
394
+ dataAbstraction ( ) . hget ( 'page ' , this . room . pageId , 'group-id' ) ,
395
+ dataAbstraction ( ) . hget ( 'page' , this . room . pageId , 'free' ) ,
396
+ ] ) ;
409
397
410
398
// Check if session is invalidated
411
399
@@ -417,16 +405,16 @@ export class SocketAuxObject {
417
405
418
406
// Check if has permission to edit
419
407
420
- const role =
421
- groupId != null && this . userId != null
422
- ? await dataAbstraction ( ) . hget (
423
- 'group-member' ,
424
- `${ groupId } :${ this . userId } ` ,
425
- 'role' ,
426
- )
427
- : null ;
408
+ const role = await dataAbstraction ( ) . hget (
409
+ 'group-member' ,
410
+ `${ pageGroupId } :${ this . userId } ` ,
411
+ 'role' ,
412
+ ) ;
428
413
429
- if ( ! rolesMap ( ) [ role ] ?. permissions . editGroupPages ) {
414
+ if (
415
+ ! rolesMap ( ) [ role ] ?. permissions . editGroupPages ||
416
+ ( userPlan !== 'pro' && ! pageIsFree )
417
+ ) {
430
418
moduleLogger . info ( 'Ignored message from unauthorized user' ) ;
431
419
return ;
432
420
}
0 commit comments