Skip to content

Commit

Permalink
Code style (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
zds-s authored Apr 19, 2024
1 parent 88b94b4 commit d0656a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
4 changes: 1 addition & 3 deletions app/System/Service/SystemUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ public function __construct(

/**
* 获取用户信息.
* @param int|null $userId
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getInfo(?int $userId = null): array
{
if ($uid = ( is_null($userId) ? user()->getId() : $userId )) {
if ($uid = (is_null($userId) ? user()->getId() : $userId)) {
return $this->getCacheInfo($uid);
}
throw new MineException(t('system.unable_get_userinfo'), 500);
Expand Down
15 changes: 5 additions & 10 deletions common/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
*/
use App\Setting\Service\SettingConfigService;
use App\System\Service\SystemUserService;
use App\System\Vo\AmqpQueueVo;
use App\System\Vo\QueueMessageVo;
use Hyperf\Cache\Listener\DeleteListenerEvent;
Expand Down Expand Up @@ -139,16 +140,13 @@ function is_in_container(): bool

if (! function_exists('has_permission')) {
/**
* 检查用户是否拥有某权限
* @param string $code
* @param int|null $userId
* @return bool
* 检查用户是否拥有某权限.
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
function has_permission(string $code, ?int $userId = null): bool
{
$codes = container()->get(\App\System\Service\SystemUserService::class)->getInfo($userId)['codes'];
$codes = container()->get(SystemUserService::class)->getInfo($userId)['codes'];
if ($codes[0] === '*') {
return true;
}
Expand All @@ -158,16 +156,13 @@ function has_permission(string $code, ?int $userId = null): bool

if (! function_exists('has_role')) {
/**
* 检查用户是否拥有某角色
* @param string $code
* @param int|null $userId
* @return bool
* 检查用户是否拥有某角色.
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
function has_role(string $code, ?int $userId = null): bool
{
$roles = container()->get(\App\System\Service\SystemUserService::class)->getInfo($userId)['roles'];
$roles = container()->get(SystemUserService::class)->getInfo($userId)['roles'];
if ($roles === 'superAdmin') {
return true;
}
Expand Down

0 comments on commit d0656a9

Please sign in to comment.