From 8fef3254c71ba2c868cf6efd8b9f723e242aa290 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Wed, 27 Mar 2019 13:03:16 -0400
Subject: [PATCH] Bug 20256: Update database

Test Plan:
1) Apply this patch set
2) Run updatedatabase.pl
3) Create two library groups with some libraries in them,
   make sure to enable the new feature to limit editing of items
4) Test the functionality, if an item is owned by a library in
   your group, you should have full editing abilities. If an item
   is from a different group, you should only be able to make the
   same changes you would be able to if IndependentBranches were.
---
 installer/data/mysql/atomicupdate/bug_20256.perl | 11 +++++++++++
 installer/data/mysql/kohastructure.sql           |  3 ++-
 installer/data/mysql/userpermissions.sql         |  1 +
 3 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_20256.perl

diff --git a/installer/data/mysql/atomicupdate/bug_20256.perl b/installer/data/mysql/atomicupdate/bug_20256.perl
new file mode 100644
index 0000000000..2080f540e7
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_20256.perl
@@ -0,0 +1,11 @@
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_any_item', 'Edit any item reguardless of home library');" );
+
+    if ( !column_exists( 'library_groups', 'ft_limit_item_editing' ) ) {
+        $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_limit_item_editing tinyint(1) NOT NULL DEFAULT 0 AFTER ft_hide_patron_info" );
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 20256 - Add ability to limit editing of items to home library)\n";
+}
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 4769973ee8..8b15ab8148 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -4202,8 +4202,9 @@ CREATE TABLE library_groups (
     title VARCHAR(100) NULL DEFAULT NULL,     -- Short description of the goup
     description MEDIUMTEXT NULL DEFAULT NULL,    -- Longer explanation of the group, if necessary
     ft_hide_patron_info tinyint(1) NOT NULL DEFAULT 0, -- Turn on the feature "Hide patron's info" for this group
+    ft_limit_item_editing tinyint(1) NOT NULL DEFAULT 0, -- Turn on the feature "Hide patron's info" for this group
     ft_search_groups_opac tinyint(1) NOT NULL DEFAULT 0, -- Use this group for staff side search groups
-     ft_search_groups_staff tinyint(1) NOT NULL DEFAULT 0, -- Use this group for opac side search groups
+    ft_search_groups_staff tinyint(1) NOT NULL DEFAULT 0, -- Use this group for opac side search groups
     created_on TIMESTAMP NULL,             -- Date and time of creation
     updated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Date and time of last
     PRIMARY KEY id ( id ),
diff --git a/installer/data/mysql/userpermissions.sql b/installer/data/mysql/userpermissions.sql
index 6876fad8ac..69913e3974 100644
--- a/installer/data/mysql/userpermissions.sql
+++ b/installer/data/mysql/userpermissions.sql
@@ -41,6 +41,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES
    ( 9, 'edit_items', 'Edit items'),
    ( 9, 'edit_items_restricted', 'Limit item modification to subfields defined in the SubfieldsToAllowForRestrictedEditing preference (please note that edit_item is still required)'),
    ( 9, 'delete_all_items', 'Delete all items at once'),
+   ( 9, 'edit_any_item', 'Edit any item reguardless of home library'),
    (10, 'writeoff', 'Write off fines and fees'),
    (10, 'remaining_permissions', 'Remaining permissions for managing fines and fees'),
    (11, 'currencies_manage', 'Manage currencies and exchange rates'),
-- 
2.20.1 (Apple Git-117)