Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
ユーザーの編集権限を調整
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Apr 15, 2023
1 parent c142781 commit d8c5c96
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions plugins/baser-core/src/Model/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ public function isDeletableUser(EntityInterface $targetUser): bool
* 対象ユーザーに対して編集可能かどうか判定する
*
* 利用可能条件
* - 自身がスーパーユーザーで対象がスーパーユーザーでない場合
* - 自身がシステム管理ユーザーで対象がシステム管理ユーザーでない場合
* - 自身がスーパーユーザーの場合無条件に可
* - 自身に対しての変更は可
* - 相手がシステム管理ユーザーでない場合は可(アクセスルールで制御)
*
* @param EntityInterface|User $targetUser
* @return bool
*/
public function isEditableUser(EntityInterface $targetUser): bool
{
return ($this->isSuper() ||
($this->id === $targetUser->id) ||
($this->isAdmin() && !$targetUser->isAdmin()));
if($this->isSuper()) return true;
if($this->id === $targetUser->id) return true;
return !$targetUser->isAdmin();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions plugins/baser-core/src/Service/Admin/UsersAdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function isEditable(?int $id): bool
/**
* ユーザーグループが更新可能かどうか
*
* ログインユーザーがシステム管理ユーザーの場合のみ可
* - ログインユーザーがシステム管理ユーザーの場合可
* - 自身に対しての編集でない場合可
*
* @param $id
* @return bool
Expand All @@ -91,7 +92,7 @@ public function isEditable(?int $id): bool
*/
public function isUserGroupEditable(?int $id): bool
{
return ($id === null || BcUtil::isAdminUser());
return ($id === null || BcUtil::isAdminUser() || !$this->isSelf($id));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function testIsUserGroupEditable()
$this->assertTrue($this->Users->isUserGroupEditable(2));
// サイト運営ユーザーで他ユーザー更新
$this->loginAdmin($this->getRequest('/baser/admin'), 2);
$this->assertFalse($this->Users->isUserGroupEditable(1));
$this->assertTrue($this->Users->isUserGroupEditable(1));
// サイト運営ユーザーで自身を更新
$this->assertFalse($this->Users->isUserGroupEditable(2));
}
Expand Down

0 comments on commit d8c5c96

Please sign in to comment.