improve approval notify + add approval_status filter

This commit is contained in:
xiaomlove
2022-06-27 13:22:16 +08:00
parent 1aca20070d
commit f88f0787f9
21 changed files with 153 additions and 32 deletions
@@ -77,7 +77,7 @@ class ExamResource extends Resource
//
])
->actions([
Tables\Actions\EditAction::make(),
// Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
@@ -95,8 +95,8 @@ class ExamResource extends Resource
{
return [
'index' => Pages\ListExams::route('/'),
'create' => Pages\CreateExam::route('/create'),
'edit' => Pages\EditExam::route('/{record}/edit'),
// 'create' => Pages\CreateExam::route('/create'),
// 'edit' => Pages\EditExam::route('/{record}/edit'),
];
}
}
@@ -14,7 +14,7 @@ class ListExams extends PageList
protected function getActions(): array
{
return [
Actions\CreateAction::make(),
// Actions\CreateAction::make(),
];
}
}
@@ -24,6 +24,8 @@ class SettingResource extends Resource
protected static ?string $navigationGroup = 'System';
protected static bool $shouldRegisterNavigation = false;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.settings');
+5 -4
View File
@@ -32,14 +32,14 @@ class UserResource extends Resource
public static function form(Form $form): Form
{
return $form
->schema(Forms\Components\Card::make()->schema([
->schema([
Forms\Components\TextInput::make('username')->required(),
Forms\Components\TextInput::make('email')->required(),
Forms\Components\TextInput::make('password')->password()->required(),
Forms\Components\TextInput::make('password_confirmation')->password()->required()->same('password'),
Forms\Components\TextInput::make('password')->password()->required()->visibleOn(Pages\CreateUser::class),
Forms\Components\TextInput::make('password_confirmation')->password()->required()->same('password')->visibleOn(Pages\CreateUser::class),
Forms\Components\TextInput::make('id')->integer(),
Forms\Components\Select::make('class')->options(array_column(User::$classes, 'text')),
]));
]);
}
public static function table(Table $table): Table
@@ -90,6 +90,7 @@ class UserResource extends Resource
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
// 'edit' => Pages\EditUser::route('/{record}/edit'),
'view' => Pages\ViewUser::route('/{record}'),
];
}
@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\User\UserResource\Pages;
use App\Filament\Resources\User\UserResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewUser extends ViewRecord
{
protected static string $resource = UserResource::class;
}
+2
View File
@@ -12,6 +12,8 @@ class TorrentTrend extends LineChartWidget
{
protected static ?int $sort = 4;
protected static ?string $pollingInterval = null;
protected function getHeading(): ?string
{
return __('dashboard.torrent_trend.page_title');
+2
View File
@@ -14,6 +14,8 @@ class UserTrend extends LineChartWidget
protected static ?int $sort = 3;
protected static ?string $pollingInterval = null;
protected function getHeading(): ?string
{
return __('dashboard.user_trend.page_title');
+15
View File
@@ -221,6 +221,21 @@ class Torrent extends NexusModel
return $fields;
}
public static function listApprovalStatus($onlyKeyValue = false): array
{
$result = self::$approvalStatus;
$keyValue = [];
foreach ($result as $status => &$info) {
$text = nexus_trans("torrent.approval.status_text.$status");
$info['text'] = $text;
$keyValue[$status] = $text;
}
if ($onlyKeyValue) {
return $keyValue;
}
return $result;
}
public function getHrAttribute(): string
{
$hrMode = Setting::get('hr.mode');
+6
View File
@@ -9,6 +9,7 @@ use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Resources\Json\JsonResource;
use Nexus\Nexus;
use Filament\Facades\Filament;
use Illuminate\Contracts\View\View;
class AppServiceProvider extends ServiceProvider
{
@@ -40,5 +41,10 @@ class AppServiceProvider extends ServiceProvider
]);
});
// Filament::registerRenderHook(
// 'content.end',
// fn (): View => view('filament.footer'),
// );
}
}
+9 -7
View File
@@ -473,7 +473,12 @@ class TorrentRepository extends BaseRepository
{
$user = $this->getUser($user);
$torrent = Torrent::query()->findOrFail($params['torrent_id'], ['id', 'banned', 'approval_status', 'visible', 'owner']);
if ($torrent->approval_status == $params['approval_status']) {
$lastLog = TorrentOperationLog::query()
->where('torrent_id', $params['torrent_id'])
->where('uid', $user->id)
->orderBy('id', 'desc')
->first();
if ($torrent->approval_status == $params['approval_status'] && $lastLog && $lastLog->comment == $params['comment']) {
//No change
return $params;
}
@@ -492,12 +497,9 @@ class TorrentRepository extends BaseRepository
} elseif ($params['approval_status'] == Torrent::APPROVAL_STATUS_DENY) {
$torrentUpdate['banned'] = 'yes';
$torrentUpdate['visible'] = 'no';
if ($torrent->approval_status != $params['approval_status']) {
$torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY;
}
if ($torrent->approval_status == Torrent::APPROVAL_STATUS_ALLOW) {
$notifyUser = true;
}
//Deny, record and notify all the time
$torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY;
$notifyUser = true;
} elseif ($params['approval_status'] == Torrent::APPROVAL_STATUS_NONE) {
$torrentUpdate['banned'] = 'no';
$torrentUpdate['visible'] = 'yes';
+16 -1
View File
@@ -2738,11 +2738,26 @@ if ($msgalert)
if (get_user_class() >= $staffmem_class)
{
//torrent approval
if (get_setting('torrent.approval_status_none_visible') == 'no') {
$cacheKey = 'TORRENT_APPROVAL_NONE';
$toApprovalCounts = $Cache->get_value($cacheKey);
if ($toApprovalCounts === false) {
$toApprovalCounts = get_row_count('torrents', 'where approval_status = 0');
$Cache->cache_value($cacheKey, $toApprovalCounts, 60);
}
if ($toApprovalCounts) {
msgalert('torrents.php?approval_status=0', sprintf($lang_functions['text_torrent_to_approval'], is_or_are($toApprovalCounts), $toApprovalCounts, add_s($toApprovalCounts)), 'darkred');
}
}
if(($complaints = $Cache->get_value('COMPLAINTS_COUNT_CACHE')) === false){
$complaints = get_row_count('complains', 'WHERE answered = 0');
$Cache->cache_value('COMPLAINTS_COUNT_CACHE', $complaints, 600);
}
if($complaints) msgalert('complains.php?action=list', sprintf($lang_functions['text_complains'], is_or_are($complaints), $complaints, add_s($complaints)), 'darkred');
if($complaints) {
msgalert('complains.php?action=list', sprintf($lang_functions['text_complains'], is_or_are($complaints), $complaints, add_s($complaints)), 'darkred');
}
$numreports = $Cache->get_value('staff_new_report_count');
if ($numreports == ""){
+1
View File
@@ -322,6 +322,7 @@ $lang_functions = array
'text_complains' => '有%s%u个待处理的申诉%s',
'text_contactstaff' => '联系管理组',
'full_site_promotion_in_effect' => '全站 [%s] 生效中!',
'text_torrent_to_approval' => '有 %s%u 个待审核的种子%s',
);
?>
+1
View File
@@ -58,6 +58,7 @@ $lang_torrents = array
'text_tv' => "电视:",
'text_music' => "音乐:",
'text_software' => "软件:",
'text_approval_status' => '审核状态:',
);
?>
+1
View File
@@ -329,6 +329,7 @@ $lang_functions = array
'text_complains' => '有%s%u個待處理的申诉%s',
'text_contactstaff' => '聯系管理組',
'full_site_promotion_in_effect' => '全站 [%s] 生效中!',
'text_torrent_to_approval' => '有 %s%u 個待審核的種子%s',
);
?>
+1
View File
@@ -58,6 +58,7 @@ $lang_torrents = array
'text_tv' => "電視:",
'text_music' => "音樂:",
'text_software' => "軟件:",
'text_approval_status' => '審核狀態:',
);
?>
+1 -1
View File
@@ -330,7 +330,7 @@ $lang_functions = array
'text_complains' => 'There %s %u pending complaint%s.',
'text_contactstaff' => 'Contact staff',
'full_site_promotion_in_effect' => 'Full site [%s] in effect!',
'text_torrent_to_approval' => 'There %s%u not approval torrent%s.',
);
?>
+1
View File
@@ -58,6 +58,7 @@ $lang_torrents = array
'text_tv' => "TV:",
'text_music' => "Music:",
'text_software' => "Software:",
'text_approval_status' => 'Approval status:',
);
?>
+31 -10
View File
@@ -11,9 +11,16 @@ header("Pragma: no-cache" );
$torrentRep = new \App\Repositories\TorrentRepository();
$id = intval($_GET['userid'] ?? 0);
$type = $_GET['type'];
if (!in_array($type,array('uploaded','seeding','leeching','completed','incomplete')))
die;
if(get_user_class() < $torrenthistory_class && $id != $CURUSER["id"])
permissiondenied();
function maketable($res, $mode = 'seeding')
{
global $lang_getusertorrentlistajax,$CURUSER,$smalldescription_main, $lang_functions;
global $lang_getusertorrentlistajax,$CURUSER,$smalldescription_main, $lang_functions, $id;
global $torrentRep;
switch ($mode)
{
@@ -94,11 +101,31 @@ function maketable($res, $mode = 'seeding')
}
default: break;
}
$results = $torrentIdArr = [];
while ($row = mysql_fetch_assoc($res)) {
$results[] = $row;
$torrentIdArr[] = $row['torrent'];
}
if ($mode == 'uploaded') {
//get seedtime, uploaded from snatch
$seedTimeAndUploaded = \App\Models\Snatch::query()
->where('userid', $id)
->whereIn('torrentid', $torrentIdArr)
->select(['seedtime', 'uploaded', 'torrentid'])
->get()
->keyBy('torrentid');
}
$ret = "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" width=\"800\"><tr><td class=\"colhead\" style=\"padding: 0px\">".$lang_getusertorrentlistajax['col_type']."</td><td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_name']."</td>".
($showsize ? "<td class=\"colhead\" align=\"center\"><img class=\"size\" src=\"pic/trans.gif\" alt=\"size\" title=\"".$lang_getusertorrentlistajax['title_size']."\" /></td>" : "").($showsenum ? "<td class=\"colhead\" align=\"center\"><img class=\"seeders\" src=\"pic/trans.gif\" alt=\"seeders\" title=\"".$lang_getusertorrentlistajax['title_seeders']."\" /></td>" : "").($showlenum ? "<td class=\"colhead\" align=\"center\"><img class=\"leechers\" src=\"pic/trans.gif\" alt=\"leechers\" title=\"".$lang_getusertorrentlistajax['title_leechers']."\" /></td>" : "").($showuploaded ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_uploaded']."</td>" : "") . ($showdownloaded ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_downloaded']."</td>" : "").($showratio ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_ratio']."</td>" : "").($showsetime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_se_time']."</td>" : "").($showletime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_le_time']."</td>" : "").($showcotime ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_time_completed']."</td>" : "").($showanonymous ? "<td class=\"colhead\" align=\"center\">".$lang_getusertorrentlistajax['col_anonymous']."</td>" : "")."</tr>\n";
$total_size = 0;
while ($arr = mysql_fetch_assoc($res))
foreach ($results as $arr)
{
if ($mode == 'uploaded') {
$seedTimeAndUploadedData = $seedTimeAndUploaded->get($arr['torrent']);
$arr['seedtime'] = $seedTimeAndUploadedData ? $seedTimeAndUploadedData->seedtime : 0;
$arr['uploaded'] = $seedTimeAndUploadedData ? $seedTimeAndUploadedData->uploaded : 0;
}
$catimage = htmlspecialchars($arr["image"]);
$catname = htmlspecialchars($arr["catname"]);
@@ -178,18 +205,12 @@ function maketable($res, $mode = 'seeding')
return [$ret, $total_size];
}
$id = intval($_GET['userid'] ?? 0);
$type = $_GET['type'];
if (!in_array($type,array('uploaded','seeding','leeching','completed','incomplete')))
die;
if(get_user_class() < $torrenthistory_class && $id != $CURUSER["id"])
permissiondenied();
switch ($type)
{
case 'uploaded':
{
$res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, snatched.seedtime, snatched.uploaded FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id AND snatched.userid=$id " . (($CURUSER["id"] != $id)?((get_user_class() < $viewanonymous_class) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__);
// $res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, snatched.seedtime, snatched.uploaded FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id AND snatched.userid=$id " . (($CURUSER["id"] != $id)?((get_user_class() < $viewanonymous_class) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__);
$res = sql_query("SELECT torrents.id AS torrent, torrents.name as torrentname, small_descr, seeders, leechers, anonymous, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr FROM torrents LEFT JOIN categories ON torrents.category = categories.id WHERE torrents.owner=$id " . (($CURUSER["id"] != $id)?((get_user_class() < $viewanonymous_class) ? " AND anonymous = 'no'":""):"") ." ORDER BY torrents.added DESC") or sqlerr(__FILE__, __LINE__);
$count = mysql_num_rows($res);
if ($count > 0)
{
+37 -1
View File
@@ -808,7 +808,19 @@ if (isset($searchstr))
//approval status
$approvalStatusNoneVisible = get_setting('torrent.approval_status_none_visible');
if ($approvalStatusNoneVisible == 'no' && get_user_class() < $staffmem_class) {
$approvalStatusIconEnabled = get_setting('torrent.approval_status_icon_enabled');
$approvalStatus = null;
$showApprovalStatusFilter = false;
//when enable approval status icon, all user can use this filter, otherwise only staff member can use
if ($approvalStatusIconEnabled == 'yes' || get_user_class() >= $staffmem_class) {
$showApprovalStatusFilter = true;
}
//when user can use approval status filter, and pass `approval_status` parameter, will affect
//OR if [not approval can not be view] and not staff member, force to view approval allowed
if ($showApprovalStatusFilter && isset($_REQUEST['approval_status']) && is_numeric($_REQUEST['approval_status'])) {
$approvalStatus = intval($_REQUEST['approval_status']);
$wherea[] = "torrents.approval_status = $approvalStatus";
} elseif ($approvalStatusNoneVisible == 'no' && get_user_class() < $staffmem_class) {
$wherea[] = "torrents.approval_status = " . \App\Models\Torrent::APPROVAL_STATUS_ALLOW;
}
@@ -1029,6 +1041,30 @@ if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showin
</select>
</td>
</tr>
<?php if ($showApprovalStatusFilter) {?>
<tr>
<td class="bottom" style="padding: 1px;padding-left: 10px">
<br />
</td>
</tr>
<tr>
<td class="bottom" style="padding: 1px;padding-left: 10px">
<font class="medium"><?php echo $lang_torrents['text_approval_status'] ?></font>
</td>
</tr>
<tr>
<td class="bottom" style="padding: 1px;padding-left: 10px">
<select class="med" name="approval_status" style="width: 100px;">
<option value="0"><?php echo $lang_torrents['select_all'] ?></option>
<?php
foreach (\App\Models\Torrent::listApprovalStatus(true) as $key => $value) {
printf('<option value="%s"%s>%s</option>', $key, isset($approvalStatus) && $approvalStatus == $key ? ' selected' : '', $value);
}
?>
</select>
</td>
</tr>
<?php }?>
</table>
</td>
</tr>
@@ -0,0 +1,5 @@
<div class="py-4 shrink-0 filament-main-footer">
<div class="flex items-center justify-center filament-footer" style="color: #50575e">
Powered By NexusPHP
</div>
</div>
+1 -4
View File
@@ -14,9 +14,6 @@ use Illuminate\Support\Facades\Route;
*/
Route::get('/', function () {
return redirect('https://nexusphp.org');
return redirect('index.php');
});
Route::get('test', function () {
dd(request()->cookie());
});