Skip to content

A free open source IT asset/license management system

changing 'shared_report_template' to 'is_shared' in DB

akemidxd53eafe87aab
diff --git a/app/Http/Controllers/ReportTemplatesController.php b/app/Http/Controllers/ReportTemplatesController.php
index 338f463808..fdc3fed078 100644
--- a/app/Http/Controllers/ReportTemplatesController.php
+++ b/app/Http/Controllers/ReportTemplatesController.php
@@ -19,8 +19,8 @@ class ReportTemplatesController extends Controller
$report = $request->user()->reportTemplates()->create([
'name' => $validated['name'],
- 'options' => $request->except(['_token', 'name', 'share_report_template']),
- 'share_report_template' => $request->has('share_report_template'),
+ 'options' => $request->except(['_token', 'name', 'is_shared']),
+ 'is_shared' => $request->has('is_shared'),
]);
session()->flash('success', trans('admin/reports/message.create.success'));
@@ -70,12 +70,12 @@ class ReportTemplatesController extends Controller
$properties = [
'name' => $request->input('name'),
- 'options' => Arr::except($request->all(), ['_token', 'id', 'name', 'share_report_template']),
- 'share_report_template' => $reportTemplate->share_report_template,
+ 'options' => Arr::except($request->all(), ['_token', 'id', 'name', 'is_shared']),
+ 'is_shared' => $reportTemplate->is_shared,
];
if ($reportTemplate->created_by == $request->user()->id) {
- $properties['share_report_template'] = $request->boolean('share_report_template');
+ $properties['is_shared'] = $request->boolean('is_shared');
}
$reportTemplate->fill($properties);
diff --git a/app/Http/Requests/UpdateSharedTemplateRequest.php b/app/Http/Requests/UpdateSharedTemplateRequest.php
deleted file mode 100644
index ac9891f514..0000000000
--- a/app/Http/Requests/UpdateSharedTemplateRequest.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-namespace App\Http\Requests;
-
-use App\Models\ReportTemplate;
-use App\Models\Setting;
-use Illuminate\Support\Facades\Gate;
-use Illuminate\Validation\Rule;
-
-class UpdateSharedTemplateRequest extends CustomAssetReportRequest
-{
- /**
- * Determine if the user is authorized to make this request.
- *
- * @return bool
- */
- public function authorize()
- {
- return Gate::allows('edit', $this->id);
- }
-
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules()
- {
- $rules = array_merge(
- parent::rules(),
- (new ReportTemplate)->getRules(),
-// [
-// if ($this->created_by == auth()->id()) {
-// } //so how do we apply this rule. is it allow or restrict?
-// ],
- );
- return $rules;
- }
-}
diff --git a/app/Models/ReportTemplate.php b/app/Models/ReportTemplate.php
index 395b26b395..bc1b2de0ca 100644
--- a/app/Models/ReportTemplate.php
+++ b/app/Models/ReportTemplate.php
@@ -21,13 +21,14 @@ class ReportTemplate extends Model
protected $casts = [
'options' => 'array',
+ 'is_shared' => 'boolean',
];
protected $fillable = [
'created_by',
'name',
'options',
- 'share_report_template',
+ 'is_shared',
];
protected $rules = [
@@ -40,7 +41,7 @@ class ReportTemplate extends Model
'required',
'array',
],
- 'share_report_template' => [
+ 'is_shared' => [
'boolean',
],
];
@@ -53,7 +54,7 @@ class ReportTemplate extends Model
if (auth()->check()) {
$builder->where('created_by', auth()->id())
- ->orWhere('share_report_template', 1);
+ ->orWhere('is_shared', 1);
}
}
);
diff --git a/database/factories/ReportTemplateFactory.php b/database/factories/ReportTemplateFactory.php
index ae7837bc81..4fdc41b40b 100644
--- a/database/factories/ReportTemplateFactory.php
+++ b/database/factories/ReportTemplateFactory.php
@@ -20,21 +20,21 @@ class ReportTemplateFactory extends Factory
'id' => '1',
],
'created_by' => User::factory(),
- 'share_report_template' => 0,
+ 'is_shared' => 0,
];
}
public function shared()
{
return $this->state(function () {
- return['share_report_template' => 1];
+ return['is_shared' => 1];
});
}
public function notShared()
{
return $this->state(function () {
- return ['share_report_template' => 0];
+ return ['is_shared' => 0];
});
}
}
diff --git a/database/migrations/2025_11_18_193933_add_share_report_template_option.php b/database/migrations/2025_11_18_193933_add_share_report_template_option.php
index 16641ae5ff..caa43e8699 100644
--- a/database/migrations/2025_11_18_193933_add_share_report_template_option.php
+++ b/database/migrations/2025_11_18_193933_add_share_report_template_option.php
@@ -12,7 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('report_templates', function (Blueprint $table) {
- $table->boolean('share_report_template', )->nullable()->default(null);
+ $table->boolean('is_shared', )->nullable()->default(null);
});
}
@@ -22,8 +22,8 @@ return new class extends Migration
public function down(): void
{
Schema::table('report_templates', function (Blueprint $table) {
- if (Schema::hasColumn('report_templates', 'share_report_template')) {
- $table->dropColumn('share_report_template');
+ if (Schema::hasColumn('report_templates', 'is_shared')) {
+ $table->dropColumn('is_shared');
}
});
}
diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php
index 9c66d72cd3..70148964c8 100644
--- a/resources/views/reports/custom.blade.php
+++ b/resources/views/reports/custom.blade.php
@@ -77,7 +77,7 @@
@if ($template->created_by == auth()->id())
<div class="col-md-3">
<label class="form-control">
- <input type="checkbox" name="share_report_template" value="1" @checked($template->share_report_template) />
+ <input type="checkbox" name="is_shared" value="1" @checked($template->is_shared) />
{{ trans('admin/reports/general.share_template') }}
</label>
</div>
@@ -685,9 +685,9 @@
<div style="margin-bottom: 5px;">
@if($template->name)
@if($template->created_by == auth()->id())
- <span class="text-center">{!! ($template->share_report_template=='1' ? '<i class="fa fa-check text-success"></i>'." ".(trans('admin/reports/general.template_shared_with_others')) : '<i class="fa fa-times text-danger"></i>'." ".(trans('admin/reports/general.template_not_shared')) )!!}</span>
+ <span class="text-center">{!! ($template->is_shared ? '<i class="fa fa-check text-success"></i>'." ".(trans('admin/reports/general.template_shared_with_others')) : '<i class="fa fa-times text-danger"></i>'." ".(trans('admin/reports/general.template_not_shared')) )!!}</span>
@else
- <span class="text-center">{!! ($template->share_report_template=='1' ? '<i class="fa fa-check text-success"></i>'." ".(trans('admin/reports/general.template_shared')) : '<i class="fa fa-times text-danger"></i>'." ".(trans('admin/reports/general.template_not_shared')) )!!}</span>
+ <span class="text-center">{!! ($template->is_shared ? '<i class="fa fa-check text-success"></i>'." ".(trans('admin/reports/general.template_shared')) : '<i class="fa fa-times text-danger"></i>'." ".(trans('admin/reports/general.template_not_shared')) )!!}</span>
@endif
@endif
</div>
diff --git a/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php b/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php
index 5d77292999..1ab3538f4a 100644
--- a/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php
+++ b/tests/Feature/ReportTemplates/UpdateReportTemplateTest.php
@@ -85,7 +85,7 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
->assertRedirectToRoute('report-templates.show', $reportTemplate->id);
$reportTemplate->refresh();
- $this->assertEquals(0, $reportTemplate->share_report_template);
+ $this->assertEquals(0, $reportTemplate->is_shared);
$this->assertEquals('Updated Name', $reportTemplate->name);
$this->assertEquals(0, $reportTemplate->checkmarkValue('category'));
$this->assertEquals([], $reportTemplate->selectValues('by_category_id'));
@@ -131,19 +131,19 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
$this->actingAs($user)
->post(route('report-templates.update', $reportTemplate), [
- 'name' => 'Updated Name',
+ 'name' => 'Original Name',
'options' => [
'category' => 1,
'by_category_id' => 2,
'company' => 1,
],
- 'share_report_template' => 1,
+ 'is_shared' => 1,
])
->assertRedirectToRoute('report-templates.show', $reportTemplate->id);
$reportTemplate->refresh();
- $this->assertEquals(1, $reportTemplate->share_report_template);
- $this->assertEquals('Updated Name', $reportTemplate->name);
+ $this->assertEquals(1, $reportTemplate->is_shared);
+ $this->assertEquals('Original Name', $reportTemplate->name);
}
}