This commit is contained in:
2026-10-20 10:26:45 +03:30
parent 4d0f0f8c8d
commit a5f3b3b4b3
8 changed files with 377 additions and 2 deletions
@@ -8,7 +8,9 @@ use App\Models\Permission;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\Setting;
use App\Services\AdminPageAccess;
use App\Services\SmsBilling\SmsWalletService;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class UserController extends SuperController
{
@@ -25,6 +27,41 @@ class UserController extends SuperController
}
public function store(Request $request)
{
$this->applyPageAccessInput($request, true);
return parent::store($request);
}
public function update(Request $request, $id)
{
$this->applyPageAccessInput($request, false);
return parent::update($request, $id);
}
private function applyPageAccessInput(Request $request, bool $creating): void
{
$actor = auth('user')->user();
if (!$actor instanceof User || !AdminPageAccess::hasFullAccess($actor)) {
if ($creating && $actor instanceof User) {
$request->merge(['page_access' => $actor->page_access]);
} else {
$request->replace($request->except('page_access'));
}
return;
}
if (!$request->exists('page_access')) {
return;
}
$normalized = AdminPageAccess::normalize($request->input('page_access'));
if (is_array($normalized) && !AdminPageAccess::hasAnyView($normalized)) {
throw new UnprocessableEntityHttpException('حداقل مشاهدهٔ یک صفحه را انتخاب کنید');
}
$request->merge(['page_access' => $normalized]);
}
public function me(){
$user = User::with($this->with)
->select($this->select)