Skip to content

Commit

Permalink
actually check permissions...
Browse files Browse the repository at this point in the history
  • Loading branch information
stokic committed Dec 7, 2023
1 parent 319eb55 commit 11788ce
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 71 deletions.
1 change: 1 addition & 0 deletions config/sales-management.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'logoLink' => '/',
'tablePrefix' => 'sales_management_',
'prefix' => '',
'permission_prefix' => 'sales_management',
'middleware' => ['web', 'auth'],
'userModel' => \App\Models\User::class,
'emails' => [
Expand Down
4 changes: 4 additions & 0 deletions src/Policies/SalesManagementPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function viewMessages()
{
return true;
}
public function viewActivities()
{
return true;
}

public function sendEmails()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Policies/SalesManagementPolicyContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public function viewWorkflows();
public function viewMessages();

public function sendEmails();

public function viewActivities();
}
21 changes: 11 additions & 10 deletions src/SalesManagementServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ public function loadViewComponents()

public function defineAbilities()
{
Gate::define(config('sales-management.prefix') . '.view-dashboard', [config('sales-management.policy'), 'viewDashboard']);
Gate::define(config('sales-management.prefix') . '.view-contacts', [config('sales-management.policy'), 'viewContacts']);
Gate::define(config('sales-management.prefix') . '.view-lists', [config('sales-management.policy'), 'viewLists']);
Gate::define(config('sales-management.prefix') . '.view-campaigns', [config('sales-management.policy'), 'viewCampaigns']);
Gate::define(config('sales-management.prefix') . '.view-pipelines', [config('sales-management.policy'), 'viewPipelines']);
Gate::define(config('sales-management.prefix') . '.view-tags', [config('sales-management.policy'), 'viewTags']);
Gate::define(config('sales-management.prefix') . '.view-docs', [config('sales-management.policy'), 'viewDocs']);
Gate::define(config('sales-management.prefix') . '.view-workflows', [config('sales-management.policy'), 'viewWorkflows']);
Gate::define(config('sales-management.prefix') . '.view-messages', [config('sales-management.policy'), 'viewMessages']);
Gate::define(config('sales-management.prefix') . '.send-emails', [config('sales-management.policy'), 'sendEmails']);
Gate::define(config('sales-management.permission_prefix') . '.view-dashboard', [config('sales-management.policy'), 'viewDashboard']);
Gate::define(config('sales-management.permission_prefix') . '.view-contacts', [config('sales-management.policy'), 'viewContacts']);
Gate::define(config('sales-management.permission_prefix') . '.view-lists', [config('sales-management.policy'), 'viewLists']);
Gate::define(config('sales-management.permission_prefix') . '.view-campaigns', [config('sales-management.policy'), 'viewCampaigns']);
Gate::define(config('sales-management.permission_prefix') . '.view-pipelines', [config('sales-management.policy'), 'viewPipelines']);
Gate::define(config('sales-management.permission_prefix') . '.view-tags', [config('sales-management.policy'), 'viewTags']);
Gate::define(config('sales-management.permission_prefix') . '.view-docs', [config('sales-management.policy'), 'viewDocs']);
Gate::define(config('sales-management.permission_prefix') . '.view-workflows', [config('sales-management.policy'), 'viewWorkflows']);
Gate::define(config('sales-management.permission_prefix') . '.view-messages', [config('sales-management.policy'), 'viewMessages']);
Gate::define(config('sales-management.permission_prefix') . '.send-emails', [config('sales-management.policy'), 'sendEmails']);
Gate::define(config('sales-management.permission_prefix') . '.view-activities', [config('sales-management.policy'), 'viewActivities']);
}
}
4 changes: 2 additions & 2 deletions src/resources/views/campaign/actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</button>

