@@ -177,30 +177,39 @@ async function checkUserGroup(userId, bulkMessage, userGroupInfo) {
177
177
try {
178
178
const excludeGroupSign = '!'
179
179
const groups = _ . get ( bulkMessage , 'recipients.groups' )
180
+
180
181
let flag = false // default
182
+ let excludeGroups = [ ]
183
+ let includeGroups = [ ]
184
+
185
+ _ . map ( groups , ( g ) => {
186
+ if ( _ . startsWith ( g , excludeGroupSign ) ) {
187
+ excludeGroups . push ( g )
188
+ } else {
189
+ includeGroups . push ( g )
190
+ }
191
+ } )
181
192
182
- if ( groups . length > 0 ) {
193
+ if ( includeGroups . length > 0 ) {
183
194
_ . map ( userGroupInfo , ( o ) => {
184
195
// particular group only condition
185
- flag = ( _ . indexOf ( groups , _ . get ( o , "name" ) ) >= 0 ) ? true : flag
196
+ flag = ( _ . indexOf ( includeGroups , _ . get ( o , "name" ) ) >= 0 ) ? true : flag
186
197
} )
187
- } else { // no group condition means its for `public` no private group
198
+ }
199
+ if ( excludeGroups . length > 0 ) {
188
200
flag = true // default allow for all
189
- let excludeGroups = [ ]
190
- _ . map ( groups , ( g ) => {
191
- if ( _ . startWith ( g , excludeGroupSign ) ) {
192
- excludeGroups . push ( g )
193
- }
194
- } )
195
201
_ . map ( userGroupInfo , ( o ) => {
196
202
// not allow if user is part of any private group i.e. excludeGroups
197
- if ( _ . indexOf ( excludeGroups , ( excludeGroupSign + _ . get ( o , "name" ) ) ) >= 0 ) {
198
- flag = false
199
- }
203
+ flag = ( _ . indexOf ( excludeGroups , ( excludeGroupSign + _ . get ( o , "name" ) ) ) >= 0 ) ? false : flag
200
204
} )
201
205
logger . info ( `public group condition for userId ${ userId } ` +
202
206
` and BC messageId ${ bulkMessage . id } , the result is: ${ flag } ` )
203
207
}
208
+
209
+ if ( groups . length === 0 ) {
210
+ flag = true // no restriction
211
+ }
212
+
204
213
return flag
205
214
} catch ( e ) {
206
215
throw new Error ( `checkUserGroup(): ${ e } ` )
0 commit comments