Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command: tenant people pronouns set. Closes #6205 #6519

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions docs/docs/cmd/tenant/people/people-pronouns-set.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# tenant people pronouns set

Manage pronouns settings for an organization

## Usage

```sh
m365 tenant people pronouns set [options]
```

## Options

```md definition-list
`-e, --enabled <enabled>`
: Specifies whether the pronouns are enabled in the organization or not.
```

<Global />

## Examples

Enable pronouns in the organization

```sh
m365 tenant people pronouns set --enabled true
```

Disable pronouns in the organization

```sh
m365 tenant people pronouns set --enabled false
```

## Response

<Tabs>
<TabItem value="JSON">

```json
{
"isEnabledInOrganization": true
}
```

</TabItem>
<TabItem value="Text">

```text
isEnabledInOrganization: true
```

</TabItem>
<TabItem value="CSV">

```csv
isEnabledInOrganization
1
```

</TabItem>
<TabItem value="Markdown">

```md
# tenant people pronouns get

Date: 12/14/2024

Property | Value
---------|-------
isEnabledInOrganization | true
```

</TabItem>
</Tabs>

## More information

- https://learn.microsoft.com/graph/api/pronounssettings-update
5 changes: 5 additions & 0 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ const sidebars: SidebarsConfig = {
type: 'doc',
label: 'people pronouns get',
id: 'cmd/tenant/people/people-pronouns-get'
},
{
type: 'doc',
label: 'people pronouns set',
id: 'cmd/tenant/people/people-pronouns-set'
}
]
},
Expand Down
1 change: 1 addition & 0 deletions src/m365/tenant/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
PEOPLE_PROFILECARDPROPERTY_REMOVE: `${prefix} people profilecardproperty remove`,
PEOPLE_PROFILECARDPROPERTY_SET: `${prefix} people profilecardproperty set`,
PEOPLE_PRONOUNS_GET: `${prefix} people pronouns get`,
PEOPLE_PRONOUNS_SET: `${prefix} people pronouns set`,
REPORT_ACTIVEUSERCOUNTS: `${prefix} report activeusercounts`,
REPORT_ACTIVEUSERDETAIL: `${prefix} report activeuserdetail`,
REPORT_OFFICE365ACTIVATIONCOUNTS: `${prefix} report office365activationcounts`,
Expand Down
110 changes: 110 additions & 0 deletions src/m365/tenant/commands/people/people-pronouns-set.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import assert from 'assert';
import sinon from 'sinon';
import auth from '../../../../Auth.js';
import { Logger } from '../../../../cli/Logger.js';
import { CommandError } from '../../../../Command.js';
import request from '../../../../request.js';
import { telemetry } from '../../../../telemetry.js';
import { pid } from '../../../../utils/pid.js';
import { session } from '../../../../utils/session.js';
import { sinonUtil } from '../../../../utils/sinonUtil.js';
import commands from '../../commands.js';
import command from './people-pronouns-set.js';
import { z } from 'zod';
import { CommandInfo } from '../../../../cli/CommandInfo.js';
import { cli } from '../../../../cli/cli.js';

describe(commands.PEOPLE_PRONOUNS_SET, () => {
let log: string[];
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;
let commandInfo: CommandInfo;
let commandOptionsSchema: z.ZodTypeAny;

before(() => {
sinon.stub(auth, 'restoreAuth').resolves();
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
auth.connection.active = true;
commandInfo = cli.getCommandInfo(command);
commandOptionsSchema = commandInfo.command.getSchemaToParse()!;
});

beforeEach(() => {
log = [];
logger = {
log: async (msg: string) => {
log.push(msg);
},
logRaw: async (msg: string) => {
log.push(msg);
},
logToStderr: async (msg: string) => {
log.push(msg);
}
};
loggerLogSpy = sinon.spy(logger, 'log');
});

afterEach(() => {
sinonUtil.restore([
request.patch
]);
});

after(() => {
sinon.restore();
auth.connection.active = false;
});

it('has correct name', () => {
assert.strictEqual(command.name, commands.PEOPLE_PRONOUNS_SET);
});

it('has a description', () => {
assert.notStrictEqual(command.description, null);
});

it('fails validation when no option is specified', async () => {
const actual = commandOptionsSchema.safeParse({});
assert.notStrictEqual(actual.success, true);
});

it(`should set pronouns settings`, async () => {
sinon.stub(request, 'patch').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/admin/people/pronouns`) {
return {
isEnabledInOrganization: true
};
}

throw 'Invalid request';
});

const parsedSchema = commandOptionsSchema.safeParse({ verbose: true, enabled: true });
await command.action(logger, {
options: parsedSchema.data
});

assert(
loggerLogSpy.calledOnceWithExactly({
isEnabledInOrganization: true
})
);
});

it('handles error when retrieving pronouns settings failed', async () => {
sinon.stub(request, 'patch').callsFake(async (opts) => {
if (opts.url === `https://graph.microsoft.com/v1.0/admin/people/pronouns`) {
throw { error: { message: 'An error has occurred' } };
}
throw `Invalid request`;
});

await assert.rejects(
command.action(logger, { options: {} } as any),
new CommandError('An error has occurred')
);
});
});
62 changes: 62 additions & 0 deletions src/m365/tenant/commands/people/people-pronouns-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { Logger } from '../../../../cli/Logger.js';
import request, { CliRequestOptions } from '../../../../request.js';
import { zod } from '../../../../utils/zod.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';

const options = globalOptionsZod
.extend({
enabled: zod.alias('e', z.boolean())
})
.strict();

declare type Options = z.infer<typeof options>;

interface CommandArgs {
options: Options;
}

class TenantPeoplePronounsSetCommand extends GraphCommand {
public get name(): string {
return commands.PEOPLE_PRONOUNS_SET;
}

public get description(): string {
return 'Manage pronouns settings for an organization';
}

public get schema(): z.ZodTypeAny | undefined {
return options;
}

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
try {
if (this.verbose) {
await logger.logToStderr('Updating pronouns settings...');
}

const requestOptions: CliRequestOptions = {
url: `${this.resource}/v1.0/admin/people/pronouns`,
headers: {
accept: 'application/json;odata.metadata=none'
},
data: {
isEnabledInOrganization: args.options.enabled
},
responseType: 'json'
};

const pronouns = await request.patch<any>(requestOptions);

await logger.log(pronouns);

}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}

export default new TenantPeoplePronounsSetCommand();
Loading