Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Sep 29, 2023
2 parents 581e561 + 0184d25 commit 352e53a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/LabelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function show(string $labelName)

$exampleAsset->id = 999999;
$exampleAsset->name = 'JEN-867-5309';
$exampleAsset->asset_tag = 'TCA-00001';
$exampleAsset->asset_tag = '100001';
$exampleAsset->serial = 'SN9876543210';

$exampleAsset->company = new Company();
Expand Down
36 changes: 20 additions & 16 deletions app/Http/Livewire/SlackSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SlackSettingsForm extends Component
public $webhook_endpoint;
public $webhook_channel;
public $webhook_botname;
public $isDisabled ='' ;
public $isDisabled ='disabled' ;
public $webhook_name;
public $webhook_link;
public $webhook_placeholder;
Expand All @@ -22,11 +22,17 @@ class SlackSettingsForm extends Component

public Setting $setting;

public $webhook_endpoint_rules;


protected $rules = [
'webhook_endpoint' => 'url|required_with:webhook_channel|starts_with:https://hooks.slack.com/services|nullable',
'webhook_endpoint' => 'required_with:webhook_channel|starts_with:http://,https://,ftp://,irc://,https://hooks.slack.com/services/|url|nullable',
'webhook_channel' => 'required_with:webhook_endpoint|starts_with:#|nullable',
'webhook_botname' => 'string|nullable',
];
public $messages = [
'webhook_endpoint.starts_with' => 'your webhook endpoint should begin with http://, https:// or other protocol.',
];

public function mount() {
$this->webhook_text= [
Expand Down Expand Up @@ -55,19 +61,16 @@ public function mount() {
$this->webhook_botname = $this->setting->webhook_botname;
$this->webhook_options = $this->setting->webhook_selected;

if($this->setting->webhook_selected == 'general'){
$this->isDisabled='';
}

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

}
public function updated($field) {

if($this->webhook_selected != 'general') {
$this->validateOnly($field, $this->rules);
}

}

public function updatedWebhookSelected() {
Expand All @@ -82,7 +85,6 @@ public function updatedWebhookSelected() {
}

private function isButtonDisabled() {
if($this->webhook_selected == 'slack') {
if (empty($this->webhook_endpoint)) {
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
Expand All @@ -91,8 +93,6 @@ private function isButtonDisabled() {
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
}
}

}

public function render()
Expand All @@ -108,6 +108,7 @@ public function testWebhook(){
'defaults' => [
'exceptions' => false,
],
'allow_redirects' => false,
]);

$payload = json_encode(
Expand All @@ -116,18 +117,23 @@ public function testWebhook(){
'text' => trans('general.webhook_test_msg', ['app' => $this->webhook_name]),
'username' => e($this->webhook_botname),
'icon_emoji' => ':heart:',

]);

try {
$test = $webhook->post($this->webhook_endpoint, ['body' => $payload]);

$webhook->post($this->webhook_endpoint, ['body' => $payload]);
if(($test->getStatusCode() == 302)||($test->getStatusCode() == 301)){
return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint]));
}
$this->isDisabled='';
$this->save_button = trans('general.save');
return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!');
return session()->flash('success' , trans('admin/settings/message.webhook.success', ['webhook_name' => $this->webhook_name]));

} catch (\Exception $e) {

$this->isDisabled= 'disabled';
$this->isDisabled='disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name]));
}

Expand Down Expand Up @@ -158,9 +164,7 @@ public function submit()
if (Helper::isDemoMode()) {
session()->flash('error',trans('general.feature_disabled'));
} else {
if ($this->webhook_selected != 'general') {
$this->validate($this->rules);
}
$this->validate($this->rules);

$this->setting->webhook_selected = $this->webhook_selected;
$this->setting->webhook_endpoint = $this->webhook_endpoint;
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Labels/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\File;
use TCPDF;
use TCPDF_STATIC;
use TypeError;

/**
* Model for Labels.
Expand Down Expand Up @@ -372,7 +373,7 @@ public final function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width,
if (empty($value)) return;
try {
$pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
} catch (\Exception $e) {
} catch (\Exception|TypeError $e) {
\Log::error('The 1D barcode ' . $value . ' is not compliant with the barcode type '. $type);
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/admin/settings/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
],
'webhook' => [
'sending' => 'Sending :app test message...',
'success' => 'Your :webhook_name Integration works!',
'success_pt1' => 'Success! Check the ',
'success_pt2' => ' channel for your test message, and be sure to click SAVE below to store your settings.',
'500' => '500 Server Error.',
'error' => 'Something went wrong. :app responded with: :error_message',
'error_redirect' => 'ERROR: 301/302 :endpoint returns a redirect. For security reasons, we don’t follow redirects. Please use the actual endpoint.',
'error_misc' => 'Something went wrong. :( ',
]
];
8 changes: 3 additions & 5 deletions resources/views/livewire/slack-settings-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
{{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }}
</div>
<div class="col-md-9 required">
<input type="text" wire:model="webhook_endpoint" class="form-control" placeholder="{{$webhook_placeholder}}" value="{{old('webhook_endpoint', $webhook_endpoint)}}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
<input type="text" wire:model.lazy="webhook_endpoint" class="form-control" placeholder="{{$webhook_placeholder}}" value="{{old('webhook_endpoint', $webhook_endpoint)}}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_endpoint', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>
Expand All @@ -95,7 +95,7 @@
{{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }}
</div>
<div class="col-md-9 required">
<input type="text" wire:model="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>
<input type="text" wire:model.lazy="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"{{ Helper::isDemoMode() ? ' disabled' : ''}}>

{!! $errors->first('webhook_channel', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
Expand All @@ -111,7 +111,7 @@
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
</div>
<div class="col-md-9">
<input type="text" wire:model="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ old('webhook_botname', $webhook_botname)}}{{ Helper::isDemoMode() ? ' disabled' : ''}}>
<input type="text" wire:model.lazy="webhook_botname" class='form-control' placeholder="Snipe-Bot" {{ old('webhook_botname', $webhook_botname)}}{{ Helper::isDemoMode() ? ' disabled' : ''}}>
{!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div><!--col-md-10-->
</div>
Expand All @@ -121,7 +121,6 @@
@endif

<!--Webhook Integration Test-->
@if($webhook_selected == 'slack')
@if($webhook_endpoint != null && $webhook_channel != null)
<div class="form-group">
<div class="col-md-offset-2 col-md-9">
Expand All @@ -138,7 +137,6 @@ class="btn btn-default btn-sm pull-left">
</div>
</div>
@endif
@endif
</div><!-- /.col-md-12 -->
</div><!-- /.box-body -->

Expand Down

0 comments on commit 352e53a

Please sign in to comment.