Bug 20568: Move value => client_id + secret
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 16 Apr 2018 19:04:26 +0000 (16:04 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 9 May 2018 15:55:59 +0000 (12:55 -0300)
This patch addresses the request from Julian that api keys are expected
to be client id/secret pairs.

It does so by
- Adding 'client_id' and 'secret' columns
- Removing 'value'

Tests got adjusted and so controller scripts and templates.
Both libs and tests changes have been squashed. This ones remain in
order to keep Owen's attribution on the template changes and avoid
rebase conflicts.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/members/apikeys.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-apikeys.tt
members/apikeys.pl
opac/opac-apikeys.pl

index 280368b..0c731b5 100644 (file)
@@ -61,7 +61,7 @@
                 [% END %]
 
                 [% IF CAN_user_borrowers_edit_borrowers %]
-                    <li><a id="apikeys" href="/cgi-bin/koha/members/apikeys.pl?patron_id=[% borrowernumber %]">Manage API keys</a></li>
+                    <li><a id="apikeys" href="/cgi-bin/koha/members/apikeys.pl?patron_id=[% patron.borrowernumber %]">Manage API keys</a></li>
                 [% ELSE %]
                     <li class="disabled"><a data-toggle="tooltip" data-placement="left" title="You are not authorized to manage API keys" id="apikeys" href="#">Manage API keys</a></li>
                 [% END %]
index e710efd..93ef624 100644 (file)
@@ -27,7 +27,7 @@
                     <input type="hidden" name="patron_id" value="[% patron.id %]" />
                     <input type="hidden" name="op" value="generate" />
                     <fieldset class="brief">
-                        <legend>Generate new key</legend>
+                        <legend>Generate new client id/secret pair</legend>
                         <ol>
                             <li>
                                 <label for="description">Description: </label>
                 <div id="keys">
                     [% IF api_keys && api_keys.size > 0 %]
                         <p>
-                            <button class="btn btn-default btn-xs toggle_element" type="submit" id="show-api-form" data-element="#add-api-key"><i class="fa fa-plus"></i> Generate a new key</button>
+                            <button class="btn btn-default btn-xs toggle_element" type="submit" id="show-api-form" data-element="#add-api-key"><i class="fa fa-plus"></i> Generate a new client id/key pair</button>
                         </p>
                         <table>
                             <thead>
                                 <tr>
                                     <th>Description</th>
-                                    <th>Key</th>
+                                    <th>Client ID</th>
+                                    <th>Secret</th>
                                     <th>Active</th>
                                     <th>Actions</th>
                                 </tr>
                                 [% FOREACH key IN api_keys %]
                                     <tr>
                                         <td>[% key.description %]</td>
-                                        <td>[% key.value %]</td>
+                                        <td>[% key.client_id %]</td>
+                                        <td>[% key.secret %]</td>
                                         <td>[% IF key.active %]Yes[% ELSE %]No[% END %]</td>
                                         <td>
                                             <form action="/cgi-bin/koha/members/apikeys.pl" method="post">
                                                 <input type="hidden" name="patron_id" value="[% patron.id %]" />
-                                                <input type="hidden" name="key" value="[% key.value %]" />
+                                                <input type="hidden" name="key" value="[% key.id %]" />
                                                 <input type="hidden" name="op" value="delete" />
                                                 <button class="btn btn-default btn-xs delete" type="submit"><i class="fa fa-trash"></i> Delete</button>
                                             </form>
                                             <form action="/cgi-bin/koha/members/apikeys.pl" method="post">
                                                 <input type="hidden" name="patron_id" value="[% patron.id %]" />
-                                                <input type="hidden" name="key" value="[% key.value %]" />
+                                                <input type="hidden" name="key" value="[% key.id %]" />
                                                 [% IF key.active %]
                                                     <input type="hidden" name="op" value="revoke" />
                                                     <button class="btn btn-default btn-xs" type="submit"><i class="fa fa-remove"></i> Revoke</button>
@@ -83,7 +85,7 @@
                             </tbody>
                         </table>
                     [% ELSE %]
-                        <div class="dialog message">No keys defined for the current patron. <a href="#" class="toggle_element" data-element="#add-api-key" id="show-api-form"><i class="fa fa-plus"></i> Generate a new key</div>
+                        <div class="dialog message">No keys defined for the current patron. <a href="#" class="toggle_element" data-element="#add-api-key" id="show-api-form"><i class="fa fa-plus"></i> Generate a new client id/secret pair</div>
                     [% END %]
                 </div>
             </div>
index 7feecdc..7aaddf4 100644 (file)
@@ -33,7 +33,7 @@
                     </p>
                     <form id="add-api-key" action="/cgi-bin/koha/opac-apikeys.pl" method="post">
                         <fieldset>
-                            <legend>Generate new key</legend>
+                            <legend>Generate new client id/secret pair</legend>
                             <input type="hidden" name="patron_id" value="[% patron.id %]" />
                             <input type="hidden" name="op" value="generate" />
                             <label for="description">Description: </label>
@@ -48,7 +48,8 @@
                             <thead>
                                 <tr>
                                     <th>Description</th>
-                                    <th>Key</th>
+                                    <th>Client ID</th>
+                                    <th>Secret</th>
                                     <th>Active</th>
                                     <th>Actions</th>
                                 </tr>
                                 [% FOREACH key IN api_keys %]
                                     <tr>
                                         <td>[% key.description %]</td>
-                                        <td>[% key.value %]</td>
+                                        <td>[% key.client_id %]</td>
+                                        <td>[% key.secret %]</td>
                                         <td>[% IF key.active %]Yes[% ELSE %]No[% END %]</td>
                                         <td>
                                             <form action="/cgi-bin/koha/opac-apikeys.pl" method="post" class="form-inline">
-                                                <input type="hidden" name="key" value="[% key.value %]" />
+                                                <input type="hidden" name="key" value="[% key.id %]" />
                                                 <input type="hidden" name="op" value="delete" />
                                                 <button class="btn btn-link btn-xs delete-key" type="submit"><i class="fa fa-trash"></i> Delete</button>
                                             </form>
                                             <form action="/cgi-bin/koha/opac-apikeys.pl" method="post" class="form-inline">
-                                                <input type="hidden" name="key" value="[% key.value %]" />
+                                                <input type="hidden" name="key" value="[% key.id %]" />
                                                 [% IF key.active %]
                                                     <input type="hidden" name="op" value="revoke" />
                                                     <button class="btn btn-link btn-xs" type="submit"><i class="fa fa-remove"></i> Revoke</button>
index 183483b..975ca86 100755 (executable)
@@ -67,8 +67,8 @@ if ($op) {
     }
 
     if ( $op eq 'delete' ) {
-        my $api_key = $cgi->param('key');
-        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, value => $api_key });
+        my $api_key_id = $cgi->param('key');
+        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
         if ($key) {
             $key->delete;
         }
