Bug 21411: Address QA concerns
authorNick Clemens <nick@bywatersolutions.com>
Tue, 23 Apr 2019 11:17:27 +0000 (11:17 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 10 May 2019 18:59:39 +0000 (18:59 +0000)
Move to admin
Add a permission
Remove descriptions from table
Clean up template

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

14 files changed:
Koha/KeyboardShortcuts.pm
admin/adveditorshortcuts.pl [moved from tools/adveditorshortcuts.pl with 93% similarity]
installer/data/mysql/atomicupdate/Bug_21411_add_keyboard_shortcuts.perl [new file with mode: 0644]
installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl [deleted file]
installer/data/mysql/kohastructure.sql
installer/data/mysql/mandatory/keyboard_shortcuts.sql [moved from installer/data/mysql/en/mandatory/keyboard_shortcuts.sql with 52% similarity]
installer/data/mysql/userpermissions.sql
koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc
koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/adveditorshortcuts.tt [moved from koha-tmpl/intranet-tmpl/prog/en/modules/tools/adveditorshortcuts.tt with 70% similarity]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt
t/db_dependent/Koha/KeyboardShortcuts.t [new file with mode: 0644]

index af26745..0fb8270 100644 (file)
@@ -35,7 +35,7 @@ Koha::KeyboardShortcuts - Koha KeyboardShortcut Object set class
 
 =cut
 
-=head3 type
+=head3 _type (internal)
 
 =cut
 
@@ -43,6 +43,10 @@ sub _type {
     return 'KeyboardShortcut';
 }
 
+=head3 object_class (internal)
+
+=cut
+
 sub object_class {
     return 'Koha::KeyboardShortcut';
 }
similarity index 93%
rename from tools/adveditorshortcuts.pl
rename to admin/adveditorshortcuts.pl
index 6e4279c..555ddc9 100755 (executable)
@@ -47,11 +47,11 @@ my $input            = new CGI;
 my $op               = $input->param('op') || 'list';
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
-    {   template_name   => "tools/adveditorshortcuts.tt",
+    {   template_name   => "admin/adveditorshortcuts.tt",
         query           => $input,
         type            => "intranet",
         authnotrequired => 1,
-        flagsrequired   => {},
+        flagsrequired   => { parameters => 'manage_keyboard_shortcuts' },
         debug           => 1,
     }
 );
diff --git a/installer/data/mysql/atomicupdate/Bug_21411_add_keyboard_shortcuts.perl b/installer/data/mysql/atomicupdate/Bug_21411_add_keyboard_shortcuts.perl
new file mode 100644 (file)
index 0000000..17c556a
--- /dev/null
@@ -0,0 +1,35 @@
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+    unless ( TableExists( 'keyboard_shortcuts' ) ) {
+        $dbh->do(q|
+            CREATE TABLE keyboard_shortcuts (
+            shortcut_name varchar(80) NOT NULL,
+            shortcut_keys varchar(80) NOT NULL,
+            PRIMARY KEY (shortcut_name)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;|
+        );
+    }
+    $dbh->do(q|
+        INSERT IGNORE INTO keyboard_shortcuts (shortcut_name, shortcut_keys) VALUES
+        ("insert_copyright","Alt-C"),
+        ("insert_copyright_sound","Alt-P"),
+        ("insert_delimiter","Ctrl-D"),
+        ("subfield_help","Ctrl-H"),
+        ("link_authorities","Shift-Ctrl-L"),
+        ("delete_field","Ctrl-X"),
+        ("delete_subfield","Shift-Ctrl-X"),
+        ("new_line","Enter"),
+        ("line_break","Shift-Enter"),
+        ("next_position","Tab"),
+        ("prev_position","Shift-Tab")
+        ;|
+    );
+    $dbh->do(q|
+        INSERT IGNORE permissions (module_bit, code, description)
+        VALUES
+        (3,'manage_keyboard_shortcuts','Manage keyboard shortcuts for advanced cataloging editor')
+        ;|
+    );
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug XXXXX - Add keyboard_shortcuts table)\n";
+}
diff --git a/installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl b/installer/data/mysql/atomicupdate/add_keyboard_shortcuts.perl
deleted file mode 100644 (file)
index a90d5a8..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-$DBversion = 'XXX';
-if( CheckVersion( $DBversion ) ) {
-    unless ( TableExists( 'keyboard_shortcuts' ) ) {
-        $dbh->do(q|
-            CREATE TABLE keyboard_shortcuts (
-            shortcut_name varchar(80) NOT NULL,
-            shortcut_keys varchar(80) NOT NULL,
-            shortcut_desc varchar(200) NOT NULL,
-            PRIMARY KEY (shortcut_name)
-            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;|
-        );
-    }
-    $dbh->do(q|
-        INSERT IGNORE INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES
-        ("insert_copyright","Alt-C","Insert copyright symbol (©)"),
-        ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"),
-        ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"),
-        ("subfield_help","Ctrl-H","Get help on current subfield"),
-        ("link_authorities","Shift-Ctrl-L","Link field to authorities"),
-        ("delete_field","Ctrl-X","Delete current field"),
-        ("delete_subfield","Shift-Ctrl-X","Delete current subfield"),
-        ("new_line","Enter","New field on next line"),
-        ("line_break","Shift-Enter","Insert line break"),
-        ("next_position","Tab","Move to next position"),
-        ("prev_position","Shift-Tab","Move to previous position")
-        ;|
-    );
-    SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug XXXXX - Add keyboard_shortcuts table)\n";
-}
index f4c9b25..d5864d1 100644 (file)
@@ -4332,7 +4332,6 @@ DROP TABLE IF EXISTS `keyboard_shortcuts`;
 CREATE TABLE keyboard_shortcuts (
 shortcut_name varchar(80) NOT NULL,
 shortcut_keys varchar(80) NOT NULL,
-shortcut_desc varchar(200) NOT NULL,
 PRIMARY KEY (shortcut_name)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 -- keyboard shortcuts
-INSERT INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES
-    ("insert_copyright","Alt-C","Insert copyright symbol (©)"),
-    ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"),
-    ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"),
-    ("subfield_help","Ctrl-H","Get help on current subfield"),
-    ("link_authorities","Shift-Ctrl-L","Link field to authorities"),
-    ("delete_field","Ctrl-X","Delete current field"),
-    ("delete_subfield","Shift-Ctrl-X","Delete current subfield"),
-    ("new_line","Enter","New field on next line"),
-    ("line_break","Shift-Enter","Insert line break"),
-    ("next_position","Tab","Move to next position"),
-    ("prev_position","Shift-Tab","Move to previous position");
+INSERT INTO keyboard_shortcuts (shortcut_name, shortcut_keys) VALUES
+    ("insert_copyright","Alt-C"),
+    ("insert_copyright_sound","Alt-P"),
+    ("insert_delimiter","Ctrl-D"),
+    ("subfield_help","Ctrl-H"),
+    ("link_authorities","Shift-Ctrl-L"),
+    ("delete_field","Ctrl-X"),
+    ("delete_subfield","Shift-Ctrl-X"),
+    ("new_line","Enter"),
+    ("line_break","Shift-Enter"),
+    ("next_position","Tab"),
+    ("prev_position","Shift-Tab");
index 9679c69..911b81f 100644 (file)
@@ -32,6 +32,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES
    ( 3, 'manage_usage_stats', 'Manage usage statistics settings'),
    ( 3, 'manage_mana', 'Manage Mana KB content sharing'),
    ( 3, 'manage_additional_fields', 'Add, edit, or delete additional custom fields for baskets or subscriptions (also requires order_manage or edit_subscription permissions)'),
+   ( 3, 'manage_keyboard_shortcuts', 'Manage keyboard shortcuts for the advanced cataloging editor'),
    ( 4, 'edit_borrowers', 'Add, modify and view patron information'),
    ( 4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries'),
    ( 6, 'place_holds', 'Place holds for patrons'),
index 1677280..f76f853 100644 (file)
             [% IF ( CAN_user_parameters_manage_additional_fields ) %]
                 <li><a href="/cgi-bin/koha/admin/additional-fields.pl">Additional fields</a></li>
             [% END %]
+            [% IF ( CAN_user_parameters_manage_keyboard_shortcuts ) %]
+                <li><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></li>
+            [% END %]
         </ul>
     [% END %]
 </div>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc
new file mode 100644 (file)
index 0000000..e04e4e7
--- /dev/null
@@ -0,0 +1,15 @@
+[%- BLOCK keyboard_shortcut_descriptions -%]
+    [% SWITCH shortcut_name %]
+    [%- CASE 'insert_copyright' -%]<span>Insert copyright symbol (©)</span>
+    [%- CASE 'insert_copyright_sound' -%]<span>Insert copyright symbol (℗) (sound recordings)</span>
+    [%- CASE 'insert_delimiter' -%]<span>Insert delimiter (‡)</span>
+    [%- CASE 'subfield_help' -%]<span>Get help on current subfield</span>
+    [%- CASE 'link_authorities' -%]<span>Link field to authorities</span>
+    [%- CASE 'delete_field' -%]<span>Delete current field</span>
+    [%- CASE 'delete_subfield' -%]<span>Delete current subfield</span>
+    [%- CASE 'new_line' -%]<span>New field on next line</span>
+    [%- CASE 'line_break' -%]<span>Insert line break</span>
+    [%- CASE 'next_position' -%]<span>Move to next position</span>
+    [%- CASE 'prev_position' -%]<span>Move to previous position</span>
+    [%- END -%]
+[%- END -%]
index 0e40101..d149cde 100644 (file)
             Manage Mana KB content sharing
         </span>
         <span class="permissioncode">([% name | html %])</span>
+    [%- CASE 'manage_keyboard_shortcuts' -%]
+        <span class="sub_permission manage_keyboard_shortcuts_subpermission">
+            Manage keyboard shortcuts for the advanced cataloging editor
+        </span>
+        <span class="permissioncode">([% name | html %])</span>
     [%- CASE 'edit_borrowers' -%]
         <span class="sub_permission edit_borrowers_subpermission">
             Add, modify and view patron information
index 60c0f57..2352bc8 100644 (file)
                     <dt><a href="/cgi-bin/koha/admin/additional-fields.pl">Additional fields</a></dt>
                     <dd>Add additional fields to certain tables</dd>
                     [% END %]
+                    [% IF ( CAN_user_parameters_manage_keyboard_shortcuts ) %]
+                        <dt><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></dt>
+                        <dd>Define which keys trigger actions in the advanced cataloging editor</dd>
+                    [% END %]
                 </dl>
             [% END %]
             </div>
@@ -2,17 +2,18 @@
 [% USE Asset %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Tools &rsaquo; Advanced editor shortcuts</title>
+<title>Koha &rsaquo; Administration &rsaquo; Advanced editor shortcuts</title>
 [% INCLUDE 'doc-head-close.inc' %]
 </head>
-<body id="adveditor_shortcuts" class="tools">
+<body id="adveditor_shortcuts" class="admin">
     [% INCLUDE 'header.inc' %]
-    [% INCLUDE 'cat-search.inc' %]
+    [% INCLUDE 'prefs-admin-search.inc' %]
+    [% PROCESS 'keyboard_shortcuts.inc' %]
 
 <div id="breadcrumbs">
     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
-    <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
-    <a href="/cgi-bin/koha/tools/adveditorshortcuts.pl">Advanced editor shortcuts</a>
+    <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;
+    <a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Advanced editor shortcuts</a>
 </div>
 
 <div class="main container-fluid">
                     <li>Control key is "Ctrl"</li>
                     <li>Alt key is "Alt"</li>
                     <li>Shift is "Shift"</li>
-                    <li>If combing multiple keys they must be in specified order: Shift-Cmd-Ctrl-Alt</li>
+                    <li>If combining multiple keys they must be in specified order: Shift-Cmd-Ctrl-Alt</li>
                     <li><a href="https://codemirror.net/doc/manual.html#keymaps">More documentation on defining key maps</a></li>
                 </ul>
 
-                <form id="adveditor_shortcuts" method="post" action="/cgi-bin/koha/tools/adveditorshortcuts.pl">
+                <form id="adveditor_shortcuts" method="post" action="/cgi-bin/koha/admin/adveditorshortcuts.pl">
+                    <fieldset>
                     <input type=hidden name="op" value="save" />
 
                     <table id="adv_editor_keyboard_shortcuts">
@@ -40,7 +42,7 @@
                         <tbody>
                            [% FOREACH shortcut IN shortcuts %]
                         <tr>
-                            <td><label for="shortcut_keys">[% shortcut.shortcut_desc | html %]</label></td>
+                            <td><label for="shortcut_keys">[% PROCESS keyboard_shortcut_descriptions shortcut_name=shortcut.shortcut_name %]</label></td>
                             <td>
                                 <input type="hidden" name="shortcut_name" value="[% shortcut.shortcut_name | html %]">
                                 <input type="text" name="shortcut_keys" value="[% shortcut.shortcut_keys | html %]">
@@ -48,7 +50,8 @@
                         </tr>
                    [% END %]
                    </table>
-                   <input type="submit" value="Save shortcuts">
+                   </fieldset>
+                   </fieldset class="action"><input type="submit" value="Save shortcuts"></fieldset>
                </form>
 
            </main>
@@ -56,7 +59,7 @@
 
         <div class="col-sm-2 col-sm-pull-10">
             <aside>
-                [% INCLUDE 'tools-menu.inc' %]
+                [% INCLUDE 'admin-menu.inc' %]
             </aside>
         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
     </div> <!-- /.row -->
index 9057530..fb00119 100644 (file)
@@ -16,6 +16,7 @@
    </div>
 
 [% INCLUDE 'header.inc' %]
+[% PROCESS 'keyboard_shortcuts.inc' %]
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a> &rsaquo; Editor</div>
 
 </div>
 
 <div id="shortcuts-contents" style="display: none">
-<a id="redefine_shortcuts" href="/cgi-bin/koha/tools/adveditorshortcuts.pl">Redefine shortcuts</a>
+<a id="redefine_shortcuts" href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Redefine shortcuts</a>
 <table class="table table-condensed">
     <thead>
         <tr>
         [% FOREACH shortcut IN shortcuts %]
             <tr>
                 <td>[% shortcut.shortcut_keys | html %]</td>
-                <td>[% shortcut.shortcut_desc | html %]</td>
+                <td>[% PROCESS keyboard_shortcut_descriptions shortcut_name=shortcut.shortcut_name %]</td>
             </tr>
         [% END %]
         <tr>
diff --git a/t/db_dependent/Koha/KeyboardShortcuts.t b/t/db_dependent/Koha/KeyboardShortcuts.t
new file mode 100644 (file)
index 0000000..6dd77e0
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+# Copyright 2019 Koha Development team
+#
+# This file is part of Koha
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+use Test::More tests => 4;
+
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+BEGIN {
+    use_ok('Koha::KeyboardShortcuts');
+}
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder = t::lib::TestBuilder->new;
+my $nb_of_shortcuts = Koha::KeyboardShortcuts->search->count;
+
+my $shortcut_hash = {
+    shortcut_name => 'this_cut',
+    shortcut_keys => 'Ctrl-D',
+    shortcut_desc => 'DOES_THE_THING'
+};
+
+my $new_shortcut = Koha::KeyboardShortcut->new($shortcut_hash)->store;
+is( Koha::KeyboardShortcuts->count, $nb_of_shortcuts + 1, 'Adding a new shortcut increases count');
+
+my $found_shortcut = Koha::KeyboardShortcuts->find( "this_cut" );
+is_deeply( $found_shortcut->unblessed, $shortcut_hash, 'We find the right object');
+
+$found_shortcut->delete;
+is( Koha::KeyboardShortcuts->count, $nb_of_shortcuts, 'Deleting a new shortcut works');
+
+$schema->storage->txn_rollback;