Skip to content

Commit

Permalink
other: added msgraphservice.isusermemberofsecuritygroup 🔧 [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
olemp committed Mar 21, 2024
1 parent 3d09732 commit 260e4fc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/services/msgraph/MSGraphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,29 @@ export class MSGraphService {
throw new MSGraphError('getEvents', error.message)
}
}

/**
* Checks if a user is a member of a security group.
*
* @param groupId The ID of the security group.
* @param mail The email address of the user.
*
* @public
*
* @memberof MSGraphService
*/
public async isUserMemberOfSecurityGroup(
groupId: string,
mail: string
): Promise<boolean> {
try {
const client = await this._getClient()
const response = await (client
.api(`/groups/${groupId}/members?$select=id,mail`)
.get() as Promise<{ value: any[] }>)
return response.value.some((member) => member.mail === mail)
} catch {
return false
}
}
}

0 comments on commit 260e4fc

Please sign in to comment.