mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user