feat(shorebird_code_push_protocol): map roles to permissions (#3425)

This commit is contained in:
Bryan Oltman
2025-12-10 17:05:40 -05:00
committed by GitHub
parent 736946117e
commit cc913680d4
3 changed files with 35 additions and 9 deletions
@@ -76,6 +76,7 @@ class Plan {
/// for accounts with unlimited collaborators.
final int? maxTeamSize;
/// Roles assignable to users associated with this plan.
final List<Role> availableRoles;
/// Roles assignable to users associated with this plan, mapped to the
/// permissions they have.
final Map<Role, List<String>> availableRoles;
}
@@ -36,9 +36,12 @@ Plan _$PlanFromJson(Map<String, dynamic> json) => $checkedCreate(
isTrial: $checkedConvert('is_trial', (v) => v as bool),
availableRoles: $checkedConvert(
'available_roles',
(v) => (v as List<dynamic>)
.map((e) => $enumDecode(_$RoleEnumMap, e))
.toList(),
(v) => (v as Map<String, dynamic>).map(
(k, e) => MapEntry(
$enumDecode(_$RoleEnumMap, k),
(e as List<dynamic>).map((e) => e as String).toList(),
),
),
),
pricePerOverageInstall: $checkedConvert(
'price_per_overage_install',
@@ -77,9 +80,9 @@ Map<String, dynamic> _$PlanToJson(Plan instance) => <String, dynamic>{
'is_tiered': instance.isTiered,
'is_trial': instance.isTrial,
'max_team_size': instance.maxTeamSize,
'available_roles': instance.availableRoles
.map((e) => _$RoleEnumMap[e]!)
.toList(),
'available_roles': instance.availableRoles.map(
(k, e) => MapEntry(_$RoleEnumMap[k]!, e),
),
};
const _$RoleEnumMap = {
@@ -17,7 +17,29 @@ void main() {
maxTeamSize: 42,
pricePerOverageInstall: Decimal.fromInt(10),
isTrial: true,
availableRoles: [Role.admin, Role.developer],
availableRoles: {
Role.admin: [
'apps.view',
'releases.view',
'patches.view',
'channels.view',
'organizations.view',
'organizationApps.view',
'organizationMembers.view',
'appRoleGrants.view',
'insights.view',
'plans.view',
],
Role.developer: [
'apps.view',
'releases.view',
'patches.view',
'channels.view',
'organizations.view',
'organizationApps.view',
'organizationMembers.view',
],
},
);
expect(Plan.fromJson(plan.toJson()).toJson(), equals(plan.toJson()));