mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #16040 from Godmartinz/template_validate_error
Some checks failed
CodeQL Security Scan / CodeQL Security Scan (javascript) (push) Has been cancelled
Codacy Security Scan / Codacy Security Scan (push) Has been cancelled
Docker images (Alpine) / docker (push) Has been cancelled
Docker images / docker (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Has been cancelled
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Has been cancelled
Some checks failed
CodeQL Security Scan / CodeQL Security Scan (javascript) (push) Has been cancelled
Codacy Security Scan / Codacy Security Scan (push) Has been cancelled
Docker images (Alpine) / docker (push) Has been cancelled
Docker images / docker (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Has been cancelled
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Has been cancelled
Adds a null check to label templates, adds return types for validation methods
This commit is contained in:
commit
1fe170e6a1
|
@ -800,6 +800,7 @@ class SettingsController extends Controller
|
|||
}
|
||||
|
||||
if ($setting->save()) {
|
||||
|
||||
return redirect()->route('settings.labels.index')
|
||||
->with('success', trans('admin/settings/message.update.success'));
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
|
||||
use App\Models\Labels\Label;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreLabelSettings extends FormRequest
|
||||
{
|
||||
|
@ -22,6 +25,10 @@ class StoreLabelSettings extends FormRequest
|
|||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$names = Label::find()?->map(function ($label) {
|
||||
return $label->getName();
|
||||
})->values()->toArray();
|
||||
|
||||
return [
|
||||
'labels_per_page' => 'numeric',
|
||||
'labels_width' => 'numeric',
|
||||
|
@ -36,6 +43,10 @@ class StoreLabelSettings extends FormRequest
|
|||
'labels_pagewidth' => 'numeric|nullable',
|
||||
'labels_pageheight' => 'numeric|nullable',
|
||||
'qr_text' => 'max:31|nullable',
|
||||
'label2_template' => [
|
||||
'required',
|
||||
Rule::in($names),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -411,14 +411,14 @@ abstract class Label
|
|||
/**
|
||||
* Checks the template is internally valid
|
||||
*/
|
||||
public final function validate() {
|
||||
public final function validate() : void {
|
||||
$this->validateUnits();
|
||||
$this->validateSize();
|
||||
$this->validateMargins();
|
||||
$this->validateSupport();
|
||||
}
|
||||
|
||||
private function validateUnits() {
|
||||
private function validateUnits() : void {
|
||||
$validUnits = [ 'pt', 'mm', 'cm', 'in' ];
|
||||
$unit = $this->getUnit();
|
||||
if (!in_array(strtolower($unit), $validUnits)) {
|
||||
|
@ -430,7 +430,7 @@ abstract class Label
|
|||
}
|
||||
}
|
||||
|
||||
private function validateSize() {
|
||||
private function validateSize() : void {
|
||||
$width = $this->getWidth();
|
||||
if (!is_numeric($width) || is_string($width)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
|
@ -450,7 +450,7 @@ abstract class Label
|
|||
}
|
||||
}
|
||||
|
||||
private function validateMargins() {
|
||||
private function validateMargins() : void {
|
||||
$marginTop = $this->getMarginTop();
|
||||
if (!is_numeric($marginTop) || is_string($marginTop)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
|
@ -488,7 +488,7 @@ abstract class Label
|
|||
}
|
||||
}
|
||||
|
||||
private function validateSupport() {
|
||||
private function validateSupport() : void {
|
||||
$support1D = $this->getSupport1DBarcode();
|
||||
if (!is_bool($support1D)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Models\Labels\Label as LabelModel;
|
|||
use App\Models\Labels\Sheet;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use TCPDF;
|
||||
|
@ -38,7 +39,7 @@ class Label implements View
|
|||
$settings = $this->data->get('settings');
|
||||
$assets = $this->data->get('assets');
|
||||
$offset = $this->data->get('offset');
|
||||
$template = LabelModel::find($settings->label2_template);
|
||||
|
||||
|
||||
// If disabled, pass to legacy view
|
||||
if ((!$settings->label2_enable)) {
|
||||
|
@ -49,6 +50,12 @@ class Label implements View
|
|||
->with('count', $this->data->get('count'));
|
||||
}
|
||||
|
||||
$template = LabelModel::find($settings->label2_template);
|
||||
|
||||
if ($template === null) {
|
||||
return redirect()->route('settings.labels.index')->with('error', trans('admin/settings/message.labels.null_template'));
|
||||
}
|
||||
|
||||
$template->validate();
|
||||
|
||||
$pdf = new TCPDF(
|
||||
|
|
|
@ -36,6 +36,9 @@ return [
|
|||
'testing_authentication' => 'Testing LDAP Authentication...',
|
||||
'authentication_success' => 'User authenticated against LDAP successfully!'
|
||||
],
|
||||
'labels' => [
|
||||
'null_template' => 'Label template not found. Please select a template.',
|
||||
],
|
||||
'webhook' => [
|
||||
'sending' => 'Sending :app test message...',
|
||||
'success' => 'Your :webhook_name Integration works!',
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
</div>
|
||||
<div class="box-body">
|
||||
|
||||
|
||||
<div class="col-md-12">
|
||||
|
||||
<!-- New Label Engine -->
|
||||
|
|
Loading…
Reference in a new issue