Skip to content

Commit 165d419

Browse files
mduftGerrit
authored andcommitted
Merge "Added --removePermission to RemoteUserTool"
2 parents d63109a + 7a170f8 commit 165d419

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

minion/src/test/java/io/bdeploy/minion/cli/UserManagementCliTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ void testUserCreationAndPermissionManagement(RemoteService remote) {
6060
assertDoesNotThrow(() -> remote(admin2Remote, RemoteUserTool.class, "--list"));
6161
assertThrows(ForbiddenException.class, () -> remote(userRemote, RemoteUserTool.class, "--list"));
6262

63+
// Remove the permission of the second administrator
64+
remote(remote, RemoteUserTool.class, "--update=" + admin2Username, "--removePermission=ADMIN");
65+
66+
// Check if the permission actually got removed
67+
admin2data = getUserRowByName(remote, admin2Username);
68+
assertEquals("[]", admin2data.get("Permissions"));
69+
6370
// Promote the permission of the user
6471
remote(remote, RemoteUserTool.class, "--update=" + userUsername, "--permission=ADMIN");
6572

ui/src/main/java/io/bdeploy/ui/cli/RemoteUserTool.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class RemoteUserTool extends RemoteServiceTool<UserConfig> {
4545
@Help("Add a specific permission to the user. Values can be READ, WRITE or ADMIN. Use in conjunction with --scope, otherwise permission is global.")
4646
String permission();
4747

48+
@Help("Removes a specific permission from the user. Values can be READ, WRITE or ADMIN. Use in conjunction with --scope, otherwise permission is global.")
49+
String removePermission();
50+
4851
@Help("Scopes a specific permission specified with --permission to a certain instance group")
4952
String scope();
5053

@@ -76,6 +79,9 @@ protected RenderableResult run(UserConfig config, RemoteService remote) {
7679
if (config.add() != null) {
7780
addUser(config, admin);
7881
} else if (config.update() != null) {
82+
if (config.permission() != null && config.removePermission() != null) {
83+
helpAndFail("Cannot add and remove a permission simultaneously");
84+
}
7985
updateUser(config, admin);
8086
} else if (config.remove() != null) {
8187
admin.deleteUser(config.remove());
@@ -143,6 +149,12 @@ private void updateUser(UserConfig config, AuthAdminResource admin) {
143149
updated = true;
144150
}
145151
}
152+
if (config.removePermission() != null) {
153+
if (user.permissions
154+
.remove(new ScopedPermission(config.scope(), Permission.valueOf(config.removePermission().toUpperCase())))) {
155+
updated = true;
156+
}
157+
}
146158
if (updated) {
147159
admin.updateUser(user);
148160
}

0 commit comments

Comments
 (0)