mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Expand test notification framework.
This commit is contained in:
32
app/Rules/Admin/IsValidDiscordUrl.php
Normal file
32
app/Rules/Admin/IsValidDiscordUrl.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules\Admin;
|
||||
|
||||
use FireflyIII\Support\Validation\ValidatesAmountsTrait;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class IsValidDiscordUrl implements ValidationRule
|
||||
{
|
||||
use ValidatesAmountsTrait;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, \Closure $fail): void
|
||||
{
|
||||
$value = (string)$value;
|
||||
if('' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!str_starts_with($value, 'https://discord.com/api/webhooks/')) {
|
||||
$fail('validation.active_url')->translate();
|
||||
$message = sprintf('IsValidDiscordUrl: "%s" is not a discord URL.', substr($value, 0, 255));
|
||||
Log::debug($message);
|
||||
Log::channel('audit')->info($message);
|
||||
}
|
||||
}
|
||||
}
|
32
app/Rules/Admin/IsValidSlackUrl.php
Normal file
32
app/Rules/Admin/IsValidSlackUrl.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules\Admin;
|
||||
|
||||
use FireflyIII\Support\Validation\ValidatesAmountsTrait;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class IsValidSlackUrl implements ValidationRule
|
||||
{
|
||||
use ValidatesAmountsTrait;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, \Closure $fail): void
|
||||
{
|
||||
$value = (string)$value;
|
||||
if('' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!str_starts_with($value, 'https://hooks.slack.com/services/')) {
|
||||
$fail('validation.active_url')->translate();
|
||||
$message = sprintf('IsValidSlackUrl: "%s" is not a discord URL.', substr($value, 0, 255));
|
||||
Log::debug($message);
|
||||
Log::channel('audit')->info($message);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user