Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/PredefinedFilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function update(Request $request, int $id): JsonResponse
'filter_data' => $updated,
]);
}
public function destroy(Request $request, int $id)
public function destroy(int $id)
{
$user = auth()->user();
$filter = PredefinedFilter::find($id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function store(Request $request): JsonResponse
]);
}

public function show(Request $request, int $id): JsonResponse
public function show(int $id): JsonResponse
{
$this->authorize('view', PredefinedFilter::class);

Expand All @@ -58,7 +58,7 @@ public function show(Request $request, int $id): JsonResponse
return response()->json($permission);
}

public function destroy(Request $request, int $id): JsonResponse
public function destroy(int $id): JsonResponse
{
$this->authorize('delete', PredefinedFilterPermission::class);

Expand All @@ -71,4 +71,4 @@ public function destroy(Request $request, int $id): JsonResponse
'message' => __('admin/reports/message.delete.success'),
], 204);
}
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/PredefinedFilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public function destroy($Id) : RedirectResponse
return redirect()->route('predefined-filters.index')
->with('error', trans('general.insufficient_permissions'));
}
}
}
12 changes: 5 additions & 7 deletions app/Http/Transformers/PredefinedFiltersTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Collection;
use App\Models\Setting;

class PredefinedFiltersTransformer
class PredefinedFiltersTransformer
{
public function transformPredefinedFilters(Collection $filters, $total)
{
Expand All @@ -15,12 +15,11 @@ public function transformPredefinedFilters(Collection $filters, $total)
$array[] = self::transformPredefinedFilter($filter);
}

return (new DatatablesTransformer) -> transformDatatables($array, $total);
return (new DatatablesTransformer)->transformDatatables($array, $total);
}

public function transformPredefinedFilter($filter)
{
$setting = Setting::getSettings();

$array = [
'id' => (int) $filter->id,
Expand All @@ -29,7 +28,7 @@ public function transformPredefinedFilter($filter)
'is_public' => (bool)$filter->is_public,
'object_type' => e($filter->object_type),
'created_by' => $filter->createdBy ? [
'id' => (int) $filter-> createdBy ->id,
'id' => (int) $filter->createdBy->id,
'name' => $filter->createdBy->present()->nameUrl(),
] : null,
'created_at' => Helper::getFormattedDateObject($filter->created_at, 'datetime'),
Expand Down Expand Up @@ -62,7 +61,6 @@ public function transformPredefinedFilter($filter)
'update' => $filter->created_by === auth()->id() || $filter->userHasPermission(auth()->user(), 'edit'),
'delete' => $filter->created_by === auth()->id() || $filter->userHasPermission(auth()->user(), 'delete')
];
$array += $permissions_array;
return $array;
return $array += $permissions_array;
}
}
}
10 changes: 5 additions & 5 deletions app/Livewire/Partials/AdvancedSearch/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public function savePredefinedFiltersModal(
$predefinedFilterService->createFilter($validated);

$this->dispatch('showNotificationInFrontend', [
'type' => 'success',
'title' => trans('general.notification_success'),
'message' => trans('admin/predefinedFilters/message.create.success'),
'tag' => 'predefinedFilter',
]);
'type' => 'success',
'title' => trans('general.notification_success'),
'message' => trans('admin/predefinedFilters/message.create.success'),
'tag' => 'predefinedFilter',
]);

$this->dispatch("savePredefinedFiltersModalEvent");
$this->dispatch("closePredefinedFiltersModal");
Expand Down
6 changes: 2 additions & 4 deletions app/Models/PredefinedFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Watson\Validating\ValidatingTrait;
use Illuminate\Database\Eloquent\Builder;

use App\Models\User;

