Martin Mucha has uploaded a new change for review.

Change subject: <core | restapi | tools | history | engine | userportal | 
webadmin>: short summary under 50 chars
......................................................................

<core | restapi | tools | history | engine | userportal | webadmin>: short 
summary under 50 chars

Change-Id: If2b2855fa3828b22d029e400fc2ddc472821cc41
Signed-off-by: Martin Mucha <mmu...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllMacPoolsQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetMacPoolByIdQuery.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
M packaging/dbscripts/create_functions.sql
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/mac_pools_sp.sql
8 files changed, 77 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/29847/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllMacPoolsQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllMacPoolsQuery.java
index 6c7c7f9..1c525bf 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllMacPoolsQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllMacPoolsQuery.java
@@ -10,6 +10,7 @@
 
     @Override
     protected void executeQueryCommand() {
-        
getQueryReturnValue().setReturnValue(getDbFacade().getMacPoolDao().getAll());
+        
getQueryReturnValue().setReturnValue(getDbFacade().getMacPoolDao().getAll(getUserID(),
+                getParameters().isFiltered()));
     }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetMacPoolByIdQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetMacPoolByIdQuery.java
index e16114c..e9ef0db 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetMacPoolByIdQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetMacPoolByIdQuery.java
@@ -2,6 +2,7 @@
 
 import org.ovirt.engine.core.common.businessentities.MacPool;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.compat.Guid;
 
 public class GetMacPoolByIdQuery extends QueriesCommandBase<IdQueryParameters> 
{
 
@@ -11,7 +12,8 @@
 
     @Override
     protected void executeQueryCommand() {
-        final MacPool macPool = 
getDbFacade().getMacPoolDao().get(getParameters().getId());
+        final Guid id = getParameters().getId();
+        final MacPool macPool = getDbFacade().getMacPoolDao().get(id, 
getUserID(), getParameters().isFiltered());
 
         getQueryReturnValue().setReturnValue(macPool);
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDao.java
index f512135..1ecfa67 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDao.java
@@ -14,4 +14,8 @@
     List<String> getAllMacsForMacPool(Guid macPoolId);
 
     MacPool getByDataCenterId(Guid id);
+
+    MacPool get(Guid id, Guid userId, boolean filtered);
+
+    List<MacPool> getAll(Guid userId, boolean filtered);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDaoDbFacadeImpl.java
index 719bec4..f702a6b 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MacPoolDaoDbFacadeImpl.java
@@ -16,6 +16,30 @@
     }
 
     @Override
+    public MacPool get(Guid id) {
+        return get(id, null, false);
+    }
+
+    @Override
+    public MacPool get(Guid id, Guid userId, boolean filtered) {
+        return getCallsHandler().executeRead(getProcedureNameForGet(),
+                createEntityRowMapper(),
+                createIdParameterMapper(id).addValue("user_id", 
userId).addValue("is_filtered", filtered));
+    }
+
+    @Override
+    public List<MacPool> getAll() {
+        return getAll(null, false);
+    }
+
+    @Override
+    public List<MacPool> getAll(Guid userId, boolean filtered) {
+        return getCallsHandler().executeReadList(getProcedureNameForGetAll(),
+                createEntityRowMapper(),
+                getCustomMapSqlParameterSource().addValue("user_id", 
userId).addValue("is_filtered", filtered));
+    }
+
+    @Override
     public void save(MacPool entity) {
         super.save(entity);
 
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
index 4df4141..adb7e39 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
@@ -16,6 +16,8 @@
 import org.ovirt.engine.core.common.businessentities.BaseDisk;
 import org.ovirt.engine.core.common.businessentities.Bookmark;
 import org.ovirt.engine.core.common.businessentities.DbUser;
+import org.ovirt.engine.core.common.businessentities.MacPool;
+import org.ovirt.engine.core.common.businessentities.Permissions;
 import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.common.businessentities.Role;
 import org.ovirt.engine.core.common.businessentities.RoleType;
@@ -33,7 +35,6 @@
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
-import org.ovirt.engine.core.common.businessentities.Permissions;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -316,4 +317,12 @@
         
assertTrue(name.equals(dbFacade.getEntityNameByIdAndType(FixturesTool.VM_NETWORK_INTERFACE_PROFILE,
 VdcObjectType.VnicProfile)));
     }
 
+    @Test
+    public void testGetEntityNameByIdAndTypeForMacPools() {
+        MacPool macPool = 
dbFacade.getMacPoolDao().get(FixturesTool.DEFAULT_MAC_POOL_ID);
+        assertNotNull(macPool);
+        String name = macPool.getName();
+        
assertTrue(name.equals(dbFacade.getEntityNameByIdAndType(FixturesTool.DEFAULT_MAC_POOL_ID,
+                VdcObjectType.MacPool)));
+    }
 }
