torrent operation log type add edit&delete

This commit is contained in:
xiaomlove
2022-12-08 03:48:20 +08:00
parent 6c58a38166
commit 7386806bd6
22 changed files with 386 additions and 71 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ class Test extends Command
public function handle()
{
$rep = new WorkRepository();
$rep->settleRole(5);
$rep->settleRole(4);
}
@@ -0,0 +1,110 @@
<?php
namespace App\Filament\Resources\Torrent;
use App\Filament\Resources\Torrent\TorrentOperationLogResource\Pages;
use App\Filament\Resources\Torrent\TorrentOperationLogResource\RelationManagers;
use App\Models\Torrent;
use App\Models\TorrentOperationLog;
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;
class TorrentOperationLogResource extends Resource
{
protected static ?string $model = TorrentOperationLog::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationGroup = 'Torrent';
protected static ?int $navigationSort = 4;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.torrent_operation_log');
}
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')->sortable(),
Tables\Columns\TextColumn::make('user.username')
->formatStateUsing(fn ($record) => username_for_admin($record->uid))
->label(__('label.user.label'))
,
Tables\Columns\TextColumn::make('torrent.name')
->formatStateUsing(fn ($record) => torrent_name_for_admin($record->torrent))
->label(__('label.torrent.label'))
,
Tables\Columns\TextColumn::make('action_type_text')
->label(__('torrent-operation-log.fields.action_type'))
,
Tables\Columns\TextColumn::make('comment')
->label(__('label.comment'))
,
Tables\Columns\TextColumn::make('created_at')
->formatStateUsing(fn ($state) => format_datetime($state))
->label(__('label.created_at'))
,
])
->filters([
Tables\Filters\Filter::make('uid')
->form([
Forms\Components\TextInput::make('uid')
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value));
})
,
Tables\Filters\Filter::make('torrent_id')
->form([
Forms\Components\TextInput::make('torrent_id')
->placeholder('Torrent ID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['torrent_id'], fn (Builder $query, $value) => $query->where("torrent_id", $value));
})
,
Tables\Filters\SelectFilter::make('action_type')
->options(TorrentOperationLog::listStaticProps(TorrentOperationLog::$actionTypes, 'torrent.operation_log.%s.type_text', true))
->label(__('torrent-operation-log.fields.action_type'))
->multiple()
,
])
->actions([
// Tables\Actions\EditAction::make(),
// Tables\Actions\DeleteAction::make(),
])
->bulkActions([
// Tables\Actions\DeleteBulkAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ManageTorrentOperationLogs::route('/'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Filament\Resources\Torrent\TorrentOperationLogResource\Pages;
use App\Filament\PageListSingle;
use App\Filament\Resources\Torrent\TorrentOperationLogResource;
use App\Models\TorrentOperationLog;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ManageRecords;
use Illuminate\Database\Eloquent\Builder;
class ManageTorrentOperationLogs extends PageListSingle
{
protected static string $resource = TorrentOperationLogResource::class;
protected function getActions(): array
{
return [
// Actions\CreateAction::make(),
];
}
protected function getTableQuery(): Builder
{
return TorrentOperationLog::query()->with(['torrent', 'user']);
}
}
@@ -6,6 +6,7 @@ use App\Filament\OptionsTrait;
use App\Filament\Resources\Torrent\TorrentResource\Pages;
use App\Filament\Resources\Torrent\TorrentResource\RelationManagers;
use App\Models\Category;
use App\Models\SearchBox;
use App\Models\Setting;
use App\Models\Tag;
use App\Models\Torrent;
@@ -27,6 +28,7 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Nexus\Database\NexusDB;
class TorrentResource extends Resource
{
@@ -75,23 +77,18 @@ class TorrentResource extends Resource
->columns([
Tables\Columns\TextColumn::make('id')->sortable(),
Tables\Columns\TextColumn::make('basic_category.name')->label(__('label.torrent.category')),
Tables\Columns\TextColumn::make('name')->formatStateUsing(function (Torrent $record) {
$name = sprintf(
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank" title="%s">%s</a></div>',
$record->id, $record->name, Str::limit($record->name, 40)
);
$tags = sprintf('&nbsp;<div>%s</div>', $record->tagsFormatted);
return new HtmlString('<div class="flex">' . $name . $tags . '</div>');
})->label(__('label.name'))->searchable(),
Tables\Columns\TextColumn::make('name')->formatStateUsing(fn ($record) => torrent_name_for_admin($record, true))
->label(__('label.name'))
->searchable(),
Tables\Columns\TextColumn::make('posStateText')->label(__('label.torrent.pos_state')),
Tables\Columns\TextColumn::make('spStateText')->label(__('label.torrent.sp_state')),
Tables\Columns\TextColumn::make('pickInfoText')
->label(__('label.torrent.picktype'))
->formatStateUsing(fn ($record) => $record->pickInfo['text'])
,
Tables\Columns\BooleanColumn::make('hr')
Tables\Columns\IconColumn::make('hr')
->label(__('label.torrent.hr'))
->boolean()
,
Tables\Columns\TextColumn::make('size')
->label(__('label.torrent.size'))
@@ -108,55 +105,11 @@ class TorrentResource extends Resource
Tables\Columns\TextColumn::make('added')->label(__('label.added'))->dateTime(),
Tables\Columns\TextColumn::make('user.username')
->label(__('label.torrent.owner'))
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->owner, false, true, true, true)))
->formatStateUsing(fn ($record) => username_for_admin($record->owner))
,
])
->defaultSort('id', 'desc')
->filters([
Tables\Filters\Filter::make('owner')
->form([
Forms\Components\TextInput::make('owner')
->label(__('label.torrent.owner'))
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['owner'], fn (Builder $query, $owner) => $query->where("owner", $owner));
})
,
Tables\Filters\SelectFilter::make('category')
->options(Category::query()->pluck('name', 'id')->toArray())
->label(__('label.torrent.category')),
Tables\Filters\SelectFilter::make('visible')
->options(self::$yesOrNo)
->label(__('label.torrent.visible')),
Tables\Filters\SelectFilter::make('pos_state')
->options(Torrent::listPosStates(true))
->label(__('label.torrent.pos_state')),
Tables\Filters\SelectFilter::make('sp_state')
->options(Torrent::listPromotionTypes(true))
->label(__('label.torrent.sp_state')),
Tables\Filters\SelectFilter::make('picktype')
->options(Torrent::listPickInfo(true))
->label(__('label.torrent.picktype')),
Tables\Filters\SelectFilter::make('approval_status')
->options(Torrent::listApprovalStatus(true))
->visible($showApproval)
->label(__('label.torrent.approval_status')),
Tables\Filters\SelectFilter::make('hr')
->options(self::getYesNoOptions())
->label(__('label.torrent.hr')),
Tables\Filters\SelectFilter::make('tags')
->relationship('tags', 'name')
->label(__('label.tag.label'))
,
])
->filters(self::getFilters())
->actions(self::getActions())
->bulkActions(self::getBulkActions());
@@ -394,4 +347,117 @@ class TorrentResource extends Resource
// return Setting::get('torrent.approval_status_none_visible') == 'no' || Setting::get('torrent.approval_status_icon_enabled') == 'yes';
}
private static function getFilters()
{
$filters = [
Tables\Filters\Filter::make('owner')
->form([
Forms\Components\TextInput::make('owner')
->label(__('label.torrent.owner'))
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['owner'], fn (Builder $query, $owner) => $query->where("owner", $owner));
})
,
Tables\Filters\SelectFilter::make('visible')
->options(self::$yesOrNo)
->label(__('label.torrent.visible'))
,
Tables\Filters\SelectFilter::make('hr')
->options(self::getYesNoOptions())
->label(__('label.torrent.hr'))
,
Tables\Filters\SelectFilter::make('pos_state')
->options(Torrent::listPosStates(true))
->label(__('label.torrent.pos_state'))
->multiple()
,
Tables\Filters\SelectFilter::make('sp_state')
->options(Torrent::listPromotionTypes(true))
->label(__('label.torrent.sp_state'))
->multiple()
,
Tables\Filters\SelectFilter::make('picktype')
->options(Torrent::listPickInfo(true))
->label(__('label.torrent.picktype'))
->multiple()
,
Tables\Filters\SelectFilter::make('approval_status')
->options(Torrent::listApprovalStatus(true))
->label(__('label.torrent.approval_status'))
->multiple()
,
Tables\Filters\SelectFilter::make('tags')
->relationship('tags', 'name')
->label(__('label.tag.label'))
->multiple()
,
Tables\Filters\SelectFilter::make('category')
->options(Category::query()->pluck('name', 'id')->toArray())
->label(__('label.torrent.category'))
->multiple()
,
];
foreach (SearchBox::$taxonomies as $torrentField => $tableModel) {
$filters[] = Tables\Filters\SelectFilter::make($torrentField)
->options(NexusDB::table($tableModel['table'])->orderBy('sort_index')->orderBy('id')->pluck('name', 'id'))
->multiple()
;
}
$filters[] = Tables\Filters\Filter::make('added_begin')
->form([
Forms\Components\DatePicker::make('added_begin')
->maxDate(now())
->label(__('label.torrent.added_begin'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['added_begin'], fn (Builder $query, $value) => $query->where("added", '>=', $value));
})
;
$filters[] = Tables\Filters\Filter::make('added_end')
->form([
Forms\Components\DatePicker::make('added_end')
->maxDate(now())
->label(__('label.torrent.added_end'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['added_end'], fn (Builder $query, $value) => $query->where("added", '<=', $value));
})
;
$filters[] = Tables\Filters\Filter::make('size_begin')
->form([
Forms\Components\TextInput::make('size_begin')
->numeric()
->placeholder('GB')
->label(__('label.torrent.size_begin'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['size_begin'], fn (Builder $query, $value) => $query->where("size", '>=', $value * 1024 * 1024 * 1024));
})
;
$filters[] = Tables\Filters\Filter::make('size_end')
->form([
Forms\Components\TextInput::make('size_end')
->numeric()
->placeholder('GB')
->label(__('label.torrent.size_end'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['size_end'], fn (Builder $query, $value) => $query->where("size", '<=', $value * 1024 * 1024 * 1024));
})
;
return $filters;
}
}
+6 -1
View File
@@ -56,7 +56,12 @@ class NexusModel extends Model
$result = $dataSource;
$keyValue = [];
foreach ($result as $key => &$info) {
$text = $textTransPrefix ? nexus_trans("$textTransPrefix.$key") : $info['text'];
if (str_contains($textTransPrefix, '%s')) {
$transKey = sprintf($textTransPrefix, $key);
} else {
$transKey = "$textTransPrefix.$key";
}
$text = $textTransPrefix ? nexus_trans($transKey) : $info['text'];
$info['text'] = $text;
$keyValue[$key] = $info[$valueField];
}
+4
View File
@@ -15,11 +15,15 @@ class TorrentOperationLog extends NexusModel
const ACTION_TYPE_APPROVAL_NONE = 'approval_none';
const ACTION_TYPE_APPROVAL_ALLOW = 'approval_allow';
const ACTION_TYPE_APPROVAL_DENY = 'approval_deny';
const ACTION_TYPE_EDIT = 'edit';
const ACTION_TYPE_DELETE = 'delete';
public static array $actionTypes = [
self::ACTION_TYPE_APPROVAL_NONE => ['text' => 'Approval none'],
self::ACTION_TYPE_APPROVAL_ALLOW => ['text' => 'Approval allow'],
self::ACTION_TYPE_APPROVAL_DENY => ['text' => 'Approval deny'],
self::ACTION_TYPE_EDIT => ['text' => 'Edit'],
self::ACTION_TYPE_DELETE => ['text' => 'Delete'],
];
public function getActionTypeTextAttribute()
+2 -2
View File
@@ -154,7 +154,7 @@ class ClaimRepository extends BaseRepository
public function settleUser($uid, $force = false, $test = false): bool
{
$user = User::query()->with('language')->findOrFail($uid);
$list = Claim::query()->where('uid', $uid)->with(['snatch'])->get();
$list = Claim::query()->where('uid', $uid)->with(['snatch', 'torrent' => fn ($query) => $query->select(Torrent::$commentFields)])->get();
$now = Carbon::now();
$startOfThisMonth = $now->clone()->startOfMonth();
$seedTimeRequiredHours = Claim::getConfigStandardSeedTimeHours();
@@ -210,7 +210,7 @@ class ClaimRepository extends BaseRepository
"reachedTorrentIdArr: %s, unReachedIdArr: %s, bonusResult: %s, seedTimeHours: %s",
json_encode($reachedTorrentIdArr), json_encode($unReachedIdArr), json_encode($bonusResult), $seedTimeHoursAvg
), 'alert');
$bonusFinal = $bonusResult['seed_bonus'] * $seedTimeHoursAvg * $bonusMultiplier;
$bonusFinal = $bonusResult['seed_points'] * $seedTimeHoursAvg * $bonusMultiplier;
do_log("bonus final: $bonusFinal", 'alert');
$totalDeduct = $bonusDeduct * count($unReachedIdArr);
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-12-04');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-12-08');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+27 -1
View File
@@ -1,6 +1,7 @@
<?php
use App\Models\SearchBox;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
function get_langfolder_cookie($transToLocale = false)
@@ -3100,7 +3101,7 @@ function loggedinorreturn($mainpage = false) {
// do_log("[USER]: " . $CURUSER['id']);
}
function deletetorrent($id) {
function deletetorrent($id, $notify = false) {
$idArr = \Illuminate\Support\Arr::wrap($id);
$idStr = implode(', ', $idArr ?: [0]);
$torrent_dir = get_setting('main.torrent_dir');
@@ -3115,6 +3116,12 @@ function deletetorrent($id) {
do_action("torrent_delete", $_id);
do_log("delete torrent: $_id", "error");
unlink(getFullDirectory("$torrent_dir/$_id.torrent"));
\App\Models\TorrentOperationLog::add([
'torrent_id' => $_id,
'uid' => get_user_id(),
'action_type' => \App\Models\TorrentOperationLog::ACTION_TYPE_DELETE,
'comment' => '',
], $notify);
}
}
@@ -6316,4 +6323,23 @@ function build_search_area($searchArea, array $options = [])
$result .= '</select>';
return $result;
}
function torrent_name_for_admin(\App\Models\Torrent $torrent, $withTags = false)
{
$name = sprintf(
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank" title="%s">%s</a></div>',
$torrent->id, $torrent->name, Str::limit($torrent->name, 40)
);
$tags = '';
if ($withTags) {
$tags = sprintf('&nbsp;<div>%s</div>', $torrent->tagsFormatted);
}
return new HtmlString('<div class="flex">' . $name . $tags . '</div>');
}
function username_for_admin(int $id)
{
return new HtmlString(get_username($id, false, true, true, true));
}
?>
+20 -9
View File
@@ -258,16 +258,27 @@ else
$searchRep = new \App\Repositories\SearchRepository();
$searchRep->updateTorrent($id);
if ($affectedRows == 1 && $row['banned'] == 'yes' && $row['owner'] == $CURUSER['id']) {
if ($affectedRows == 1) {
$torrentUrl = sprintf('details.php?id=%s', $row['id']);
\App\Models\StaffMessage::query()->insert([
'sender' => $CURUSER['id'],
'subject' => nexus_trans('torrent.owner_update_torrent_subject', ['detail_url' => $torrentUrl, 'torrent_name' => $_POST['name']]),
'msg' => nexus_trans('torrent.owner_update_torrent_msg', ['detail_url' => $torrentUrl, 'torrent_name' => $_POST['name']]),
'added' => now(),
'permission' => 'torrent-approval',
]);
clear_staff_message_cache();
if ($row['banned'] == 'yes' && $row['owner'] == $CURUSER['id']) {
\App\Models\StaffMessage::query()->insert([
'sender' => $CURUSER['id'],
'subject' => nexus_trans('torrent.owner_update_torrent_subject', ['detail_url' => $torrentUrl, 'torrent_name' => $_POST['name']]),
'msg' => nexus_trans('torrent.owner_update_torrent_msg', ['detail_url' => $torrentUrl, 'torrent_name' => $_POST['name']]),
'added' => now(),
'permission' => 'torrent-approval',
]);
clear_staff_message_cache();
}
if ($row['owner'] != $CURUSER['id']) {
\App\Models\TorrentOperationLog::add([
'torrent_id' => $row['id'],
'uid' => $CURUSER['id'],
'action_type' => \App\Models\TorrentOperationLog::ACTION_TYPE_EDIT,
'comment' => '',
], true);
}
}
$returl = "details.php?id=$id&edited=1";
+1
View File
@@ -31,6 +31,7 @@ return [
'plugin' => 'Plugins',
'category' => 'Categories',
'second_icon' => 'Second icons',
'torrent_operation_log' => 'Torrent operation logs',
],
'resources' => [
'agent_allow' => [
+4
View File
@@ -163,6 +163,10 @@ return [
'picktype' => 'Recommend',
'promotion_time_type' => 'Promotion type time',
'hr' => 'H&R',
'added_begin' => 'Added greater than',
'added_end' => 'Added less than',
'size_begin' => 'Size greater than',
'size_end' => 'Size less than',
],
'hit_and_run' => [
'label' => 'User H&R',
@@ -0,0 +1,7 @@
<?php
return [
'fields' => [
'action_type' => 'Action type',
],
];
+10
View File
@@ -59,6 +59,16 @@ return [
'type_text' => 'Not reviewed',
'notify_subject' => 'Torrent was mark as not reviewed',
'notify_msg' => 'Your torrent: [url=:detail_url]:torrent_name[/url] was mark as not reviewed by :operator',
],
\App\Models\TorrentOperationLog::ACTION_TYPE_EDIT => [
'type_text' => 'Edit',
'notify_subject' => 'Torrent was edited',
'notify_msg' => 'Your torrent: [url=:detail_url]:torrent_name[/url] was edited by :operator',
],
\App\Models\TorrentOperationLog::ACTION_TYPE_DELETE => [
'type_text' => 'Delete',
'notify_subject' => 'Torrent was deleted',
'notify_msg' => 'Your torrent: :torrent_name was deleted by :operator',
]
],
'owner_update_torrent_subject' => 'Denied torrent have been updated',
+1
View File
@@ -29,6 +29,7 @@ return [
'plugin' => '插件',
'category' => '主分类',
'second_icon' => '第二图标',
'torrent_operation_log' => '种子操作记录',
],
'resources' => [
'agent_allow' => [
+4
View File
@@ -163,6 +163,10 @@ return [
'picktype' => '推荐',
'promotion_time_type' => '优惠时间类型',
'hr' => 'H&R',
'added_begin' => '发布时间大于',
'added_end' => '发布时间小于',
'size_begin' => '体积大于',
'size_end' => '体积小于',
],
'hit_and_run' => [
'label' => '用户 H&R',
@@ -0,0 +1,7 @@
<?php
return [
'fields' => [
'action_type' => '操作类型',
],
];
+10
View File
@@ -59,6 +59,16 @@ return [
'type_text' => '标记未审核',
'notify_subject' => '种子标记未审核',
'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 标记未审核',
],
\App\Models\TorrentOperationLog::ACTION_TYPE_EDIT => [
'type_text' => '编辑',
'notify_subject' => '种子被编辑',
'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 编辑',
],
\App\Models\TorrentOperationLog::ACTION_TYPE_DELETE => [
'type_text' => '删除',
'notify_subject' => '种子被删除',
'notify_msg' => '你的种子::torrent_name 被 :operator 删除',
]
],
'owner_update_torrent_subject' => '审核拒绝种子已更新',
+1
View File
@@ -31,6 +31,7 @@ return [
'plugin' => '插件',
'category' => '主分類',
'second_icon' => '第二圖標',
'torrent_operation_log' => '種子操作記錄',
],
'resources' => [
'agent_allow' => [
+4
View File
@@ -163,6 +163,10 @@ return [
'picktype' => '推薦',
'promotion_time_type' => '優惠時間類型',
'hr' => 'H&R',
'added_begin' => '發布時間大於',
'added_end' => '發布時間小於',
'size_begin' => '體積大於',
'size_end' => '體積小於',
],
'hit_and_run' => [
'label' => '用戶 H&R',
@@ -0,0 +1,7 @@
<?php
return [
'fields' => [
'action_type' => '操作類型',
],
];
+10
View File
@@ -59,6 +59,16 @@ return [
'type_text' => '標記未審核',
'notify_subject' => '種子標記未審核',
'notify_msg' => '妳的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 標記未審核',
],
\App\Models\TorrentOperationLog::ACTION_TYPE_EDIT => [
'type_text' => '編輯',
'notify_subject' => '種子被編輯',
'notify_msg' => '你的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 編輯',
],
\App\Models\TorrentOperationLog::ACTION_TYPE_DELETE => [
'type_text' => '刪除',
'notify_subject' => '種子被刪除',
'notify_msg' => '你的種子::torrent_name 被 :operator 刪除',
]
],
'owner_update_torrent_subject' => '審核拒絕種子已更新',