Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/forms/DeleteSourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function removeSource(Connection $db): void

$db->update(
'source',
['changed_at' => (int) (new DateTime())->format("Uv"), 'deleted' => 'y'],
['changed_at' => (int) (new DateTime())->format("Uv"), 'deleted' => 'y', 'listener_username' => null],
['id = ?' => $this->source->id]
);
}
Expand Down
27 changes: 26 additions & 1 deletion application/forms/SourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ protected function assemble(): void
'disabledOptions' => ['']
]
);

$this->addElement(
'text',
'listener_username',
[
'required' => true,
'label' => $this->translate('Username'),
'validators' => [new CallbackValidator(
function ($value, CallbackValidator $validator) {
// Username must be unique
$source = Source::on($this->db)
->filter(Filter::equal('listener_username', $value))
->first();
if ($source !== null) {
$validator->addMessage($this->translate('This username is already in use.'));
return false;
}

return true;
}
)]
]
);

$this->addElement(
'password',
'listener_password',
Expand Down Expand Up @@ -217,7 +241,8 @@ private function fetchDbValues(): array

return [
'name' => $source->name,
'type' => $source->type
'type' => $source->type,
'listener_username' => $source->listener_username
];
}
}
9 changes: 6 additions & 3 deletions library/Notifications/Model/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @property int $id The primary key
* @property string $type Type identifier
* @property string $name The user-defined name
* @property ?string $listener_username The username for HTTP authentication
* @property ?string $listener_password_hash
* @property DateTime $changed_at
* @property bool $deleted
Expand Down Expand Up @@ -48,6 +49,7 @@ public function getColumns(): array
return [
'type',
'name',
'listener_username',
'listener_password_hash',
'changed_at',
'deleted'
Expand All @@ -57,9 +59,10 @@ public function getColumns(): array
public function getColumnDefinitions(): array
{
return [
'type' => t('Type'),
'name' => t('Name'),
'changed_at' => t('Changed At')
'type' => t('Type'),
'name' => t('Name'),
'listener_username' => t('Username'),
'changed_at' => t('Changed At')
];
}

Expand Down
Loading