mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
adds google notifs for asset check in and out
This commit is contained in:
parent
dfa33f651a
commit
87bce0c097
|
@ -37,11 +37,11 @@ class SlackSettingsForm extends Component
|
|||
|
||||
public function mount() {
|
||||
$this->webhook_text= [
|
||||
"slack" => array(
|
||||
"slack" => array(
|
||||
"name" => trans('admin/settings/general.slack') ,
|
||||
"icon" => 'fab fa-slack',
|
||||
"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",
|
||||
"link" => 'https://api.slack.com/messaging/webhooks',
|
||||
"icon" => 'fab fa-slack',
|
||||
"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",
|
||||
"link" => 'https://api.slack.com/messaging/webhooks',
|
||||
"test" => "testWebhook"
|
||||
),
|
||||
"general"=> array(
|
||||
|
|
|
@ -60,7 +60,7 @@ class CheckoutableListener
|
|||
if ($this->shouldSendWebhookNotification()) {
|
||||
|
||||
//slack doesn't include the url in its messaging format so this is needed to hit the endpoint
|
||||
if(Setting::getSettings()->webhook_selected =='slack') {
|
||||
if(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {
|
||||
|
||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||
->notify($this->getCheckoutNotification($event));
|
||||
|
|
|
@ -10,6 +10,11 @@ use Illuminate\Bus\Queueable;
|
|||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\GoogleChat\Card;
|
||||
use NotificationChannels\GoogleChat\GoogleChatChannel;
|
||||
use NotificationChannels\GoogleChat\GoogleChatMessage;
|
||||
use NotificationChannels\GoogleChat\Section;
|
||||
use NotificationChannels\GoogleChat\Widgets\KeyValue;
|
||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
|
||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
|
||||
|
||||
|
@ -46,6 +51,10 @@ class CheckinAssetNotification extends Notification
|
|||
public function via()
|
||||
{
|
||||
$notifyBy = [];
|
||||
if (Setting::getSettings()->webhook_selected == 'google'){
|
||||
|
||||
$notifyBy[] = GoogleChatChannel::class;
|
||||
}
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'microsoft'){
|
||||
|
||||
|
@ -108,6 +117,33 @@ class CheckinAssetNotification extends Notification
|
|||
->fact(trans('admin/hardware/form.status'), $item->assetstatus->name)
|
||||
->fact(trans('mail.notes'), $note ?: '');
|
||||
}
|
||||
public function toGoogleChat()
|
||||
{
|
||||
$target = $this->target;
|
||||
$item = $this->item;
|
||||
$note = $this->note;
|
||||
|
||||
return GoogleChatMessage::create()
|
||||
->to($this->settings->webhook_endpoint)
|
||||
->card(
|
||||
Card::create()
|
||||
->header(
|
||||
'<strong>'.trans('mail.Asset_Checkin_Notification').'</strong>' ?: '',
|
||||
htmlspecialchars_decode($item->present()->name) ?: '',
|
||||
)
|
||||
->section(
|
||||
Section::create(
|
||||
KeyValue::create(
|
||||
trans('mail.checked_into') ?: '',
|
||||
$item->location->name ? $item->location->name : '',
|
||||
trans('admin/hardware/form.status').":".$item->assetstatus->name,
|
||||
)
|
||||
->onClick(route('hardware.show', $item->id))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
|
|
|
@ -11,6 +11,13 @@ use Illuminate\Bus\Queueable;
|
|||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\GoogleChat\Card;
|
||||
use NotificationChannels\GoogleChat\Enums\Icon;
|
||||
use NotificationChannels\GoogleChat\Enums\ImageStyle;
|
||||
use NotificationChannels\GoogleChat\GoogleChatChannel;
|
||||
use NotificationChannels\GoogleChat\GoogleChatMessage;
|
||||
use NotificationChannels\GoogleChat\Section;
|
||||
use NotificationChannels\GoogleChat\Widgets\KeyValue;
|
||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
|
||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
|
||||
|
||||
|
@ -54,13 +61,18 @@ class CheckoutAssetNotification extends Notification
|
|||
*/
|
||||
public function via()
|
||||
{
|
||||
$notifyBy = [];
|
||||
if (Setting::getSettings()->webhook_selected == 'google'){
|
||||
|
||||
$notifyBy[] = GoogleChatChannel::class;
|
||||
}
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'microsoft'){
|
||||
|
||||
return [MicrosoftTeamsChannel::class];
|
||||
$notifyBy[] = MicrosoftTeamsChannel::class;
|
||||
}
|
||||
$notifyBy = [];
|
||||
|
||||
if ((Setting::getSettings()) && (Setting::getSettings()->webhook_selected == 'slack')) {
|
||||
if ((Setting::getSettings()->webhook_selected == 'slack') || (Setting::getSettings()->webhook_selected == '')) {
|
||||
\Log::debug('use webhook');
|
||||
$notifyBy[] = 'slack';
|
||||
}
|
||||
|
@ -143,6 +155,33 @@ class CheckoutAssetNotification extends Notification
|
|||
|
||||
|
||||
}
|
||||
public function toGoogleChat()
|
||||
{
|
||||
$target = $this->target;
|
||||
$item = $this->item;
|
||||
$note = $this->note;
|
||||
|
||||
return GoogleChatMessage::create()
|
||||
->to($this->settings->webhook_endpoint)
|
||||
->card(
|
||||
Card::create()
|
||||
->header(
|
||||
'<strong>'.trans('mail.Asset_Checkout_Notification').'</strong>' ?: '',
|
||||
htmlspecialchars_decode($item->present()->name) ?: '',
|
||||
)
|
||||
->section(
|
||||
Section::create(
|
||||
KeyValue::create(
|
||||
trans('mail.assigned_to') ?: '',
|
||||
$target->present()->name ?: '',
|
||||
$note ?: '',
|
||||
)
|
||||
->onClick(route('users.show', $target->id))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"intervention/image": "^2.5",
|
||||
"javiereguiluz/easyslugger": "^1.0",
|
||||
"laravel-notification-channels/google-chat": "*",
|
||||
"laravel-notification-channels/microsoft-teams": "^1.1",
|
||||
"laravel/framework": "^8.46",
|
||||
"laravel/helpers": "^1.4",
|
||||
|
|
59
composer.lock
generated
59
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "89580c52de91168aac8321460bd428e2",
|
||||
"content-hash": "bc968c279762208bd4856bb6ebed42c3",
|
||||
"packages": [
|
||||
{
|
||||
"name": "alek13/slack",
|
||||
|
@ -3188,6 +3188,63 @@
|
|||
},
|
||||
"time": "2015-04-12T19:57:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel-notification-channels/google-chat",
|
||||
"version": "v1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel-notification-channels/google-chat.git",
|
||||
"reference": "843078439403a925b484cef99a26b447e30a9c32"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel-notification-channels/google-chat/zipball/843078439403a925b484cef99a26b447e30a9c32",
|
||||
"reference": "843078439403a925b484cef99a26b447e30a9c32",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^6.3 || ^7.0",
|
||||
"illuminate/notifications": "~8.0",
|
||||
"illuminate/support": "~8.0",
|
||||
"php": ">=7.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^6.0",
|
||||
"phpunit/phpunit": "^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"NotificationChannels\\GoogleChat\\GoogleChatServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"NotificationChannels\\GoogleChat\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Frank Dixon",
|
||||
"email": "frank@thetreehouse.family",
|
||||
"homepage": "https://thetreehouse.family",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Google Chat Notification Channel for Laravel (fka. Hangouts Chat)",
|
||||
"homepage": "https://github.com/laravel-notification-channels/google-chat",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel-notification-channels/google-chat/issues",
|
||||
"source": "https://github.com/laravel-notification-channels/google-chat/tree/v1.0.1"
|
||||
},
|
||||
"time": "2021-07-15T22:40:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel-notification-channels/microsoft-teams",
|
||||
"version": "v1.1.4",
|
||||
|
|
|
@ -16,7 +16,7 @@ return [
|
|||
'checkedout_to' => 'Checked Out To',
|
||||
'checkout_date' => 'Checkout Date',
|
||||
'checkin_date' => 'Checkin Date',
|
||||
'checkout_to' => 'Checkout to',
|
||||
'checkout_to' => 'Checked out to',
|
||||
'cost' => 'Purchase Cost',
|
||||
'create' => 'Create Asset',
|
||||
'date' => 'Purchase Date',
|
||||
|
|
Loading…
Reference in a new issue