@@ -291,6 +291,16 @@ await this.Client.UpdateDefaultUserRolePermissionGrantPoliciesAssigned(
291291 }
292292 else if ( this . State == MicrosoftGraphRscConfigurationState . EnabledForPreApprovedAppsOnly )
293293 {
294+ // Disable chat RSC Teams Setting.
295+ await this . Client . UpdateTeamsAppSettings (
296+ isChatResourceSpecificConsentEnabled : false ,
297+ eventListener : this ,
298+ sender : Pipeline ) ;
299+
300+ WriteVerbose ( $ "Disabled Chat RSC Teams setting.") ;
301+
302+ if ( ( ( Microsoft . Graph . Beta . PowerShell . Runtime . IEventListener ) this ) . Token . IsCancellationRequested ) { return ; }
303+
294304 // Remove all permission grant policies assigned to default user role permissions which are relevant to chat scope and add
295305 // Microsoft created.policy enabling pre-approvals.
296306 IEnumerable < string > updatedPermissionGrantPolicies = authorizationPolicy . DefaultUserRolePermissions . PermissionGrantPoliciesAssigned
@@ -306,7 +316,9 @@ await this.Client.UpdateDefaultUserRolePermissionGrantPoliciesAssigned(
306316 WriteVerbose ( $ "Updated permission grant policies assigned to default user role: '{ string . Join ( ", " , updatedPermissionGrantPolicies ) } '.") ;
307317
308318 if ( ( ( Microsoft . Graph . Beta . PowerShell . Runtime . IEventListener ) this ) . Token . IsCancellationRequested ) { return ; }
309-
319+ }
320+ else if ( this . State == MicrosoftGraphRscConfigurationState . ManagedByMicrosoft )
321+ {
310322 // Disable chat RSC Teams Setting.
311323 await this . Client . UpdateTeamsAppSettings (
312324 isChatResourceSpecificConsentEnabled : false ,
@@ -316,30 +328,48 @@ await this.Client.UpdateTeamsAppSettings(
316328 WriteVerbose ( $ "Disabled Chat RSC Teams setting.") ;
317329
318330 if ( ( ( Microsoft . Graph . Beta . PowerShell . Runtime . IEventListener ) this ) . Token . IsCancellationRequested ) { return ; }
331+
332+ // Remove all permission grant policies assigned to default user role permissions which are relevant to chat scope and add
333+ // Microsoft created.policy enabling pre-approvals.
334+ IEnumerable < string > updatedPermissionGrantPolicies = authorizationPolicy . DefaultUserRolePermissions . PermissionGrantPoliciesAssigned
335+ . Except (
336+ assignedPermissionGrantPoliciesApplicableToChatScope . Select ( p => p . ManagePermissionGrantsForOwnedResourcePrefixedId ) ,
337+ StringComparer . OrdinalIgnoreCase )
338+ . Union ( new string [ ] { RscConfigurationSynthesizer . MicrosoftCreatedPermissionGrantPolicyManagedByMicrosoftForChats } , StringComparer . OrdinalIgnoreCase ) ;
339+ await this . Client . UpdateDefaultUserRolePermissionGrantPoliciesAssigned (
340+ updatedPermissionGrantPolicies ,
341+ this ,
342+ Pipeline ) ;
343+
344+ WriteVerbose ( $ "Updated permission grant policies assigned to default user role: '{ string . Join ( ", " , updatedPermissionGrantPolicies ) } '.") ;
345+
346+ if ( ( ( Microsoft . Graph . Beta . PowerShell . Runtime . IEventListener ) this ) . Token . IsCancellationRequested ) { return ; }
319347 }
320348 else if ( this . State == MicrosoftGraphRscConfigurationState . EnabledForAllApps )
321349 {
322- // Enable chat RSC Teams Setting.
350+ // Disable chat RSC Teams Setting.
323351 await this . Client . UpdateTeamsAppSettings (
324- isChatResourceSpecificConsentEnabled : true ,
352+ isChatResourceSpecificConsentEnabled : false ,
325353 eventListener : this ,
326354 sender : Pipeline ) ;
327355
328- WriteVerbose ( $ "Enabled Chat RSC Teams setting.") ;
356+ WriteVerbose ( $ "Disabled Chat RSC Teams setting.") ;
329357
330358 if ( ( ( Microsoft . Graph . Beta . PowerShell . Runtime . IEventListener ) this ) . Token . IsCancellationRequested ) { return ; }
331359
332- // Remove all permission grant policies assigned to default user role permissions which are relevant to chat scope.
333- IEnumerable < string > existingPermissionGrantPoliciesExceptChatScopePolicies = authorizationPolicy . DefaultUserRolePermissions . PermissionGrantPoliciesAssigned
360+ // Remove all permission grant policies assigned to default user role permissions which are relevant to chat scope and add
361+ // Microsoft created.policy enabling permissions for all apps.
362+ IEnumerable < string > updatedPermissionGrantPolicies = authorizationPolicy . DefaultUserRolePermissions . PermissionGrantPoliciesAssigned
334363 . Except (
335364 assignedPermissionGrantPoliciesApplicableToChatScope . Select ( p => p . ManagePermissionGrantsForOwnedResourcePrefixedId ) ,
336- StringComparer . OrdinalIgnoreCase ) ;
365+ StringComparer . OrdinalIgnoreCase )
366+ . Union ( new string [ ] { RscConfigurationSynthesizer . MicrosoftCreatedPermissionGrantPolicyEnabledForAllAppsForChats } , StringComparer . OrdinalIgnoreCase ) ;
337367 await this . Client . UpdateDefaultUserRolePermissionGrantPoliciesAssigned (
338- existingPermissionGrantPoliciesExceptChatScopePolicies ,
368+ updatedPermissionGrantPolicies ,
339369 this ,
340370 Pipeline ) ;
341371
342- WriteVerbose ( $ "Updated permission grant policies assigned to default user role: '{ string . Join ( ", " , existingPermissionGrantPoliciesExceptChatScopePolicies ) } '.") ;
372+ WriteVerbose ( $ "Updated permission grant policies assigned to default user role: '{ string . Join ( ", " , updatedPermissionGrantPolicies ) } '.") ;
343373
344374 if ( ( ( Microsoft . Graph . Beta . PowerShell . Runtime . IEventListener ) this ) . Token . IsCancellationRequested ) { return ; }
345375 }
0 commit comments