Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,14 @@ public function show(Request $request, $id): JsonResponse|array
{
if (
$asset = Asset::with('assetstatus')
->with('assignedTo')->withTrashed()
->withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')->find($id)
->with('assignedTo')
->withTrashed()
->withCount(
'checkins as checkins_count',
'checkouts as checkouts_count',
'userRequests as user_requests_count'
)
->find($id)
) {
$this->authorize('view', $asset);

Expand Down
33 changes: 22 additions & 11 deletions app/Http/Controllers/Api/PredefinedFilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function show(int $id)
return response()->json(['message' => trans('admin/predefinedFilters/message.does_not_exist')], 404);
}

if ($filter->userHasPermission(Auth::user(), 'view')){
if ($filter->userHasPermission(Auth::user(), 'view')) {
return response()->json($filter->toArray());
}

Expand Down Expand Up @@ -124,16 +124,9 @@ public function update(Request $request, int $id): JsonResponse

$validated = $validator->validated();

$newIsPublic = $validated['is_public'] ?? $filter->is_public;
$currentIsPublic = $filter->is_public;

if (!$filter->userHasPermission($user, 'edit')){
return response()->json(['message' => trans('admin/predefinedFilters/message.not_allowed_to_edit')], 403);
}

//create permission
if ((!$currentIsPublic && $newIsPublic) && !$filter->userHasPermission($user, 'create')){
return response()->json(['message' => trans('admin/predefinedFilters/message.update.not_allowed_to_change_isPublic')], 403);
$updatedPermission = updatePermissions($validated, $filter);
if($updatedPermission !== null) {
return $updatedPermission;
}

$updated = $this->service->updateFilter($filter, $validated);
Expand All @@ -143,6 +136,7 @@ public function update(Request $request, int $id): JsonResponse
'filter_data' => $updated,
]);
}

public function destroy(int $id)
{
$user = auth()->user();
Expand All @@ -165,4 +159,21 @@ public function selectlist(Request $request)
$filters = $this->service->selectList($request, true);
return (new SelectlistTransformer)->transformSelectlist($filters);
}

