Skip to content

Commit 4e00911

Browse files
author
serverpod_cloud
committed
refactor: 31e6faf9a246d24fa7a38b4850c96ed64ff88f65
1 parent 81206b4 commit 4e00911

4 files changed

Lines changed: 35 additions & 27 deletions

File tree

ground_control_client/lib/src/protocol/client.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,42 +436,42 @@ class EndpointProjects extends _i1.EndpointRef {
436436
{'cloudProjectId': cloudProjectId},
437437
);
438438

439-
/// Attaches an existing user to a project by assigning the specified roles.
439+
/// Invites a user to a project by assigning the specified project roles.
440440
///
441-
/// Throws [NotFoundException] if the user, project, or any of the roles
441+
/// Throws [NotFoundException] if the project or any of the roles
442442
/// do not exist.
443-
_i2.Future<void> attachUser({
443+
_i2.Future<void> inviteUser({
444444
required String cloudProjectId,
445445
required String email,
446446
required List<String> assignRoleNames,
447447
}) =>
448448
caller.callServerEndpoint<void>(
449449
'projects',
450-
'attachUser',
450+
'inviteUser',
451451
{
452452
'cloudProjectId': cloudProjectId,
453453
'email': email,
454454
'assignRoleNames': assignRoleNames,
455455
},
456456
);
457457

458-
/// Detaches an existing user from a project by removing the specified roles.
458+
/// Revokes a user from a project by unassigning the specified project roles.
459459
/// If any of the roles do not exist or are not previously assigned to the
460460
/// user, they are simply ignored.
461461
/// If [unassignAllRoles] is true, all roles on the project are unassigned
462462
/// from the user.
463463
///
464464
/// Returns the list of role names that were actually unassigned.
465-
/// Throws [NotFoundException] if the user or project does not exist.
466-
_i2.Future<List<String>> detachUser({
465+
/// Throws [NotFoundException] if the project does not exist.
466+
_i2.Future<List<String>> revokeUser({
467467
required String cloudProjectId,
468468
required String email,
469469
List<String>? unassignRoleNames,
470470
bool? unassignAllRoles,
471471
}) =>
472472
caller.callServerEndpoint<List<String>>(
473473
'projects',
474-
'detachUser',
474+
'revokeUser',
475475
{
476476
'cloudProjectId': cloudProjectId,
477477
'email': email,

serverpod_cloud_cli/lib/command_runner/commands/project_command.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ void _emailValidator(final value) {
208208
}
209209
}
210210

211+
const _projectRoleNames = ['owners'];
212+
const _projectRoleHelp = {'owners': 'Owners have full access to the project.'};
213+
211214
enum ProjectInviteUserOption<V> implements OptionDefinition<V> {
212215
projectId(
213216
_ProjectOptions.projectId,
@@ -226,6 +229,8 @@ enum ProjectInviteUserOption<V> implements OptionDefinition<V> {
226229
argName: 'role',
227230
argAbbrev: 'r',
228231
helpText: 'One or more project roles to assign.',
232+
allowedValues: _projectRoleNames,
233+
allowedHelp: _projectRoleHelp,
229234
mandatory: true,
230235
),
231236
);
@@ -287,6 +292,8 @@ enum ProjectRevokeUserOption<V> implements OptionDefinition<V> {
287292
argName: 'role',
288293
argAbbrev: 'r',
289294
helpText: 'One or more project roles to revoke.',
295+
allowedValues: _projectRoleNames,
296+
allowedHelp: _projectRoleHelp,
290297
group: MutuallyExclusive('Roles', mode: MutuallyExclusiveMode.mandatory),
291298
),
292299
),

serverpod_cloud_cli/lib/commands/project/project.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ abstract class ProjectCommands {
208208
required final List<String> assignRoleNames,
209209
}) async {
210210
try {
211-
await cloudApiClient.projects.attachUser(
211+
await cloudApiClient.projects.inviteUser(
212212
cloudProjectId: projectId,
213213
email: email,
214214
assignRoleNames: assignRoleNames,
@@ -235,7 +235,7 @@ abstract class ProjectCommands {
235235
}) async {
236236
final List<String> actuallyUnassigned;
237237
try {
238-
actuallyUnassigned = await cloudApiClient.projects.detachUser(
238+
actuallyUnassigned = await cloudApiClient.projects.revokeUser(
239239
cloudProjectId: projectId,
240240
email: email,
241241
unassignRoleNames: unassignRoleNames,

serverpod_cloud_cli/test_integration/commands/project_command/invite_project_user_test.dart

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void main() {
6060
'--user',
6161
'test@example.com',
6262
'--role',
63-
'owner',
63+
'owners',
6464
]);
6565
});
6666

@@ -91,7 +91,7 @@ void main() {
9191
'--user',
9292
'test@example.com',
9393
'--role',
94-
'owner',
94+
'owners',
9595
]);
9696
});
9797

@@ -120,7 +120,7 @@ void main() {
120120
group('when executing project invite user', () {
121121
late Future commandResult;
122122
setUp(() async {
123-
when(() => client.projects.attachUser(
123+
when(() => client.projects.inviteUser(
124124
cloudProjectId: any(named: 'cloudProjectId'),
125125
email: any(named: 'email'),
126126
assignRoleNames: any(named: 'assignRoleNames'),
@@ -136,7 +136,7 @@ void main() {
136136
'--user',
137137
'test@example.com',
138138
'--role',
139-
'owner',
139+
'owners',
140140
]);
141141
});
142142

@@ -148,7 +148,7 @@ void main() {
148148
expect(
149149
logger.successCalls.single,
150150
equalsSuccessCall(
151-
message: 'User invited to the project with roles: owner.',
151+
message: 'User invited to the project with roles: owners.',
152152
newParagraph: true,
153153
),
154154
);
@@ -158,7 +158,7 @@ void main() {
158158
group('when executing project invite with non-existent user', () {
159159
late Future commandResult;
160160
setUp(() async {
161-
when(() => client.projects.attachUser(
161+
when(() => client.projects.inviteUser(
162162
cloudProjectId: any(named: 'cloudProjectId'),
163163
email: any(named: 'email'),
164164
assignRoleNames: any(named: 'assignRoleNames'),
@@ -174,7 +174,7 @@ void main() {
174174
'--user',
175175
'test@example.com',
176176
'--role',
177-
'owner',
177+
'owners',
178178
]);
179179
});
180180

@@ -197,13 +197,13 @@ void main() {
197197
group('when executing project revoke user with specific role', () {
198198
late Future commandResult;
199199
setUp(() async {
200-
when(() => client.projects.detachUser(
200+
when(() => client.projects.revokeUser(
201201
cloudProjectId: any(named: 'cloudProjectId'),
202202
email: any(named: 'email'),
203203
unassignRoleNames: any(named: 'unassignRoleNames'),
204204
unassignAllRoles: any(named: 'unassignAllRoles'),
205205
)).thenAnswer(
206-
(final invocation) async => Future.value(['owner']),
206+
(final invocation) async => Future.value(['owners']),
207207
);
208208

209209
commandResult = cli.run([
@@ -214,7 +214,7 @@ void main() {
214214
'--user',
215215
'test@example.com',
216216
'--role',
217-
'owner',
217+
'owners',
218218
]);
219219
});
220220

@@ -226,7 +226,8 @@ void main() {
226226
expect(
227227
logger.successCalls.single,
228228
equalsSuccessCall(
229-
message: 'Revoked access roles of the user from the project: owner',
229+
message:
230+
'Revoked access roles of the user from the project: owners',
230231
newParagraph: true,
231232
),
232233
);
@@ -238,13 +239,13 @@ void main() {
238239
() {
239240
late Future commandResult;
240241
setUp(() async {
241-
when(() => client.projects.detachUser(
242+
when(() => client.projects.revokeUser(
242243
cloudProjectId: any(named: 'cloudProjectId'),
243244
email: any(named: 'email'),
244245
unassignRoleNames: any(named: 'unassignRoleNames'),
245246
unassignAllRoles: any(named: 'unassignAllRoles'),
246247
)).thenAnswer(
247-
(final invocation) async => Future.value(['owner']),
248+
(final invocation) async => Future.value(['owners']),
248249
);
249250

250251
commandResult = cli.run([
@@ -267,7 +268,7 @@ void main() {
267268
logger.successCalls.single,
268269
equalsSuccessCall(
269270
message:
270-
"Revoked all access roles of the user from the project: owner",
271+
"Revoked all access roles of the user from the project: owners",
271272
newParagraph: true,
272273
),
273274
);
@@ -278,7 +279,7 @@ void main() {
278279
() {
279280
late Future commandResult;
280281
setUp(() async {
281-
when(() => client.projects.detachUser(
282+
when(() => client.projects.revokeUser(
282283
cloudProjectId: any(named: 'cloudProjectId'),
283284
email: any(named: 'email'),
284285
unassignRoleNames: any(named: 'unassignRoleNames'),
@@ -295,7 +296,7 @@ void main() {
295296
'--user',
296297
'test@example.com',
297298
'--role',
298-
'owner',
299+
'owners',
299300
]);
300301
});
301302

@@ -319,7 +320,7 @@ void main() {
319320
() {
320321
late Future commandResult;
321322
setUp(() async {
322-
when(() => client.projects.detachUser(
323+
when(() => client.projects.revokeUser(
323324
cloudProjectId: any(named: 'cloudProjectId'),
324325
email: any(named: 'email'),
325326
unassignRoleNames: any(named: 'unassignRoleNames'),

0 commit comments

Comments
 (0)