-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command: tenant people pronouns set
- Loading branch information
Showing
5 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/m365/tenant/commands/people/people-pronouns-set.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
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'; | ||
}); | ||
|
||
await command.action(logger, { | ||
options: { verbose: true, enabled: true } | ||
}); | ||
|
||
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') | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |