fixed table action permission issue

This commit is contained in:
Cüneyt Şentürk 2023-05-22 15:55:23 +03:00
parent 4f31721396
commit 311b6c7da8
2 changed files with 48 additions and 51 deletions

View File

@ -548,7 +548,7 @@ class Company extends Eloquent implements Ownable
'title' => trans('general.switch'), 'title' => trans('general.switch'),
'icon' => 'settings_ethernet', 'icon' => 'settings_ethernet',
'url' => route('companies.switch', $this->id), 'url' => route('companies.switch', $this->id),
'permission' => 'read-common-companies', //'permission' => 'read-common-companies', remove this permission to allow switching to any company
'attributes' => [ 'attributes' => [
'id' => 'index-line-actions-switch-company-' . $this->id, 'id' => 'index-line-actions-switch-company-' . $this->id,
], ],

View File

@ -8,73 +8,70 @@
@else @else
<div class="absolute ltr:right-12 rtl:left-12 -top-4 hidden items-center group-hover:flex"> <div class="absolute ltr:right-12 rtl:left-12 -top-4 hidden items-center group-hover:flex">
@foreach ($actions as $action) @foreach ($actions as $action)
@if (! empty($action['permission']))
@can($action['permission'])
@endif
@if ($count_buttons > 3 && $loop->count > 4) @if ($count_buttons > 3 && $loop->count > 4)
@break @break
@endif @endif
@php @if (
$type = ! empty($action['type']) ? $action['type'] : 'link'; empty($action['permission'])
@endphp || (! empty($action['permission']) && user()->can($action['permission']))
)
@switch($type) @php
@case('button') $type = ! empty($action['type']) ? $action['type'] : 'link';
<button type="button" class="relative bg-white hover:bg-gray-100 border py-0.5 px-1 cursor-pointer index-actions group/tooltip" {!! $action['attributes'] ?? null !!}> @endphp
<span class="material-icons-outlined text-purple text-lg pointer-events-none">
{{ $action['icon'] }}
</span>
<div class="inline-block absolute invisible z-20 py-1 px-2 text-sm font-medium text-gray-900 bg-white rounded-lg border border-gray-200 shadow-sm whitespace-nowrap opacity-0 -top-10 -left-2 group-hover/tooltip:opacity-100 group-hover/tooltip:visible" data-tooltip-placement="top"> @switch($type)
<span>{{ $action['title'] }}</span> @case('button')
<div class="absolute w-2 h-2 -bottom-1 before:content-[' '] before:absolute before:w-2 before:h-2 before:bg-white before:border-gray-200 before:transform before:rotate-45 before:border before:border-t-0 before:border-l-0" data-popper-arrow></div> <button type="button" class="relative bg-white hover:bg-gray-100 border py-0.5 px-1 cursor-pointer index-actions group/tooltip" {!! $action['attributes'] ?? null !!}>
</div> <span class="material-icons-outlined text-purple text-lg pointer-events-none">
</button> {{ $action['icon'] }}
@break </span>
@case('delete') <div class="inline-block absolute invisible z-20 py-1 px-2 text-sm font-medium text-gray-900 bg-white rounded-lg border border-gray-200 shadow-sm whitespace-nowrap opacity-0 -top-10 -left-2 group-hover/tooltip:opacity-100 group-hover/tooltip:visible" data-tooltip-placement="top">
@php <span>{{ $action['title'] }}</span>
$text = $action['text'] ?? null; <div class="absolute w-2 h-2 -bottom-1 before:content-[' '] before:absolute before:w-2 before:h-2 before:bg-white before:border-gray-200 before:transform before:rotate-45 before:border before:border-t-0 before:border-l-0" data-popper-arrow></div>
$title = $action['title'] ?? null; </div>
$modelId = ! empty($action['model-id']) ? $action['model-id'] : 'id'; </button>
$modelName = ! empty($action['model-name']) ? $action['model-name'] : 'name'; @break
@endphp
<x-delete-button :model="$action['model']" :route="$action['route']" :title="$title" :text="$text" :model-id="$modelId" :model-name="$modelName" /> @case('delete')
@break @php
$text = $action['text'] ?? null;
$title = $action['title'] ?? null;
$modelId = ! empty($action['model-id']) ? $action['model-id'] : 'id';
$modelName = ! empty($action['model-name']) ? $action['model-name'] : 'name';
@endphp
@default <x-delete-button :model="$action['model']" :route="$action['route']" :title="$title" :text="$text" :model-id="$modelId" :model-name="$modelName" />
<a href="{{ $action['url'] }}" class="relative bg-white hover:bg-gray-100 border py-0.5 px-1 cursor-pointer index-actions group/tooltip" {!! $action['attributes'] ?? null !!}> @break
<span class="material-icons-outlined text-purple text-lg pointer-events-none">
{{ $action['icon'] }}
</span>
<div class="inline-block absolute invisible z-20 py-1 px-2 text-sm font-medium text-gray-900 bg-white rounded-lg border border-gray-200 shadow-sm whitespace-nowrap opacity-0 -top-10 -left-2 group-hover/tooltip:opacity-100 group-hover/tooltip:visible" data-tooltip-placement="top"> @default
<span>{{ $action['title'] }}</span> <a href="{{ $action['url'] }}" class="relative bg-white hover:bg-gray-100 border py-0.5 px-1 cursor-pointer index-actions group/tooltip" {!! $action['attributes'] ?? null !!}>
<div class="absolute w-2 h-2 -bottom-1 before:content-[' '] before:absolute before:w-2 before:h-2 before:bg-white before:border-gray-200 before:transform before:rotate-45 before:border before:border-t-0 before:border-l-0" data-popper-arrow></div> <span class="material-icons-outlined text-purple text-lg pointer-events-none">
</div> {{ $action['icon'] }}
</a> </span>
@endswitch
@php <div class="inline-block absolute invisible z-20 py-1 px-2 text-sm font-medium text-gray-900 bg-white rounded-lg border border-gray-200 shadow-sm whitespace-nowrap opacity-0 -top-10 -left-2 group-hover/tooltip:opacity-100 group-hover/tooltip:visible" data-tooltip-placement="top">
array_shift($actions); <span>{{ $action['title'] }}</span>
<div class="absolute w-2 h-2 -bottom-1 before:content-[' '] before:absolute before:w-2 before:h-2 before:bg-white before:border-gray-200 before:transform before:rotate-45 before:border before:border-t-0 before:border-l-0" data-popper-arrow></div>
</div>
</a>
@endswitch
$count_buttons++; @php
@endphp array_shift($actions);
@if (! empty($action['permission'])) $count_buttons++;
@endcan @endphp
@endif @endif
@endforeach @endforeach
@foreach ($actions as $action) @foreach ($actions as $action)
@if (! empty($action['permission'])) @if (
@can($action['permission']) empty($action['permission'])
@php $more_actions[] = $action; @endphp || (! empty($action['permission']) && user()->can($action['permission']))
@endcan )
@else
@php $more_actions[] = $action; @endphp @php $more_actions[] = $action; @endphp
@endif @endif
@endforeach @endforeach