forked from miguel456/rbrecruiter
Compare commits
2 Commits
develop
...
feature/RS
Author | SHA1 | Date | |
---|---|---|---|
82123b1c26 | |||
2a43e213f9 |
@@ -3,7 +3,17 @@
|
||||
|
||||
namespace App\Facades;
|
||||
use \Illuminate\Support\Facades\Facade;
|
||||
use phpDocumentor\Reflection\Types\Boolean;
|
||||
|
||||
/**
|
||||
* Class Options
|
||||
* @package App\Facades
|
||||
*
|
||||
* @method static void setOption(string $option, string $value, string $description)
|
||||
* @method static string getOption(string $option)
|
||||
* @method static void changeOption(string $option, string $newValue)
|
||||
* @method static Boolean optionExists(string $option)
|
||||
*/
|
||||
class Options extends Facade
|
||||
{
|
||||
public static function getFacadeAccessor()
|
||||
|
@@ -13,9 +13,12 @@ class Options
|
||||
public function getOption(string $option): string
|
||||
{
|
||||
$value = Cache::get($option);
|
||||
$fromCache = true;
|
||||
|
||||
if (is_null($value))
|
||||
{
|
||||
$fromCache = false;
|
||||
|
||||
Log::debug('Option ' . $option . 'not found in cache, refreshing from database');
|
||||
$value = Option::where('option_name', $option)->first();
|
||||
if (is_null($value))
|
||||
@@ -25,7 +28,9 @@ class Options
|
||||
Cache::put($option . '_desc', 'Undefined description');
|
||||
}
|
||||
|
||||
return $value->option_value;
|
||||
return (!$fromCache)
|
||||
? $value->option_value
|
||||
: $value;
|
||||
}
|
||||
|
||||
public function setOption(string $option, string $value, string $description)
|
||||
|
@@ -4,6 +4,7 @@ namespace App\Notifications;
|
||||
|
||||
use App\Facades\Options;
|
||||
use App\Traits\Cancellable;
|
||||
use App\Traits\DiscordRoutable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -13,7 +14,7 @@ use App\Application;
|
||||
|
||||
class ApplicationApproved extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable, Cancellable;
|
||||
use Queueable, Cancellable, DiscordRoutable;
|
||||
|
||||
public $application;
|
||||
|
||||
@@ -80,6 +81,11 @@ class ApplicationApproved extends Notification implements ShouldQueue
|
||||
});
|
||||
}
|
||||
|
||||
public function toDiscord($notifiable)
|
||||
{
|
||||
return $this->toSlack($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
|
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Facades\Options;
|
||||
use App\Traits\DiscordRoutable;
|
||||
use Awssat\Notifications\Messages\DiscordMessage;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -11,7 +14,7 @@ use App\Application;
|
||||
|
||||
class ApplicationDenied extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use Queueable, DiscordRoutable;
|
||||
|
||||
|
||||
public $application;
|
||||
@@ -34,14 +37,22 @@ class ApplicationDenied extends Notification implements ShouldQueue
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail', 'slack'];
|
||||
$options = ['mail'];
|
||||
|
||||
if (Options::getOption('enable_discord_notifications'))
|
||||
array_push($options, 'discord');
|
||||
|
||||
if (Options::getOption('enable_slack_notifications'))
|
||||
array_push($options, 'slack');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
@@ -70,6 +81,13 @@ class ApplicationDenied extends Notification implements ShouldQueue
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function toDiscord($notifiable)
|
||||
{
|
||||
// SlackMessage is similar to DiscordMessage, so they're compatible
|
||||
return $this->toSlack($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Traits\DiscordRoutable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -15,7 +16,7 @@ use App\Facades\Options;
|
||||
|
||||
class NewApplicant extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable, Cancellable;
|
||||
use Queueable, Cancellable, DiscordRoutable;
|
||||
|
||||
|
||||
protected $application;
|
||||
@@ -26,7 +27,8 @@ class NewApplicant extends Notification implements ShouldQueue
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
* @param Application $application
|
||||
* @param Vacancy $vacancy
|
||||
*/
|
||||
public function __construct(Application $application, Vacancy $vacancy)
|
||||
{
|
||||
@@ -36,12 +38,7 @@ class NewApplicant extends Notification implements ShouldQueue
|
||||
|
||||
public function channels()
|
||||
{
|
||||
if (Options::getOption('enable_slack_notifications') == 1)
|
||||
{
|
||||
return ['slack'];
|
||||
}
|
||||
|
||||
return [];
|
||||
$this->chooseChannelsViaOptions();
|
||||
}
|
||||
|
||||
public function optOut($notifiable)
|
||||
@@ -90,6 +87,12 @@ class NewApplicant extends Notification implements ShouldQueue
|
||||
->action('Review application', $url);
|
||||
});
|
||||
}
|
||||
|
||||
public function toDiscord($notifiable)
|
||||
{
|
||||
return $this->toSlack($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
|
@@ -21,7 +21,8 @@ class NewComment extends Notification implements ShouldQueue
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
* @param Comment $comment
|
||||
* @param Application $application
|
||||
*/
|
||||
public function __construct(Comment $comment, Application $application)
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Traits\DiscordRoutable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -15,7 +16,7 @@ use App\Facades\Options;
|
||||
|
||||
class NewUser extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable, Cancellable;
|
||||
use Queueable, Cancellable, DiscordRoutable;
|
||||
|
||||
public $user;
|
||||
|
||||
@@ -83,6 +84,11 @@ class NewUser extends Notification implements ShouldQueue
|
||||
});
|
||||
}
|
||||
|
||||
public function toDiscord($notifiable)
|
||||
{
|
||||
return $this->toSlack($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
|
@@ -8,6 +8,7 @@ class Options extends Model
|
||||
{
|
||||
public $fillable = [
|
||||
'option_name',
|
||||
'option_value'
|
||||
'option_value',
|
||||
'friendly_name'
|
||||
];
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ use App\Facades\Options;
|
||||
trait Cancellable
|
||||
{
|
||||
|
||||
// This method is only used if you want this default set of channels;
|
||||
// Other channels can always be configured by overloading the channels method here.
|
||||
public function chooseChannelsViaOptions()
|
||||
{
|
||||
$channels = [];
|
||||
@@ -17,11 +19,17 @@ trait Cancellable
|
||||
{
|
||||
array_push($channels, 'slack');
|
||||
}
|
||||
elseif(Options::getOption('enable_email_notifications') == 1)
|
||||
|
||||
if (Options::getOption('enable_email_notifications') == 1)
|
||||
{
|
||||
array_push($channels, 'email');
|
||||
}
|
||||
|
||||
if (Options::getOption('enable_discord_notifications'))
|
||||
{
|
||||
array_push($channels, 'discord');
|
||||
}
|
||||
|
||||
return $channels;
|
||||
}
|
||||
|
||||
|
15
app/Traits/DiscordRoutable.php
Normal file
15
app/Traits/DiscordRoutable.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
|
||||
trait DiscordRoutable
|
||||
{
|
||||
|
||||
public function routeNotificationForDiscord()
|
||||
{
|
||||
return config('channels.notifications.discord.webhook_url');
|
||||
}
|
||||
|
||||
}
|
17
config/channels.php
Normal file
17
config/channels.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'notifications' => [
|
||||
|
||||
'discord' => [
|
||||
'webhook_url' => env('DISCORD_INTEGRATION_WEBHOOK')
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'webhook_url' => env('SLACK_INTEGRATION_WEBHOOK')
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
];
|
@@ -23,6 +23,7 @@ class DefaultOptionsSeeder extends Seeder
|
||||
|
||||
Options::setOption('enable_slack_notifications', true, 'Enable slack notifications');
|
||||
Options::setOption('enable_email_notifications', true, 'Enable e-mail notifications');
|
||||
Options::setOption('enable_discord_notifications', true, 'Enable discord notifications');
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ use App\Http\Controllers\TeamController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Http\Controllers\VacancyController;
|
||||
use App\Http\Controllers\VoteController;
|
||||
use App\Http\Controllers\OptionsController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
@@ -63,7 +64,7 @@ Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => [ 'l
|
||||
|
||||
Route::resource('teams', TeamController::class);
|
||||
|
||||
|
||||
|
||||
Route::post('teams/{team}/invites/send', [TeamController::class, 'invite'])
|
||||
->name('sendInvite');
|
||||
|
||||
@@ -77,7 +78,7 @@ Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => [ 'l
|
||||
Route::get('teams/invites/{action}/{token}', [TeamController::class, 'processInviteAction'])
|
||||
->name('processInvite');
|
||||
|
||||
|
||||
|
||||
|
||||
Route::group(['prefix' => '/applications'], function (){
|
||||
|
||||
|
Reference in New Issue
Block a user