<div class="dropdown-menu dropdown-menu-end">
@can(config('sales-management.prefix').'.view-workflows')
@can(config('sales-management.permission_prefix').'.view-workflows')
<a href="{{ route('workflows.index', $id) }}" class="dropdown-item">{{__('Workflows')}}</a>
@endcan
@can(config('sales-management.prefix').'.view-messages')
@can(config('sales-management.permission_prefix').'.view-messages')
<a href="{{ route('messages.index', $id) }}" class="dropdown-item">{{__('Messages')}}</a>
@endcan
<a href="{{ route('campaign.show', $id) }}" class="dropdown-item">{{__('Show')}}</a>
Expand Down
6 changes: 3 additions & 3 deletions src/resources/views/campaign/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
<h1 class="h3 mb-3">{{ $campaign->name }}</h1>
<h6 class="mb-3">{{ $campaign->description }}</h6>
<div class="d-flex gap-2">
@can(config('sales-management.prefix').'.send-emails')
@can(config('sales-management.permission_prefix').'.send-emails')
<a href="{{ route('messages.create', $campaign->id) }}" class="btn btn-warning mb-3">
<span class="d-flex align-items-center">
<x-sales-management::icons.mail class="me-1"/> {{ __("Send email to leads") }}
</span>
</a>
@endcan
@can(config('sales-management.prefix').'.view-workflows')
@can(config('sales-management.permission_prefix').'.view-workflows')
<a href="{{ route('workflows.index', $campaign->id) }}" class="btn btn-info mb-3">
<span class="d-flex align-items-center">
<x-sales-management::icons.workflow class="me-1"/> {{ __("Workflows") }}
</span>
</a>
@endcan
@can(config('sales-management.prefix').'.view-messages')
@can(config('sales-management.permission_prefix').'.view-messages')
<a href="{{ route('messages.index', $campaign->id) }}" class="btn btn-info mb-3">
<span class="d-flex align-items-center">
<x-sales-management::icons.mail class="me-1"/> {{ __("Messages") }}
Expand Down
16 changes: 8 additions & 8 deletions src/resources/views/layouts/partials/left-navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,63 @@
<li class="sidebar-header">
{{__("Sales Management")}}
</li>
@can(config('sales-management.prefix').'.view-dashboard')
@can(config('sales-management.permission_prefix').'.view-dashboard')
<li class="sidebar-item {{ request()->is('dashboard') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('dashboard') }}">
<i class="align-middle" data-feather="sliders"></i> <span
class="align-middle">{{ __("Dashboard")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-contacts')
@can(config('sales-management.permission_prefix').'.view-contacts')
<li class="sidebar-item {{ request()->is('contacts*') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('contacts.index') }}">
<i class="align-middle" data-feather="user"></i> <span
class="align-middle">{{ __("Contacts")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-lists')
@can(config('sales-management.permission_prefix').'.view-lists')
<li class="sidebar-item {{ request()->is('list*') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('lists.index') }}">
<i class="align-middle" data-feather="clipboard"></i> <span
class="align-middle">{{ __("Lists")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-campaigns')
@can(config('sales-management.permission_prefix').'.view-campaigns')
<li class="sidebar-item {{ request()->is('campaign*') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('campaign.index') }}">
<i class="align-middle me-2 fas fa-fw fa-bullhorn"></i> <span
class="align-middle">{{ __("Campaigns")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-activities')
@can(config('sales-management.permission_prefix').'.view-activities')
<li class="sidebar-item {{ request()->is('activities*') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('lead-activities.index') }}">
<i class="align-middle me-2 fas fa-fw fa-phone"></i> <span
class="align-middle">{{ __("Activities")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-pipelines')
@can(config('sales-management.permission_prefix').'.view-pipelines')
<li class="sidebar-item {{ request()->is('pipelines*') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('pipelines.index') }}">
<i class="align-middle" data-feather="list"></i> <span
class="align-middle">{{ __("Pipelines")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-tags')
@can(config('sales-management.permission_prefix').'.view-tags')
<li class="sidebar-item {{ request()->is('tags*') ? 'active' : '' }}">
<a class="sidebar-link" href="{{ route('tags.index') }}">
<i class="align-middle" data-feather="tag"></i> <span
class="align-middle">{{ __("Tags")}}</span>
</a>
</li>
@endcan
@can(config('sales-management.prefix').'.view-docs')
@can(config('sales-management.permission_prefix').'.view-docs')
<li class="sidebar-item {{ request()->is('docs*') ? 'active' : '' }}">
<a class="sidebar-link" href="#docsMenu" data-bs-toggle="collapse" aria-expanded="false">
<i class="align-middle" data-feather="book"></i> <span class="align-middle">Docs</span>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/messages/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<h1 class="h3 mb-3">{{ __('Messages') }}</h1>
<div class="d-flex mb-3 justify-content-between align-items-center">
@can(config('sales-management.prefix').'.view-workflows')
@can(config('sales-management.permission_prefix').'.view-workflows')
<a href="{{ route('workflows.index', $campaign->id) }}" class="btn btn-info ">
<span class="d-flex align-items-center">
<x-sales-management::icons.workflow class="me-1"/> {{ __("Workflows") }}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/workflows/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="container-fluid p-0">
<h1 class="h3 mb-3">{{ __('Workflows') }}</h1>
<div class="d-flex mb-3 justify-content-between align-items-center">
@can(config('sales-management.prefix').'.view-messages')
@can(config('sales-management.permission_prefix').'.view-messages')
<a href="{{ route('messages.index', $campaign->id) }}" class="btn btn-info">
<span class="d-flex align-items-center">
<x-sales-management::icons.mail class="me-1"/> {{ __("Messages") }}
Expand Down
Loading

0 comments on commit 11788ce

Please sign in to comment.