@@ -673,7 +673,10 @@ await _organizationApiKeyRepository.CreateAsync(new OrganizationApiKey
673
673
AccessSecretsManager = organization . UseSecretsManager ,
674
674
Type = OrganizationUserType . Owner ,
675
675
Status = OrganizationUserStatusType . Confirmed ,
676
- AccessAll = true ,
676
+
677
+ // If using Flexible Collections, AccessAll is deprecated and set to false.
678
+ // If not using Flexible Collections, set AccessAll to true (previous behavior)
679
+ AccessAll = ! organization . FlexibleCollections ,
677
680
CreationDate = organization . CreationDate ,
678
681
RevisionDate = organization . CreationDate
679
682
} ;
@@ -885,6 +888,18 @@ public async Task<List<OrganizationUser>> InviteUsersAsync(Guid organizationId,
885
888
throw new NotFoundException ( ) ;
886
889
}
887
890
891
+ // If the organization is using Flexible Collections, prevent use of any deprecated permissions
892
+ if ( organization . FlexibleCollections && invites . Any ( i => i . invite . Type is OrganizationUserType . Manager ) )
893
+ {
894
+ throw new BadRequestException ( "The Manager role has been deprecated by collection enhancements. Use the collection Can Manage permission instead." ) ;
895
+ }
896
+
897
+ if ( organization . FlexibleCollections && invites . Any ( i => i . invite . AccessAll ) )
898
+ {
899
+ throw new BadRequestException ( "The AccessAll property has been deprecated by collection enhancements. Assign the user to collections instead." ) ;
900
+ }
901
+ // End Flexible Collections
902
+
888
903
var existingEmails = new HashSet < string > ( await _organizationUserRepository . SelectKnownEmailsAsync (
889
904
organizationId , invites . SelectMany ( i => i . invite . Emails ) , false ) , StringComparer . InvariantCultureIgnoreCase ) ;
890
905
@@ -1377,6 +1392,19 @@ public async Task SaveUserAsync(OrganizationUser user, Guid? savingUserId,
1377
1392
throw new BadRequestException ( "Organization must have at least one confirmed owner." ) ;
1378
1393
}
1379
1394
1395
+ // If the organization is using Flexible Collections, prevent use of any deprecated permissions
1396
+ var organizationAbility = await _applicationCacheService . GetOrganizationAbilityAsync ( user . OrganizationId ) ;
1397
+ if ( organizationAbility ? . FlexibleCollections == true && user . Type == OrganizationUserType . Manager )
1398
+ {
1399
+ throw new BadRequestException ( "The Manager role has been deprecated by collection enhancements. Use the collection Can Manage permission instead." ) ;
1400
+ }
1401
+
1402
+ if ( organizationAbility ? . FlexibleCollections == true && user . AccessAll )
1403
+ {
1404
+ throw new BadRequestException ( "The AccessAll property has been deprecated by collection enhancements. Assign the user to collections instead." ) ;
1405
+ }
1406
+ // End Flexible Collections
1407
+
1380
1408
// Only autoscale (if required) after all validation has passed so that we know it's a valid request before
1381
1409
// updating Stripe
1382
1410
if ( ! originalUser . AccessSecretsManager && user . AccessSecretsManager )
@@ -2027,15 +2055,6 @@ public async Task ValidateOrganizationUserUpdatePermissions(Guid organizationId,
2027
2055
{
2028
2056
throw new BadRequestException ( "Custom users can only grant the same custom permissions that they have." ) ;
2029
2057
}
2030
-
2031
- // TODO: pass in the whole organization object when this is refactored into a command/query
2032
- // See AC-2036
2033
- var organizationAbility = await _applicationCacheService . GetOrganizationAbilityAsync ( organizationId ) ;
2034
- var flexibleCollectionsEnabled = organizationAbility ? . FlexibleCollections ?? false ;
2035
- if ( flexibleCollectionsEnabled && newType == OrganizationUserType . Manager && oldType is not OrganizationUserType . Manager )
2036
- {
2037
- throw new BadRequestException ( "Manager role is deprecated after Flexible Collections." ) ;
2038
- }
2039
2058
}
2040
2059
2041
2060
private async Task ValidateOrganizationCustomPermissionsEnabledAsync ( Guid organizationId , OrganizationUserType newType )
@@ -2451,7 +2470,10 @@ public async Task CreatePendingOrganization(Organization organization, string ow
2451
2470
Key = null ,
2452
2471
Type = OrganizationUserType . Owner ,
2453
2472
Status = OrganizationUserStatusType . Invited ,
2454
- AccessAll = true
2473
+
2474
+ // If using Flexible Collections, AccessAll is deprecated and set to false.
2475
+ // If not using Flexible Collections, set AccessAll to true (previous behavior)
2476
+ AccessAll = ! organization . FlexibleCollections ,
2455
2477
} ;
2456
2478
await _organizationUserRepository . CreateAsync ( ownerOrganizationUser ) ;
2457
2479
0 commit comments