From 75670f66c25941399ec4ab2271a449af24895903 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 27 Sep 2018 13:15:50 +0000 Subject: [PATCH] Bug 17047: add a dedicated page for Mana setup Signed-off-by: Michal Denar Signed-off-by: Michal Denar Signed-off-by: Kyle M Hall --- admin/share_content.pl | 89 ++++++++++ .../intranet-tmpl/lib/jquery/activatemana.js | 18 -- .../prog/en/modules/admin/admin-home.tt | 10 +- .../prog/en/modules/admin/preferences.tt | 1 - .../admin/preferences/web_services.pref | 1 - .../prog/en/modules/admin/share_content.tt | 158 ++++++++++++++++++ svc/mana/token | 55 ------ 7 files changed, 254 insertions(+), 78 deletions(-) create mode 100755 admin/share_content.pl delete mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/share_content.tt delete mode 100755 svc/mana/token diff --git a/admin/share_content.pl b/admin/share_content.pl new file mode 100755 index 0000000000..d900b3e6d6 --- /dev/null +++ b/admin/share_content.pl @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +# 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 . + +use Modern::Perl; + +use CGI qw ( -utf8 ); +use JSON; +use HTTP::Request; + +use C4::Auth; +use C4::Output; + +use Koha::SharedContent; + +my $query = new CGI; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "admin/share_content.tt", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { parameters => '*' }, + debug => 1, + } +); + +my $op = $query->param('op') || q||; + +if ( $op eq 'save' ) { + my $auto_share = $query->param('autosharewithmana'); + my $mana = $query->param('mana'); + + C4::Context->set_preference('Mana', $mana); + + if ( $auto_share ne '' ) { + C4::Context->set_preference('AutoShareWithMana', 'subscription'); + } else { + C4::Context->set_preference('AutoShareWithMana', ''); + } +} + +if ( $op eq 'reset' ) { + C4::Context->set_preference('ManaToken', ''); +} + +if ( $op eq 'send' ) { + my $name = $query->param('lastname'); + my $firstname = $query->param('firstname'); + my $email = $query->param('email'); + + my $content = to_json({firstname => $firstname, + lastname => $name, + email => $email}); + + my $mana_ip = C4::Context->config('mana_config'); + my $url = "$mana_ip/getsecuritytoken"; + my $request = HTTP::Request->new( POST => $url ); + $request->content($content); + my $result = Koha::SharedContent::process_request($request); + + $template->param( result => $result ); + + if ( $result->{code} eq '201' && $result->{token} ) { + C4::Context->set_preference('ManaToken', $result->{token}); + } +} + + +my $mana_url = C4::Context->config('mana_config') || ''; + +$template->param( + mana_url => $mana_url, +); + +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js b/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js deleted file mode 100644 index 0e9b2e2eb2..0000000000 --- a/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js +++ /dev/null @@ -1,18 +0,0 @@ -$(document).ready(function(){ - $("#activatemana").on("click", function(){ - var mylastname = $("#lastname").val() - var myfirstname = $("#firstname").val() - var myemail = $("#email").val() - $.ajax( { - type: "POST", - url: "/cgi-bin/koha/svc/mana/token", - data: { lastname: mylastname, firstname: myfirstname, email: myemail}, - dataType: "json", - }) - .done(function(result){ - $("#pref_ManaToken").val(result.token); - $("#pref_ManaToken").trigger("input"); - }); - return false; - }); -}); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index e1e77674f6..6212e30e7a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -14,10 +14,10 @@
[% IF ( Koha.Preference('Mana') == 2) %] -
+

You haven't decided if you want to activate Mana Knowlede Base, please let us know by clicking

-
Here
-
+
Here
+
[% END %]

Koha administration

