From 47ffec1fd4939fec068417db4e4e841ecb60674f Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 26 Aug 2019 11:18:21 +0900 Subject: [PATCH] Add JSON additional ACL field to edit user page --- 4dev/database/table/edit_user.sql | 1 + www/includes/edit_base.inc | 1 + www/includes/table_arrays/array_edit_users.inc | 13 +++++++++++-- www/layout/admin/javascript/edit.jq.js | 10 +++++++--- www/layout/admin/javascript/edit.pt.js | 10 +++++++--- www/lib/CoreLibs/Output/Form/Generate.inc | 11 ++++++++++- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/4dev/database/table/edit_user.sql b/4dev/database/table/edit_user.sql index 1051b7ee..3cdd28aa 100644 --- a/4dev/database/table/edit_user.sql +++ b/4dev/database/table/edit_user.sql @@ -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, diff --git a/www/includes/edit_base.inc b/www/includes/edit_base.inc index 2dfc2517..d4fc00a8 100644 --- a/www/includes/edit_base.inc +++ b/www/includes/edit_base.inc @@ -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"); diff --git a/www/includes/table_arrays/array_edit_users.inc b/www/includes/table_arrays/array_edit_users.inc index 1c0bd35b..55a10769 100644 --- a/www/includes/table_arrays/array_edit_users.inc +++ b/www/includes/table_arrays/array_edit_users.inc @@ -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", diff --git a/www/layout/admin/javascript/edit.jq.js b/www/layout/admin/javascript/edit.jq.js index ac3aa7e8..a0ea1601 100644 --- a/www/layout/admin/javascript/edit.jq.js +++ b/www/layout/admin/javascript/edit.jq.js @@ -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); diff --git a/www/layout/admin/javascript/edit.pt.js b/www/layout/admin/javascript/edit.pt.js index a0e50eb1..0f66430b 100644 --- a/www/layout/admin/javascript/edit.pt.js +++ b/www/layout/admin/javascript/edit.pt.js @@ -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); diff --git a/www/lib/CoreLibs/Output/Form/Generate.inc b/www/lib/CoreLibs/Output/Form/Generate.inc index 3cee2666..e37218fe 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.inc +++ b/www/lib/CoreLibs/Output/Form/Generate.inc @@ -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 %s: %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];