mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Address forwarding editor review feedback
This commit is contained in:
1 parent
8d631d2ce8
commit
3ab0104d1a
13 files changed
+74
-127
No files matched your search
@@ -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:
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+26
-9
@@ -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
|
||||
|
||||
@@ -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 ;-)
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Backward-compatible entry point for the old user forwarding form.
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/edit-forward.php');
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Redirect users to the shared AliasHandler forwarding form.
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../common.php');
|
||||
|
||||
authentication_require_role('user');
|
||||
|
||||
if (!Config::bool('edit_alias')) {
|
||||
header('Location: main.php');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$username = authentication_get_username();
|
||||
$query = http_build_query(array(
|
||||
'table' => 'alias',
|
||||
'edit' => $username,
|
||||
));
|
||||
|
||||
header('Location: ../edit.php?' . $query);
|
||||
exit(0);
|
||||
@@ -99,9 +99,6 @@
|
||||
<div class="card-footer">
|
||||
<div class="btn-toolbar" role="toolbar">
|
||||
<div class="btn-group float-end">
|
||||
{if $cancelview}
|
||||
<a class="btn btn-secondary" href="{$cancelview}">{$PALANG.cancel}</a>
|
||||
{/if}
|
||||
<button class="btn btn-primary" type="submit" name="submit">
|
||||
<span class="bi bi-pencil" aria-hidden="true"></span> {$submitbutton}
|
||||
</button>
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
<form name="alias" method="post" action="" class="form-horizontal">
|
||||
<div id="edit_form" class="card">
|
||||
<div class="card-header"><h4>{$PALANG.pEdit_alias_welcome}</h4></div>
|
||||
<div class="card-body enable-asterisk">
|
||||
{CSRF_Token}
|
||||
<p class="text-center"><em>{$PALANG.pEdit_alias_help}</em></p>
|
||||
<div class="mb-3">
|
||||
<label class="col-md-4">{$PALANG.alias}:</label>
|
||||
<div class="col-md-6 col-sm-8"><p class="form-control-plaintext"><em>{$USERID_USERNAME}</em></p></div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="col-md-4" for="fGoto">{$PALANG.to}:</label>
|
||||
<div class="col-md-6 col-sm-8">
|
||||
<textarea class="form-control" rows="8" cols="50" name="fGoto"
|
||||
id="fGoto">{foreach key=key2 item=field2 from=$tGotoArray}{$field2} {/foreach}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="col-md-4"></label>
|
||||
<div class="col-md-6 col-sm-8">
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="fForward_and_store" id="fForward_and_store1"
|
||||
value="1"{$forward_and_store}/>
|
||||
{$PALANG.pEdit_alias_forward_and_store}
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="fForward_and_store" id="fForward_and_store0"
|
||||
value="0" {$forward_only}/>
|
||||
{$PALANG.pEdit_alias_forward_only}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="btn-toolbar">
|
||||
<div class="float-end">
|
||||
<a href="main.php" class="mr btn btn-secondary">{$PALANG.exit}</a>
|
||||
|
||||
<button class="ml btn btn-lg btn-primary" type="submit" name="submit" value="{$PALANG.save}">{$PALANG.save}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -9,7 +9,7 @@
|
||||
{/if}
|
||||
{if $CONF.edit_alias===YES}
|
||||
<tr>
|
||||
<td nowrap="nowrap"><a class="btn btn-primary" href="edit-forward.php">{$PALANG.pUsersMenu_edit_alias}</a>
|
||||
<td nowrap="nowrap"><a class="btn btn-primary" href="../edit.php?table=alias&edit={$smarty.session.sessid.username|escape:url}">{$PALANG.pUsersMenu_edit_alias}</a>
|
||||
</td>
|
||||
<td>{$PALANG.pUsersMain_edit_alias}</td>
|
||||
</tr>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<li><a class="nav-item nav-link" target="_top" href="{#url_user_vacation#}">{$PALANG.pUsersMenu_vacation}</a></li>
|
||||
{/if}
|
||||
{if $CONF.edit_alias===YES}
|
||||
<li><a class="nav-item nav-link" target="_top" href="{#url_user_edit_alias#}">{$PALANG.pUsersMenu_edit_alias}</a></li>
|
||||
<li><a class="nav-item nav-link" target="_top" href="{#url_user_edit_alias#}&edit={$smarty.session.sessid.username|escape:url}">{$PALANG.pUsersMenu_edit_alias}</a></li>
|
||||
{/if}
|
||||
{* TOTP *}
|
||||
{if $CONF.totp==='YES'}
|
||||
|
||||
@@ -50,8 +50,6 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals('address', $formconf['user_hardcoded_field']);
|
||||
$this->assertEquals('users/main.php', $formconf['listview']);
|
||||
$this->assertFalse($formconf['user_can_list']);
|
||||
$this->assertFalse($formconf['user_can_delete']);
|
||||
$this->assertTrue($handler->init('alice@example.com'));
|
||||
|
||||
$struct = $handler->getStruct();
|
||||
@@ -60,6 +58,8 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertSame(0, $struct['description']['display_in_form']);
|
||||
$this->assertSame(0, $struct['active']['display_in_form']);
|
||||
|
||||
# Except for goto and goto_mailbox, submitted fields are read-only for
|
||||
# users and therefore silently preserve their stored values.
|
||||
$this->assertTrue($handler->set([
|
||||
'address' => 'bob@example.com',
|
||||
'description' => 'changed by user',
|
||||
@@ -90,9 +90,50 @@ class AliasHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
];
|
||||
|
||||
$handler = new AliasHandler(1, 'alice@example.com', false);
|
||||
$formconf = $handler->webformConfig();
|
||||
$this->assertFalse($handler->init('new@example.com'));
|
||||
$this->assertNotEmpty($handler->errormsg);
|
||||
}
|
||||
|
||||
$this->assertFalse($formconf['user_can_create']);
|
||||
public function testUserListContainsOnlyOwnMailboxAlias()
|
||||
{
|
||||
$this->addDomain('example.com', 'admin');
|
||||
$this->addMailboxAlias('alice@example.com', 'example.com');
|
||||
$this->addMailboxAlias('bob@example.com', 'example.com');
|
||||
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
'roles' => ['user']
|
||||
]
|
||||
];
|
||||
|
||||
$handler = new AliasHandler(0, 'alice@example.com', false);
|
||||
$handler->webformConfig();
|
||||
$this->assertTrue($handler->getList(''));
|
||||
$this->assertSame(['alice@example.com'], array_keys($handler->result()));
|
||||
$this->assertSame(0, $handler->result()['alice@example.com']['_can_delete']);
|
||||
|
||||
$struct = $handler->getStruct();
|
||||
$this->assertSame(1, $struct['address']['display_in_list']);
|
||||
$this->assertSame(1, $struct['goto']['display_in_list']);
|
||||
$this->assertSame(1, $struct['goto_mailbox']['display_in_list']);
|
||||
$this->assertSame(0, $struct['description']['display_in_list']);
|
||||
$this->assertSame(0, $struct['active']['display_in_list']);
|
||||
}
|
||||
|
||||
public function testUserCannotDeleteOwnMailboxAlias()
|
||||
{
|
||||
$this->addDomain('example.com', 'admin');
|
||||
$this->addMailboxAlias('alice@example.com', 'example.com');
|
||||
|
||||
$_SESSION = [
|
||||
'sessid' => [
|
||||
'roles' => ['user']
|
||||
]
|
||||
];
|
||||
|
||||
$handler = new AliasHandler(0, 'alice@example.com', false);
|
||||
$this->assertTrue($handler->init('alice@example.com'));
|
||||
$this->assertFalse($handler->delete());
|
||||
}
|
||||
|
||||
public function testUserForwardingPreservesVacationAndLocalDelivery()
|
||||
|
||||
Reference in new issue
Block a user