mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-01 01:27:22 +08:00
update filament + change admin access class to ad
This commit is contained in:
@@ -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,89 +107,8 @@ 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');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
])
|
|
||||||
->bulkActions([
|
|
||||||
// Tables\Actions\DeleteBulkAction::make(),
|
|
||||||
Tables\Actions\BulkAction::make('posState')
|
|
||||||
->label(__('admin.resources.torrent.bulk_action_pos_state'))
|
|
||||||
->form([
|
|
||||||
Forms\Components\Select::make('pos_state')
|
|
||||||
->label(__('label.torrent.pos_state'))
|
|
||||||
->options(Torrent::listPosStates(true))
|
|
||||||
->required()
|
|
||||||
])
|
|
||||||
->icon('heroicon-o-arrow-circle-up')
|
|
||||||
->action(function (Collection $records, array $data) {
|
|
||||||
$idArr = $records->pluck('id')->toArray();
|
|
||||||
Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $data['pos_state']]);
|
|
||||||
})
|
|
||||||
->deselectRecordsAfterCompletion(),
|
|
||||||
|
|
||||||
Tables\Actions\BulkAction::make('remove_tag')
|
|
||||||
->label(__('admin.resources.torrent.bulk_action_remove_tag'))
|
|
||||||
->requiresConfirmation()
|
|
||||||
->icon('heroicon-o-minus-circle')
|
|
||||||
->action(function (Collection $records) {
|
|
||||||
$idArr = $records->pluck('id')->toArray();
|
|
||||||
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
|
|
||||||
})
|
|
||||||
->deselectRecordsAfterCompletion(),
|
|
||||||
|
|
||||||
Tables\Actions\BulkAction::make('attach_tag')
|
|
||||||
->label(__('admin.resources.torrent.bulk_action_attach_tag'))
|
|
||||||
->form([
|
|
||||||
Forms\Components\CheckboxList::make('tags')
|
|
||||||
->label(__('label.tag.label'))
|
|
||||||
->columns(4)
|
|
||||||
->options(TagRepository::createBasicQuery()->pluck('name', 'id')->toArray())
|
|
||||||
->required(),
|
|
||||||
])
|
|
||||||
->icon('heroicon-o-tag')
|
|
||||||
->action(function (Collection $records, array $data) {
|
|
||||||
if (empty($data['tags'])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$insert = $torrentIdArr = [];
|
|
||||||
$time = now()->toDateTimeString();
|
|
||||||
foreach ($records as $torrent) {
|
|
||||||
$torrentIdArr[] = $torrent->id;
|
|
||||||
foreach ($data['tags'] as $tagId) {
|
|
||||||
$insert[] = [
|
|
||||||
'torrent_id' => $torrent->id,
|
|
||||||
'tag_id' => $tagId,
|
|
||||||
'created_at' => $time,
|
|
||||||
'updated_at' => $time,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->delete();
|
|
||||||
TorrentTag::query()->insert($insert);
|
|
||||||
})
|
|
||||||
->deselectRecordsAfterCompletion(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,4 +133,109 @@ class TorrentResource extends Resource
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'))
|
||||||
|
->form([
|
||||||
|
Forms\Components\Select::make('pos_state')
|
||||||
|
->label(__('label.torrent.pos_state'))
|
||||||
|
->options(Torrent::listPosStates(true))
|
||||||
|
->required()
|
||||||
|
])
|
||||||
|
->icon('heroicon-o-arrow-circle-up')
|
||||||
|
->action(function (Collection $records, array $data) {
|
||||||
|
$idArr = $records->pluck('id')->toArray();
|
||||||
|
Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $data['pos_state']]);
|
||||||
|
})
|
||||||
|
->deselectRecordsAfterCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($userClass >= Setting::get('authority.torrentmanage')) {
|
||||||
|
$actions[] = Tables\Actions\BulkAction::make('remove_tag')
|
||||||
|
->label(__('admin.resources.torrent.bulk_action_remove_tag'))
|
||||||
|
->requiresConfirmation()
|
||||||
|
->icon('heroicon-o-minus-circle')
|
||||||
|
->action(function (Collection $records) {
|
||||||
|
$idArr = $records->pluck('id')->toArray();
|
||||||
|
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
|
||||||
|
})
|
||||||
|
->deselectRecordsAfterCompletion();
|
||||||
|
|
||||||
|
$actions[] = Tables\Actions\BulkAction::make('attach_tag')
|
||||||
|
->label(__('admin.resources.torrent.bulk_action_attach_tag'))
|
||||||
|
->form([
|
||||||
|
Forms\Components\CheckboxList::make('tags')
|
||||||
|
->label(__('label.tag.label'))
|
||||||
|
->columns(4)
|
||||||
|
->options(TagRepository::createBasicQuery()->pluck('name', 'id')->toArray())
|
||||||
|
->required(),
|
||||||
|
])
|
||||||
|
->icon('heroicon-o-tag')
|
||||||
|
->action(function (Collection $records, array $data) {
|
||||||
|
if (empty($data['tags'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$insert = $torrentIdArr = [];
|
||||||
|
$time = now()->toDateTimeString();
|
||||||
|
foreach ($records as $torrent) {
|
||||||
|
$torrentIdArr[] = $torrent->id;
|
||||||
|
foreach ($data['tags'] as $tagId) {
|
||||||
|
$insert[] = [
|
||||||
|
'torrent_id' => $torrent->id,
|
||||||
|
'tag_id' => $tagId,
|
||||||
|
'created_at' => $time,
|
||||||
|
'updated_at' => $time,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->delete();
|
||||||
|
TorrentTag::query()->insert($insert);
|
||||||
|
})
|
||||||
|
->deselectRecordsAfterCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $actions;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getActions()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function shouldShowApproval(): bool
|
||||||
|
{
|
||||||
|
return Setting::get('torrent.approval_status_none_visible') == 'no' || Setting::get('torrent.approval_status_icon_enabled') == 'yes';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
||||||
App::setLocale($locale);
|
} else {
|
||||||
Carbon::setLocale($locale);
|
$locale = self::getLocaleFromCookie() ?? 'en';
|
||||||
|
do_log("locale from cookie, set locale: $locale");
|
||||||
}
|
}
|
||||||
|
App::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
@@ -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;
|
||||||
|
|||||||
@@ -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
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||||
|
|||||||
@@ -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 />
|
||||||
|
|||||||
Reference in New Issue
Block a user