Skip to content

Commit

Permalink
Makes group type option case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlingstuyl committed Dec 4, 2023
1 parent 7e609c0 commit 8e7ee71
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/m365/aad/commands/group/group-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface ExtendedGroup extends Group {
}

class AadGroupListCommand extends GraphCommand {
private static readonly groupTypes: string[] = ['microsoft365', 'security', 'distribution', 'mailEnabledSecurity'];

public get name(): string {
return commands.GROUP_LIST;
}
Expand Down Expand Up @@ -52,15 +54,15 @@ class AadGroupListCommand extends GraphCommand {
this.options.unshift(
{
option: '--type [type]',
autocomplete: ['microsoft365', 'security', 'distribution', 'mailEnabledSecurity']
autocomplete: AadGroupListCommand.groupTypes
}
);
}

#initValidators(): void {
this.validators.push(
async (args: CommandArgs) => {
if (args.options.type && ['microsoft365', 'security', 'distribution', 'mailEnabledSecurity'].indexOf(args.options.type) === -1) {
if (args.options.type && AadGroupListCommand.groupTypes.every(g => g.toLowerCase() !== args.options.type?.toLowerCase())) {
return `${args.options.type} is not a valid type value. Allowed values microsoft365|security|distribution|mailEnabledSecurity.`;
}

Expand All @@ -72,9 +74,12 @@ class AadGroupListCommand extends GraphCommand {
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
try {
let requestUrl: string = `${this.resource}/v1.0/groups`;
let useConsistencyLevelHeader = false;

if (args.options.type) {
switch (args.options.type) {
const groupType = AadGroupListCommand.groupTypes.find(g => g.toLowerCase() === args.options.type?.toLowerCase());

switch (groupType) {
case 'microsoft365':
requestUrl += `?$filter=groupTypes/any(c:c+eq+'Unified')`;
break;
Expand All @@ -85,14 +90,15 @@ class AadGroupListCommand extends GraphCommand {
requestUrl += '?$filter=securityEnabled eq false and mailEnabled eq true';
break;
case 'mailEnabledSecurity':
useConsistencyLevelHeader = true;
requestUrl += `?$filter=securityEnabled eq true and mailEnabled eq true and not(groupTypes/any(t:t eq 'Unified'))&$count=true`;
break;
}
}

let groups: Group[] = [];

if (args.options.type === 'mailEnabledSecurity') {
if (useConsistencyLevelHeader) {
// While using not() function in the filter, we need to specify the ConsistencyLevel header.
const requestOptions: CliRequestOptions = {
url: requestUrl,
Expand Down

0 comments on commit 8e7ee71

Please sign in to comment.