Skip to content

Commit 0d12e3e

Browse files
committed
CLOUDSTACK-4830: allow create account and user by domain admin
1 parent d5cca46 commit 0d12e3e

6 files changed

Lines changed: 42 additions & 12 deletions

File tree

‎client/tomcatconf/commands.properties.in‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
### Please standardize naming conventions to camel-case (even for acronyms).
2020

2121
### Account commands
22-
createAccount=3
23-
deleteAccount=3
24-
updateAccount=3
22+
createAccount=7
23+
deleteAccount=7
24+
updateAccount=7
2525
disableAccount=7
2626
enableAccount=7
2727
lockAccount=7
2828
listAccounts=15
2929
markDefaultZoneForAccount=1
3030

3131
#### User commands
32-
createUser=3
33-
deleteUser=3
32+
createUser=7
33+
deleteUser=7
3434
updateUser=15
3535
listUsers=7
3636
lockUser=7

‎server/src/com/cloud/api/ApiDBUtils.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,15 @@ public static InstanceGroupJoinVO newInstanceGroupView(InstanceGroup e){
14731473
}
14741474

14751475
public static UserResponse newUserResponse(UserAccountJoinVO usr) {
1476-
return _userAccountJoinDao.newUserResponse(usr);
1476+
return newUserResponse(usr, null);
1477+
}
1478+
public static UserResponse newUserResponse(UserAccountJoinVO usr, Long domainId) {
1479+
UserResponse response = _userAccountJoinDao.newUserResponse(usr);
1480+
if (domainId != null && usr.getDomainId() != domainId)
1481+
response.setIsCallerChildDomain(true);
1482+
else
1483+
response.setIsCallerChildDomain(false);
1484+
return response;
14771485
}
14781486

14791487
public static UserAccountJoinVO newUserView(User usr){

‎server/src/com/cloud/api/query/QueryManagerImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
336336
public ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException {
337337
Pair<List<UserAccountJoinVO>, Integer> result = searchForUsersInternal(cmd);
338338
ListResponse<UserResponse> response = new ListResponse<UserResponse>();
339-
List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(result.first().toArray(
340-
new UserAccountJoinVO[result.first().size()]));
339+
List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(UserContext.current().getCaller().getDomainId(),
340+
result.first().toArray(new UserAccountJoinVO[result.first().size()]));
341341
response.setResponses(userResponses, result.second());
342342
return response;
343343
}

‎server/src/com/cloud/api/query/ViewResponseHelper.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ public class ViewResponseHelper {
8181
public static final Logger s_logger = Logger.getLogger(ViewResponseHelper.class);
8282

8383
public static List<UserResponse> createUserResponse(UserAccountJoinVO... users) {
84+
return createUserResponse(null, users);
85+
}
86+
87+
public static List<UserResponse> createUserResponse(Long domainId, UserAccountJoinVO... users) {
8488
List<UserResponse> respList = new ArrayList<UserResponse>();
8589
for (UserAccountJoinVO vt : users){
86-
respList.add(ApiDBUtils.newUserResponse(vt));
90+
respList.add(ApiDBUtils.newUserResponse(vt, domainId));
8791
}
8892
return respList;
8993
}

‎ui/scripts/accounts.js‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
add: {
6767
label: 'label.add.account',
6868
preFilter: function(args) {
69-
if (isAdmin())
69+
if (isAdmin() || isDomainAdmin())
7070
return true;
7171
else
7272
return false;
@@ -1103,7 +1103,7 @@
11031103
label: 'label.add.user',
11041104

11051105
preFilter: function(args) {
1106-
if (isAdmin())
1106+
if (isAdmin() || isDomainAdmin())
11071107
return true;
11081108
else
11091109
return false;
@@ -1602,6 +1602,16 @@
16021602
}
16031603
allowedActions.push("updateResourceCount");
16041604
} else if (isDomainAdmin()) {
1605+
if (jsonObj.name != g_account) {
1606+
allowedActions.push("edit"); //updating networkdomain is allowed on any account, including system-generated default admin account
1607+
if (jsonObj.state == "enabled") {
1608+
allowedActions.push("disable");
1609+
allowedActions.push("lock");
1610+
} else if (jsonObj.state == "disabled" || jsonObj.state == "locked") {
1611+
allowedActions.push("enable");
1612+
}
1613+
allowedActions.push("remove");
1614+
}
16051615
allowedActions.push("updateResourceCount");
16061616
}
16071617
return allowedActions;
@@ -1627,6 +1637,14 @@
16271637
}
16281638
} else {
16291639
if (isSelfOrChildDomainUser(jsonObj.username, jsonObj.accounttype, jsonObj.domainid, jsonObj.iscallerchilddomain)) {
1640+
if (isDomainAdmin() && jsonObj.username != g_username) {
1641+
allowedActions.push("edit");
1642+
if (jsonObj.state == "enabled")
1643+
allowedActions.push("disable");
1644+
if (jsonObj.state == "disabled")
1645+
allowedActions.push("enable");
1646+
allowedActions.push("remove");
1647+
}
16301648
allowedActions.push("changePassword");
16311649
allowedActions.push("generateKeys");
16321650
}

‎ui/scripts/sharedFunctions.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ var addGuestNetworkDialog = {
750750
function isSelfOrChildDomainUser(username, useraccounttype, userdomainid, iscallerchilddomain) {
751751
if (username == g_username) { //is self
752752
return true;
753-
} else if (isDomainAdmin() && iscallerchilddomain && (useraccounttype == 0)) { //domain admin to user
753+
} else if (isDomainAdmin() && !iscallerchilddomain && (useraccounttype == 0)) { //domain admin to user
754754
return true;
755755
} else if (isDomainAdmin() && iscallerchilddomain && (userdomainid != g_domainid)) { //domain admin to subdomain admin and user
756756
return true;

0 commit comments

Comments
 (0)