Skip to content

Commit 3da6333

Browse files
gavinbarronmusale
andauthored
fix: scopes used to query team channels (#2519)
removes config to use legacy scopes for teams access clean up construction of team channel items tree fix proxy provider to use v3.0.2 of graph client BREAKING CHANGE: removes MgtTeamsChannelPickerConfig BREAKING CHANGE: removes use of user.read.all and group.read.all scopes for team/channel reading Co-authored-by: Musale Martin <[email protected]>
1 parent 8691055 commit 3da6333

File tree

5 files changed

+22
-75
lines changed

5 files changed

+22
-75
lines changed

packages/mgt-components/src/components/mgt-teams-channel-picker/mgt-teams-channel-picker.graph.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import { IGraph, BetaGraph, CacheService, CacheStore } from '@microsoft/mgt-element';
8+
import { IGraph, BetaGraph, CacheService, CacheStore, prepScopes } from '@microsoft/mgt-element';
99
import { Team } from '@microsoft/microsoft-graph-types';
1010
import {
1111
getPhotoForResource,
@@ -22,19 +22,18 @@ import { CollectionResponse } from '@microsoft/mgt-element';
2222
* @returns {Promise<Team[]>}
2323
* @memberof Graph
2424
*/
25-
export const getAllMyTeams = async (graph: IGraph): Promise<Team[]> => {
25+
export const getAllMyTeams = async (graph: IGraph, scopes: string[]): Promise<Team[]> => {
2626
const teams = (await graph
2727
.api('/me/joinedTeams')
2828
.select(['displayName', 'id', 'isArchived'])
29+
.middlewareOptions(prepScopes(...scopes))
2930
.get()) as CollectionResponse<Team>;
3031

3132
return teams?.value;
3233
};
3334

3435
/** An object collection of cached photos. */
35-
type CachePhotos = {
36-
[key: string]: CachePhoto;
37-
};
36+
type CachePhotos = Record<string, CachePhoto>;
3837

3938
/**
4039
* Load the photos for a give set of teamIds

packages/mgt-components/src/components/mgt-teams-channel-picker/mgt-teams-channel-picker.ts

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
MgtTemplatedComponent,
1616
BetaGraph,
1717
customElement,
18-
mgtHtml
18+
mgtHtml,
19+
CollectionResponse
1920
} from '@microsoft/mgt-element';
2021
import '../../styles/style-helper';
2122
import '../sub-components/mgt-spinner/mgt-spinner';
@@ -142,22 +143,6 @@ interface ChannelPickerItemState {
142143
parent: ChannelPickerItemState;
143144
}
144145

145-
/**
146-
* Configuration object for the TeamsChannelPicker component
147-
*
148-
* @export
149-
* @interface MgtTeamsChannelPickerConfig
150-
*/
151-
export interface MgtTeamsChannelPickerConfig {
152-
/**
153-
* Sets or gets whether the teams channel picker component should use
154-
* the Teams based scopes instead of the User and Group based scopes
155-
*
156-
* @type {boolean}
157-
*/
158-
useTeamsBasedScopes: boolean;
159-
}
160-
161146
/**
162147
* Web component used to select channels from a User's Microsoft Teams profile
163148
*
@@ -209,21 +194,6 @@ export class MgtTeamsChannelPicker extends MgtTemplatedComponent {
209194
return strings;
210195
}
211196

212-
/**
213-
* Global Configuration object for all
214-
* teams channel picker components
215-
*
216-
* @static
217-
* @type {MgtTeamsChannelPickerConfig}
218-
* @memberof MgtTeamsChannelPicker
219-
*/
220-
public static get config(): MgtTeamsChannelPickerConfig {
221-
return this._config;
222-
}
223-
224-
private static readonly _config = {
225-
useTeamsBasedScopes: false
226-
};
227197
private teamsPhotos = {};
228198

229199
/**
@@ -249,11 +219,7 @@ export class MgtTeamsChannelPicker extends MgtTemplatedComponent {
249219
* @memberof MgtTeamsChannelPicker
250220
*/
251221
public static get requiredScopes(): string[] {
252-
if (this.config.useTeamsBasedScopes) {
253-
return ['team.readbasic.all', 'channel.readbasic.all'];
254-
} else {
255-
return ['user.read.all', 'group.read.all'];
256-
}
222+
return ['team.readbasic.all', 'channel.readbasic.all'];
257223
}
258224

259225
private set items(value) {
@@ -695,49 +661,31 @@ export class MgtTeamsChannelPicker extends MgtTemplatedComponent {
695661
if (provider && provider.state === ProviderState.SignedIn) {
696662
const graph = provider.graph.forComponent(this);
697663

698-
// make sure we have the needed scopes
699-
if (!(await provider.getAccessTokenForScopes(...MgtTeamsChannelPicker.requiredScopes))) {
700-
return;
701-
}
702-
703-
teams = await getAllMyTeams(graph);
664+
teams = await getAllMyTeams(graph, MgtTeamsChannelPicker.requiredScopes);
704665
teams = teams.filter(t => !t.isArchived);
705666

706-
const teamsIds = teams.map(t => t.id);
707-
708667
const beta = BetaGraph.fromGraph(graph);
709668

669+
const teamsIds = teams.map(t => t.id);
710670
this.teamsPhotos = await getTeamsPhotosforPhotoIds(beta, teamsIds);
711671

712-
const batch = graph.createBatch();
713-
const scopes = ['team.readbasic.all'];
672+
const batch = graph.createBatch<CollectionResponse<MicrosoftGraph.Channel>>();
714673

715674
for (const team of teams) {
716-
batch.get(team.id, `teams/${team.id}/channels`, scopes);
675+
batch.get(team.id, `teams/${team.id}/channels`, MgtTeamsChannelPicker.requiredScopes);
717676
}
718677

719678
const responses = await batch.executeAll();
720-
679+
this._items = [];
721680
for (const team of teams) {
722-
const response = responses.get(team.id);
723-
724-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
725-
if (response?.content?.value) {
726-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
727-
team.channels = response.content.value.map((c: MicrosoftGraph.Team) => {
728-
return {
729-
item: c
730-
};
731-
});
732-
}
681+
const channelsForTeam = responses.get(team.id);
682+
// skip over any teams that don't have channels
683+
if (!channelsForTeam.content?.value?.length) continue;
684+
this.items.push({
685+
item: team,
686+
channels: channelsForTeam.content.value.map(c => ({ item: c }))
687+
});
733688
}
734-
735-
this.items = teams.map(t => {
736-
return {
737-
channels: t.channels as DropdownItem[],
738-
item: t
739-
};
740-
});
741689
}
742690
this.filterList();
743691
this.resetFocusState();

packages/mgt-element/src/CollectionResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export interface CollectionResponse<T> {
1616
/**
1717
* The collection of items
1818
*/
19-
value: T[];
19+
value?: T[];
2020
}

packages/providers/mgt-proxy-provider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@microsoft/mgt-element": "*",
41-
"@microsoft/microsoft-graph-client": "^3.0.0"
41+
"@microsoft/microsoft-graph-client": "3.0.2"
4242
},
4343
"publishConfig": {
4444
"directory": "dist"

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5650,7 +5650,7 @@
56505650
"@microsoft/load-themed-styles" "1.10.292"
56515651
loader-utils "~1.1.0"
56525652

5653-
"@microsoft/[email protected]", "@microsoft/microsoft-graph-client@^3.0.0", "@microsoft/microsoft-graph-client@^3.0.1":
5653+
"@microsoft/[email protected]", "@microsoft/microsoft-graph-client@^3.0.1":
56545654
version "3.0.2"
56555655
resolved "https://registry.npmjs.org/@microsoft/microsoft-graph-client/-/microsoft-graph-client-3.0.2.tgz"
56565656
integrity sha512-eYDiApYmiGsm1s1jfAa/rhB2xQCsX4pWt0vCTd1LZmiApMQfT/c0hXj2hvpuGz5GrcLdugbu05xB79rIV57Pjw==

0 commit comments

Comments
 (0)