From 3b743be7874823c28be26ca5299ea768c5b9329b Mon Sep 17 00:00:00 2001
From: Katrin Fischer <katrin.fischer.83@web.de>
Date: Wed, 16 May 2018 01:19:53 +0200
Subject: [PATCH] Bug 2426: Remove deprecated management permission
Content-Type: text/plain; charset=utf-8

After review of the code it turns out that the management permission
that has been marked as deprecated a long time ago, does not have
any function.

The patch removes all remaining code related to it.

To test:
- Make sure you have a patron with the management permission
- Apply patch
- Run database update
- Check everything still works as expected

Bonus:
borrowers.flags is recalculated for patrons with management
permission.

To check:
- Create some 'permission twins' with and without management
  permission
- Note the value in borrowers.flags
- Apply patch, don't run database update
- Save permissions from GUI for one of the twins
- Note the newly calculated value
- Run database update
- Now both twins should have the same borrowers.flags value

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 C4/Auth.pm                                                       | 6 +-----
 C4/InstallAuth.pm                                                | 1 -
 .../mysql/atomicupdate/bug2426_remove_management_permission.sql  | 3 +++
 installer/data/mysql/userflags.sql                               | 1 -
 koha-tmpl/intranet-tmpl/prog/en/includes/header.inc              | 2 +-
 koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc         | 1 -
 .../intranet-tmpl/prog/en/modules/help/members/member-flags.tt   | 9 ---------
 t/db_dependent/Auth.t                                            | 2 +-
 t/db_dependent/Search/History.t                                  | 2 +-
 9 files changed, 7 insertions(+), 20 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug2426_remove_management_permission.sql

diff --git a/C4/Auth.pm b/C4/Auth.pm
index 7442b1d..c4dd0c4 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -289,7 +289,7 @@ sub get_template_and_user {
         my $all_perms = get_all_subpermissions();
 
         my @flagroots = qw(circulate catalogue parameters borrowers permissions reserveforothers borrow
-          editcatalogue updatecharges management tools editauthorities serials reports acquisition clubs);
+          editcatalogue updatecharges tools editauthorities serials reports acquisition clubs);
 
         # We are going to use the $flags returned by checkauth
         # to create the template's parameters that will indicate
