From 3ab0104d1a8bb6f53a34afa9a7f62f795a0187f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Cort=C3=A9s=20Cano?= <38475681+TrapoSAMA@users.noreply.github.com> Date: Mon, 20 Jul 2026 20:15:11 -0400 Subject: [PATCH] Address forwarding editor review feedback --- DOCUMENTS/HANDLER_CLASSES.md | 13 --------- configs/menu.conf | 2 +- model/AliasHandler.php | 35 +++++++++++++++++------- public/delete.php | 5 ---- public/edit.php | 6 ----- public/list.php | 5 ---- public/users/edit-alias.php | 7 ----- public/users/edit-forward.php | 23 ---------------- templates/editform.tpl | 3 --- templates/users_edit-alias.tpl | 49 ---------------------------------- templates/users_main.tpl | 2 +- templates/users_menu.tpl | 2 +- tests/AliasHandlerTest.php | 49 +++++++++++++++++++++++++++++++--- 13 files changed, 74 insertions(+), 127 deletions(-) delete mode 100644 public/users/edit-alias.php delete mode 100644 public/users/edit-forward.php delete mode 100644 templates/users_edit-alias.tpl diff --git a/DOCUMENTS/HANDLER_CLASSES.md b/DOCUMENTS/HANDLER_CLASSES.md index e2896d7e..f35beb9e 100644 --- a/DOCUMENTS/HANDLER_CLASSES.md +++ b/DOCUMENTS/HANDLER_CLASSES.md @@ -167,10 +167,6 @@ public function webformConfig() 'listview' => 'list.php?table=foo', // redirect target after edit 'early_init' => 0, // 1 = call init() before set() 'user_hardcoded_field' => 'username', // required if users can access - 'user_can_create' => true, // optional per-entry-point restriction - 'user_can_list' => true, - 'user_can_delete' => true, - 'cancelview' => '', // optional Cancel link in editform.tpl ); } ``` @@ -182,15 +178,6 @@ non-empty — they do not automatically set the field value. User scoping for SELECT queries is handled by `PFAHandler::$user_field`, and write enforcement must be done in the Handler itself (e.g. via `_validate_*` or `preSave()`). -Handlers can restrict individual user-mode entry points by explicitly setting -`user_can_create`, `user_can_list`, or `user_can_delete` to `false`. Missing -keys preserve the historical behaviour and therefore allow the operation once -`user_hardcoded_field` is configured. These flags are entry-point guards only; -the Handler must still enforce ownership and field-level write permissions. - -If `cancelview` is non-empty, `editform.tpl` displays a Cancel link to that -server-defined URL. Do not populate it from an untrusted request parameter. - ### 7. Auto-increment IDs If your table uses auto-increment for the primary key: diff --git a/configs/menu.conf b/configs/menu.conf index 14c7587a..b5f069cd 100644 --- a/configs/menu.conf +++ b/configs/menu.conf @@ -38,7 +38,7 @@ url_logout = login.php # user-menu url_user_main = main.php -url_user_edit_alias = edit-forward.php +url_user_edit_alias = ../edit.php?table=alias url_user_vacation = vacation.php url_user_password = password.php url_user_totp = totp.php diff --git a/model/AliasHandler.php b/model/AliasHandler.php index 3d18d495..e9ad4cb3 100644 --- a/model/AliasHandler.php +++ b/model/AliasHandler.php @@ -56,7 +56,7 @@ class AliasHandler extends PFAHandler 'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''), 'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1), '_can_edit' => self::pacol(0, 0, 1, 'vnum', '' , '' , 0, array(), 0, 0, '1 as _can_edit'), - '_can_delete' => self::pacol(0, 0, 1, 'vnum', '' , '' , 0, array(), 0, 0, '1 as _can_delete'), # read_from_db_postprocess() updates the value + '_can_delete' => self::pacol(0, 0, 1, 'vnum', '' , '' , 0, array(), 0, 0, ($this->is_admin ? '1' : '0') . ' as _can_delete'), # read_from_db_postprocess() updates the value # aliases listed in $CONF[default_aliases] are read-only for domain admins if $CONF[special_alias_control] is NO. ); @@ -67,6 +67,11 @@ class AliasHandler extends PFAHandler $this->struct['address']['display_in_form'] = 1; $this->struct['address']['label'] = Config::lang('pOverview_mailbox_username'); $this->struct['address']['desc'] = ''; + + # Keep the user list focused on the only editable forwarding data. + foreach (['domain', 'description', 'on_vacation', 'modified', 'active'] as $field) { + $this->struct[$field]['display_in_list'] = 0; + } $this->struct['description']['editable'] = 0; $this->struct['description']['display_in_form'] = 0; $this->struct['active']['editable'] = 0; @@ -122,6 +127,10 @@ class AliasHandler extends PFAHandler $this->msg['store_error'] = 'pEdit_alias_result_error'; $this->msg['successmessage'] = 'alias_updated'; } + + if (!$this->is_admin) { + $this->msg['can_create'] = false; + } } @@ -133,7 +142,7 @@ class AliasHandler extends PFAHandler $this->struct['domain']['display_in_form'] = 1; } - if (Config::bool('show_status')) { + if ($this->is_admin && Config::bool('show_status')) { $this->struct['status']['display_in_list'] = 1; $this->struct['status']['label'] = ' '; } @@ -153,10 +162,6 @@ class AliasHandler extends PFAHandler 'early_init' => 0, 'prefill' => array('domain'), 'user_hardcoded_field' => 'address', - 'user_can_create' => false, - 'user_can_list' => false, - 'user_can_delete' => false, - 'cancelview' => $this->is_admin ? '' : 'users/main.php', ); } @@ -166,7 +171,7 @@ class AliasHandler extends PFAHandler */ public function init(string $id): bool { - if (!$this->is_admin) { + if (!$this->is_admin && !$this->new) { if (!Config::bool('edit_alias') || strtolower($id) !== strtolower($this->username)) { $this->errormsg[] = Config::lang_f('pEdit_alias_result_error', $id); return false; @@ -218,6 +223,11 @@ class AliasHandler extends PFAHandler protected function validate_new_id() { + if (!$this->is_admin) { + $this->errormsg[$this->id_field] = Config::lang_f('edit_not_allowed', $this->id); + return false; + } + if ($this->id == '') { $this->errormsg[$this->id_field] = Config::lang('pCreate_alias_address_text_error1'); return false; @@ -405,7 +415,12 @@ class AliasHandler extends PFAHandler public function getList($condition, $searchmode = array(), $limit = -1, $offset = -1): bool { - list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); + # Admin alias lists intentionally exclude mailbox aliases. A user must + # see their own mailbox alias, with PFAHandler::$user_field providing + # the ownership restriction. + if ($this->is_admin) { + list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); + } $this->set_is_mailbox_extrafrom($condition, $searchmode); $result = parent::getList($condition, $searchmode, $limit, $offset); $this->set_is_mailbox_extrafrom(); # reset to default @@ -414,7 +429,9 @@ class AliasHandler extends PFAHandler public function getPagebrowser($condition, $searchmode = array()) { - list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); + if ($this->is_admin) { + list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); + } $this->set_is_mailbox_extrafrom($condition, $searchmode); $result = parent::getPagebrowser($condition, $searchmode); $this->set_is_mailbox_extrafrom(); # reset to default diff --git a/public/delete.php b/public/delete.php index 703923e2..b07e2f2a 100644 --- a/public/delete.php +++ b/public/delete.php @@ -53,11 +53,6 @@ if ($is_admin) { if (empty($formconf['user_hardcoded_field'])) { throw new \InvalidArgumentException($handlerclass . ' is not available for users'); } - if (isset($formconf['user_can_delete']) && !$formconf['user_can_delete']) { - flash_error(Config::lang_f('edit_not_allowed', $table)); - header("Location: " . $formconf['listview']); - exit; - } } if ($handler->init($id)) { # errors will be displayed as last step anyway, no need for duplicated code ;-) diff --git a/public/edit.php b/public/edit.php index 27001502..275b5689 100644 --- a/public/edit.php +++ b/public/edit.php @@ -60,11 +60,6 @@ if ($is_admin) { if (empty($formconf['user_hardcoded_field'])) { throw new \InvalidArgumentException($handlerclass . ' is not available for users'); } - if ($new && isset($formconf['user_can_create']) && !$formconf['user_can_create']) { - flash_error(Config::lang_f('edit_not_allowed', $table)); - header("Location: " . $formconf['listview']); - exit; - } } if ($new == 0 || $formconf['early_init']) { @@ -270,7 +265,6 @@ if ($new) { $smarty->assign('struct', $form_fields); $smarty->assign('fielderror', $fielderror); $smarty->assign('table', $table); -$smarty->assign('cancelview', $formconf['cancelview'] ?? ''); $smarty->assign('smarty_template', 'editform'); $smarty->display('index.tpl'); diff --git a/public/list.php b/public/list.php index f17307b2..18f2be72 100644 --- a/public/list.php +++ b/public/list.php @@ -65,11 +65,6 @@ if ($is_admin) { if (empty($formconf['user_hardcoded_field'])) { throw new InvalidArgumentException($handlerclass . ' is not available for users'); } - if (isset($formconf['user_can_list']) && !$formconf['user_can_list']) { - flash_error(Config::lang_f('edit_not_allowed', $table)); - header("Location: " . $formconf['listview']); - exit; - } } $search = []; diff --git a/public/users/edit-alias.php b/public/users/edit-alias.php deleted file mode 100644 index 6eba88f5..00000000 --- a/public/users/edit-alias.php +++ /dev/null @@ -1,7 +0,0 @@ - 'alias', - 'edit' => $username, -)); - -header('Location: ../edit.php?' . $query); -exit(0); diff --git a/templates/editform.tpl b/templates/editform.tpl index 41ee598a..e2c3e900 100644 --- a/templates/editform.tpl +++ b/templates/editform.tpl @@ -99,9 +99,6 @@