Added template editor separate role

This commit is contained in:
JhumanJ 2022-11-16 13:12:48 +01:00
parent d8bf96501b
commit 88812776db
7 changed files with 37 additions and 5 deletions

View File

@ -17,7 +17,7 @@ class TemplateController extends Controller
public function create(CreateTemplateRequest $request)
{
$this->middleware('admin');
$this->authorize('create', Template::class);
// Create template
$template = $request->getTemplate();
@ -28,5 +28,4 @@ class TemplateController extends Controller
'template_id' => $template->id
]);
}
}

View File

@ -18,6 +18,7 @@ class UserResource extends JsonResource
'is_subscribed' => $this->is_subscribed,
'has_enterprise_subscription' => $this->has_enterprise_subscription,
'admin' => $this->admin,
'template_editor' => $this->template_editor,
'has_customer_id' => $this->has_customer_id,
'has_forms' => $this->has_forms,
] : [];

View File

@ -99,6 +99,11 @@ class User extends Authenticatable implements JWTSubject //, MustVerifyEmail
return in_array($this->email, config('services.admin_emails'));
}
public function getTemplateEditorAttribute()
{
return $this->admin || in_array($this->email, config('services.template_editor_emails'));
}
/**
* =================================
* Helper Related

View File

@ -0,0 +1,23 @@
<?php
namespace App\Policies;
use App\Models\Template;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class TemplatePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
return $user->template_editor;
}
}

View File

@ -4,10 +4,12 @@ namespace App\Providers;
use App\Models\Forms\Form;
use App\Models\Integration\FormZapierWebhook;
use App\Models\Template;
use App\Models\Workspace;
use App\Models\User;
use App\Policies\FormPolicy;
use App\Policies\Integration\FormZapierWebhookPolicy;
use App\Policies\TemplatePolicy;
use App\Policies\WorkspacePolicy;
use App\Policies\UserPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
@ -22,7 +24,8 @@ class AuthServiceProvider extends ServiceProvider
protected $policies = [
Form::class => FormPolicy::class,
Workspace::class => WorkspacePolicy::class,
FormZapierWebhook::class => FormZapierWebhookPolicy::class
FormZapierWebhook::class => FormZapierWebhookPolicy::class,
Template::class => TemplatePolicy::class,
];
/**

View File

@ -52,5 +52,6 @@ return [
'amplitude_code' => env('AMPLITUDE_CODE'),
'crisp_website_id' => env('CRISP_WEBSITE_ID'),
'admin_emails' => explode(",", env('ADMIN_EMAILS') ?? '')
'admin_emails' => explode(",", env('ADMIN_EMAILS') ?? ''),
'template_editor_emails' => explode(",", env('TEMPLATE_EDITOR_EMAILS') ?? '')
];

View File

@ -67,7 +67,7 @@
</svg>
Duplicate form
</a>
<a href="#" v-if="user.admin"
<a href="#" v-if="user.template_editor"
class="block block px-4 py-2 text-md text-gray-700 dark:text-white hover:bg-gray-100 hover:text-gray-900 dark:text-gray-100 dark:hover:text-white dark:hover:bg-gray-600 flex items-center"
@click.prevent="showCreateTemplateModal=true"
>