1- import { genericConfig } from "../../common/config.js" ;
21import {
2+ execCouncilGroupId ,
3+ execCouncilTestingGroupId ,
4+ genericConfig ,
5+ officersGroupId ,
6+ officersGroupTestingId ,
7+ } from "../../common/config.js" ;
8+ import {
9+ BaseError ,
310 EntraGroupError ,
411 EntraInvitationError ,
512 InternalServerError ,
@@ -190,7 +197,32 @@ export async function modifyGroup(
190197 message : "User's domain must be illinois.edu to be added to the group." ,
191198 } ) ;
192199 }
193-
200+ // if adding to exec group, check that all exec members we want to add are paid members
201+ const paidMemberRequiredGroups = [
202+ execCouncilGroupId ,
203+ execCouncilTestingGroupId ,
204+ officersGroupId ,
205+ officersGroupTestingId ,
206+ ] ;
207+ if (
208+ paidMemberRequiredGroups . includes ( group ) &&
209+ action === EntraGroupActions . ADD
210+ ) {
211+ const netId = email . split ( "@" ) [ 0 ] ;
212+ const response = await fetch (
213+ `https://membership.acm.illinois.edu/api/v1/checkMembership?netId=${ netId } ` ,
214+ ) ;
215+ const membershipStatus = ( await response . json ( ) ) as {
216+ netId : string ;
217+ isPaidMember : boolean ;
218+ } ;
219+ if ( ! membershipStatus [ "isPaidMember" ] ) {
220+ throw new EntraGroupError ( {
221+ message : `${ netId } is not a paid member. This group requires that all members are paid members.` ,
222+ group,
223+ } ) ;
224+ }
225+ }
194226 try {
195227 const oid = await resolveEmailToOid ( token , email ) ;
196228 const methodMapper = {
@@ -220,6 +252,12 @@ export async function modifyGroup(
220252 const errorData = ( await response . json ( ) ) as {
221253 error ?: { message ?: string } ;
222254 } ;
255+ if (
256+ errorData ?. error ?. message ===
257+ "One or more added object references already exist for the following modified properties: 'members'."
258+ ) {
259+ return true ;
260+ }
223261 throw new EntraGroupError ( {
224262 message : errorData ?. error ?. message ?? response . statusText ,
225263 group,
@@ -231,12 +269,15 @@ export async function modifyGroup(
231269 if ( error instanceof EntraGroupError ) {
232270 throw error ;
233271 }
234-
235- throw new EntraGroupError ( {
236- message : error instanceof Error ? error . message : String ( error ) ,
237- group,
238- } ) ;
272+ const message = error instanceof Error ? error . message : String ( error ) ;
273+ if ( message ) {
274+ throw new EntraGroupError ( {
275+ message,
276+ group,
277+ } ) ;
278+ }
239279 }
280+ return false ;
240281}
241282
242283/**
0 commit comments