@@ -304,7 +304,6 @@ sub get_template_and_user {
             $template->param( CAN_user_editcatalogue    => 1 );
             $template->param( CAN_user_updatecharges    => 1 );
             $template->param( CAN_user_acquisition      => 1 );
-            $template->param( CAN_user_management       => 1 );
             $template->param( CAN_user_tools            => 1 );
             $template->param( CAN_user_editauthorities  => 1 );
             $template->param( CAN_user_serials          => 1 );
@@ -340,9 +339,6 @@ sub get_template_and_user {
             foreach my $module ( keys %$flags ) {
                 if ( $flags->{$module} == 1 or ref( $flags->{$module} ) ) {
                     $template->param( "CAN_user_$module" => 1 );
-                    if ( $module eq "parameters" ) {
-                        $template->param( CAN_user_management => 1 );
-                    }
                 }
             }
         }
diff --git a/C4/InstallAuth.pm b/C4/InstallAuth.pm
index 9d285bd..500d740 100644
--- a/C4/InstallAuth.pm
+++ b/C4/InstallAuth.pm
@@ -143,7 +143,6 @@ sub get_template_and_user {
             $template->param( CAN_user_editcatalogue    => 1 );
             $template->param( CAN_user_updatecharges    => 1 );
             $template->param( CAN_user_acquisition      => 1 );
-            $template->param( CAN_user_management       => 1 );
             $template->param( CAN_user_tools            => 1 );
             $template->param( CAN_user_editauthorities  => 1 );
             $template->param( CAN_user_serials          => 1 );
diff --git a/installer/data/mysql/atomicupdate/bug2426_remove_management_permission.sql b/installer/data/mysql/atomicupdate/bug2426_remove_management_permission.sql
new file mode 100644
index 0000000..884721d
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug2426_remove_management_permission.sql
@@ -0,0 +1,3 @@
+DELETE FROM userflags WHERE bit = 12 AND flag = 'management';
+UPDATE borrowers SET flags = flags - ( flags & (1<<12) ) WHERE flags & (1 << 12);
+-- Bug 2426 - Remove deprecated management permission
diff --git a/installer/data/mysql/userflags.sql b/installer/data/mysql/userflags.sql
index 3e8f5dc..ae36478 100644
--- a/installer/data/mysql/userflags.sql
+++ b/installer/data/mysql/userflags.sql
@@ -9,7 +9,6 @@ INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES
 (9,'editcatalogue','Edit catalog (Modify bibliographic/holdings data)',0),
 (10,'updatecharges','Manage patrons fines and fees',0),
 (11,'acquisition','Acquisition and/or suggestion management',0),
-(12,'management','Set library management parameters (deprecated)',0),
 (13,'tools','Use all tools (expand for granular tools permissions)',0),
 (14,'editauthorities','Edit authorities',0),
 (15,'serials','Manage serial subscriptions',0),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
index 365abbc..3c112ee 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
@@ -101,7 +101,7 @@
 
                     <li role="separator" class="loggedin-menu-label divider"></li>
                     [% IF ( IndependentBranches ) %]
-                        [% IF ( CAN_user_management || CAN_user_editcatalogue_edit_catalogue ) %]
+                        [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
                     <li>
                         <a class="toplinks" href="/cgi-bin/koha/circ/selectbranchprinter.pl">Set library</a>
                     </li>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc
index 017ffb9..4de96f8 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc
@@ -10,7 +10,6 @@
     [%- CASE 'editcatalogue' -%]<span>Edit catalog (Modify bibliographic/holdings data)</span>
     [%- CASE 'updatecharges' -%]<span>Manage patrons fines and fees</span>
     [%- CASE 'acquisition' -%]<span>Acquisition and/or suggestion management</span>
-    [%- CASE 'management' -%]<span>Set library management parameters (deprecated)</span>
     [%- CASE 'tools' -%]<span>Use all tools (expand for granular tools permissions)</span>
     [%- CASE 'editauthorities' -%]<span>Edit authorities</span>
     [%- CASE 'serials' -%]<span>Manage serial subscriptions</span>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/members/member-flags.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/members/member-flags.tt
index 1237f30..41c8127 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/members/member-flags.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/members/member-flags.tt
@@ -86,15 +86,6 @@
 	<li>This section can be expanded</li>
 </ul>
 </li>
-	<li>management
-<ul>
-	<li>Set library management parameters (deprecated)
-<ul>
-	<li style="color: #990000;">Important: This permission level no longer controls anything.</li>
-</ul>
-</li>
-</ul>
-</li>
 	<li>tools
 <ul>
 	<li>Use all tools</li>
diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t
index c08060e..0f5dc65 100644
--- a/t/db_dependent/Auth.t
+++ b/t/db_dependent/Auth.t
@@ -105,7 +105,7 @@ my $hash2 = hash_password('password');
             borrowers         => 0,
             catalogue         => 1, circulate         => 0,
             coursereserves    => 0, editauthorities   => 0,
-            editcatalogue     => 0, management        => 0,
+            editcatalogue     => 0,
             parameters        => 0, permissions       => 0,
             plugins           => 0, reports           => 0,
             reserveforothers  => 0, serials           => 0,
diff --git a/t/db_dependent/Search/History.t b/t/db_dependent/Search/History.t
index ee01734..0e74e2d 100644
--- a/t/db_dependent/Search/History.t
+++ b/t/db_dependent/Search/History.t
@@ -409,7 +409,7 @@ sub MockedCheckauth {
         borrowers         => 0,
         catalogue         => 1, circulate         => 0,
         coursereserves    => 0, editauthorities   => 0,
-        editcatalogue     => 0, management        => 0,
+        editcatalogue     => 0,
         parameters        => 0, permissions       => 0,
         plugins           => 0, reports           => 0,
         reserveforothers  => 0, serials           => 0,
-- 
2.1.4