Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 892961008A for ; Mon, 15 Apr 2013 13:10:12 +0000 (UTC) Received: (qmail 46657 invoked by uid 500); 15 Apr 2013 13:10:03 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 46498 invoked by uid 500); 15 Apr 2013 13:10:03 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 45586 invoked by uid 99); 15 Apr 2013 13:10:02 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Apr 2013 13:10:02 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 488A11B018; Mon, 15 Apr 2013 13:10:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: koushik@apache.org To: commits@cloudstack.apache.org Date: Mon, 15 Apr 2013 13:10:34 -0000 Message-Id: In-Reply-To: <2eea6d881c11435fbec743a05ed5e09e@git.apache.org> References: <2eea6d881c11435fbec743a05ed5e09e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [35/50] [abbrv] git commit: updated refs/heads/cisco-vnmc-api-integration to 7ce45ea Fix CLOUDSTACK-1987: Deleted service offering still shows for domain users. Also extend this fix for Disk offering as well. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4b1a9f14 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4b1a9f14 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4b1a9f14 Branch: refs/heads/cisco-vnmc-api-integration Commit: 4b1a9f146c7316ba885d0889bd10ae09074e1169 Parents: 7b4e195 Author: Min Chen Authored: Fri Apr 12 11:29:16 2013 -0700 Committer: Min Chen Committed: Fri Apr 12 13:47:45 2013 -0700 ---------------------------------------------------------------------- .../src/com/cloud/api/query/QueryManagerImpl.java | 65 ++++---------- 1 files changed, 19 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b1a9f14/server/src/com/cloud/api/query/QueryManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index ea58427..5ffc2db 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -1941,7 +1941,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); isAscending = (isAscending == null ? true : isAscending); Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchBuilder sb = _diskOfferingJoinDao.createSearchBuilder(); + SearchCriteria sc = _diskOfferingJoinDao.createSearchCriteria(); Account account = UserContext.current().getCaller(); @@ -1956,9 +1956,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { if (account.getType() == Account.ACCOUNT_TYPE_ADMIN || isPermissible(account.getDomainId(), domainId) ) { // check if the user's domain == do's domain || user's domain is // a child of so's domain for non-root users - sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); - SearchCriteria sc = sb.create(); - sc.setParameters("domainId", domainId); + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); return _diskOfferingJoinDao.searchAndCount(sc, searchFilter); } else { throw new PermissionDeniedException("The account:" + account.getAccountName() @@ -1966,11 +1964,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } - sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - - boolean includePublicOfferings = false; List domainIds = null; // For non-root users, only return all offerings for the user's domain, and everything above till root if ((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) @@ -1987,16 +1981,17 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { domainRecord = _domainDao.findById(domainRecord.getParent()); domainIds.add(domainRecord.getId()); } - sb.and("domainIdIn", sb.entity().getDomainId(), SearchCriteria.Op.IN); + + SearchCriteria spc = _diskOfferingJoinDao.createSearchCriteria(); - // include also public offering if no keyword, name and id specified - if ( keyword == null && name == null && id == null ){ - includePublicOfferings = true; - } + spc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray()); + spc.addOr("domainId", SearchCriteria.Op.NULL); // include public offering as where + sc.addAnd("domainId", SearchCriteria.Op.SC, spc); + sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); // non-root users should not see system offering at all + } - SearchCriteria sc = sb.create(); - if (keyword != null) { + if (keyword != null) { SearchCriteria ssc = _diskOfferingJoinDao.createSearchCriteria(); ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -2004,26 +1999,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("name", SearchCriteria.Op.SC, ssc); } - if (name != null) { - sc.setParameters("name", "%" + name + "%"); - } - if (id != null) { - sc.setParameters("id", id); - } - - if (domainIds != null ){ - sc.setParameters("domainIdIn", domainIds.toArray()); + sc.addAnd("id", SearchCriteria.Op.EQ, id); } - if (includePublicOfferings){ - SearchCriteria spc = _diskOfferingJoinDao.createSearchCriteria(); - spc.addAnd("domainId", SearchCriteria.Op.NULL); - spc.addAnd("systemUse", SearchCriteria.Op.EQ, false); - - sc.addOr("systemUse", SearchCriteria.Op.SC, spc); + if (name != null) { + sc.addAnd("name", SearchCriteria.Op.EQ, name); } - + // FIXME: disk offerings should search back up the hierarchy for // available disk offerings... /* @@ -2100,10 +2083,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } - boolean includePublicOfferings = false; + // boolean includePublicOfferings = false; if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { - // For non-root users + // For non-root users. if (isSystem) { throw new InvalidParameterValueException("Only root admins can access system's offering"); } @@ -2122,13 +2105,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { SearchCriteria spc = _srvOfferingJoinDao.createSearchCriteria(); spc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray()); - spc.addOr("domainId", SearchCriteria.Op.NULL); + spc.addOr("domainId", SearchCriteria.Op.NULL); // include public offering as where sc.addAnd("domainId", SearchCriteria.Op.SC, spc); - // include also public offering if no keyword, name and id specified - if ( keyword == null && name == null && id == null ){ - includePublicOfferings = true; - } } else { // for root users @@ -2171,24 +2150,18 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } if (isSystem != null) { + // note that for non-root users, isSystem is always false when control comes to here sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem); } if (name != null) { - sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + sc.addAnd("name", SearchCriteria.Op.EQ, name); } if (vmTypeStr != null) { sc.addAnd("vm_type", SearchCriteria.Op.EQ, vmTypeStr); } - if (includePublicOfferings){ - SearchCriteria spc = _srvOfferingJoinDao.createSearchCriteria(); - spc.addAnd("domainId", SearchCriteria.Op.NULL); - spc.addAnd("systemUse", SearchCriteria.Op.EQ, false); - sc.addOr("systemUse", SearchCriteria.Op.SC, spc); - } - return _srvOfferingJoinDao.searchAndCount(sc, searchFilter); }