mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
fix change user class + medal display
This commit is contained in:
@@ -95,8 +95,8 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$r = getLogFile();
|
||||
dd($r);
|
||||
$work = new WorkRepository();
|
||||
$work->settleRole(6, 1, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,15 +44,18 @@ class MedalResource extends Resource
|
||||
Forms\Components\Radio::make('get_type')
|
||||
->options(Medal::listGetTypes(true))
|
||||
->inline()
|
||||
->columnSpan(['sm' => 2])
|
||||
->label(__('label.medal.get_type'))
|
||||
->required(),
|
||||
Forms\Components\Toggle::make('display_on_medal_page')
|
||||
->label(__('label.medal.display_on_medal_page'))
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('duration')
|
||||
->integer()
|
||||
->columnSpan(['sm' => 2])
|
||||
->label(__('label.medal.duration'))
|
||||
->helperText(__('label.medal.duration_help')),
|
||||
Forms\Components\Textarea::make('description')->columnSpan(['sm' => 2])->label(__('label.description')),
|
||||
Forms\Components\Textarea::make('description')
|
||||
->label(__('label.description'))
|
||||
,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -67,6 +70,7 @@ class MedalResource extends Resource
|
||||
Tables\Columns\TextColumn::make('getTypeText')->label('Get type')->label(__('label.medal.get_type')),
|
||||
Tables\Columns\TextColumn::make('price')->label(__('label.price')),
|
||||
Tables\Columns\TextColumn::make('duration')->label(__('label.medal.duration')),
|
||||
Tables\Columns\IconColumn::make('display_on_medal_page')->label(__('label.medal.display_on_medal_page'))->boolean(),
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->filters([
|
||||
|
||||
@@ -16,4 +16,9 @@ class EditMedal extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): ?string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class UsernameChangeLogResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'User';
|
||||
|
||||
protected static ?int $navigationSort = 8;
|
||||
protected static ?int $navigationSort = 100;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\User;
|
||||
|
||||
use App\Filament\OptionsTrait;
|
||||
use App\Filament\Resources\User\InviteResource\Pages;
|
||||
use App\Filament\Resources\User\InviteResource\RelationManagers;
|
||||
use App\Models\Invite;
|
||||
@@ -15,6 +16,8 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class InviteResource extends Resource
|
||||
{
|
||||
use OptionsTrait;
|
||||
|
||||
protected static ?string $model = Invite::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-user-add';
|
||||
@@ -52,6 +55,7 @@ class InviteResource extends Resource
|
||||
,
|
||||
Tables\Columns\TextColumn::make('invitee')
|
||||
->label(__('invite.fields.invitee'))
|
||||
->searchable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('hash')
|
||||
,
|
||||
@@ -64,15 +68,15 @@ class InviteResource extends Resource
|
||||
,
|
||||
Tables\Columns\TextColumn::make('invitee_register_uid')
|
||||
->label(__('invite.fields.invitee_register_uid'))
|
||||
->searchable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('invitee_register_email')
|
||||
->label(__('invite.fields.invitee_register_email'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('invitee_register_email')
|
||||
->label(__('invite.fields.invitee_register_email'))
|
||||
->searchable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('invitee_register_username')
|
||||
->label(__('invite.fields.invitee_register_username'))
|
||||
->searchable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('expired_at')
|
||||
->label(__('invite.fields.expired_at'))
|
||||
@@ -84,7 +88,20 @@ class InviteResource extends Resource
|
||||
,
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
Tables\Filters\Filter::make('inviter')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('inviter')
|
||||
->label(__('invite.fields.inviter'))
|
||||
->placeholder('UID')
|
||||
,
|
||||
])->query(function (Builder $query, array $data) {
|
||||
return $query->when($data['inviter'], fn (Builder $query, $value) => $query->where("inviter", $value));
|
||||
})
|
||||
,
|
||||
Tables\Filters\SelectFilter::make('valid')
|
||||
->options(self::getYesNoOptions())
|
||||
->label(__('invite.fields.valid'))
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User;
|
||||
|
||||
use App\Filament\Resources\User\UserMetaResource\Pages;
|
||||
use App\Filament\Resources\User\UserMetaResource\RelationManagers;
|
||||
use App\Models\UserMeta;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class UserMetaResource extends Resource
|
||||
{
|
||||
protected static ?string $model = UserMeta::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-collection';
|
||||
|
||||
protected static ?string $navigationGroup = 'User';
|
||||
|
||||
protected static ?int $navigationSort = 8;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.user_props');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('uid')
|
||||
->searchable()
|
||||
->label(__('label.username'))
|
||||
->formatStateUsing(fn ($state) => username_for_admin($state))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('meta_key_text')
|
||||
->label(__('label.name'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('deadline')
|
||||
->label(__('label.deadline'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('label.created_at'))
|
||||
->formatStateUsing(fn ($state) => format_datetime($state))
|
||||
,
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('uid')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('uid')
|
||||
->label(__('label.username'))
|
||||
->placeholder('UID')
|
||||
,
|
||||
])->query(function (Builder $query, array $data) {
|
||||
return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value));
|
||||
})
|
||||
,
|
||||
Tables\Filters\SelectFilter::make('meta_key')
|
||||
->options(UserMeta::listProps())
|
||||
->label(__('label.name'))
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
// Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListUserMetas::route('/'),
|
||||
'create' => Pages\CreateUserMeta::route('/create'),
|
||||
'edit' => Pages\EditUserMeta::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User\UserMetaResource\Pages;
|
||||
|
||||
use App\Filament\Resources\User\UserMetaResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUserMeta extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserMetaResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User\UserMetaResource\Pages;
|
||||
|
||||
use App\Filament\Resources\User\UserMetaResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUserMeta extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserMetaResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User\UserMetaResource\Pages;
|
||||
|
||||
use App\Filament\PageList;
|
||||
use App\Filament\Resources\User\UserMetaResource;
|
||||
use App\Models\UserMeta;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListUserMetas extends PageList
|
||||
{
|
||||
protected static string $resource = UserMetaResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
// Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return UserMeta::query()->whereIn('meta_key', array_keys(UserMeta::$metaKeys));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class UserProfile extends ViewRecord
|
||||
->hidden(fn (\Closure $get) => $get('field') != 'tmp_invites')
|
||||
,
|
||||
|
||||
Forms\Components\Textarea::make('reason')
|
||||
Forms\Components\TextInput::make('reason')
|
||||
->label(__('admin.resources.user.actions.change_bonus_etc_reason_label'))
|
||||
,
|
||||
])
|
||||
@@ -365,7 +365,7 @@ class UserProfile extends ViewRecord
|
||||
->label(__('admin.resources.user.actions.change_class_btn'))
|
||||
->form([
|
||||
Forms\Components\Select::make('class')
|
||||
->options(User::listClass())
|
||||
->options(User::listClass(User::CLASS_PEASANT, Auth::user()->class - 1))
|
||||
->default($this->record->class)
|
||||
->label(__('user.labels.class'))
|
||||
->required()
|
||||
|
||||
@@ -15,7 +15,7 @@ class Medal extends NexusModel
|
||||
self::GET_TYPE_GRANT => ['text' => 'Grant'],
|
||||
];
|
||||
|
||||
protected $fillable = ['name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type'];
|
||||
protected $fillable = ['name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type', 'display_on_medal_page'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
@@ -43,4 +43,9 @@ class UserMeta extends NexusModel
|
||||
return $this->status == self::STATUS_NORMAL && ($this->getRawOriginal('deadline') === null || ($this->deadline && $this->deadline->gte(now())));
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uid');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -471,7 +471,8 @@ class UserRepository extends BaseRepository
|
||||
user_can('user-change-class', true);
|
||||
$operator = $this->getUser($operator);
|
||||
$targetUser = $this->getUser($targetUser);
|
||||
if ($operator && $operator->class <= $targetUser->class) {
|
||||
if ($operator) {
|
||||
if ($operator->class <= $targetUser->class || $operator->class <= $newClass)
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
if ($targetUser->class == $newClass) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('medals', function (Blueprint $table) {
|
||||
$table->integer('display_on_medal_page')->default(1)->after('price');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('medals', function (Blueprint $table) {
|
||||
$table->dropColumn('display_on_medal_page');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-01-07');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-01-10');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require "../include/bittorrent.php";
|
||||
|
||||
$query = \App\Models\Medal::query();
|
||||
$query = \App\Models\Medal::query()->where('display_on_medal_page', 1);
|
||||
$q = htmlspecialchars($_REQUEST['q'] ?? '');
|
||||
if (!empty($q)) {
|
||||
$query->where('username', 'name', "%{$q}%");
|
||||
|
||||
@@ -33,6 +33,7 @@ return [
|
||||
'second_icon' => 'Second icons',
|
||||
'torrent_operation_log' => 'Torrent operation logs',
|
||||
'invite' => 'Invites',
|
||||
'user_props' => 'User props',
|
||||
],
|
||||
'resources' => [
|
||||
'agent_allow' => [
|
||||
|
||||
@@ -31,6 +31,7 @@ return [
|
||||
'second_icon' => '第二图标',
|
||||
'torrent_operation_log' => '种子操作记录',
|
||||
'invite' => '用户邀请',
|
||||
'user_props' => '用户道具',
|
||||
],
|
||||
'resources' => [
|
||||
'agent_allow' => [
|
||||
|
||||
@@ -111,6 +111,7 @@ return [
|
||||
'get_type' => '获取方式',
|
||||
'duration' => '有效时长',
|
||||
'duration_help' => '单位:天。如果留空,用户永久拥有',
|
||||
'display_on_medal_page' => '展示在勋章页面',
|
||||
],
|
||||
'user_medal' => [
|
||||
'label' => '用户勋章',
|
||||
|
||||
@@ -33,6 +33,7 @@ return [
|
||||
'second_icon' => '第二圖標',
|
||||
'torrent_operation_log' => '種子操作記錄',
|
||||
'invite' => '用戶邀請',
|
||||
'user_props' => '用戶道具',
|
||||
],
|
||||
'resources' => [
|
||||
'agent_allow' => [
|
||||
|
||||
Reference in New Issue
Block a user