Advertisement
psi_mmobile

Untitled

Feb 26th, 2020
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.85 KB | None | 0 0
  1.   PROCEDURE checkPersonAccessRights2(p_vehicle_owner_id IN NUMBER, p_person_id IN NUMBER) IS      
  2.     -- POST : users with access on p_vehicle_owner_id and preferences like '%checkinAtWork%' will have a right on p_person_id (a record in gu_person)  
  3.     --        right is with CAW_only null if the person has a right on p_person_id vehicle owner
  4.     --        right is with CAW_only ='Y' in other cases
  5.     --        if right already exist, lm_date is updated
  6.     -- list gui_users with access on p_vehicle_owner_id
  7.     CURSOR c_gu IS
  8.                   SELECT DISTINCT gu.gui_user_id
  9.                   FROM gui_users gu, gu_vehicle_owner guvo
  10.                   WHERE guvo.vehicle_owner_id=p_vehicle_owner_id
  11.                   AND gu.gui_user_id = guvo.gui_user_id
  12.                   AND gu.preferences LIKE '%checkinAtWork%'
  13.                   AND (  (gu.user_admin_right IN ('SO','FM','VAR'))
  14.                       OR ( (guvo.vo_vehicle_category_id IS NULL) AND (guvo.vo_person_category_id IS NULL) AND (guvo.vo_group_id IS NULL) )
  15.                       );
  16.     v_current_date DATE;
  17.     v_gu_person_id NUMBER(10);
  18.     v_nbr_access NUMBER(10); -- already existing rights for the hui_user on the person
  19.     v_nbr_vo_access NUMBER(10); -- nbr rights on the person VO in gu_vehicle_owner.
  20.     v_caw_limited CHAR(1);
  21.   BEGIN
  22.        v_current_date := SYSDATE;
  23.        FOR r_gu IN c_gu
  24.        LOOP
  25.            SELECT COUNT(*)
  26.            INTO v_nbr_access
  27.            FROM gu_person gup
  28.            WHERE gup.person_id= p_person_id
  29.            AND gup.gui_user_id = r_gu.gui_user_id;
  30.            IF v_nbr_access > 0
  31.            THEN
  32.                 -- right on p_person_id already exist, update lm_date
  33.                 UPDATE gu_person gup
  34.                 SET lm_date = v_current_date
  35.                 WHERE gup.person_id= p_person_id
  36.                 AND gup.gui_user_id = r_gu.gui_user_id;
  37.            ELSE
  38.                 -- check if gui_user has access to p_person_id vehicle owner
  39.                 SELECT COUNT(*)
  40.                 INTO v_nbr_vo_access
  41.                 FROM gu_vehicle_owner guvo, person p, vo_person_category vopc
  42.                 WHERE guvo.gui_user_id = r_gu.gui_user_id
  43.                 AND guvo.vehicle_owner_id = vopc.vehicle_owner_id
  44.                 AND vopc.vo_person_category_id = p.vo_person_category_id
  45.                 AND p.person_id = p_person_id;              
  46.                 IF v_nbr_vo_access > 0
  47.                 THEN
  48.                     v_caw_limited :=NULL;
  49.                 ELSE
  50.                     v_caw_limited :='Y';
  51.                 END IF;
  52.                 INSERT INTO gu_person (gui_user_id, person_id, caw_limited, creation_date, lm_date)
  53.                 VALUES (r_gu.gui_user_id, p_person_id, v_caw_limited, v_current_date,v_current_date);
  54.            END IF;
  55.        END LOOP; -- c_gup
  56.   EXCEPTION WHEN OTHERS THEN
  57.     NULL;
  58.   END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement