wip
This commit is contained in:
parent
c92967c6ca
commit
a1d063b0dd
@ -12,7 +12,6 @@ class StudiesController extends HashidControllerBase
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$studies = UserStudyListerFactory::getLister()->all();
|
$studies = UserStudyListerFactory::getLister()->all();
|
||||||
dd($studies);
|
|
||||||
|
|
||||||
return view('staff.studies.index', compact('studies'));
|
return view('staff.studies.index', compact('studies'));
|
||||||
}
|
}
|
||||||
|
@ -66,11 +66,11 @@ public function getHistoryLink(): string
|
|||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
if ($user->may(Permission::StudyHistoryEdit)) {
|
if ($user->may(Permission::StudyHistoryEdit)) {
|
||||||
return route('staff.history.edit', _h($this->id));
|
return route('staff.history.edit', $this->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->may(Permission::StudyHistoryView)) {
|
if ($user->may(Permission::StudyHistoryView)) {
|
||||||
return route('staff.history.view', _h($this->id));
|
return route('staff.history.view', $this->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '#';
|
return '#';
|
||||||
|
@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Traits\HashableId;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class StudyDetails extends BaseModel
|
class StudyDetails extends BaseModel
|
||||||
{
|
{
|
||||||
protected $table = 'study_details';
|
protected $table = 'study_details';
|
||||||
|
|
||||||
|
use HashableId;
|
||||||
|
|
||||||
public function study(): BelongsTo
|
public function study(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Study::class);
|
return $this->belongsTo(Study::class);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use App\Models\Enums\Permission;
|
use App\Models\Enums\Permission;
|
||||||
use App\Models\Enums\UserRole;
|
use App\Models\Enums\UserRole;
|
||||||
|
use App\Models\Traits\HashableId;
|
||||||
use Database\Factories\UserFactory;
|
use Database\Factories\UserFactory;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
@ -21,6 +22,7 @@ class User extends Authenticatable
|
|||||||
/** @use HasFactory<UserFactory> */
|
/** @use HasFactory<UserFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
use HashableId;
|
||||||
use HasProfilePhoto;
|
use HasProfilePhoto;
|
||||||
use HasRoles;
|
use HasRoles;
|
||||||
use Notifiable;
|
use Notifiable;
|
||||||
@ -90,11 +92,14 @@ public function scopeActive($query)
|
|||||||
|
|
||||||
public function isAdmin(): bool
|
public function isAdmin(): bool
|
||||||
{
|
{
|
||||||
return $this->hasRole(UserRole::Admin);
|
return cache()->remember('user.is_admin:'.$this->id,
|
||||||
|
5 * 60,
|
||||||
|
fn () => $this->hasRole(UserRole::Admin)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function may(Permission $perm): bool
|
public function may(Permission|iterable|string $perm): bool
|
||||||
{
|
{
|
||||||
return $this->hasRole(UserRole::Admin) || $this->can($perm);
|
return $this->isAdmin() || $this->can($perm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,3 +47,14 @@ function user_per_page(?int $user_id = null): int
|
|||||||
return settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
|
return settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('may')) {
|
||||||
|
function may(BackedEnum|iterable|string $perm): bool
|
||||||
|
{
|
||||||
|
if (auth()->user()->isAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return auth()->user()->can($perm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user