mirror of
https://github.com/grokability/snipe-it.git
synced 2026-03-12 17:52:00 +08:00
changing 'shared_report_template' to 'is_shared' in DB
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user