-- Only run if system being upgraded did not have orangehrmRegionalAdminAuthorizationPlugin
-- Insert screen viewAuthorizationSystemUsers (advanced action)
INSERT INTO ohrm_screen (`name`, `module_id`, `action_url`) VALUES
('User List', 2, 'viewAuthorizationSystemUsers'),
('View Employee List', 3, 'viewAuthorizationEmployeeList');


-- Give 'Admin' access to viewAuthorizationSystemUsers screen
INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete)
SELECT r.id, s.id, 1, 1, 1, 1 FROM ohrm_screen s, ohrm_user_role r WHERE 
    s.action_url in ('viewAuthorizationSystemUsers', 'viewSystemUsers', 'saveSystemUser', 'deleteSystemUsers', 'viewAuthorizationEmployeeList')
    AND r.`name` = 'Admin';

-- Give supervisor access to viewAuthorization employee list
INSERT INTO ohrm_user_role_screen (user_role_id, screen_id, can_read, can_create, can_update, can_delete)
SELECT r.id, s.id, 1, 0, 0, 0 FROM ohrm_screen s, ohrm_user_role r WHERE 
    s.action_url in ('viewAuthorizationEmployeeList')
    AND r.`name` = 'Supervisor';