Add JSON additional ACL field to edit user page

This commit is contained in:
Clemens Schwaighofer
2019-08-26 11:18:21 +09:00
parent 72c6844e74
commit 47ffec1fd4
6 changed files with 37 additions and 9 deletions

View File

@@ -32,6 +32,7 @@ CREATE TABLE edit_user (
locked SMALLINT DEFAULT 0,
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
additional_acl JSONB, -- additional ACL as JSON string (can be set by other pages)
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,

View File

@@ -340,6 +340,7 @@ if ($form->my_page_name == 'edit_order') {
$elements[] = $form->formCreateElement("edit_language_id");
$elements[] = $form->formCreateElement("edit_scheme_id");
$elements[] = $form->formCreateElementListTable("edit_access_user");
$elements[] = $form->formCreateElement("additional_acl");
break;
case "edit_schemes":
$elements[] = $form->formCreateElement("enabled");

View File

@@ -103,7 +103,8 @@ $edit_users = array (
"email" => array (
"value" => $GLOBALS["email"],
"output_name" => "E-Mail",
"type" => "text"
"type" => "text",
"error_check" => "email"
),
"last_name" => array (
"value" => $GLOBALS["last_name"],
@@ -173,7 +174,15 @@ $edit_users = array (
"1" => "Yes",
"0" => "No"
)
)
),
"additional_acl" => array (
"value" => $GLOBALS["additional_acl"],
"output_name" => "Additional ACL (as JSON)",
"type" => "textarea",
"error_check" => "json",
"rows" => 10,
"cols" => 60
),
),
"load_query" => "SELECT edit_user_id, username, enabled, debug, db_debug, strict, locked, login_error_count FROM edit_user ORDER BY username",
"table_name" => "edit_user",

View File

@@ -606,14 +606,15 @@ function html_options(name, data, selected = '', options_only = false, return_st
// METHOD: html_options
// PARAMS: name/id, array for the options,
// selected item uid
// multiple [def false] if this is true, the drop down will be turned into multiple select
// multiple [def 0] if this is 1 or larger, the drop down will be turned into multiple select
// the number sets the size value unless it is 1, then it is default
// options_only [def false] if this is true, it will not print the select part
// return_string [def false]: return as string and not as element
// sort [def '']: if empty as is, else allowed 'keys', 'values' all others are ignored
// RETURN: html with build options block
// DESC : creates an select/options drop down block.
// the array needs to be key -> value format. key is for the option id and value is for the data output
function html_options_block(name, data, selected = '', multiple = false, options_only = false, return_string = false, sort = '')
function html_options_block(name, data, selected = '', multiple = 0, options_only = false, return_string = false, sort = '')
{
var content = [];
var element_select;
@@ -622,8 +623,11 @@ function html_options_block(name, data, selected = '', multiple = false, options
var data_list = []; // for sorted output
var value;
var option;
if (multiple === true) {
if (multiple > 0) {
select_options.multiple = '';
if (multiple > 1) {
select_options.size = multiple;
}
}
// set outside select, gets stripped on return if options only is true
element_select = cel('select', name, '', [], select_options);

View File

@@ -684,14 +684,15 @@ function html_options(name, data, selected = '', options_only = false, return_st
// METHOD: html_options
// PARAMS: name/id, array for the options,
// selected item uid
// multiple [def false] if this is true, the drop down will be turned into multiple select
// multiple [def 0] if this is 1 or larger, the drop down will be turned into multiple select
// the number sets the size value unless it is 1, then it is default
// options_only [def false] if this is true, it will not print the select part
// return_string [def false]: return as string and not as element
// sort [def '']: if empty as is, else allowed 'keys', 'values' all others are ignored
// RETURN: html with build options block
// DESC : creates an select/options drop down block.
// the array needs to be key -> value format. key is for the option id and value is for the data output
function html_options_block(name, data, selected = '', multiple = false, options_only = false, return_string = false, sort = '')
function html_options_block(name, data, selected = '', multiple = 0, options_only = false, return_string = false, sort = '')
{
var content = [];
var element_select;
@@ -700,8 +701,11 @@ function html_options_block(name, data, selected = '', multiple = false, options
var data_list = []; // for sorted output
var value;
var option;
if (multiple === true) {
if (multiple > 0) {
select_options.multiple = '';
if (multiple > 1) {
select_options.size = multiple;
}
}
// set outside select, gets stripped on return if options only is true
element_select = cel('select', name, '', [], select_options);

View File

@@ -844,6 +844,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
//if ($value['mandatory'] && $value['error_check'])
// if error value set && somethign input, check if input okay
if ($value['error_check'] && $this->table_array[$key]['value']) {
$this->debug('ERROR CHECK', 'Key: '.$key.' => '.$value['error_check']);
// each error check can be a piped seperated value, lets split it
// $this->debug('edit', $value['error_check']);
foreach (explode('|', $value['error_check']) as $error_check) {
@@ -918,6 +919,14 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// error
}
break;
case 'json':
// check if valid json
$json_out = json_decode($this->table_array[$key]['value'], true);
$this->debug('JSON ENCODE', 'LAST ERROR: '.json_last_error());
if (json_last_error()) {
$this->msg .= sprintf($this->l->__('Please enter a valid JSON string for the field <b>%s<b>: %s'), $this->table_array[$key]['output_name'], json_last_error_msg());
}
break;
} // switch
} // for each error to check
} elseif ($value['mandatory'] &&
@@ -1585,7 +1594,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
if ($data_array['type'] == 'drop_down_db') {
$md_q = md5($data_array['query']);
while ($res = $this->dbReturn($data_array['query'])) {
$this->debug('edit', 'Q[$md_q] pos: '.$this->cursor_ext[$md_q]['pos'].' | want: '.$data_array['preset'].' | set: '.$data['preset'][$el_name]);
$this->debug('edit', 'Q['.$md_q.'] pos: '.$this->cursor_ext[$md_q]['pos'].' | want: '.$data_array['preset'].' | set: '.$data['preset'][$el_name]);
// first is default for this element
if (!$data['preset'][$el_name] && ($this->cursor_ext[$md_q]['pos'] == $data_array['preset'])) {
$data['preset'][$el_name] = $res[0];