Merge pull request #3282 from elarifr/develop-userapikey

fix user role and store fake api_key if api module no enabled
This commit is contained in:
Laurent Destailleur 2015-07-19 23:28:36 +02:00
commit d08a1ec116

View File

@ -10,6 +10,7 @@
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2013-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -825,7 +826,8 @@ if (($action == 'create') || ($action == 'adduserldap'))
} }
print '</td></tr>'; print '</td></tr>';
if(! empty($conf->api->enabled)) { if(! empty($conf->api->enabled))
{
// API key // API key
$generated_api_key = ''; $generated_api_key = '';
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@ -836,50 +838,56 @@ if (($action == 'create') || ($action == 'adduserldap'))
if (! empty($conf->use_javascript_ajax)) if (! empty($conf->use_javascript_ajax))
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject"'); print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject"');
print '</td></tr>'; print '</td></tr>';
}
else
{
// PARTIAL WORKAROUND
$generated_fake_api_key=getRandomPassword(false);
print '<input type="hidden" name="api_key" value="'.$generated_fake_api_key.'">';
}
// Administrator // Administrator
if (! empty($user->admin)) if (! empty($user->admin))
{
print '<tr><td>'.$langs->trans("Administrator").'</td>';
print '<td>';
print $form->selectyesno('admin',GETPOST('admin'),1);
if (! empty($conf->multicompany->enabled) && ! $user->entity && empty($conf->multicompany->transverse_mode))
{ {
print '<tr><td>'.$langs->trans("Administrator").'</td>'; if (! empty($conf->use_javascript_ajax))
print '<td>';
print $form->selectyesno('admin',GETPOST('admin'),1);
if (! empty($conf->multicompany->enabled) && ! $user->entity && empty($conf->multicompany->transverse_mode))
{ {
if (! empty($conf->use_javascript_ajax)) print '<script type="text/javascript">
{ $(function() {
print '<script type="text/javascript"> $("select[name=admin]").change(function() {
$(function() { if ( $(this).val() == 0 ) {
$("select[name=admin]").change(function() { $("input[name=superadmin]")
if ( $(this).val() == 0 ) { .prop("disabled", true)
$("input[name=superadmin]") .prop("checked", false);
.prop("disabled", true) $("select[name=entity]")
.prop("checked", false); .prop("disabled", false);
$("select[name=entity]") } else {
.prop("disabled", false); $("input[name=superadmin]")
} else { .prop("disabled", false);
$("input[name=superadmin]") }
.prop("disabled", false);
}
});
$("input[name=superadmin]").change(function() {
if ( $(this).is(":checked") ) {
$("select[name=entity]")
.prop("disabled", true);
} else {
$("select[name=entity]")
.prop("disabled", false);
}
});
}); });
</script>'; $("input[name=superadmin]").change(function() {
} if ( $(this).is(":checked") ) {
$checked=($_POST["superadmin"]?' checked':''); $("select[name=entity]")
$disabled=($_POST["superadmin"]?'':' disabled'); .prop("disabled", true);
print '<input type="checkbox" name="superadmin" value="1"'.$checked.$disabled.' /> '.$langs->trans("SuperAdministrator"); } else {
$("select[name=entity]")
.prop("disabled", false);
}
});
});
</script>';
} }
print "</td></tr>\n"; $checked=($_POST["superadmin"]?' checked':'');
$disabled=($_POST["superadmin"]?'':' disabled');
print '<input type="checkbox" name="superadmin" value="1"'.$checked.$disabled.' /> '.$langs->trans("SuperAdministrator");
} }
print "</td></tr>\n";
} }
// Type // Type