@@ -77,8 +77,8 @@ if ($op) {
     }
 
     if ( $op eq 'revoke' ) {
-        my $api_key = $cgi->param('key');
-        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, value => $api_key });
+        my $api_key_id = $cgi->param('key');
+        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
         if ($key) {
             $key->active(0);
             $key->store;
@@ -88,8 +88,8 @@ if ($op) {
     }
 
     if ( $op eq 'activate' ) {
-        my $api_key = $cgi->param('key');
-        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, value => $api_key });
+        my $api_key_id = $cgi->param('key');
+        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
         if ($key) {
             $key->active(1);
             $key->store;
index 7a776f3..66167e8 100755 (executable)
@@ -47,7 +47,6 @@ if ( not defined $patron
     exit;
 }
 
-
 my $op = $cgi->param('op');
 
 if ($op) {
@@ -63,8 +62,8 @@ if ($op) {
     }
 
     if ($op eq 'delete') {
-        my $key = $cgi->param('key');
-        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, value => $key});
+        my $key_id  = $cgi->param('key');
+        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
         if ($api_key) {
             $api_key->delete;
         }
@@ -73,8 +72,8 @@ if ($op) {
     }
 
     if ($op eq 'revoke') {
-        my $key = $cgi->param('key');
-        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, value => $key });
+        my $key_id  = $cgi->param('key');
+        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
         if ($api_key) {
             $api_key->active(0);
             $api_key->store;
@@ -84,8 +83,8 @@ if ($op) {
     }
 
     if ($op eq 'activate') {
-        my $key = $cgi->param('key');
-        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, value => $key });
+        my $key_id  = $cgi->param('key');
+        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
         if ($api_key) {
             $api_key->active(1);
             $api_key->store;