@@ -192,6 +192,10 @@
Share your usage statistics
Share with the Koha community the usage statistics of your Koha installation.
[% END %] + [% IF ( CAN_user_parameters ) %] +
Using Mana-KB
+
Share content (subscriptions, reports) with Koha communty
+ [% END %] [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index d9d705ce57..6cc0570db3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -197,7 +197,6 @@ [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% Asset.js("js/ajax.js") | $raw %] [% Asset.js("js/pages/preferences.js") | $raw %] - [% Asset.js("lib/jquery/activatemana.js") | $raw %] [%# Add WYSIWYG editor for htmlarea system preferences %] [% INCLUDE 'wysiwyg-systempreferences.inc' %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref index fe4a942bf3..7b13f8089a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref @@ -71,7 +71,6 @@ Web services: - "Security token used to authenticate on mana:" - pref: ManaToken class: Text - -
You need a security token to authenticate on Mana. If this sytem preference is empty, please fill in the following form, you will receive an email to confirm and activate your token.
First name
Last name
Email address
- - 'Fields automatically shared with mana' - pref: AutoShareWithMana diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/share_content.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/share_content.tt new file mode 100644 index 0000000000..9fce6f63fb --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/share_content.tt @@ -0,0 +1,158 @@ +[% USE raw %] +[% USE Asset %] +[% SET footerjs = 1 %] +[% USE Koha %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › Koha usage statistics +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
+
+
+
+ [% IF result.code != 201 && result.msg %] + + [% END %] + + [% IF result.code == 201 %] + + [% END %] + + [% UNLESS (mana_url) %] + + [% END %] + +

Share content with the Koha community using Mana KB

+

Mana-kb is a global knowledge base for library-centric data. It has been designed initially to interact with Koha, the Open Source ILS, but can be used by any other software.

+ +

Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana. The informations shared with Mana KB are shared under the CC-0 license. More infos about CC-0 license here.

+ +

Learn more about Mana on the official documentation.

+ + [% IF (mana_url) %] +

Your Mana KB server is currently: [% mana_url | url %]

+ [% END %] + +
+
+
    +
  1. + + +
    Enable Mana allow you to search, import and comment content from Mana server, and, to share your own.
    +
  2. +
  3. + + [% IF Koha.Preference('AutoShareWithMana').grep('subscription').size == 0 %] + + [% ELSE %] + + [% END %] +
    If checked, new subscriptions you created yourself will be automatically shared with Mana KB.
    +
  4. +
  5. + + +
  6. +
+
+
+ + [% UNLESS Koha.Preference('ManaToken') %] +

Configure Mana KB

+

Once you have enabled Mana, let's start to set it up. Type your first name, last name, email address and click on send. This will send a account creation request to Mana KB that will respond back with a Mana token (a crypted id that uniquely identify your Koha). This token will automatically be saved in your database. Just after that, you will receive an email. Read it and follow the instructions.

+ [% END %] + + [% IF Koha.Preference('ManaToken') %] +
+
+ Mana KB token +
    +
  1. + + +
    Your unique security token used for authentication on Mana KB service (anti spam).
    +
  2. +
  3. + + +
  4. +
+
+
+ [% ELSE %] +
+
+
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. + + +
  8. +
+
+
+ [% END %] +
+
+ +
+ +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") | $raw %] + +[% END %] +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/svc/mana/token b/svc/mana/token deleted file mode 100755 index 3ea6254358..0000000000 --- a/svc/mana/token +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/perl - -# Copyright 2016 BibLibre Baptiste Wojtkowski -# -# 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 . -# - - -use Modern::Perl; - -use Koha::SharedContent; -use C4::Auth qw(check_cookie_auth); - -use CGI; -use JSON; - -my $input = new CGI; -binmode STDOUT, ":encoding(UTF-8)"; -print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); - -my ( $auth_status, $sessionID ) = - check_cookie_auth( $input->cookie('CGISESSID'), - { serials => 'create_subscription' } ); - -if ( $auth_status ne "ok" ) { - exit 0; -} - -my $mana_ip = C4::Context->config('mana_config'); - -my $url = "$mana_ip/getsecuritytoken"; -my $request = HTTP::Request->new( POST => $url ); - -my $content; -$content->{ firstname }= $input->param("firstname"); -$content->{ lastname }= $input->param("lastname"); -$content->{ email }= $input->param("email"); -my $json = to_json( $content, { utf8 => 1 } ); -$request->content($json); -my $result = Koha::SharedContent::process_request($request); - -print(to_json($result)); -- 2.17.2 (Apple Git-113)