-
Notifications
You must be signed in to change notification settings - Fork 384
Add support for shared channels to: teams channel member add #7133
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
Draft
adamlonsdale
wants to merge
3
commits into
pnp:main
Choose a base branch
from
adamlonsdale:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -109,6 +109,18 @@ describe(commands.CHANNEL_MEMBER_ADD, () => { | |
| ] | ||
| }; | ||
|
|
||
| const singleSharedChannelResponse: any = { | ||
| "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('47d6625d-a540-4b59-a4ab-19b787e40593')/channels", | ||
| "@odata.count": 1, | ||
| "value": [ | ||
| { | ||
| "id": "19:[email protected]", | ||
| "displayName": "Shared Channel", | ||
| "membershipType": "shared" | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| const channelIdResponse: any = { | ||
| "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('47d6625d-a540-4b59-a4ab-19b787e40593')/channels/$entity", | ||
| "id": "19:[email protected]", | ||
|
|
@@ -225,6 +237,10 @@ describe(commands.CHANNEL_MEMBER_ADD, () => { | |
| return singleChannelResponse; | ||
| } | ||
|
|
||
| if (opts.url === `https://graph.microsoft.com/v1.0/teams/${formatting.encodeQueryParameter('47d6625d-a540-4b59-a4ab-19b787e40593')}/channels?$filter=displayName eq '${formatting.encodeQueryParameter('Shared Channel')}'`) { | ||
| return singleSharedChannelResponse; | ||
| } | ||
|
|
||
| throw 'Invalid request'; | ||
| }); | ||
| log = []; | ||
|
|
@@ -443,6 +459,27 @@ describe(commands.CHANNEL_MEMBER_ADD, () => { | |
| assert(loggerLogSpy.notCalled); | ||
| }); | ||
|
|
||
| it('adds conversation members using teamId, shared channelName, and userIds', async () => { | ||
| sinonUtil.restore(request.post); | ||
| sinon.stub(request, 'post').callsFake(async (opts) => { | ||
| if (opts.url === `https://graph.microsoft.com/v1.0/teams/${formatting.encodeQueryParameter('47d6625d-a540-4b59-a4ab-19b787e40593')}/channels/${formatting.encodeQueryParameter('19:[email protected]')}/members`) { | ||
| return conversationMembersOwnerResponse; | ||
| } | ||
|
|
||
| throw 'Invalid request'; | ||
| }); | ||
|
|
||
| await command.action(logger, { | ||
| options: { | ||
| teamId: "47d6625d-a540-4b59-a4ab-19b787e40593", | ||
| channelName: "Shared Channel", | ||
| userIds: "[email protected]", | ||
| owner: true | ||
| } | ||
| }); | ||
| assert(loggerLogSpy.notCalled); | ||
| }); | ||
|
|
||
| it('fails adding conversation members with invalid channelName', async () => { | ||
| sinonUtil.restore(request.get); | ||
| sinon.stub(request, 'get').callsFake(async (opts) => { | ||
|
|
@@ -469,7 +506,7 @@ describe(commands.CHANNEL_MEMBER_ADD, () => { | |
| } as any), new CommandError(`The specified channel 'Other Private Channel' does not exist in the Microsoft Teams team with ID '47d6625d-a540-4b59-a4ab-19b787e40593'`)); | ||
| }); | ||
|
|
||
| it('fails to get channel when channel does is not private', async () => { | ||
| it('fails to get channel when channel is not private or shared', async () => { | ||
| sinonUtil.restore(request.get); | ||
| sinon.stub(request, 'get').callsFake(async (opts) => { | ||
| if (opts.url === `https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '${formatting.encodeQueryParameter('Human Resources')}'`) { | ||
|
|
@@ -495,7 +532,7 @@ describe(commands.CHANNEL_MEMBER_ADD, () => { | |
| teamId: "47d6625d-a540-4b59-a4ab-19b787e40593", | ||
| channelName: "Other Channel" | ||
| } | ||
| } as any), new CommandError('The specified channel is not a private channel')); | ||
| } as any), new CommandError('The specified channel is not a private or shared channel')); | ||
| }); | ||
|
|
||
| it('fails when group has no team', async () => { | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this fix correctly adds support for shared channels to
teams channel member add, there are related commandsteams channel member remove(src/m365/teams/commands/channel/channel-member-remove.ts:210-211) andteams channel member set(src/m365/teams/commands/channel/channel-member-set.ts:193-194) that have the same limitation. Their descriptions already mention "private or shared team channel" but their validation logic still only accepts private channels. Consider updating those commands as well to maintain consistency and ensure all channel member management commands fully support shared channels.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a valid point @adamlonsdale. Could you have a look at the other commands as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fair point, I was weighing up the tradeoff between multiple commits / PRs vs this one. I'll add these now, test and push an update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the fix is not that large, I think we can do them in one PR.