Skip to content

Commit c3b4875

Browse files
author
serverpod_cloud
committed
feat(scloud): a5db0ff4eff3e79c5d16e6ed5aaedb766b13f3e4
1 parent cc8e5de commit c3b4875

12 files changed

Lines changed: 40 additions & 46 deletions

File tree

ground_control_client/lib/src/test_tools/builders/project_builder.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class ProjectBuilder {
88
DateTime? _archivedAt;
99
String _cloudProjectId;
1010
Owner? _owner;
11-
Subscription? _subscription;
1211
List<Role>? _roles;
1312
List<Capsule>? _capsules;
1413

@@ -18,7 +17,6 @@ class ProjectBuilder {
1817
_updatedAt = DateTime.now(),
1918
_archivedAt = null,
2019
_cloudProjectId = 'test-project',
21-
_subscription = null,
2220
_roles = [],
2321
_capsules = [] {
2422
withUserOwner(UserBuilder().build());
@@ -72,11 +70,6 @@ class ProjectBuilder {
7270
return this;
7371
}
7472

75-
ProjectBuilder withSubscription(final Subscription? subscription) {
76-
_subscription = subscription;
77-
return this;
78-
}
79-
8073
ProjectBuilder withRoles(final List<Role>? roles) {
8174
_roles = roles;
8275
return this;
@@ -96,7 +89,6 @@ class ProjectBuilder {
9689
cloudProjectId: _cloudProjectId,
9790
owner: _owner,
9891
ownerId: _owner?.id ?? Uuid().v4obj(),
99-
subscription: _subscription,
10092
roles: _roles,
10193
capsules: _capsules,
10294
);

ground_control_client/lib/src/test_tools/builders/user_builder.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class UserBuilder {
1010
String? _userAuthId;
1111
String _email;
1212
List<UserRoleMembership>? _memberships;
13-
int? _maxOwnedProjects;
1413
_i1.UuidValue? _ownerId;
1514
Owner? _owner;
1615

@@ -22,8 +21,7 @@ class UserBuilder {
2221
_accountStatus = UserAccountStatus.registered,
2322
_userAuthId = 'auth-user-123',
2423
_email = 'test@example.com',
25-
_memberships = [],
26-
_maxOwnedProjects = null {
24+
_memberships = [] {
2725
_ownerId = Uuid().v4obj();
2826
}
2927

@@ -67,11 +65,6 @@ class UserBuilder {
6765
return this;
6866
}
6967

70-
UserBuilder withMaxOwnedProjects(final int? maxOwnedProjects) {
71-
_maxOwnedProjects = maxOwnedProjects;
72-
return this;
73-
}
74-
7568
UserBuilder withOwnerId(final _i1.UuidValue? ownerId) {
7669
_ownerId = ownerId;
7770
return this;
@@ -92,7 +85,6 @@ class UserBuilder {
9285
userAuthId: _userAuthId,
9386
email: _email,
9487
memberships: _memberships,
95-
maxOwnedProjects: _maxOwnedProjects,
9688
ownerId: _owner?.id ?? _ownerId,
9789
owner: _owner,
9890
);

ground_control_client/lib/src/test_tools/mocks/client.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class EndpointAdminProjectsMock extends Mock implements EndpointAdminProjects {}
3838

3939
class EndpointBillingMock extends Mock implements EndpointBilling {}
4040

41+
class EndpointPlansMock extends Mock implements EndpointPlans {}
42+
4143
/// Modules mocks
4244
class ModulesMock extends Mock implements Modules {}
4345

@@ -138,4 +140,7 @@ class ClientMock extends Mock implements Client {
138140

139141
@override
140142
final EndpointBilling billing = EndpointBillingMock();
143+
144+
@override
145+
final EndpointPlans plans = EndpointPlansMock();
141146
}

serverpod_cloud_cli/lib/command_runner/commands/admin/admin_users_commands.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ enum AdminInviteUserOption<V> implements OptionDefinition<V> {
7474
mandatory: true,
7575
customValidator: _emailValidator,
7676
),
77-
),
78-
maxOwnedProjects(
79-
IntOption(
80-
argName: 'max-owned-projects',
81-
helpText:
82-
'The number of projects the user may own. If unspecified, the default value is used.',
83-
min: 0,
84-
),
8577
);
8678

8779
const AdminInviteUserOption(this.option);
@@ -105,14 +97,11 @@ class AdminInviteUserCommand extends CloudCliCommand<AdminInviteUserOption> {
10597
final Configuration<AdminInviteUserOption> commandConfig,
10698
) async {
10799
final email = commandConfig.value(AdminInviteUserOption.user);
108-
final maxOwnedProjects =
109-
commandConfig.optionalValue(AdminInviteUserOption.maxOwnedProjects);
110100

111101
await UserAdminCommands.inviteUser(
112102
runner.serviceProvider.cloudApiClient,
113103
logger: logger,
114104
email: email,
115-
maxOwnedProjectsQuota: maxOwnedProjects,
116105
);
117106
}
118107
}

serverpod_cloud_cli/lib/commands/admin/user_admin.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ abstract class UserAdminCommands {
2525
headers: [
2626
'User',
2727
'Account status',
28-
'Max owned projects',
2928
'Created at ($timezoneName)',
3029
'Archived at ($timezoneName)',
3130
],
3231
rows: users.map((final user) => [
3332
user.email,
3433
user.accountStatus.toString(),
35-
user.maxOwnedProjects?.toString(),
3634
user.createdAt.toTzString(inUtc, 19),
3735
user.archivedAt?.toTzString(inUtc, 19),
3836
]),
@@ -44,12 +42,10 @@ abstract class UserAdminCommands {
4442
final Client cloudApiClient, {
4543
required final CommandLogger logger,
4644
required final String email,
47-
final int? maxOwnedProjectsQuota,
4845
}) async {
4946
try {
5047
await cloudApiClient.adminUsers.inviteUser(
5148
email: email,
52-
maxOwnedProjectsQuota: maxOwnedProjectsQuota,
5349
);
5450
} on Exception catch (e, s) {
5551
throw FailureException.nested(e, s, 'Failed to invite user');

serverpod_cloud_cli/lib/commands/project/project.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ abstract class ProjectCommands {
2424
}) async {
2525
logger.init('Creating Serverpod Cloud project "$projectId".');
2626

27+
// Check that the user is on a plan and automatically procure one if not.
28+
// This behavior will be changed in the future.
29+
final planNames = await cloudApiClient.plans.listProcuredPlanNames();
30+
if (planNames.isEmpty) {
31+
const defaultPlanName = 'closed-beta';
32+
await cloudApiClient.plans.procurePlan(planName: defaultPlanName);
33+
logger.info('On plan: $defaultPlanName');
34+
} else {
35+
logger.debug('On plan: ${planNames.first}');
36+
}
37+
2738
try {
2839
await logger.progress(
2940
'Registering Serverpod Cloud project.',

serverpod_cloud_cli/lib/shared/helpers/common_exceptions_handler.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ void processCommonClientExceptions(
4242
stackTrace,
4343
);
4444

45-
case ForbiddenException():
45+
case ResourceDeniedException():
4646
logger.error(
47-
'The action was not allowed.',
47+
'The resource was not allowed.',
4848
hint: e.message,
4949
);
5050

serverpod_cloud_cli/test/common_exceptions_handler_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ void main() {
6262
});
6363

6464
test(
65-
'Given a ForbiddenException '
65+
'Given a ResourceDeniedException '
6666
'when calling processCommonClientExceptions '
6767
'then should throw ExitErrorException and log error message', () {
6868
expect(
6969
() => processCommonClientExceptions(
7070
logger,
71-
ForbiddenException(
71+
ResourceDeniedException(
7272
message:
7373
'The maximum number of projects that can be created has been reached (5).',
7474
),
@@ -79,7 +79,7 @@ void main() {
7979
expect(
8080
logger.errorCalls.last,
8181
equalsErrorCall(
82-
message: 'The action was not allowed.',
82+
message: 'The resource was not allowed.',
8383
hint:
8484
'The maximum number of projects that can be created has been reached (5).',
8585
),

serverpod_cloud_cli/test_integration/commands/admin/admin_user_invite_cmd_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ void main() {
7474
setUp(() async {
7575
when(() => client.adminUsers.inviteUser(
7676
email: any(named: 'email'),
77-
maxOwnedProjectsQuota: any(named: 'maxOwnedProjectsQuota'),
7877
)).thenAnswer(
7978
(final invocation) async => Future.value(),
8079
);
@@ -84,8 +83,6 @@ void main() {
8483
'invite-user',
8584
'--user',
8685
'test@example.com',
87-
'--max-owned-projects',
88-
'5',
8986
]);
9087
});
9188

serverpod_cloud_cli/test_integration/commands/admin/admin_user_list_cmd_test.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ void main() {
8181
UserBuilder()
8282
.withEmail('test@example.com')
8383
.withCreatedAt(DateTime.parse('2025-07-02T11:00:00'))
84-
.withMaxOwnedProjects(5)
8584
.withAccountStatus(UserAccountStatus.registered)
8685
.build(),
8786
UserBuilder()
8887
.withEmail('test2@example.com')
8988
.withCreatedAt(DateTime.parse('2025-07-02T12:00:00'))
90-
.withMaxOwnedProjects(5)
9189
.withAccountStatus(UserAccountStatus.invited)
9290
.withArchivedAt(DateTime.parse('2025-07-02T12:10:00'))
9391
.build(),
@@ -113,16 +111,16 @@ void main() {
113111
containsAllInOrder([
114112
equalsLineCall(
115113
line:
116-
'User | Account status | Max owned projects | Created at (local) | Archived at (local)'),
114+
'User | Account status | Created at (local) | Archived at (local)'),
117115
equalsLineCall(
118116
line:
119-
'------------------+----------------+--------------------+---------------------+--------------------'),
117+
'------------------+----------------+---------------------+--------------------'),
120118
equalsLineCall(
121119
line:
122-
'test@example.com | registered | 5 | 2025-07-02 11:00:00 | '),
120+
'test@example.com | registered | 2025-07-02 11:00:00 | '),
123121
equalsLineCall(
124122
line:
125-
'test2@example.com | invited | 5 | 2025-07-02 12:00:00 | 2025-07-02 12:10:00'),
123+
'test2@example.com | invited | 2025-07-02 12:00:00 | 2025-07-02 12:10:00'),
126124
]),
127125
);
128126
});

0 commit comments

Comments
 (0)