mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #16414 from Godmartinz/Audit_error_fix
Adds audit notification for MS Teams
This commit is contained in:
commit
bc618fcef4
|
@ -6,6 +6,8 @@ use App\Models\Setting;
|
||||||
use App\Notifications\AuditNotification;
|
use App\Notifications\AuditNotification;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Osama\LaravelTeamsNotification\TeamsNotification;
|
||||||
|
|
||||||
trait Loggable
|
trait Loggable
|
||||||
{
|
{
|
||||||
|
@ -242,7 +244,14 @@ trait Loggable
|
||||||
'location' => ($location) ? $location->name : '',
|
'location' => ($location) ? $location->name : '',
|
||||||
'note' => $note,
|
'note' => $note,
|
||||||
];
|
];
|
||||||
|
if(Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')){
|
||||||
|
$message = AuditNotification::toMicrosoftTeams($params);
|
||||||
|
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
|
||||||
|
$notification->success()->sendMessage($message[0], $message[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
Setting::getSettings()->notify(new AuditNotification($params));
|
Setting::getSettings()->notify(new AuditNotification($params));
|
||||||
|
}
|
||||||
|
|
||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,13 @@ namespace App\Notifications;
|
||||||
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Channels\SlackWebhookChannel;
|
||||||
use Illuminate\Notifications\Messages\SlackMessage;
|
use Illuminate\Notifications\Messages\SlackMessage;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
|
||||||
|
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
|
||||||
|
|
||||||
class AuditNotification extends Notification
|
class AuditNotification extends Notification
|
||||||
{
|
{
|
||||||
|
@ -35,10 +40,14 @@ class AuditNotification extends Notification
|
||||||
public function via()
|
public function via()
|
||||||
{
|
{
|
||||||
$notifyBy = [];
|
$notifyBy = [];
|
||||||
if (Setting::getSettings()->webhook_endpoint) {
|
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
|
||||||
$notifyBy[] = 'slack';
|
Log::debug('use webhook');
|
||||||
|
$notifyBy[] = SlackWebhookChannel::class;
|
||||||
}
|
}
|
||||||
|
if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {
|
||||||
|
|
||||||
|
$notifyBy[] = MicrosoftTeamsChannel::class;
|
||||||
|
}
|
||||||
return $notifyBy;
|
return $notifyBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,4 +72,30 @@ class AuditNotification extends Notification
|
||||||
->fields($fields);
|
->fields($fields);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function toMicrosoftTeams($params)
|
||||||
|
{
|
||||||
|
$item = $params['item'];
|
||||||
|
$admin_user = $params['admin'];
|
||||||
|
$note = $params['note'];
|
||||||
|
$location = $params['location'];
|
||||||
|
$setting = Setting::getSettings();
|
||||||
|
|
||||||
|
if(!Str::contains($setting->webhook_endpoint, 'workflows')) {
|
||||||
|
return MicrosoftTeamsMessage::create()
|
||||||
|
->to($setting->webhook_endpoint)
|
||||||
|
->type('success')
|
||||||
|
->title(class_basename(get_class($params['item'])) . ' Audited')
|
||||||
|
->addStartGroupToSection('activityText')
|
||||||
|
->fact(trans('mail.asset'), $item)
|
||||||
|
->fact(trans('general.administrator'), $admin_user->present()->viewUrl() . '|' . $admin_user->present()->fullName());
|
||||||
|
}
|
||||||
|
$message = class_basename(get_class($params['item'])) . ' Audited By '.$admin_user->present()->fullName();
|
||||||
|
$details = [
|
||||||
|
trans('mail.asset') => htmlspecialchars_decode($item->present()->name),
|
||||||
|
trans('mail.notes') => $note ?: '',
|
||||||
|
trans('general.location') => $location ?: '',
|
||||||
|
];
|
||||||
|
return [$message, $details];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue