123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Repositories\Enums;
- use Closure;
- use Illuminate\Support\Str;
- use Jiannei\Enum\Laravel\Contracts\LocalizedEnumContract;
- use Jiannei\Enum\Laravel\Enum;
- class PermissionEnum extends Enum implements LocalizedEnumContract
- {
- // 系统级别内置的权限:不允许分配权限给普通用户;(比如,只能超级管理员才能拥有)
- // const SYSTEM = '000000';
- // const SYSTEM_ACTIVITY_LOG_CLEAN = '000001';
- // const SYSTEM_CACHE_CLEAR = '000002';
- /**
- * 任务
- */
- // const controller_openAppointment_all = '100100';
- const controller_task_list = '100101';
- const controller_task_add = '100102';
- const controller_task_del = '100103';
- const controller_task_allot = '100104';
- const controller_task_allot_all = '100105';
- const model_task_all = '200100';
- const model_task_me = '200101';
- const controller_paper_list = '100201';
- const controller_paper_add = '100202';
- const controller_paper_del = '100203';
- const model_paper_all = '200200';
- const model_paper_monitor = '200201';
- const model_paper_me = '200202';
- const controller_paperResult_list = '100301';
- const controller_paperResult_add = '100302';
- const controller_paperResult_del = '100303';
- const controller_paperResult_answer = '100304';
- const model_paperResult_all = '200300';
- const model_paperResult_monitor = '200301';
- const model_paperResult_me = '200302';
- const controller_topic_list = '100401';
- const controller_topic_add = '100402';
- const controller_topic_del = '100403';
- const controller_admin_list = '100501';
- const controller_admin_add = '100502';
- const controller_admin_del = '100503';
- const model_admin_all = '200500';
- const model_admin_monitor = '200501';
- public $name;
- public $code;
- public $type;
- public $description;
- public function __construct($enumValue, $strict = true)
- {
- parent::__construct($enumValue, $strict);
- $this->name = Str::lower(str_replace('_', ':', $this->key));
- $this->code = $enumValue;
- $this->type = Str::lower(current(explode('_', $this->key)));
- }
- /**
- * 根据常量定义构建权限.
- *
- * @return array
- */
- public static function makePermissions(): array
- {
- $rawPermissions = self::getInstances();
- $permissions = [];
- collect($rawPermissions)->each(function ($item) use (&$permissions) {
- $permissions[] = [
- // 'name' => $item->name,
- 'name' => $item->value,
- ];
- });
- return $permissions;
- }
- /**
- * 前置-授权拦截检查.
- *
- * @return Closure
- */
- public static function gateBeforeCallback(): Closure
- {
- return function ($user, $ability) {
- return $user->isSuperAdmin() ?: null;
- };
- }
- }
|