fixed issue 15554: Automate access to widgets on non manual roles
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 07 Jan 2011 12:00:49 +0100
changeset 9599 3bec808908d2
parent 9598 8b6ee1577c93
child 9600 66e62da85efd
fixed issue 15554: Automate access to widgets on non manual roles
-Trigger in AD_Role table
-Trigger in OBKMO_Widget_Class
-Extension point for AD_Update_Access
modules/org.openbravo.client.myob/src-db/database/model/functions/OBKMO_UPDATE_ACCESS.xml
modules/org.openbravo.client.myob/src-db/database/model/tables/OBKMO_WIDGET_CLASS.xml
modules/org.openbravo.client.myob/src-db/database/model/triggers/OBKMO_AD_ROLE_TRG.xml
modules/org.openbravo.client.myob/src-db/database/model/triggers/OBKMO_WIDGET_CLASS_TRG.xml
modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_EP_PROCEDURES.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.myob/src-db/database/model/functions/OBKMO_UPDATE_ACCESS.xml	Fri Jan 07 12:00:49 2011 +0100
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+  <database name="FUNCTION OBKMO_UPDATE_ACCESS">
+    <function name="OBKMO_UPDATE_ACCESS" type="NULL">
+      <parameter name="p_ep_instance_id" type="VARCHAR" mode="in">
+        <default/>
+      </parameter>
+      <body><![CDATA[/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SLU
+* All portions are Copyright (C) 2011 Openbravo SLU
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+
+BEGIN
+
+  INSERT INTO OBKMO_Widget_Class_Access
+    (
+      OBKMO_Widget_Class_Access_ID, OBKMO_Widget_Class_ID, AD_Role_ID, AD_Client_ID,
+      AD_Org_ID, IsActive, Created,
+      CreatedBy, Updated, UpdatedBy
+    )
+  SELECT get_uuid(), W.OBKMO_Widget_Class_ID, R.AD_ROLE_ID, R.AD_CLIENT_ID,
+    R.AD_ORG_ID, 'Y', now(),
+    '0', now(), '0'
+  FROM OBKMO_Widget_Class W, AD_ROLE R
+  WHERE R.ISMANUAL = 'N'
+  AND W.IsActive='Y'
+    AND (
+      (R.USERLEVEL = 'S' AND W.ACCESSLEVEL IN ('4','7','6'))
+      OR
+      (R.USERLEVEL IN (' CO', ' C') AND W.ACCESSLEVEL IN ('7','6','3','1'))
+      OR
+      (R.USERLEVEL = '  O' AND W.ACCESSLEVEL IN ('3','1','7'))
+    )
+    AND NOT EXISTS (SELECT 1
+                     FROM OBKMO_Widget_Class_Access
+                    WHERE OBKMO_Widget_Class_ID = W.OBKMO_Widget_Class_ID
+                      AND AD_ROLE_ID = R.AD_ROLE_ID);
+      
+END OBKMO_UPDATE_ACCESS
+]]></body>
+    </function>
+  </database>
--- a/modules/org.openbravo.client.myob/src-db/database/model/tables/OBKMO_WIDGET_CLASS.xml	Fri Jan 07 11:57:57 2011 +0100
+++ b/modules/org.openbravo.client.myob/src-db/database/model/tables/OBKMO_WIDGET_CLASS.xml	Fri Jan 07 12:00:49 2011 +0100
@@ -69,6 +69,10 @@
         <default><![CDATA[N]]></default>
         <onCreateDefault><![CDATA['N']]></onCreateDefault>
       </column>
