diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 30cd7da8..45b77e30 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -78,7 +78,7 @@ class Test extends Command */ public function handle() { - $r = \Composer\InstalledVersions::getPrettyVersion('filament/filament'); + $r = NexusDB::cache_get('ssbb'); dd($r); } diff --git a/app/Filament/Resources/System/ExamResource/Pages/CreateExam.php b/app/Filament/Resources/System/ExamResource/Pages/CreateExam.php index 675aaa7a..897b48b7 100644 --- a/app/Filament/Resources/System/ExamResource/Pages/CreateExam.php +++ b/app/Filament/Resources/System/ExamResource/Pages/CreateExam.php @@ -17,7 +17,7 @@ class CreateExam extends CreateRecord // dd($data); $examRep = new ExamRepository(); try { - $examRep->store($data); + $this->record = $examRep->store($data); $this->notify('success', $this->getCreatedNotificationMessage()); if ($another) { // Ensure that the form record is anonymized so that relationships aren't loaded. diff --git a/app/Filament/Resources/System/ExamResource/Pages/EditExam.php b/app/Filament/Resources/System/ExamResource/Pages/EditExam.php index 95d1fedc..a29a2ba9 100644 --- a/app/Filament/Resources/System/ExamResource/Pages/EditExam.php +++ b/app/Filament/Resources/System/ExamResource/Pages/EditExam.php @@ -23,7 +23,7 @@ class EditExam extends EditRecord $data = $this->form->getState(); $examRep = new ExamRepository(); try { - $examRep->update($data, $this->record->id); + $this->record = $examRep->update($data, $this->record->id); $this->notify('success', $this->getSavedNotificationMessage()); $this->redirect($this->getResource()::getUrl('index')); } catch (\Exception $exception) { diff --git a/app/Filament/Resources/System/MedalResource/Pages/CreateMedal.php b/app/Filament/Resources/System/MedalResource/Pages/CreateMedal.php index f927f58b..0c952f5f 100644 --- a/app/Filament/Resources/System/MedalResource/Pages/CreateMedal.php +++ b/app/Filament/Resources/System/MedalResource/Pages/CreateMedal.php @@ -9,4 +9,9 @@ use Filament\Resources\Pages\CreateRecord; class CreateMedal extends CreateRecord { protected static string $resource = MedalResource::class; + + protected function getRedirectUrl(): string + { + return $this->getResource()::getUrl('index'); + } } diff --git a/app/Filament/Resources/System/TorrentStateResource.php b/app/Filament/Resources/System/TorrentStateResource.php new file mode 100644 index 00000000..60015652 --- /dev/null +++ b/app/Filament/Resources/System/TorrentStateResource.php @@ -0,0 +1,81 @@ +schema([ + Forms\Components\Select::make('global_sp_state') + ->options(Torrent::listPromotionTypes(true)) + ->label(__('label.torrent_state.global_sp_state')) + ->required(), + Forms\Components\DateTimePicker::make('deadline') + ->required() + ->label(__('label.deadline')), + ])->columns(1); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('global_sp_state_text')->label(__('label.torrent_state.global_sp_state')), + Tables\Columns\TextColumn::make('deadline')->label(__('label.deadline')), + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make()->after(function () { + do_log("cache_del: global_promotion_state"); + NexusDB::cache_del('global_promotion_state'); + NexusDB::cache_del('global_promotion_state_deadline'); + }), +// Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ +// Tables\Actions\DeleteBulkAction::make(), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ManageTorrentStates::route('/'), + ]; + } +} diff --git a/app/Filament/Resources/System/TorrentStateResource/Pages/ManageTorrentStates.php b/app/Filament/Resources/System/TorrentStateResource/Pages/ManageTorrentStates.php new file mode 100644 index 00000000..910afc6b --- /dev/null +++ b/app/Filament/Resources/System/TorrentStateResource/Pages/ManageTorrentStates.php @@ -0,0 +1,26 @@ +updateRecord($record); + static::authorizeResourceAccess(); + + $this->record = $this->resolveRecord($record); + + abort_unless(static::getResource()::canView($this->getRecord()), 403); + } protected function getActions(): array @@ -196,9 +202,9 @@ class UserProfile extends Page ]) ->action(function ($data) { - $examRep = new ExamRepository(); + $medalRep = new MedalRepository(); try { - $examRep->assignToUser($this->record->id, $data['exam_id'], $data['begin'], $data['end']); + $medalRep->grantToUser($this->record->id, $data['medal_id'], $data['duration']); $this->notify('success', 'Success!'); $this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id); } catch (\Exception $exception) { diff --git a/app/Models/TorrentState.php b/app/Models/TorrentState.php index fbe8f7b7..f0d32f1b 100644 --- a/app/Models/TorrentState.php +++ b/app/Models/TorrentState.php @@ -5,7 +5,12 @@ namespace App\Models; class TorrentState extends NexusModel { - public $incrementing = false; + protected $fillable = ['global_sp_state', 'deadline']; protected $table = 'torrents_state'; + + public function getGlobalSpStateTextAttribute() + { + return Torrent::$promotionTypes[$this->global_sp_state]['text'] ?? ''; + } } diff --git a/app/Models/User.php b/app/Models/User.php index 0727ee13..d7217bca 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,10 +17,11 @@ use Laravel\Sanctum\HasApiTokens; use Nexus\Database\NexusDB; use Filament\Models\Contracts\FilamentUser; use Filament\Models\Contracts\HasName; +use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable implements FilamentUser, HasName { - use HasFactory, Notifiable, HasApiTokens; + use HasFactory, Notifiable, HasApiTokens, HasRoles; public $timestamps = false; @@ -476,7 +477,7 @@ class User extends Authenticatable implements FilamentUser, HasName public function canAccessAdmin(): bool { - $targetClass = self::CLASS_SYSOP; + $targetClass = Setting::get('authority.staffmem'); if (!$this->class || $this->class < $targetClass) { do_log(sprintf('user: %s, no class or class < %s, can not access admin.', $this->id, $targetClass)); return false; diff --git a/app/Policies/AgentAllowPolicy.php b/app/Policies/AgentAllowPolicy.php new file mode 100644 index 00000000..6385e586 --- /dev/null +++ b/app/Policies/AgentAllowPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentAllow $agentAllow + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, AgentAllow $agentAllow) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentAllow $agentAllow + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, AgentAllow $agentAllow) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentAllow $agentAllow + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, AgentAllow $agentAllow) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentAllow $agentAllow + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, AgentAllow $agentAllow) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/AgentDenyPolicy.php b/app/Policies/AgentDenyPolicy.php new file mode 100644 index 00000000..95ac94b2 --- /dev/null +++ b/app/Policies/AgentDenyPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentDeny $agentDeny + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, AgentDeny $agentDeny) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentDeny $agentDeny + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, AgentDeny $agentDeny) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentDeny $agentDeny + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, AgentDeny $agentDeny) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\AgentDeny $agentDeny + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, AgentDeny $agentDeny) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/BasePolicy.php b/app/Policies/BasePolicy.php new file mode 100644 index 00000000..08a2d5f7 --- /dev/null +++ b/app/Policies/BasePolicy.php @@ -0,0 +1,20 @@ +class >= User::CLASS_STAFF_LEADER) { + return true; + } + } +} diff --git a/app/Policies/ClaimPolicy.php b/app/Policies/ClaimPolicy.php new file mode 100644 index 00000000..5bc77d12 --- /dev/null +++ b/app/Policies/ClaimPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\Claim $claim + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, Claim $claim) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Claim $claim + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, Claim $claim) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\Claim $claim + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, Claim $claim) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Claim $claim + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, Claim $claim) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/ExamPolicy.php b/app/Policies/ExamPolicy.php new file mode 100644 index 00000000..0722c67a --- /dev/null +++ b/app/Policies/ExamPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\Exam $exam + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, Exam $exam) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Exam $exam + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, Exam $exam) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\Exam $exam + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, Exam $exam) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Exam $exam + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, Exam $exam) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/ExamUserPolicy.php b/app/Policies/ExamUserPolicy.php new file mode 100644 index 00000000..0d08f874 --- /dev/null +++ b/app/Policies/ExamUserPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\ExamUser $examUser + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, ExamUser $examUser) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\ExamUser $examUser + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, ExamUser $examUser) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\ExamUser $examUser + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, ExamUser $examUser) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\ExamUser $examUser + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, ExamUser $examUser) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/HitAndRunPolicy.php b/app/Policies/HitAndRunPolicy.php new file mode 100644 index 00000000..1a1131ed --- /dev/null +++ b/app/Policies/HitAndRunPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\HitAndRun $hitAndRun + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, HitAndRun $hitAndRun) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\HitAndRun $hitAndRun + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, HitAndRun $hitAndRun) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\HitAndRun $hitAndRun + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, HitAndRun $hitAndRun) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\HitAndRun $hitAndRun + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, HitAndRun $hitAndRun) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/MedalPolicy.php b/app/Policies/MedalPolicy.php new file mode 100644 index 00000000..568fe00b --- /dev/null +++ b/app/Policies/MedalPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\Medal $medal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, Medal $medal) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Medal $medal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, Medal $medal) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\Medal $medal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, Medal $medal) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Medal $medal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, Medal $medal) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/SettingPolicy.php b/app/Policies/SettingPolicy.php new file mode 100644 index 00000000..d6fd797d --- /dev/null +++ b/app/Policies/SettingPolicy.php @@ -0,0 +1,103 @@ +class >= User::CLASS_SYSOP) { + return true; + } + return false; + } + +} diff --git a/app/Policies/TagPolicy.php b/app/Policies/TagPolicy.php new file mode 100644 index 00000000..8fb7316e --- /dev/null +++ b/app/Policies/TagPolicy.php @@ -0,0 +1,102 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\Tag $tag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, Tag $tag) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Tag $tag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, Tag $tag) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\Tag $tag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, Tag $tag) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\Tag $tag + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, Tag $tag) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_ADMINISTRATOR) { + return true; + } + return false; + } +} diff --git a/app/Policies/TorrentPolicy.php b/app/Policies/TorrentPolicy.php new file mode 100644 index 00000000..1a60b993 --- /dev/null +++ b/app/Policies/TorrentPolicy.php @@ -0,0 +1,102 @@ +class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/TorrentStatePolicy.php b/app/Policies/TorrentStatePolicy.php new file mode 100644 index 00000000..c4b3671e --- /dev/null +++ b/app/Policies/TorrentStatePolicy.php @@ -0,0 +1,95 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\UserMedal $userMedal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, UserMedal $userMedal) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\UserMedal $userMedal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, UserMedal $userMedal) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\UserMedal $userMedal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, UserMedal $userMedal) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\UserMedal $userMedal + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, UserMedal $userMedal) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php new file mode 100644 index 00000000..9f3fce00 --- /dev/null +++ b/app/Policies/UserPolicy.php @@ -0,0 +1,101 @@ +can($user); + } + + /** + * Determine whether the user can update the model. + * + * @param \App\Models\User $user + * @param \App\Models\User $model + * @return \Illuminate\Auth\Access\Response|bool + */ + public function update(User $user, User $model) + { + return $this->can($user); + } + + /** + * Determine whether the user can delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\User $model + * @return \Illuminate\Auth\Access\Response|bool + */ + public function delete(User $user, User $model) + { + return $this->can($user); + } + + /** + * Determine whether the user can restore the model. + * + * @param \App\Models\User $user + * @param \App\Models\User $model + * @return \Illuminate\Auth\Access\Response|bool + */ + public function restore(User $user, User $model) + { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param \App\Models\User $user + * @param \App\Models\User $model + * @return \Illuminate\Auth\Access\Response|bool + */ + public function forceDelete(User $user, User $model) + { + // + } + + private function can(User $user) + { + if ($user->class >= User::CLASS_SYSOP) { + return true; + } + return false; + } +} diff --git a/composer.json b/composer.json index f806f5d8..c31fa0c8 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "orangehill/iseed": "^3.0", "phpgangsta/googleauthenticator": "dev-master", "rhilip/bencode": "^2.0", + "spatie/laravel-permission": "^5.5", "spiral/roadrunner": "^2.8" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 63d07265..a452c95b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3f8e2bfc2d866abff6ef37466f43be7c", + "content-hash": "7a9971b631dca4a5322634b89075a35b", "packages": [ { "name": "akaunting/laravel-money", @@ -6181,6 +6181,94 @@ ], "time": "2022-06-28T14:29:26+00:00" }, + { + "name": "spatie/laravel-permission", + "version": "5.5.5", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-permission.git", + "reference": "f2303a70be60919811ca8afc313e8244fda00974" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/f2303a70be60919811ca8afc313e8244fda00974", + "reference": "f2303a70be60919811ca8afc313e8244fda00974", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "illuminate/auth": "^7.0|^8.0|^9.0", + "illuminate/container": "^7.0|^8.0|^9.0", + "illuminate/contracts": "^7.0|^8.0|^9.0", + "illuminate/database": "^7.0|^8.0|^9.0", + "php": "^7.3|^8.0|^8.1" + }, + "require-dev": { + "orchestra/testbench": "^5.0|^6.0|^7.0", + "phpunit/phpunit": "^9.4", + "predis/predis": "^1.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Permission\\PermissionServiceProvider" + ] + }, + "branch-alias": { + "dev-main": "5.x-dev", + "dev-master": "5.x-dev" + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\Permission\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Permission handling for Laravel 6.0 and up", + "homepage": "https://github.com/spatie/laravel-permission", + "keywords": [ + "acl", + "laravel", + "permission", + "permissions", + "rbac", + "roles", + "security", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-permission/issues", + "source": "https://github.com/spatie/laravel-permission/tree/5.5.5" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-06-29T23:11:42+00:00" + }, { "name": "spiral/goridge", "version": "v3.1.2", @@ -12771,5 +12859,5 @@ "ext-xml": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/config/permission.php b/config/permission.php new file mode 100644 index 00000000..5b6e184c --- /dev/null +++ b/config/permission.php @@ -0,0 +1,161 @@ + [ + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * Eloquent model should be used to retrieve your permissions. Of course, it + * is often just the "Permission" model but you may use whatever you like. + * + * The model you want to use as a Permission model needs to implement the + * `Spatie\Permission\Contracts\Permission` contract. + */ + + 'permission' => Spatie\Permission\Models\Permission::class, + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your roles. Of course, it + * is often just the "Role" model but you may use whatever you like. + * + * The model you want to use as a Role model needs to implement the + * `Spatie\Permission\Contracts\Role` contract. + */ + + 'role' => Spatie\Permission\Models\Role::class, + + ], + + 'table_names' => [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'roles' => 'roles', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your permissions. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'permissions' => 'permissions', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your models permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_permissions' => 'model_has_permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models roles. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_roles' => 'model_has_roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'role_has_permissions' => 'role_has_permissions', + ], + + 'column_names' => [ + /* + * Change this if you want to name the related pivots other than defaults + */ + 'role_pivot_key' => null, //default 'role_id', + 'permission_pivot_key' => null, //default 'permission_id', + + /* + * Change this if you want to name the related model primary key other than + * `model_id`. + * + * For example, this would be nice if your primary keys are all UUIDs. In + * that case, name this `model_uuid`. + */ + + 'model_morph_key' => 'model_id', + + /* + * Change this if you want to use the teams feature and your related model's + * foreign key is other than `team_id`. + */ + + 'team_foreign_key' => 'team_id', + ], + + /* + * When set to true, the method for checking permissions will be registered on the gate. + * Set this to false, if you want to implement custom logic for checking permissions. + */ + + 'register_permission_check_method' => true, + + /* + * When set to true the package implements teams using the 'team_foreign_key'. If you want + * the migrations to register the 'team_foreign_key', you must set this to true + * before doing the migration. If you already did the migration then you must make a new + * migration to also add 'team_foreign_key' to 'roles', 'model_has_roles', and + * 'model_has_permissions'(view the latest version of package's migration file) + */ + + 'teams' => false, + + /* + * When set to true, the required permission names are added to the exception + * message. This could be considered an information leak in some contexts, so + * the default setting is false here for optimum safety. + */ + + 'display_permission_in_exception' => false, + + /* + * When set to true, the required role names are added to the exception + * message. This could be considered an information leak in some contexts, so + * the default setting is false here for optimum safety. + */ + + 'display_role_in_exception' => false, + + /* + * By default wildcard permission lookups are disabled. + */ + + 'enable_wildcard_permission' => false, + + 'cache' => [ + + /* + * By default all permissions are cached for 24 hours to speed up performance. + * When permissions or roles are updated the cache is flushed automatically. + */ + + 'expiration_time' => \DateInterval::createFromDateString('24 hours'), + + /* + * The cache key used to store all permissions. + */ + + 'key' => 'spatie.permission.cache', + + /* + * You may optionally indicate a specific cache driver to use for permission and + * role caching using any of the `store` drivers listed in the cache.php config + * file. Using 'default' here means to use the `default` set in cache.php. + */ + + 'store' => 'default', + ], +]; diff --git a/database/migrations/2022_07_08_215348_add_deadline_to_torrents_state_table.php b/database/migrations/2022_07_08_215348_add_deadline_to_torrents_state_table.php new file mode 100644 index 00000000..dc8112aa --- /dev/null +++ b/database/migrations/2022_07_08_215348_add_deadline_to_torrents_state_table.php @@ -0,0 +1,33 @@ +id(); + $table->dateTime('deadline')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('torrents_state', function (Blueprint $table) { + $table->dropColumn(['id', 'deadline']); + }); + } +}; diff --git a/database/migrations/2022_07_09_011856_create_permission_tables.php b/database/migrations/2022_07_09_011856_create_permission_tables.php new file mode 100644 index 00000000..f3711956 --- /dev/null +++ b/database/migrations/2022_07_09_011856_create_permission_tables.php @@ -0,0 +1,141 @@ +bigIncrements('id'); // permission id + $table->string('name', 125); // For MySQL 8.0 use string('name', 125); + $table->string('guard_name', 125); // For MySQL 8.0 use string('guard_name', 125); + $table->timestamps(); + + $table->unique(['name', 'guard_name']); + }); + + Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) { + $table->bigIncrements('id'); // role id + if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing + $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); + $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); + } + $table->string('name', 125); // For MySQL 8.0 use string('name', 125); + $table->string('guard_name', 125); // For MySQL 8.0 use string('guard_name', 125); + $table->timestamps(); + if ($teams || config('permission.testing')) { + $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); + } else { + $table->unique(['name', 'guard_name']); + } + }); + + Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); + + $table->foreign(PermissionRegistrar::$pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } else { + $table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } + + }); + + Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); + + $table->foreign(PermissionRegistrar::$pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } else { + $table->primary([PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } + }); + + Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); + $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); + + $table->foreign(PermissionRegistrar::$pivotPermission) + ->references('id') // permission id + ->on($tableNames['permissions']) + ->onDelete('cascade'); + + $table->foreign(PermissionRegistrar::$pivotRole) + ->references('id') // role id + ->on($tableNames['roles']) + ->onDelete('cascade'); + + $table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary'); + }); + + app('cache') + ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) + ->forget(config('permission.cache.key')); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $tableNames = config('permission.table_names'); + + if (empty($tableNames)) { + throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); + } + + Schema::drop($tableNames['role_has_permissions']); + Schema::drop($tableNames['model_has_roles']); + Schema::drop($tableNames['model_has_permissions']); + Schema::drop($tableNames['roles']); + Schema::drop($tableNames['permissions']); + } +} diff --git a/include/functions.php b/include/functions.php index 48af7714..e8944e98 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1939,7 +1939,7 @@ function get_user_row($id) } function userlogin() { - do_log("COOKIE:" . json_encode($_COOKIE) . ", uid: " . (isset($_COOKIE['c_secure_uid']) ? base64($_COOKIE["c_secure_uid"],false) : '')); +// do_log("COOKIE:" . json_encode($_COOKIE) . ", uid: " . (isset($_COOKIE['c_secure_uid']) ? base64($_COOKIE["c_secure_uid"],false) : '')); static $loginResult; if (!is_null($loginResult)) { return $loginResult; @@ -2637,7 +2637,7 @@ else { H&R: %s]', (new \App\Repositories\HitAndRunRepository())->getStatusStats($CURUSER['id']))?> %s]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?> - = UC_SYSOP) printf('[%s]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?> + = get_setting('authority.staffmem')) printf('[%s]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>