This script will only insert Circulation
subsystem permissions. I’ve tried to genericize the script the best I could while still keeping some the specific pieces I felt could be applicable to other libraries. You can comment out the first line and the ) d
line to run a select only version first to review what will be inserted.
begin tran insert into polaris.polaris.permissiongroups select d.ControlRecordID, d.PermissionID, d.GroupID from (
select distinct g.GroupID, g.GroupName, pp_new.PermissionID, pp_new.ControlRecordID, pp_new.ControlRecordName, pp_new.PermissionName, pp_new.OrganizationID, o_new.Name, pp_new.ControlRecordDefID, pp_new.PermissionNameID, pp_source.SubSystem
from Polaris.Polaris.Groups g
join polaris.Polaris.PermissionGroups pg
on pg.GroupID = g.GroupID
join Polaris.dbo.CLC_Custom_PolarisPermissions pp_source
on pp_source.SubSystemID = 2 and pp_source.ControlRecordID = pg.ControlRecordID and pp_source.PermissionID = pg.PermissionID
join Polaris.Polaris.Organizations o_source
on o_source.OrganizationID = pp_source.OrganizationID
join Polaris.dbo.CLC_Custom_PolarisPermissions pp_new
on pp_new.ControlRecordName not like '%patron record sets%' and pp_new.ControlRecordDefID = pp_source.ControlRecordDefID and pp_new.PermissionNameID = pp_source.PermissionNameID and pp_new.OrganizationID != pp_source.OrganizationID
join polaris.Polaris.Organizations o_new
on o_new.OrganizationID = pp_new.OrganizationID
where pp_source.SubSystemID = 2
-- permission not already granted
and not exists ( select 1 from Polaris.Polaris.PermissionGroups _pg where _pg.GroupID = g.GroupID and _pg.ControlRecordID = pp_new.ControlRecordID and _pg.PermissionID = pp_new.PermissionID )
-- only add permissions to valid groups
and g.GroupID >= 22
-- exclude 'deny item request'
and pp_new.PermissionNameID not in (35)
) d
--rollback
--commit