+      <column name="ACCESSLEVEL" primaryKey="false" required="true" type="VARCHAR" size="60" autoIncrement="false">
+        <default><![CDATA[3]]></default>
+        <onCreateDefault><![CDATA['3']]></onCreateDefault>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="OBKMO_WIDGET_CLIENT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.myob/src-db/database/model/triggers/OBKMO_AD_ROLE_TRG.xml	Fri Jan 07 12:00:49 2011 +0100
@@ -0,0 +1,86 @@
+<?xml version="1.0"?>
+  <database name="TRIGGER OBKMO_AD_ROLE_TRG">
+    <trigger name="OBKMO_AD_ROLE_TRG" table="AD_ROLE" fires="after" insert="true" update="true" delete="false" foreach="row">
+      <body><![CDATA[
+/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SLU
+* All portions are Copyright (C) 2011 Openbravo SLU
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+    
+BEGIN
+    
+    IF AD_isTriggerEnabled()='N' THEN RETURN;
+    END IF;
+
+
+IF (UPDATING) THEN
+ IF NOT(COALESCE(:OLD.UserLevel,'.')<>COALESCE(:NEW.UserLevel,'.')) THEN
+  RETURN;
+ END IF;
+ END IF;
+
+
+ IF (INSERTING) THEN
+  NULL;
+ ELSIF (:new.IsManual = 'Y') THEN
+  RETURN;
+ ELSE
+  DELETE FROM OBKMO_Widget_Class_Access
+  WHERE AD_Role_ID = :new.AD_Role_ID;
+ END IF;
+
+
+ -- System
+ IF (:new.UserLevel='S') AND (:new.IsManual <> 'Y') THEN
+  INSERT INTO OBKMO_Widget_Class_Access
+   (OBKMO_Widget_Class_Access_ID, OBKMO_Widget_Class_ID, AD_Role_ID,
+   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy)
+  SELECT get_uuid(), w.OBKMO_Widget_Class_ID, :new.AD_Role_ID,
+   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy
+  FROM (select distinct w.OBKMO_Widget_Class_ID
+  from OBKMO_Widget_Class w
+  WHERE w.AccessLevel IN ('4','7','6')
+    AND w.IsActive = 'Y') w;
+
+ -- Client/Org
+ ELSIF (:new.UserLevel=' CO' OR :new.UserLevel=' C') AND (:new.IsManual <> 'Y') THEN
+  INSERT INTO OBKMO_Widget_Class_Access
+   (OBKMO_Widget_Class_Access_ID, OBKMO_Widget_Class_ID, AD_Role_ID,
+   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy)
+  SELECT get_uuid(), w.OBKMO_Widget_Class_ID, :new.AD_Role_ID,
+   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy
+  FROM (select distinct w.OBKMO_Widget_Class_ID
+  from OBKMO_Widget_Class w
+  WHERE w.AccessLevel IN ('7','6','3','1')
+    AND w.IsActive = 'Y') w;
+
+ -- Organization
+ ELSIF (:new.UserLevel='  O') AND (:new.IsManual <> 'Y') THEN
+   INSERT INTO OBKMO_Widget_Class_Access
+   (OBKMO_Widget_Class_Access_ID, OBKMO_Widget_Class_ID, AD_Role_ID,
+   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy)
+  SELECT get_uuid(), w.OBKMO_Widget_Class_ID, :new.AD_Role_ID,
+   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy
+  FROM (select distinct w.OBKMO_Widget_Class_ID
+  from OBKMO_Widget_Class w
+  WHERE w.AccessLevel IN ('3','1','7')
+    AND w.IsActive = 'Y') w;
+
+ END IF;
+
+END OBKMO_AD_ROLE_TRG
+]]></body>
+    </trigger>
+  </database>
--- a/modules/org.openbravo.client.myob/src-db/database/model/triggers/OBKMO_WIDGET_CLASS_TRG.xml	Fri Jan 07 11:57:57 2011 +0100
+++ b/modules/org.openbravo.client.myob/src-db/database/model/triggers/OBKMO_WIDGET_CLASS_TRG.xml	Fri Jan 07 12:00:49 2011 +0100
@@ -15,7 +15,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) 2010 Openbravo SLU
+* All portions are Copyright (C) 2010-2011 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -83,7 +83,26 @@
         AND l.IsSystemLanguage='Y'
         AND m.AD_Module_ID = :new.AD_Module_ID
         AND M.AD_Language != l.AD_Language;
-  END IF;
+        
+     INSERT INTO OBKMO_Widget_Class_Access
+      (
+        OBKMO_Widget_Class_Access_ID, OBKMO_Widget_Class_ID, AD_Role_ID, AD_Client_ID,
+        AD_Org_ID, IsActive, Created,
+        CreatedBy, Updated, UpdatedBy
+      )
+      SELECT get_uuid(), :new.OBKMO_Widget_Class_ID, R.AD_ROLE_ID, R.AD_CLIENT_ID,
+        R.AD_ORG_ID, 'Y', now(),
+        '0', now(), '0'
+      FROM AD_ROLE R
+      WHERE R.ISMANUAL = 'N'
+        AND (
+          (R.USERLEVEL = 'S' AND :new.ACCESSLEVEL IN ('4','7','6'))
+          OR
+          (R.USERLEVEL IN (' CO', ' C') AND :new.ACCESSLEVEL IN ('7','6','3','1'))
+          OR
+          (R.USERLEVEL = '  O' AND :new.ACCESSLEVEL IN ('3','1','7'))
+        );
+    END IF;
 
   IF UPDATING THEN
     IF coalesce(:new.title,'.') != coalesce(:old.title,'.')
--- a/modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_EP_PROCEDURES.xml	Fri Jan 07 11:57:57 2011 +0100
+++ b/modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_EP_PROCEDURES.xml	Fri Jan 07 12:00:49 2011 +0100
@@ -10,4 +10,14 @@
 <!--27A43E417DF440C6979B17095F9BB1DC-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
 <!--27A43E417DF440C6979B17095F9BB1DC--></AD_EP_PROCEDURES>
 
+<!--E1F4573C8D2D4A8A829ECE508039E5A7--><AD_EP_PROCEDURES>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <AD_EP_PROCEDURES_ID><![CDATA[E1F4573C8D2D4A8A829ECE508039E5A7]]></AD_EP_PROCEDURES_ID>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <AD_EXTENSION_POINTS_ID><![CDATA[8261F79453B64AC7998873A9F81A1E5A]]></AD_EXTENSION_POINTS_ID>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <PROCEDURENAME><![CDATA[OBKMO_UPDATE_ACCESS]]></PROCEDURENAME>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
+<!--E1F4573C8D2D4A8A829ECE508039E5A7--></AD_EP_PROCEDURES>
+
 </data>