related to issue 18878: Advanced features
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 28 Feb 2012 08:50:14 +0100
changeset 15629 747f9d62c378
parent 15628 4697d6f24c82
child 15630 e2a37f741b4a
related to issue 18878: Advanced features

Some fixes/improvements:
* Fixed update access: previously is added access to advanced features to
not advanced roles.
* When executing update access, remove advanced features access from non
advanced roles.
* When creating/updating form, processes or window take into account adv
features to grant access.
src-db/database/model/functions/AD_UPDATE_ACCESS.xml
src-db/database/model/triggers/AD_FORM_TRG.xml
src-db/database/model/triggers/AD_PROCESS_TRG.xml
src-db/database/model/triggers/AD_WINDOW_TRG.xml
--- a/src-db/database/model/functions/AD_UPDATE_ACCESS.xml	Mon Feb 27 19:35:37 2012 +0100
+++ b/src-db/database/model/functions/AD_UPDATE_ACCESS.xml	Tue Feb 28 08:50:14 2012 +0100
@@ -13,7 +13,7 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2007-2011 Openbravo SLU
+* All portions are Copyright (C) 2007-2012 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -41,11 +41,20 @@
       OR
       (AD_ROLE.USERLEVEL = '  O' AND AD_FORM.ACCESSLEVEL IN ('3','1','7'))
     )
+    AND (AD_ROLE.ISADVANCED = 'Y' OR AD_FORM.ISADVANCEDFEATURE = 'N')
     AND NOT EXISTS (SELECT 1
                      FROM AD_FORM_ACCESS
                     WHERE AD_FORM_ID = AD_FORM.AD_FORM_ID
-                      AND AD_ROLE_ID = AD_ROLE.AD_ROLE_ID
-                      AND (AD_ROLE.ISADVANCED = 'Y' OR AD_FORM.ISADVANCEDFEATURE = 'N'));
+                      AND AD_ROLE_ID = AD_ROLE.AD_ROLE_ID);
+
+   DELETE FROM AD_Form_Access a 
+    WHERE EXISTS (SELECT 1
+                    FROM AD_Role r, AD_Form F
+                   WHERE r.IsAdvanced = 'N' 
+                     AND f.IsAdvancedFeature = 'Y' 
+                     AND r.AD_Role_ID = a.AD_Role_ID
+                     AND f.ad_form_ID = a.ad_form_id
+                     AND r.isManual = 'N');
 
 --AD_PROCESS_ACCESS
   INSERT INTO AD_Process_Access
@@ -65,12 +74,20 @@
       OR
       (AD_ROLE.USERLEVEL = '  O' AND AD_PROCESS.ACCESSLEVEL IN ('3','1','7'))
     )
+    AND (AD_ROLE.ISADVANCED = 'Y' OR AD_PROCESS.ISADVANCEDFEATURE = 'N')
     AND NOT EXISTS (SELECT 1 
                       FROM AD_PROCESS_ACCESS
                      WHERE AD_PROCESS_ID = AD_PROCESS.AD_PROCESS_ID
-                       AND AD_ROLE_ID    = AD_ROLE.AD_ROLE_ID
-                       AND (AD_ROLE.ISADVANCED = 'Y' OR AD_PROCESS.ISADVANCEDFEATURE = 'N'));
+                       AND AD_ROLE_ID    = AD_ROLE.AD_ROLE_ID);
 
+   DELETE FROM AD_Process_Access a 
+    WHERE EXISTS (SELECT 1
+                    FROM AD_Role r, AD_Process p
+                   WHERE r.IsAdvanced = 'N' 
+                     AND p.IsAdvancedFeature = 'Y' 
+                     AND r.AD_Role_ID = a.AD_Role_ID
+                     AND p.ad_Process_ID = a.ad_Process_id
+										 AND r.isManual = 'N');
  --Add org 0 to role 0                
  INSERT INTO AD_Role_OrgAccess
     (
@@ -113,11 +130,20 @@
       (AD_ROLE.USERLEVEL = '  O' AND AD_TABLE.ACCESSLEVEL IN ('3','1','7'))
     )
     AND AD_TAB.SEQNO = (SELECT MIN(SEQNO) FROM AD_TAB t WHERE t.AD_WINDOW_ID = AD_WINDOW.AD_WINDOW_ID)
+    AND (AD_ROLE.ISADVANCED = 'Y' OR AD_WINDOW.ISADVANCEDFEATURE = 'N')
     AND NOT EXISTS (SELECT 1 
                        FROM AD_WINDOW_ACCESS
                       WHERE AD_WINDOW_ID = AD_WINDOW.AD_WINDOW_ID
-                        AND AD_ROLE_ID = AD_ROLE.AD_ROLE_ID
-                        AND (AD_ROLE.ISADVANCED = 'Y' OR AD_WINDOW.ISADVANCEDFEATURE = 'N'));
+                        AND AD_ROLE_ID = AD_ROLE.AD_ROLE_ID);
+
+   DELETE FROM AD_Window_Access a 
+    WHERE EXISTS (SELECT 1
+                    FROM AD_Role r, AD_Window w
+                   WHERE r.IsAdvanced = 'N' 
+                     AND w.IsAdvancedFeature = 'Y' 
+                     AND r.AD_Role_ID = a.AD_Role_ID
+                     AND w.ad_Window_ID = a.ad_Window_ID
+                     AND r.isManual = 'N');
 
   --Add role 0 to user 100 (Openbravo)
   INSERT INTO AD_USER_ROLES
