update filament + change admin access class to ad

This commit is contained in:
xiaomlove
2022-07-19 13:28:04 +08:00
parent 2912c89202
commit 64809aa436
9 changed files with 706 additions and 1480 deletions
+2
View File
@@ -1,11 +1,13 @@
<?php <?php
namespace App\Auth; namespace App\Auth;
use Carbon\Carbon;
use Illuminate\Auth\GuardHelpers; use Illuminate\Auth\GuardHelpers;
use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class NexusWebGuard implements Guard class NexusWebGuard implements Guard
{ {
@@ -56,7 +56,7 @@ class TorrentResource extends Resource
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
$showApproval = Setting::get('torrent.approval_status_none_visible') == 'no' || Setting::get('torrent.approval_status_icon_enabled') == 'yes'; $showApproval = self::shouldShowApproval();
return $table return $table
->columns([ ->columns([
Tables\Columns\TextColumn::make('id')->sortable(), Tables\Columns\TextColumn::make('id')->sortable(),
@@ -107,33 +107,38 @@ class TorrentResource extends Resource
->visible($showApproval) ->visible($showApproval)
->label(__('label.torrent.approval_status')), ->label(__('label.torrent.approval_status')),
]) ])
->actions([ ->actions(self::getActions())
// Tables\Actions\EditAction::make(), ->bulkActions(self::getBulkActions());
Tables\Actions\Action::make('approval')
->label(__('admin.resources.torrent.action_approval'))
->visible($showApproval)
->form([
Forms\Components\Radio::make('approval_status')
->label(__('label.torrent.approval_status'))
->inline()
->required()
->options(Torrent::listApprovalStatus(true))
,
Forms\Components\Textarea::make('comment')->label(__('label.comment')),
])
->action(function (Torrent $record, array $data) {
$torrentRep = new TorrentRepository();
try {
$data['torrent_id'] = $record->id;
$torrentRep->approval(Auth::user(), $data);
} catch (\Exception $exception) {
do_log($exception->getMessage(), 'error');
} }
})
]) public static function getEloquentQuery(): Builder
->bulkActions([ {
// Tables\Actions\DeleteBulkAction::make(), return parent::getEloquentQuery()->with(['user', 'basic_category', 'tags']);
Tables\Actions\BulkAction::make('posState') }
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListTorrents::route('/'),
'create' => Pages\CreateTorrent::route('/create'),
'edit' => Pages\EditTorrent::route('/{record}/edit'),
];
}
private static function getBulkActions(): array
{
$actions = [];
$userClass = Auth::user()->class;
if ($userClass >= Setting::get('authority.torrentsticky')) {
$actions[] = Tables\Actions\BulkAction::make('posState')
->label(__('admin.resources.torrent.bulk_action_pos_state')) ->label(__('admin.resources.torrent.bulk_action_pos_state'))
->form([ ->form([
Forms\Components\Select::make('pos_state') Forms\Components\Select::make('pos_state')
@@ -146,9 +151,11 @@ class TorrentResource extends Resource
$idArr = $records->pluck('id')->toArray(); $idArr = $records->pluck('id')->toArray();
Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $data['pos_state']]); Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $data['pos_state']]);
}) })
->deselectRecordsAfterCompletion(), ->deselectRecordsAfterCompletion();
}
Tables\Actions\BulkAction::make('remove_tag') if ($userClass >= Setting::get('authority.torrentmanage')) {
$actions[] = Tables\Actions\BulkAction::make('remove_tag')
->label(__('admin.resources.torrent.bulk_action_remove_tag')) ->label(__('admin.resources.torrent.bulk_action_remove_tag'))
->requiresConfirmation() ->requiresConfirmation()
->icon('heroicon-o-minus-circle') ->icon('heroicon-o-minus-circle')
@@ -156,9 +163,9 @@ class TorrentResource extends Resource
$idArr = $records->pluck('id')->toArray(); $idArr = $records->pluck('id')->toArray();
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete(); TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
}) })
->deselectRecordsAfterCompletion(), ->deselectRecordsAfterCompletion();
Tables\Actions\BulkAction::make('attach_tag') $actions[] = Tables\Actions\BulkAction::make('attach_tag')
->label(__('admin.resources.torrent.bulk_action_attach_tag')) ->label(__('admin.resources.torrent.bulk_action_attach_tag'))
->form([ ->form([
Forms\Components\CheckboxList::make('tags') Forms\Components\CheckboxList::make('tags')
@@ -188,30 +195,47 @@ class TorrentResource extends Resource
TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->delete(); TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->delete();
TorrentTag::query()->insert($insert); TorrentTag::query()->insert($insert);
}) })
->deselectRecordsAfterCompletion(), ->deselectRecordsAfterCompletion();
]); }
return $actions;
} }
public static function getEloquentQuery(): Builder private static function getActions()
{ {
return parent::getEloquentQuery()->with(['user', 'basic_category', 'tags']); $actions = [];
$userClass = Auth::user()->class;
if (self::shouldShowApproval() && $userClass >= Setting::get('authority.torrentmanage')) {
$actions[] = Tables\Actions\Action::make('approval')
->label(__('admin.resources.torrent.action_approval'))
->form([
Forms\Components\Radio::make('approval_status')
->label(__('label.torrent.approval_status'))
->inline()
->required()
->options(Torrent::listApprovalStatus(true))
,
Forms\Components\Textarea::make('comment')->label(__('label.comment')),
])
->action(function (Torrent $record, array $data) {
$torrentRep = new TorrentRepository();
try {
$data['torrent_id'] = $record->id;
$torrentRep->approval(Auth::user(), $data);
} catch (\Exception $exception) {
do_log($exception->getMessage(), 'error');
}
});
}
return $actions;
} }
public static function getRelations(): array private static function shouldShowApproval(): bool
{ {
return [ return Setting::get('torrent.approval_status_none_visible') == 'no' || Setting::get('torrent.approval_status_icon_enabled') == 'yes';
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListTorrents::route('/'),
'create' => Pages\CreateTorrent::route('/create'),
'edit' => Pages\EditTorrent::route('/{record}/edit'),
];
} }
} }
+20 -2
View File
@@ -8,6 +8,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cookie;
class Locale class Locale
{ {
@@ -29,10 +30,14 @@ class Locale
$user = $request->user(); $user = $request->user();
if ($user) { if ($user) {
$locale = $user->locale; $locale = $user->locale;
do_log("user: {$user->id}, set locale: $locale"); do_log("locale from user: {$user->id}, set locale: $locale");
} else {
$locale = self::getLocaleFromCookie() ?? 'en';
do_log("locale from cookie, set locale: $locale");
}
App::setLocale($locale); App::setLocale($locale);
Carbon::setLocale($locale); Carbon::setLocale($locale);
}
/** @var Response $response */ /** @var Response $response */
$response = $next($request); $response = $next($request);
if ($response instanceof Response || $response instanceof JsonResponse) { if ($response instanceof Response || $response instanceof JsonResponse) {
@@ -41,4 +46,17 @@ class Locale
return $response; return $response;
} }
public static function getLocaleFromCookie()
{
if (IN_NEXUS) {
$lang = get_langfolder_cookie();
$log = "IN_NEXUS, get_langfolder_cookie(): $lang";
} else {
$lang = Cookie::get('c_lang_folder');
$log = "Cookie::get(): $lang";
}
do_log($log);
return self::$languageMaps[$lang] ?? null;
}
} }
+7 -12
View File
@@ -247,20 +247,15 @@ class User extends Authenticatable implements FilamentUser, HasName
public function getLocaleAttribute() public function getLocaleAttribute()
{ {
$log = ""; $locale = Locale::getLocaleFromCookie();
if (IN_NEXUS) { $log = "locale from cookie: $locale";
$lang = get_langfolder_cookie(); if (!$locale) {
$log .= ", IN_NEXUS, get_langfolder_cookie(): $lang";
} else {
$lang = Cookie::get('c_lang_folder');
$log .= ", Cookie::get(): $lang";
}
if (!$lang) {
$lang = $this->language->site_lang_folder; $lang = $this->language->site_lang_folder;
$log .= ", [NO_DATA], from database: $lang"; $locale = Locale::$languageMaps[$lang] ?? 'en';
$log .= ", [NO_DATA], lang from database: $lang, locale: $locale";
} }
do_log($log); do_log($log);
return Locale::$languageMaps[$lang] ?? 'en'; return $locale;
} }
public function getSiteLangFolderAttribute() public function getSiteLangFolderAttribute()
@@ -477,7 +472,7 @@ class User extends Authenticatable implements FilamentUser, HasName
public function canAccessAdmin(): bool public function canAccessAdmin(): bool
{ {
$targetClass = Setting::get('authority.staffmem'); $targetClass = self::CLASS_ADMINISTRATOR;
if (!$this->class || $this->class < $targetClass) { if (!$this->class || $this->class < $targetClass) {
do_log(sprintf('user: %s, no class or class < %s, can not access admin.', $this->id, $targetClass)); do_log(sprintf('user: %s, no class or class < %s, can not access admin.', $this->id, $targetClass));
return false; return false;
+1
View File
@@ -2,6 +2,7 @@
namespace App\Providers; namespace App\Providers;
use App\Http\Middleware\Locale;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
+1 -1
View File
@@ -33,7 +33,7 @@
"ext-xml": "*", "ext-xml": "*",
"doctrine/dbal": "^3.1", "doctrine/dbal": "^3.1",
"elasticsearch/elasticsearch": "^7.16", "elasticsearch/elasticsearch": "^7.16",
"filament/filament": "^2.0", "filament/filament": "2.14.2",
"flowframe/laravel-trend": "^0.1.1", "flowframe/laravel-trend": "^0.1.1",
"fruitcake/laravel-cors": "^2.0", "fruitcake/laravel-cors": "^2.0",
"geoip2/geoip2": "~2.0", "geoip2/geoip2": "~2.0",
Generated
+564 -1378
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.18'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.7.18');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-07-18'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-07-19');
defined('IN_TRACKER') || define('IN_TRACKER', true); defined('IN_TRACKER') || define('IN_TRACKER', true);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+1 -1
View File
@@ -2637,7 +2637,7 @@ else {
<font class='color_connectable'><?php echo $lang_functions['text_connectable'] ?></font><?php echo $connectable?> <?php echo maxslots();?> <font class='color_connectable'><?php echo $lang_functions['text_connectable'] ?></font><?php echo $connectable?> <?php echo maxslots();?>
<?php if(\App\Models\HitAndRun::getIsEnabled()) { ?><font class='color_bonus'>H&R: </font> <?php echo sprintf('[<a href="myhr.php">%s</a>]', (new \App\Repositories\HitAndRunRepository())->getStatusStats($CURUSER['id']))?><?php }?> <?php if(\App\Models\HitAndRun::getIsEnabled()) { ?><font class='color_bonus'>H&R: </font> <?php echo sprintf('[<a href="myhr.php">%s</a>]', (new \App\Repositories\HitAndRunRepository())->getStatusStats($CURUSER['id']))?><?php }?>
<?php if(\App\Models\Claim::getConfigIsEnabled()) { ?><font class='color_bonus'><?php echo $lang_functions['menu_claim']?></font> <?php echo sprintf('[<a href="claim.php?uid=%s">%s</a>]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?><?php }?> <?php if(\App\Models\Claim::getConfigIsEnabled()) { ?><font class='color_bonus'><?php echo $lang_functions['menu_claim']?></font> <?php echo sprintf('[<a href="claim.php?uid=%s">%s</a>]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?><?php }?>
<?php if(get_user_class() >= get_setting('authority.staffmem')) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?> <?php if(get_user_class() >= \App\Models\User::CLASS_ADMINISTRATOR) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
</span> </span>
</td> </td>
<td class="bottom" align="right"><span class="medium"><?php echo $lang_functions['text_the_time_is_now'] ?><?php echo $datum['hours'].":".$datum['minutes']?><br /> <td class="bottom" align="right"><span class="medium"><?php echo $lang_functions['text_the_time_is_now'] ?><?php echo $datum['hours'].":".$datum['minutes']?><br />