Bug 17663: Forgotten userpermissions from bug 14686
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Sun, 20 Nov 2016 15:35:53 +0000 (16:35 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 21 Nov 2016 16:33:16 +0000 (16:33 +0000)
Bug 14686 added in a dbrev:
    (13, 'upload_general_files', 'Upload any file'),
    (13, 'upload_manage', 'Manage uploaded files');

But these were not added in userpermissions.sql somehow :)
So, what now?

This patch:
[1] adds them to userpermissions.sql as should have been done,
[2] adds a dbrev to add them for newer installs that did not run the
    14686 dbrev.

Test plan:
[1] Run this sql statement:
    DELETE FROM permissions WHERE code = 'upload_general_files' OR
        code = 'upload_manage'
[2] Run the db rev.
[3] Check if you see Tools/Upload (with sufficient perms).

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
installer/data/mysql/atomicupdate/bug17663.perl [new file with mode: 0644]
installer/data/mysql/userpermissions.sql

diff --git a/installer/data/mysql/atomicupdate/bug17663.perl b/installer/data/mysql/atomicupdate/bug17663.perl
new file mode 100644 (file)
index 0000000..128a501
--- /dev/null
@@ -0,0 +1,26 @@
+$DBversion = 'XXX';  # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q|
+INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
+    (13, 'upload_general_files', 'Upload any file'),
+    (13, 'upload_manage', 'Manage uploaded files');
+    |);
+
+# Update user_permissions for current users (check count in uploaded_files)
+# Note 9 == edit_catalogue and 13 == tools
+# We do not insert if someone is superlibrarian, does not have edit_catalogue,
+# or already has all tools
+    $dbh->do(q|
+INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code)
+    SELECT borrowernumber, 13, 'upload_general_files'
+    FROM borrowers bo
+    WHERE flags<>1 AND flags & POW(2,13) = 0 AND
+        ( flags & POW(2,9) > 0 OR (
+            SELECT COUNT(*) FROM user_permissions
+            WHERE borrowernumber=bo.borrowernumber AND module_bit=9 ) > 0 )
+        AND ( SELECT COUNT(*) FROM uploaded_files ) > 0;
+    |);
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17663 - Forgotten userpermissions)\n";
+}
index 26b4e5c..6b72278 100644 (file)
@@ -57,6 +57,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES
    (13, 'records_batchmod', 'Perform batch modification of records (biblios or authorities)'),
    (13, 'marc_modification_templates', 'Manage marc modification templates'),
    (13, 'records_batchdel', 'Perform batch deletion of records (bibliographic or authority)'),
+   (13, 'upload_general_files', 'Upload any file'),
+   (13, 'upload_manage', 'Manage uploaded files'),
    (15, 'check_expiration', 'Check the expiration of a serial'),
    (15, 'claim_serials', 'Claim missing serials'),
    (15, 'create_subscription', 'Create a new subscription'),