BEGIN;

SELECT evergreen.upgrade_deps_block_check('0542', :eg_version);

-- stock Users group

INSERT INTO permission.grp_perm_map ( grp, perm, depth )
    SELECT
        1,
        id,
        0
    FROM permission.perm_list
    WHERE code in (
        'CREATE_PURCHASE_REQUEST'
    );

-- stock Staff group

INSERT INTO permission.grp_perm_map ( grp, perm, depth )
    SELECT
        3,
        id,
        0
    FROM permission.perm_list
    WHERE code in (
        'VIEW_USER_SETTING_TYPE'
    );

-- stock Circulators group

INSERT INTO permission.grp_perm_map ( grp, perm, depth )
    SELECT
        5,
        id,
        0
    FROM permission.perm_list
    WHERE code in (
        'MARK_ITEM_MISSING_PIECES'
    );

--- stock Circulation Administrator group

INSERT INTO permission.grp_perm_map ( grp, perm, depth, grantable )
    SELECT
        4,
        id,
        0,
        't'
    FROM permission.perm_list
    WHERE code in (
        'MARK_ITEM_MISSING_PIECES'
        ,'UPDATE_HOLD_REQUEST_TIME'
    );

-- stock Catalogers group

INSERT INTO permission.grp_perm_map ( grp, perm, depth )
    SELECT
        5,
        id,
        0
    FROM permission.perm_list
    WHERE code in (
        'MAP_MONOGRAPH_PART'
        ,'ADMIN_SERIAL_ITEM'
    );

-- stock Cataloging Administrator group

INSERT INTO permission.grp_perm_map ( grp, perm, depth, grantable )
    SELECT
        8,
        id,
        0,
        't'
    FROM permission.perm_list
    WHERE code in (
        'MAP_MONOGRAPH_PART'
        ,'ADMIN_SERIAL_ITEM'
        ,'CREATE_VOLUME_SUFFIX'
        ,'UPDATE_VOLUME_SUFFIX'
        ,'DELETE_VOLUME_SUFFIX'
        ,'CREATE_VOLUME_PREFIX'
        ,'UPDATE_VOLUME_PREFIX'
        ,'DELETE_VOLUME_PREFIX'
        ,'CREATE_MONOGRAPH_PART'
        ,'UPDATE_MONOGRAPH_PART'
        ,'DELETE_MONOGRAPH_PART'
        ,'CREATE_BIB_PTYPE'
        ,'UPDATE_BIB_PTYPE'
        ,'DELETE_BIB_PTYPE'
    );

-- stock Serials group

INSERT INTO permission.grp_perm_map ( grp, perm, depth )
    SELECT
        11,
        id,
        0
    FROM permission.perm_list
    WHERE code in (
        'ADMIN_SERIAL_ITEM'
    );


-- stock Acquisitions group

INSERT INTO permission.grp_perm_map ( grp, perm, depth )
    SELECT
        7,
        id,
        0
    FROM permission.perm_list
    WHERE code in (
        'UPDATE_PICKLIST'
    );

--- stock Acquisitions Administrator group

INSERT INTO permission.grp_perm_map ( grp, perm, depth, grantable )
    SELECT
        8,
        id,
        0,
        't'
    FROM permission.perm_list
    WHERE code in (
        'UPDATE_PICKLIST'
    );

--- stock Local Administrator group

INSERT INTO permission.grp_perm_map ( grp, perm, depth, grantable )
    SELECT
        10,
        id,
        2,
        't'
    FROM permission.perm_list
    WHERE code in (
        'UPDATE_WORKSTATION'
    );

--- stock System Administrator group

INSERT INTO permission.grp_perm_map ( grp, perm, depth, grantable )
    SELECT
        11,
        id,
        1,
        't'
    FROM permission.perm_list
    WHERE code in (
        'UPDATE_WORKSTATION'
    );

--- stock Global Administrator group

INSERT INTO permission.grp_perm_map ( grp, perm, depth, grantable )
    SELECT
        12,
        id,
        0,
        't'
    FROM permission.perm_list
    WHERE code in (
        'UPDATE_WORKSTATION'
        ,'ADMIN_SVF'
        ,'ADMIN_CODED_VALUE'
    );

COMMIT;
