Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #21 add a way to get ldap conf from koha-conf file #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package Koha::Plugin::Com::Biblibre::PatronImport::Controller::ConfigHandler;

use Modern::Perl;
use Mojo::Base 'Mojolicious::Controller';
use YAML::XS qw(Dump LoadFile);

use C4::Context;
use Koha::Plugin::Com::Biblibre::PatronImport::Helper::SQL qw( :DEFAULT );
use Koha::Plugin::Com::Biblibre::PatronImport::Helper::Config;

Expand Down Expand Up @@ -43,7 +45,34 @@ sub configapply {

print $cgi->redirect('/cgi-bin/koha/plugins/run.pl?class=Koha%3A%3APlugin%3A%3ACom%3A%3ABiblibre%3A%3APatronImport&method=configure');
return;
}

sub get_ldap_conf {
my $c = shift->openapi->valid_input or return;

my $ldap_hash = C4::Context->config("ldapserver");

unless ($ldap_hash) {
return $c->render(
status => 404,
openapi => {
error =>
"No 'ldapserver' in server hash from KOHA_CONF: $ENV{KOHA_CONF}"
}
);
}
my $ldap_conf = $ldap_hash->{ldapserver};

return $c->render(
status => 200,
openapi => {
host => $ldap_conf->{hostname} || '',
anonymous_bind => $ldap_conf->{anonymous_bind},
user => $ldap_conf->{user} || '',
password => $ldap_conf->{pass} || '',
search_base => $ldap_conf->{base} || '',
}
);
}

1;
1;
147 changes: 104 additions & 43 deletions Koha/Plugin/Com/Biblibre/PatronImport/openapi.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

{
"/history/by_run/{run_id}": {
"get": {
"x-mojo-to": "Com::Biblibre::PatronImport::Controller::History#by_run",
"operationId": "PatronImportHistoryRun",
"tags": ["patron-import"],
"tags": [
"patron-import"
],
"parameters": [
{
"name": "run_id",
Expand All @@ -23,7 +24,8 @@
"contains",
"exact",
"starts_with",
"ends_with" ]
"ends_with"
]
},
{
"name": "_order_by",
Expand Down Expand Up @@ -58,27 +60,27 @@
"200": {
"description": "A run patron history",
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"run_id": {
"description": "The run identifier",
"type": "integer"
},
"borrowernumber": {
"description": "The patron identifier",
"type": "integer"
},
"action": {
"description": "The action name",
"type": "string"
},
"action_date": {
"description": "The action date",
"type": "string"
}
"type": "array",
"items": {
"type": "object",
"properties": {
"run_id": {
"description": "The run identifier",
"type": "integer"
},
"borrowernumber": {
"description": "The patron identifier",
"type": "integer"
},
"action": {
"description": "The action name",
"type": "string"
},
"action_date": {
"description": "The action date",
"type": "string"
}
}
}
}
},
Expand All @@ -97,46 +99,105 @@
"403": {
"description": "No permission",
"schema": {
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
}
}
}
}
},
"404": {
"description": "No history for the given run",
"schema": {
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
}
}
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
}
}
}
}
}
},
"x-koha-authorization": {
"permissions": {
"parameters": "reports"
}
}
}
},
"/get-ldap-conf": {
"get": {
"x-mojo-to": "Com::Biblibre::PatronImport::Controller::ConfigHandler#get_ldap_conf",
"operationId": "PatronImportLdapConf",
"tags": [
"patron-import",
"ldap"
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "The ldap configuration",
"schema": {
"type": "object",
"properties": {
"host": {
"description": "Host or IP adress of the LDAP server",
"type": "string"
},
"anonymous_bind": {
"description": "Anonymous bind option",
"type": "boolean"
},
"user": {
"description": "LDAP user",
"type": "string"
},
"password": {
"description": "LDAP user's password",
"type": "string"
},
"search_base": {
"description": "LDAP search base",
"type": "string"
}
}
}
},
"404": {
"description": "No LDAP configuration found",
"schema": {
"type": "object",
"properties": {
"error": {
"description": "Error message",
"type": "string"
}
}
}
},
"x-koha-authorization": {
"permissions": {
"borrowers": "edit_borrowers"
}
}
}
}
}
}

}
39 changes: 37 additions & 2 deletions Koha/Plugin/Com/Biblibre/PatronImport/templates/import/edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@
$('#csv-file').hide();
}
});

$('.ldap-conf-link').click(function () {
$.ajax({
url: '/api/v1/contrib/patron-import/get-ldap-conf',
success: function(response) {
var fields = {
'ldap_host': response.host,
'ldap_user': response.user,
'ldap_pass': response.password,
'search_base': response.search_base
};

$.each(fields, function(name, newValue) {
var input = $('input[name="' + name + '"]');
input.val(newValue);
});

var anonymousBind = $('input[name="anonymous_bind"]');
anonymousBind.prop('checked', response.anonymous_bind === true || response.anonymous_bind === '1' || response.anonymous_bind === 1);

$('#ldap-conf-logs').addClass('alert alert-success');
$('#ldap-conf-logs').text("Configuration loaded don't forget to save it");
},
error: function(xhr, status, error) {
var errorMessage = xhr.responseJSON && xhr.responseJSON.error ? xhr.responseJSON.error : 'Something is wrong, check the logs';
$('#ldap-conf-logs').addClass('alert alert-danger');
$('#ldap-conf-logs').text(errorMessage);
}
});
});
});
</script>
</head>
Expand Down Expand Up @@ -214,8 +244,13 @@
</fieldset>

<fieldset class="rows" id="ldap">
<legend>LDAP settings</legend>

<div class="ldap-conf-header">
<legend>LDAP settings</legend>
<a class="ldap-conf-link btn btn-link btn-sm">
<i class="fa fa-gears"></i> Get configuration settings from 'koha-conf' file
</a>
</div>
<div id="ldap-conf-logs"></div>
<ol>
<li>
<label for="ldap_host">Host or IP address :</label>
Expand Down