mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
use permission torrent-approval
This commit is contained in:
@@ -137,8 +137,7 @@ class TorrentResource extends Resource
|
||||
private static function getBulkActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
$userClass = Auth::user()->class;
|
||||
if ($userClass >= Setting::get('authority.torrentsticky')) {
|
||||
if (user_can('torrentsticky')) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('posState')
|
||||
->label(__('admin.resources.torrent.bulk_action_pos_state'))
|
||||
->form([
|
||||
@@ -160,7 +159,7 @@ class TorrentResource extends Resource
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
|
||||
if ($userClass >= Setting::get('authority.torrentmanage')) {
|
||||
if (user_can('torrentmanage')) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('remove_tag')
|
||||
->label(__('admin.resources.torrent.bulk_action_remove_tag'))
|
||||
->requiresConfirmation()
|
||||
|
||||
@@ -57,11 +57,4 @@ class Controller extends BaseController
|
||||
return Str::slug("$title.$action", '.');
|
||||
}
|
||||
|
||||
protected function checkPermission($permission)
|
||||
{
|
||||
if (Auth::user()->class < Setting::get($permission)) {
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ class TorrentController extends Controller
|
||||
|
||||
public function approvalPage(Request $request)
|
||||
{
|
||||
user_can('torrent-approval', true);
|
||||
$request->validate(['torrent_id' => 'required']);
|
||||
$this->checkPermission('authority.torrentmanage');
|
||||
$torrentId = $request->torrent_id;
|
||||
$torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields);
|
||||
$denyReasons = TorrentDenyReason::query()->orderBy('priority', 'desc')->get();
|
||||
@@ -116,8 +116,8 @@ class TorrentController extends Controller
|
||||
|
||||
public function approvalLogs(Request $request)
|
||||
{
|
||||
user_can('torrent-approval', true);
|
||||
$request->validate(['torrent_id' => 'required']);
|
||||
$this->checkPermission('authority.torrentmanage');
|
||||
$torrentId = $request->torrent_id;
|
||||
$actionTypes = [
|
||||
TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE,
|
||||
@@ -138,11 +138,11 @@ class TorrentController extends Controller
|
||||
|
||||
public function approval(Request $request)
|
||||
{
|
||||
user_can('torrent-approval', true);
|
||||
$request->validate([
|
||||
'torrent_id' => 'required',
|
||||
'approval_status' => 'required',
|
||||
]);
|
||||
$this->checkPermission('authority.torrentmanage');
|
||||
$params = $request->all();
|
||||
$this->repository->approval(Auth::user(), $params);
|
||||
return $this->success($params);
|
||||
|
||||
@@ -434,9 +434,7 @@ class TorrentRepository extends BaseRepository
|
||||
public function buildApprovalModal($user, $torrentId)
|
||||
{
|
||||
$user = $this->getUser($user);
|
||||
if ($user->class < Setting::get('authority.torrentmanage')) {
|
||||
throw new \RuntimeException("No permission !");
|
||||
}
|
||||
user_can('torrent-approval', true);
|
||||
$torrent = Torrent::query()->findOrFail($torrentId, ['id', 'approval_status', 'banned']);
|
||||
$radios = [];
|
||||
foreach (Torrent::$approvalStatus as $key => $value) {
|
||||
@@ -479,9 +477,7 @@ class TorrentRepository extends BaseRepository
|
||||
public function approval($user, array $params): array
|
||||
{
|
||||
$user = $this->getUser($user);
|
||||
if ($user->class < Setting::get('authority.torrentmanage')) {
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
user_can('torrent-approval', true);
|
||||
$torrent = Torrent::query()->findOrFail($params['torrent_id'], ['id', 'banned', 'approval_status', 'visible', 'owner']);
|
||||
$lastLog = TorrentOperationLog::query()
|
||||
->where('torrent_id', $params['torrent_id'])
|
||||
@@ -578,9 +574,7 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
public function syncTags($id, array $tagIdArr = [])
|
||||
{
|
||||
if (Auth::user()->class < Setting::get('authority.torrentmanage')) {
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
user_can('torrentmanage', true);
|
||||
$idArr = Arr::wrap($id);
|
||||
return NexusDB::transaction(function () use ($idArr, $tagIdArr) {
|
||||
$insert = [];
|
||||
@@ -606,9 +600,7 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
public function setPosState($id, $posState): int
|
||||
{
|
||||
if (Auth::user()->class < Setting::get('authority.torrentsticky')) {
|
||||
throw new InsufficientPermissionException();
|
||||
}
|
||||
user_can('torrentsticky', true);
|
||||
$idArr = Arr::wrap($id);
|
||||
return Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $posState]);
|
||||
}
|
||||
|
||||
@@ -922,11 +922,15 @@ function user_can($permission, $fail = false, $uid = 0): bool
|
||||
$requireClass = get_setting("authority.$permission");
|
||||
if (!is_bool($result)) {
|
||||
$result = is_numeric($requireClass) && $requireClass >= 0 && $requireClass < $userInfo['class'];
|
||||
do_log("$log, requireClass: $requireClass, result: $result");
|
||||
$log .= ", requireClass: $requireClass, result: $result";
|
||||
} else {
|
||||
$log .= ", get result: $result from filter nexus_user_can";
|
||||
}
|
||||
if (!$fail || $result) {
|
||||
do_log($log);
|
||||
return $result;
|
||||
}
|
||||
do_log("$log, [FAIL]");
|
||||
if (IN_NEXUS && !IN_TRACKER) {
|
||||
global $lang_functions;
|
||||
if (isset(User::$classes[$requireClass])) {
|
||||
@@ -935,5 +939,5 @@ function user_can($permission, $fail = false, $uid = 0): bool
|
||||
stderr($lang_functions['std_error'], $lang_functions['std_permission_denied']);
|
||||
}
|
||||
}
|
||||
throw new \Illuminate\Auth\Access\AuthorizationException();
|
||||
throw new \App\Exceptions\InsufficientPermissionException();
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ if (!$row) {
|
||||
if (user_can('askreseed') && $row['seeders'] == 0) {
|
||||
$actions[] = "<a title=\"".$lang_details['title_ask_for_reseed']."\" href=\"takereseed.php?reseedid=$id\"><img class=\"dt_reseed\" src=\"pic/trans.gif\" alt=\"reseed\"> <b><font class=\"small\">".$lang_details['text_ask_for_reseed'] ."</font></b></a>";
|
||||
}
|
||||
if (user_can('torrentmanage') && (get_setting('torrent.approval_status_icon_enabled') == 'yes' || get_setting('torrent.approval_status_none_visible') == 'no')) {
|
||||
if (user_can('torrent-approval') && (get_setting('torrent.approval_status_icon_enabled') == 'yes' || get_setting('torrent.approval_status_none_visible') == 'no')) {
|
||||
$approvalIcon = '<svg t="1655224943277" class="icon" viewBox="0 0 1397 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="45530" width="16" height="16"><path d="M1396.363636 121.018182c0 0-223.418182 74.472727-484.072727 372.363636-242.036364 269.963636-297.890909 381.672727-390.981818 530.618182C512 1014.690909 372.363636 744.727273 0 549.236364l195.490909-186.181818c0 0 176.872727 121.018182 297.890909 344.436364 0 0 307.2-474.763636 902.981818-707.490909L1396.363636 121.018182 1396.363636 121.018182zM1396.363636 121.018182" p-id="45531" fill="#e78d0f"></path></svg>';
|
||||
$actions[] = sprintf(
|
||||
'<a href="javascript:;"><b><font id="approval" class="small approval" data-torrent_id="%s">%s %s</font></b></a>',
|
||||
|
||||
Reference in New Issue
Block a user