--- a/src-db/database/model/triggers/AD_FORM_TRG.xml	Mon Feb 27 19:35:37 2012 +0100
+++ b/src-db/database/model/triggers/AD_FORM_TRG.xml	Tue Feb 28 08:50:14 2012 +0100
@@ -17,7 +17,7 @@
     * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
     * All Rights Reserved.
     * Contributor(s): Openbravo SLU
-    * Contributions are Copyright (C) 2001-2009 Openbravo, S.L.U.
+    * Contributions are Copyright (C) 2001-2012 Openbravo, S.L.U.
     *
     * Specifically, this derivative work is based upon the following Compiere
     * file and version.
@@ -68,12 +68,22 @@
      'Y', now(), '0',
     now(), '0',  'Y'
   FROM AD_Role r
-  where ismanual = 'N';
+  where ismanual = 'N'
+  AND (r.IsAdvanced = 'Y' OR :new.IsAdvancedFeature='N');
  END IF;
  -- Inserting
  -- AD_Form update trigger
  --  synchronize name,... with Field if not centrally maintained
  IF(UPDATING) THEN
+  IF (:new.IsAdvancedFeature ='Y' and :old.IsAdvancedFeature ='N') THEN
+    delete from ad_form_access a
+    where a.ad_form_id = :new.ad_form_id
+      and exists (select 1 
+                    from ad_role r
+                   where r.ad_role_id = a.ad_role_id
+                    and r.isManual = 'N'
+                    and r.IsAdvanced = 'N');
+  END IF;
   IF((COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
   OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.')
   OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')))
--- a/src-db/database/model/triggers/AD_PROCESS_TRG.xml	Mon Feb 27 19:35:37 2012 +0100
+++ b/src-db/database/model/triggers/AD_PROCESS_TRG.xml	Tue Feb 28 08:50:14 2012 +0100
@@ -17,7 +17,7 @@
 * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
 * All Rights Reserved.
 * Contributor(s): Openbravo SLU
-* Contributions are Copyright (C) 2001-2010 Openbravo, S.L.U.
+* Contributions are Copyright (C) 2001-2012 Openbravo, S.L.U.
 *
 * Specifically, this derivative work is based upon the following Compiere
 * file and version.
@@ -63,7 +63,8 @@
       SELECT get_uuid(), :NEW.AD_Process_ID, r.AD_Role_ID, r.AD_CLIENT_ID, r.AD_ORG_ID,
              'Y', now(), '0', now(), '0', 'Y'
         FROM AD_Role r
-       where isManual='N';
+       where isManual='N'
+        AND (r.IsAdvanced = 'Y' OR :new.IsAdvancedFeature='N');
   END IF;
 
 -- Inserting
@@ -72,7 +73,15 @@
 --      update AD_Column/AD_Field Name
   IF UPDATING
   THEN
-
+    IF (:new.IsAdvancedFeature ='Y' and :old.IsAdvancedFeature ='N') THEN
+      delete from ad_process_access a
+      where a.ad_process_id = :new.ad_process_id
+        and exists (select 1 
+                      from ad_role r
+                     where r.ad_role_id = a.ad_role_id
+                      and r.isManual = 'N'
+                      and r.IsAdvanced = 'N');
+    END IF;
     IF(    COALESCE (:OLD.NAME, '.') <> COALESCE (:NEW.NAME, '.')
         OR COALESCE (:OLD.Description, '.') <> COALESCE (:NEW.Description, '.')
         OR COALESCE (:OLD.HELP, '.') <> COALESCE (:NEW.HELP, '.') )
--- a/src-db/database/model/triggers/AD_WINDOW_TRG.xml	Mon Feb 27 19:35:37 2012 +0100
+++ b/src-db/database/model/triggers/AD_WINDOW_TRG.xml	Tue Feb 28 08:50:14 2012 +0100
@@ -17,7 +17,7 @@
     * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
     * All Rights Reserved.
     * Contributor(s): Openbravo SLU
-    * Contributions are Copyright (C) 2001-2010 Openbravo, S.L.U.
+    * Contributions are Copyright (C) 2001-2012 Openbravo, S.L.U.
     *
     * Specifically, this derivative work is based upon the following Compiere
     * file and version.
@@ -76,12 +76,23 @@
      'Y', now(), '0',
     now(), '0',  'Y'
   FROM AD_Role r
-   WHERE isManual='N';
+   WHERE isManual='N'
+     AND (r.IsAdvanced = 'Y' OR :new.IsAdvancedFeature='N');
  END IF;
  -- Inserting
  -- AD_Window update trigger
  --  synchronize name,...
  IF UPDATING THEN
+  IF (:new.IsAdvancedFeature ='Y' and :old.IsAdvancedFeature ='N') THEN
+    delete from ad_window_access a
+    where a.ad_window_id = :new.ad_window_id
+      and exists (select 1 
+                    from ad_role r
+                   where r.ad_role_id = a.ad_role_id
+                    and r.isManual = 'N'
+                    and r.IsAdvanced = 'N');
+  END IF;
+  
   IF(COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
   OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
   OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.'))