src-db/database/model/triggers/AD_ROLE_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 873 340a2dc51591
child 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER AD_ROLE_TRG">
adrian@94
     3
    <trigger name="AD_ROLE_TRG" table="AD_ROLE" fires="after" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
/*************************************************************************
juanpablo@771
     6
* The contents of this file are subject to the Compiere Public
juanpablo@771
     7
* License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
* compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
* the legal folder of your Openbravo installation.
juanpablo@771
    10
* Software distributed under the License is distributed on an
juanpablo@771
    11
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
juanpablo@771
    12
* implied. See the License for the specific language governing rights
juanpablo@771
    13
* and limitations under the License.
juanpablo@778
    14
* The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
juanpablo@771
    16
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
juanpablo@771
    17
* parts created by ComPiere are Copyright (C) ComPiere, Inc.;
juanpablo@771
    18
* All Rights Reserved.
juanpablo@771
    19
* Contributor(s): Openbravo SL
juanpablo@785
    20
* Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    21
*
juanpablo@771
    22
* Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
* file and version.
juanpablo@771
    24
*************************************************************************
juanpablo@771
    25
* $Id: AD_Role_Trg.sql,v 1.5 2003/07/22 05:41:26 jjanke Exp $
juanpablo@771
    26
***
juanpablo@771
    27
* Title: Role Setup
juanpablo@771
    28
* Description:
juanpablo@771
    29
* - Create Role_OrgAccess + User_Roles
juanpablo@771
    30
* - Insert Access for Role
juanpablo@771
    31
************************************************************************/
adrian@94
    32
BEGIN
adrian@94
    33
IF (UPDATING) THEN
gorkaion@239
    34
 IF NOT(COALESCE(:OLD.UserLevel,'.')<>COALESCE(:NEW.UserLevel,'.')) THEN
adrian@94
    35
  RETURN;
adrian@94
    36
 END IF;
adrian@94
    37
 END IF;
adrian@94
    38
adrian@94
    39
adrian@94
    40
 IF (INSERTING) THEN
asier@873
    41
  NULL;
adrian@94
    42
 ELSIF (:new.IsManual = 'Y') THEN
asier@873
    43
  RETURN;
asier@873
    44
 ELSE
adrian@94
    45
  -- Window
adrian@94
    46
  DELETE FROM AD_Window_Access
adrian@94
    47
  WHERE AD_Role_ID = :new.AD_Role_ID;
adrian@94
    48
  -- Process
adrian@94
    49
  DELETE FROM AD_Process_Access
adrian@94
    50
  WHERE AD_Role_ID = :new.AD_Role_ID;
adrian@94
    51
  -- Form
adrian@94
    52
  DELETE FROM AD_Form_Access
adrian@94
    53
  WHERE AD_Role_ID = :new.AD_Role_ID;
adrian@94
    54
  -- WorkFlow
adrian@94
    55
  DELETE FROM AD_WorkFlow_Access
adrian@94
    56
  WHERE AD_Role_ID = :new.AD_Role_ID;
adrian@94
    57
 END IF;
adrian@94
    58
adrian@94
    59
 /**
adrian@94
    60
  * Fill AD_Window_Access + AD_Process_Access
adrian@94
    61
  * ---------------------------------------------------------------------------
adrian@94
    62
  * SCO# Levels   S__ 100  4 System info
adrian@94
    63
  *      SCO 111  7 System shared info
adrian@94
    64
  *      SC_ 110  6 System/Client info
adrian@94
    65
  *      _CO 011  3 Client shared info
adrian@94
    66
  *      __O 001  1 Organization info
adrian@94
    67
  * Roles:
adrian@94
    68
  *  S  4,7,6
adrian@94
    69
  *  _CO  7,6,3,1
adrian@94
    70
  *  __O  3,1,7
adrian@94
    71
  */
adrian@94
    72
 -- System
gorkaion@239
    73
 IF (:new.UserLevel='S') AND (:new.IsManual <> 'Y') THEN
