Github user pdube commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1134#discussion_r46553780 --- Diff: server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java --- @@ -229,59 +205,99 @@ public AffinityGroupVO doInTransaction(TransactionStatus status) { return group; } }); + } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created affinity group =" + affinityGroupName); + private DomainVO getDomain(Long domainId) { + DomainVO domain = _domainDao.findById(domainId); + if (domain == null) { + throw new InvalidParameterValueException("Unable to find domain by specified id"); } + return domain; + } - return group; + private void verifyAffinityGroupNameInUse(long accountId, long domainId, String affinityGroupName) { + if (_affinityGroupDao.isNameInUse(accountId, domainId, affinityGroupName)) { + throw new InvalidParameterValueException("Unable to create affinity group, a group with name " + affinityGroupName + " already exists."); + } + } + + private void verifyDomainLevelAffinityGroupName(boolean domainLevel, long domainId, String affinityGroupName) { + if (domainLevel && _affinityGroupDao.findDomainLevelGroupByName(domainId, affinityGroupName) != null) { + throw new InvalidParameterValueException("Unable to create affinity group, a group with name " + affinityGroupName + " already exists under the domain."); + } } @DB - @Override @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") - public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String affinityGroupName) { + public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long projectId, Long domainId, String affinityGroupName) { + + AffinityGroupVO group = getAffinityGroup(affinityGroupId, account, projectId, domainId, affinityGroupName); + // check permissions Account caller = CallContext.current().getCallingAccount(); - Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null); + _accountMgr.checkAccess(caller, AccessType.OperateEntry, true, group); --- End diff -- I think that if a user is able to create an AG, then he should be able to delete it
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---