private updatePermissions($validated, $filter) {
$newIsPublic = $validated['is_public'] ?? $filter->is_public;
$currentIsPublic = $filter->is_public;

if (!$filter->userHasPermission($user, 'edit')) {
return response()->json(['message' => trans('admin/predefinedFilters/message.not_allowed_to_edit')], 403);
}

//create permission
if ((!$currentIsPublic && $newIsPublic)
&& !$filter->userHasPermission($user, 'create')) {
return response()->json(['message' => trans('admin/predefinedFilters/message.update.not_allowed_to_change_isPublic')], 403);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class PredefinedFilterPermissionController extends Controller
{

protected PredefinedFilterPermissionService $service;

public function __construct(PredefinedFilterPermissionService $service)
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
class AssetsController extends Controller
{
protected $qrCodeDimensions = ['height' => 3.5, 'width' => 3.5];

protected $barCodeDimensions = ['height' => 2, 'width' => 22];

protected PredefinedFilterService $predefinedFilterService;

public function __construct(PredefinedFilterService $predefinedFilterService)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PredefinedFilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function view(PredefinedFilter $filter) : View|RedirectResponse
/**
* Delete the given Predefined Filter.
*
* @param int $Id
* @param int $id
*/
public function destroy($id) : RedirectResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Transformers/PredefinedFiltersTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function transformPredefinedFilter($filter)
'id' => (int) $filter->id,
'name'=> e($filter->name),
'filter_data' => json_decode($filter->filter_data),
'is_public' => (bool)$filter->is_public,
'is_public' => (bool) $filter->is_public,
'object_type' => e($filter->object_type),
'created_by' => $filter->createdBy ? [
'id' => (int) $filter->createdBy->id,
Expand Down
18 changes: 9 additions & 9 deletions app/Livewire/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Notifications extends Component
*
* @var array<int, array<string,mixed>>
*/
public array $liveAlerts = [];
public array $liveAlerts=[];

/**
* Main notification listener.
Expand All @@ -67,14 +67,14 @@ class Notifications extends Component
#[On('showNotification')]
#[On('notify')]
public function notify(
$type = null,
$message = null,
$title = null,
$description = null,
$icon = null,
$html = null,
$tag = null,
$payload = null // wrapper form: { payload: { ... } }
$type=null,
$message=null,
$title=null,
$description=null,
$icon=null,
$html=null,
$tag=null,
$payload=null // wrapper form: { payload: { ... } }
): void {
// Wrapper form: { payload: { ...full data... } }
if (is_array($payload)) {
Expand Down
99 changes: 50 additions & 49 deletions app/Livewire/Partials/AdvancedSearch/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ enum AdvancedsearchModalAction: string

class Modal extends Component
{
public $showModal = false;
public $showModal=false;
public AdvancedsearchModalAction $modalActionType;

#[Validate("required")]
public FilterVisibility $visibility = FilterVisibility::Private;

#[Validate("required")]
public ?string $name = "";
public ?string $name="";

#[Validate("sometimes")]
public $groupSelect = [];
public $groupSelect=[];

#[Validate("sometimes")]
public array $groupSelectOtherOptions = [];
public array $groupSelectOtherOptions=[];

protected $listeners = ["groupSelect"];
protected $listeners=["groupSelect"];

public ?int $filterId;

Expand Down Expand Up @@ -75,42 +75,45 @@ public function openPredefinedFiltersModal(
}

if (
$this->modalActionType === AdvancedsearchModalAction::Edit &&
$predefinedFilterId !== null
$this->modalActionType === AdvancedsearchModalAction::Edit
&& $predefinedFilterId !== null
) {
$predefinedFilter = $predefinedFilterService->getFilterWithOptionalPermissionsById(
$predefinedFilterId
);
$this->openPredefinedFiltersEditModal($predefinedFilterId);
}

$this->dispatch("openPredefinedFiltersModalEvent");
}

private function openPredefinedFiltersEditModal($predefinedFilterId) {
$predefinedFilter = $predefinedFilterService->getFilterWithOptionalPermissionsById(
$predefinedFilterId
);

if ($predefinedFilter === null) {
$this->showModal = false;
$this->dispatchNotFoundNotification();
return;
}
if ($predefinedFilter === null) {
$this->showModal = false;
$this->dispatchNotFoundNotification();
return;
}

$this->name = $predefinedFilter["name"];

if ($predefinedFilter["is_public"] == 1) {
$this->visibility = FilterVisibility::Public;
} else {
$this->visibility = FilterVisibility::Private;
}
$this->name = $predefinedFilter["name"];

foreach ($predefinedFilter["permissions"] as $permission) {
array_push(
$this->groupSelect,
$permission->permission_group_id
);
}
if ($predefinedFilter["is_public"] == 1) {
$this->visibility = FilterVisibility::Public;
} else {
$this->visibility = FilterVisibility::Private;
}

$this->groupSelectOtherOptions = array_diff(
$this->groupSelectOtherOptions,
$this->groupSelect
foreach ($predefinedFilter["permissions"] as $permission) {
array_push(
$this->groupSelect,
$permission->permission_group_id
);
}
// end if

$this->dispatch("openPredefinedFiltersModalEvent");
$this->groupSelectOtherOptions = array_diff(
$this->groupSelectOtherOptions,
$this->groupSelect
);
}

#[On("closePredefinedFiltersModal")]
Expand All @@ -131,13 +134,7 @@ public function savePredefinedFiltersModal(
) {
$this->validate();

if ($this->validateMaxLenghtForFiltername()) {
$this->dispatch('showNotificationInFrontend', [
'type' => 'error',
'title' => trans('general.notification_error'),
'message' => trans('admin/predefinedFilters/message.name_too_long'),
'tag' => 'predefinedFilter',
]);
if(!$this->validateMaxLenghtForFiltername()) {
return;
}

Expand Down Expand Up @@ -210,13 +207,7 @@ public function updatePredefinedFiltersModal(
'groupSelect.*' => 'required|integer|exists:permission_groups,id',
]);

if($this->validateMaxLenghtForFiltername()) {
$this->dispatch('showNotificationInFrontend', [
'type' => 'error',
'title' => trans('general.notification_error'),
'message' => trans('admin/predefinedFilters/message.name_too_long'),
'tag' => 'predefinedFilter',
]);
if(!$this->validateMaxLenghtForFiltername()) {
return;
}

Expand Down Expand Up @@ -316,7 +307,7 @@ public function deletePredefinedFiltersModal(

$predefinedFilter = $predefinedFilterService->getFilterWithOptionalPermissionsById($this->filterId);

if ($predefinedFilter === null){
if ($predefinedFilter === null) {
$this->dispatchNotFoundNotification();
return;
}
Expand Down Expand Up @@ -414,6 +405,16 @@ private function dispatchNotFoundNotification()
}

private function validateMaxLenghtForFiltername(): bool {
return mb_strlen($this->name) > 190;
if (mb_strlen($this->name) > 190) {
$this->dispatch('showNotificationInFrontend', [
'type' => 'error',
'title' => trans('general.notification_error'),
'message' => trans('admin/predefinedFilters/message.name_too_long'),
'tag' => 'predefinedFilter',
]);
return false;
}
return true;
}

}
10 changes: 5 additions & 5 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
class Asset extends Depreciable
{

protected ?FilterService $filterService = null;

public function filterService(): FilterService
Expand Down Expand Up @@ -451,17 +452,16 @@ public function company()
*/
public function availableForCheckout()
{

// This asset is not currently assigned to anyone and is not deleted...
if ((!$this->assigned_to) && (!$this->deleted_at)) {

// The asset status is not archived and is deployable
if (
($this->assetstatus) && ($this->assetstatus->archived == '0')
&& ($this->assetstatus->deployable == '1')
($this->assetstatus) &&
($this->assetstatus->archived == '0') &&
($this->assetstatus->deployable == '1')
) {
return true;

}
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions app/Policies/PredefinedFilterPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function columnName()
}


public function view(User $user, $filter = null)
public function view(User $user, $filter=null)
{
// Global permission
if (parent::view($user, $filter)) {
Expand All @@ -33,7 +33,7 @@ public function view(User $user, $filter = null)
return false;
}

public function update(User $user, $filter = null)
public function update(User $user, $filter=null)
{
if (parent::update($user, $filter)) {
return true;
Expand All @@ -46,7 +46,7 @@ public function update(User $user, $filter = null)
return false;
}

public function delete(User $user, $filter = null)
public function delete(User $user, $filter=null)
{
if (parent::delete($user, $filter)) {
return true;
Expand Down
1 change: 1 addition & 0 deletions database/factories/PermissionGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class PermissionGroupFactory extends Factory
{

protected $model = PermissionGroup::class;

public function definition()
Expand Down
3 changes: 2 additions & 1 deletion database/seeders/PredefinedFilterPermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\PredefinedFilter;

use App\Models\PredefinedFilterPermission;
use Exception;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function run(): void
]);

if (!$user instanceof User) {
throw new \Exception('user could not be created.. seeder aborting..');
throw new Exception('user could not be created.. seeder aborting..');
}

$filters = PredefinedFilter::limit(3)->get();
Expand Down
Loading
Loading