adrian@94
    74
  -- Window
adrian@94
    75
  INSERT INTO AD_Window_Access
juanpablo@1605
    76
   (AD_Window_Access_ID, AD_Window_ID, AD_Role_ID,
adrian@94
    77
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
    78
  SELECT get_uuid(), w.AD_Window_ID, :new.AD_Role_ID,
antonio@735
    79
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
juanpablo@1605
    80
  FROM (select distinct w.ad_window_id
juanpablo@1605
    81
  from AD_Window w, AD_Tab t, AD_Table tt
adrian@94
    82
  WHERE w.AD_Window_ID=t.AD_Window_ID
adrian@94
    83
    AND t.AD_Table_ID=tt.AD_Table_ID
juanpablo@1605
    84
    AND tt.AccessLevel IN ('4','7','6')) w;
adrian@94
    85
  -- Process
adrian@94
    86
  INSERT INTO AD_Process_Access
juanpablo@1605
    87
   ( AD_Process_Access_ID, AD_Process_ID, AD_Role_ID,
adrian@94
    88
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
    89
  SELECT get_uuid(), p.AD_Process_ID, :new.AD_Role_ID,
antonio@735
    90
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
    91
  FROM AD_Process p
adrian@94
    92
  WHERE AccessLevel IN ('4','7','6');
adrian@94
    93
  -- Form
adrian@94
    94
  INSERT INTO AD_Form_Access
juanpablo@1605
    95
   (AD_Form_Access_ID, AD_Form_ID, AD_Role_ID,
adrian@94
    96
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
    97
  SELECT get_uuid(), f.AD_Form_ID, :new.AD_Role_ID,
antonio@735
    98
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
    99
  FROM AD_Form f
adrian@94
   100
  WHERE AccessLevel IN ('4','7','6');
adrian@94
   101
  -- Workflow
adrian@94
   102
  INSERT INTO AD_WorkFlow_Access
juanpablo@1605
   103
   (AD_WorkFlow_Access_ID, AD_WorkFlow_ID, AD_Role_ID,
adrian@94
   104
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   105
  SELECT get_uuid(), w.AD_WorkFlow_ID, :new.AD_Role_ID,
antonio@735
   106
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   107
  FROM AD_WorkFlow w
adrian@94
   108
  WHERE AccessLevel IN ('4','7','6');
adrian@94
   109
adrian@94
   110
 -- Client/Org
gorkaion@239
   111
 ELSIF (:new.UserLevel=' CO' OR :new.UserLevel=' C') AND (:new.IsManual <> 'Y') THEN
adrian@94
   112
  -- Window
adrian@94
   113
  INSERT INTO AD_Window_Access
juanpablo@1605
   114
  ( AD_Window_Access_ID, AD_Window_ID, AD_Role_ID,
adrian@94
   115
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   116
  SELECT get_uuid(), w.AD_Window_ID, :new.AD_Role_ID,
antonio@735
   117
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
juanpablo@1605
   118
  FROM (select distinct w.ad_window_id
juanpablo@1605
   119
  from AD_Window w, AD_Tab t, AD_Table tt
adrian@94
   120
  WHERE w.AD_Window_ID=t.AD_Window_ID
adrian@94
   121
    AND t.AD_Table_ID=tt.AD_Table_ID
juanpablo@1605
   122
    AND tt.AccessLevel IN ('7','6','3','1')
juanpablo@1605
   123
    AND w.AD_Window_ID NOT IN ('100','102','165','187')) w;
adrian@94
   124
  -- Process
adrian@94
   125
  INSERT INTO AD_Process_Access
juanpablo@1605
   126
   (AD_Process_Access_ID, AD_Process_ID, AD_Role_ID,
adrian@94
   127
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   128
  SELECT DISTINCT get_uuid(), p.AD_Process_ID, :new.AD_Role_ID,
antonio@735
   129
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   130
  FROM AD_Process p
adrian@94
   131
  WHERE AccessLevel IN ('7','6','3','1');
adrian@94
   132
  -- Form
adrian@94
   133
  INSERT INTO AD_Form_Access
juanpablo@1605
   134
   (AD_Form_Access_ID, AD_Form_ID, AD_Role_ID,
adrian@94
   135
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   136
  SELECT get_uuid(), f.AD_Form_ID, :new.AD_Role_ID,
antonio@735
   137
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   138
  FROM AD_Form f
adrian@94
   139
  WHERE AccessLevel IN ('7','6','3','1');
adrian@94
   140
  -- Workflow
adrian@94
   141
  INSERT INTO AD_WorkFlow_Access
juanpablo@1605
   142
   (AD_WorkFlow_Access_ID, AD_WorkFlow_ID, AD_Role_ID,
adrian@94
   143
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   144
  SELECT get_uuid(), w.AD_WorkFlow_ID, :new.AD_Role_ID,
antonio@735
   145
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   146
  FROM AD_WorkFlow w
adrian@94
   147
  WHERE AccessLevel IN ('7','6','3','1');
adrian@94
   148
adrian@94
   149
 -- Organization
gorkaion@239
   150
 ELSIF (:new.UserLevel='  O') AND (:new.IsManual <> 'Y') THEN
adrian@94
   151
  -- Window
adrian@94
   152
  INSERT INTO AD_Window_Access
juanpablo@1605
   153
   (AD_Window_Access_ID, AD_Window_ID, AD_Role_ID,
adrian@94
   154
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   155
  SELECT  get_uuid(), w.AD_Window_ID, :new.AD_Role_ID,
antonio@735
   156
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
juanpablo@1605
   157
  FROM (select distinct w.aD_window_id
juanpablo@1605
   158
  from AD_Window w, AD_Tab t, AD_Table tt
adrian@94
   159
  WHERE w.AD_Window_ID=t.AD_Window_ID
adrian@94
   160
    AND t.AD_Table_ID=tt.AD_Table_ID
juanpablo@1605
   161
    AND tt.AccessLevel IN ('3','1','7')) w;
adrian@94
   162
  -- Process
adrian@94
   163
  INSERT INTO AD_Process_Access
juanpablo@1605
   164
   (AD_Process_Access_ID, AD_Process_ID, AD_Role_ID,
adrian@94
   165
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   166
  SELECT  get_uuid(), p.AD_Process_ID, :new.AD_Role_ID,
antonio@735
   167
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   168
  FROM AD_Process p
adrian@94
   169
  WHERE AccessLevel IN ('3','1','7');
adrian@94
   170
  -- Form
adrian@94
   171
  INSERT INTO AD_Form_Access
juanpablo@1605
   172
   (AD_Form_Access_ID, AD_Form_ID, AD_Role_ID,
adrian@94
   173
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   174
  SELECT get_uuid(), f.AD_Form_ID, :new.AD_Role_ID,
antonio@735
   175
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   176
  FROM AD_Form f
adrian@94
   177
  WHERE AccessLevel IN ('3','1','7');
adrian@94
   178
  -- Workflow
adrian@94
   179
  INSERT INTO AD_WorkFlow_Access
juanpablo@1605
   180
   (AD_WorkFlow_Access_ID, AD_WorkFlow_ID, AD_Role_ID,
adrian@94
   181
   AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy, IsReadWrite)
juanpablo@1605
   182
  SELECT get_uuid(), w.AD_WorkFlow_ID, :new.AD_Role_ID,
antonio@735
   183
   :new.AD_CLIENT_ID, :new.AD_ORG_ID, 'Y', now(), :new.UpdatedBy, now(), :new.UpdatedBy, 'Y'
adrian@94
   184
  FROM AD_WorkFlow w
adrian@94
   185
  WHERE AccessLevel IN ('3','1','7');
adrian@94
   186
adrian@94
   187
 END IF;
adrian@94
   188
antonio@735
   189
END AD_ROLE_TRG
gorkaion@239
   190
]]></body>
adrian@94
   191
    </trigger>
adrian@94
   192
  </database>