class PredefinedFilter extends Model
{
use HasFactory;
Expand Down Expand Up @@ -101,7 +99,7 @@ private function checkPermissions(User $user, $action): bool
foreach ($this->permissionGroups as $group) {
if (in_array($group->id, $userGroupIds)) {
$permissions = json_decode($group->permissions, true);
if ((isset($permissions["predefinedFilter.$action"]) && $permissions["predefinedFilter.$action"] == '1')) {
if (isset($permissions["predefinedFilter.$action"]) && $permissions["predefinedFilter.$action"] == '1') {
return true;
}
}
Expand Down Expand Up @@ -187,4 +185,4 @@ public function checkIfNameAlreadyExists(string $name, int $id = null): bool
return sizeof($query->get()->toArray()) > 1;

}
}
}
5 changes: 2 additions & 3 deletions app/Policies/PredefinedFilterPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\User;
use App\Models\PredefinedFilter;
use App\Policies\SnipePermissionsPolicy;

class PredefinedFilterPolicy extends SnipePermissionsPolicy
{
Expand All @@ -23,8 +22,8 @@ public function view(User $user, $filter = null)

//Controller
if (is_string($filter) && $filter === PredefinedFilter::class) {
return true;
}
return true;
}

// Record-level permissions
if ($filter instanceof PredefinedFilter) {
Expand Down
23 changes: 11 additions & 12 deletions app/Services/FilterService/FilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ protected function applyAssignedToUser($inner, $assignedValue, $operator){
$this->applyRelationalValue($r, $last, $operator, ['column' => 'users.last_name']);
});
});

});
}
protected function applyAssignedToAsset($inner, $assignedValue, $operator){
Expand All @@ -293,18 +292,18 @@ protected function applyAssignedToAsset($inner, $assignedValue, $operator){
$inner->where(function ($q) use ($assignedValue, $operator) {
$q->whereNotNull('assets.assigned_to')
->where('assets.assigned_type', Asset::class)
->whereExists(function ($sub) use ($assignedValue, $operator) {
$sub->from('assets as b')
->whereExists(function ($sub) use ($assignedValue, $operator) {
$sub->from('assets as b')
->select('b.id')
->whereColumn('b.id', 'assets.assigned_to')
->where(function ($q2) use ($assignedValue, $operator) {
if ($operator === 'equals') {
$q2->where('b.asset_tag', '=', $assignedValue)
->orWhere('b.name', '=', $assignedValue);
} else {
$q2->where('b.asset_tag', 'LIKE', '%' . $assignedValue . '%')
->orWhere('b.name', 'LIKE', '%' . $assignedValue . '%');
}
->whereColumn('b.id', 'assets.assigned_to')
->where(function ($q2) use ($assignedValue, $operator) {
if ($operator === 'equals') {
$q2->where('b.asset_tag', '=', $assignedValue)
->orWhere('b.name', '=', $assignedValue);
} else {
$q2->where('b.asset_tag', 'LIKE', '%' . $assignedValue . '%')
->orWhere('b.name', 'LIKE', '%' . $assignedValue . '%');
}
});
});
});
Expand Down
1 change: 0 additions & 1 deletion app/Services/PredefinedFilterPermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function store(array $validated): PredefinedFilterPermission
}

return $permission;

}

public function show(int $id): PredefinedFilterPermission
Expand Down
4 changes: 1 addition & 3 deletions app/Services/PredefinedFilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Throwable;
use App\Models\PredefinedFilter;
use App\Services\FilterService\FilterService;
use App\Services\PredefinedFilterPermissionService;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
Expand All @@ -35,7 +34,6 @@ public function __construct(PredefinedFilterPermissionService $predefinedFilterP
public function filterService(): FilterService
{
return $this->filterService ??= app(FilterService::class);

}

public function getAllViewableFilters(): Collection
Expand Down Expand Up @@ -141,7 +139,7 @@ public function getFilterWithOptionalPermissionsById(int $id, bool $include_pred
}
break;
default:
break;
break;
}
}

Expand Down
1 change: 0 additions & 1 deletion routes/web/predefined-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
->name('predefined-filters.view');
Route::delete('predefined-filters/{id}', [PredefinedFilterController::class, 'destroy'])->name('predefined-filters.destroy');
});