diff --git a/packaging/dbscripts/create_functions.sql 
b/packaging/dbscripts/create_functions.sql
index 9d92dae..269bedbb 100644
--- a/packaging/dbscripts/create_functions.sql
+++ b/packaging/dbscripts/create_functions.sql
@@ -1,4 +1,3 @@
-
     -- Constraint is not used dropping it to clean the dependency before 
dropping the function.
     ----------------------------------
 --             create functions                --
@@ -128,7 +127,8 @@
                GlusterVolume = 18,
         Disk = 19,
         Network = 20,
-        VNICProfile = 27
+        VNICProfile = 27,
+        MacPool = 28
 */
 DECLARE
        v_entity_type int4 := v_object_type;
@@ -339,7 +339,7 @@
             UNION
             SELECT v_entity_id AS id;
        ELSE
-               IF v_entity_type IN ( 1,14,15,16 ) THEN -- Data Center, users 
and roles are under system
+               IF v_entity_type IN ( 1,14,15,16,28 ) THEN -- Data Center, 
users, roles and mac pools are under system
                        RETURN QUERY
                                SELECT system_root_id AS id
                                UNION
@@ -509,7 +509,8 @@
         GlusterVolume = 18,
         Disk = 19,
         Network = 20,
-        VNICProfile = 27
+        VNICProfile = 27,
+        MacPool = 28
 */
 DECLARE
     v_entity_type int4 := v_object_type;
@@ -554,6 +555,8 @@
         result := ( SELECT service_name FROM gluster_services where id = 
v_entity_id );
     WHEN v_entity_type = 27 THEN
         result := ( SELECT name FROM vnic_profiles where id = v_entity_id );
+    WHEN v_entity_type = 28 THEN
+        result := ( SELECT name FROM mac_pools where id = v_entity_id );
     ELSE
         result := 'Unknown type ' ||  v_entity_type;
     END CASE;
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index e51ac4d..1e97408 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -1323,7 +1323,6 @@
 FROM         user_storage_pool_permissions_view_base
 NATURAL JOIN user_flat_groups;
 
-
 -- Permissions for Storage Domains
 -- The user has permissions on a storage domain
 CREATE OR REPLACE VIEW user_storage_domain_permissions_view_base (entity_id, 
granted_id)
@@ -1762,3 +1761,21 @@
        vm_static.vds_group_id
 FROM numa_node as vm_numa_node
 LEFT OUTER JOIN vm_static on vm_numa_node.vm_id = vm_static.vm_guid;
+
+-- The user has permissions on a mac pool
+CREATE OR REPLACE VIEW user_mac_pool_permissions_view_base (entity_id, 
granted_id)
+AS
+SELECT     object_id, ad_element_id
+FROM       internal_permissions_view
+WHERE      object_type_id = 28 AND role_type = 2
+UNION ALL
+SELECT     mac_pools.id, ad_element_id
+FROM       internal_permissions_view
+CROSS JOIN mac_pools
+WHERE      object_type_id = 1 AND role_type = 2;
+
+CREATE OR REPLACE VIEW user_mac_pool_permissions_view (entity_id, user_id)
+AS
+SELECT       DISTINCT entity_id, user_id
+FROM         user_mac_pool_permissions_view_base
+NATURAL JOIN user_flat_groups;
diff --git a/packaging/dbscripts/mac_pools_sp.sql 
b/packaging/dbscripts/mac_pools_sp.sql
index ee28f85..16a2e35 100644
--- a/packaging/dbscripts/mac_pools_sp.sql
+++ b/packaging/dbscripts/mac_pools_sp.sql
@@ -48,13 +48,15 @@
 LANGUAGE plpgsql;
 
 
-Create or replace FUNCTION Getmac_poolBymac_poolId(v_id UUID) RETURNS SETOF 
mac_pools STABLE
+Create or replace FUNCTION Getmac_poolBymac_poolId(v_id UUID, v_user_id uuid, 
v_is_filtered boolean) RETURNS SETOF mac_pools STABLE
    AS $procedure$
 BEGIN
    RETURN QUERY SELECT *
    FROM mac_pools
-   WHERE id = v_id;
-
+   WHERE id = v_id
+   AND (NOT v_is_filtered OR EXISTS (SELECT 1
+                                     FROM   user_mac_pool_permissions_view
+                                     WHERE  user_id = v_user_id AND entity_id 
= mac_pools.id));
 
 END; $procedure$
 LANGUAGE plpgsql;
@@ -86,7 +88,10 @@
 AS $procedure$
 BEGIN
    RETURN QUERY SELECT *
-   FROM mac_pools;
+   FROM mac_pools
+   WHERE NOT v_is_filtered OR EXISTS (SELECT 1
+                                      FROM   user_mac_pool_permissions_view
+                                      WHERE  user_id = v_user_id AND entity_id 
= mac_pools.id);
 
 END; $procedure$
 LANGUAGE plpgsql;


-- 
To view, visit http://gerrit.ovirt.org/29847
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If2b2855fa3828b22d029e400fc2ddc472821cc41
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Mucha <mmu...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to