Skip to content

Commit

Permalink
adds notifications for deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Oct 28, 2024
1 parent b987b3d commit ed81973
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
18 changes: 18 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Contracts\Encryption\DecryptException;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Intervention\Image\ImageManagerStatic as Image;
use Illuminate\Support\Facades\Session;

Expand Down Expand Up @@ -708,6 +709,23 @@ public static function generateRandomString($length = 10)

return $randomString;
}
/**
* A method to be used to handle deprecations and giving notifications, currently handling MS Teams. more can be added when needed.
*
*
* @author [Godfrey Martinez]
* @since [v7.0.14]
* @return array
*/
public static function deprecationCheck(){
$deprecations = [
'ms_teams_deprecated' => array(
'check' => Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows'),
'message' => 'The Microsoft Teams webhook URL being used will be deprecated Jan 31st, 2025. <a class="btn btn-primary" href="' . route('settings.slack.index') . '">Change your webhook URL</a>'),
];

return $deprecations;
}

/**
* This nasty little method gets the low inventory info for the
Expand Down
13 changes: 8 additions & 5 deletions app/Livewire/SlackSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@ public function mount() {
$this->webhook_channel = $this->setting->webhook_channel;
$this->webhook_botname = $this->setting->webhook_botname;
$this->webhook_options = $this->setting->webhook_selected;
if($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google'){
$this->teams_webhook_deprecated = Str::contains($this->webhook_endpoint, 'workflows');
if($this->webhook_selected === 'microsoft' || $this->webhook_selected === 'google'){
$this->webhook_channel = '#NA';
}


if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){
$this->isDisabled= '';
}

if($this->webhook_selected === 'microsoft' && !$this->teams_webhook_deprecated) {
session()->flash('warning', 'The selected Microsoft Teams webhook URL will be deprecated Jan 31st, 2025. Please use a workflow URL. Microsofts Documentation on creating a workflow can be found <a href="https://support.microsoft.com/en-us/office/create-incoming-webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498" target="_blank"> here.</a>');
}
}
public function updated($field) {

Expand All @@ -111,7 +113,6 @@ public function updatedWebhookSelected() {
if($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google'){
$this->webhook_channel = '#NA';
}

}

private function isButtonDisabled() {
Expand All @@ -128,7 +129,9 @@ private function isButtonDisabled() {
public function render()
{
$this->isButtonDisabled();

return view('livewire.slack-settings-form');

}

public function testWebhook(){
Expand Down Expand Up @@ -237,7 +240,7 @@ public function googleWebhookTest(){
}
}
public function msTeamTestWebhook(){
$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows');

try {

if($this->teams_webhook_deprecated){
Expand Down
9 changes: 6 additions & 3 deletions resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,20 @@
@can('admin')
@if ($snipeSettings->show_alerts_in_menu=='1')
<!-- Tasks: style can be found in dropdown.less -->
<?php $alert_items = Helper::checkLowInventory(); ?>
<?php $alert_items = Helper::checkLowInventory(); $deprecations = Helper::deprecationCheck()?>

<li class="dropdown tasks-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<x-icon type="alerts" />
<span class="sr-only">{{ trans('general.alerts') }}</span>
@if (count($alert_items))
<span class="label label-danger">{{ count($alert_items) }}</span>
@if (count($alert_items) || count($deprecations))
<span class="label label-danger">{{ count($alert_items) + count($deprecations) }}</span>
@endif
</a>
<ul class="dropdown-menu">
@if($snipeSettings->webhook_selected === 'microsoft' && $deprecations['ms_teams_deprecated']['check'])
<li class="header alert-warning">{!! $deprecations['ms_teams_deprecated']['message'] !!}</li>
@endif
<li class="header">{{ trans_choice('general.quantity_minimum', count($alert_items)) }}</li>
<li>
<!-- inner menu: contains the actual data -->
Expand Down
9 changes: 8 additions & 1 deletion resources/views/livewire/slack-settings-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
<div><!-- livewire div - do not remove -->
<form class="form-horizontal" role="form" wire:submit="submit">
{{csrf_field()}}

@if (session()->has('warning'))
<div class="alert alert-warning">
{!! session('warning') !!}
@php
session()->forget('warning'); // Clear the session flash immediately
@endphp
</div>
@endif
<div class="row">

<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
Expand Down

0 comments on commit ed81973

Please sign in to comment.