Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Add) Manual User Warning #1705 #2020

Merged
merged 2 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
(Add) Manual User Warning #1705
  • Loading branch information
Alkl58 committed Nov 28, 2021
commit fa586b0b1701a2918271eb2054d37bc9c07072fa
7 changes: 6 additions & 1 deletion app/Console/Commands/AutoDeactivateWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public function handle()
$pm->sender_id = 1;
$pm->receiver_id = $warning->warneduser->id;
$pm->subject = 'Hit and Run Warning Deactivated';
$pm->message = 'The [b]WARNING[/b] you received relating to Torrent '.$warning->torrenttitle->name.' has expired! Try not to get more! [color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
if (isset($warning->torrent)) {
$pm->message = 'The [b]WARNING[/b] you received relating to Torrent '.$warning->torrenttitle->name.' has expired! Try not to get more! [color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
} else {
$pm->message = 'The [b]WARNING[/b] you received: "'.$warning->reason.'" has expired! [color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]';
}

$pm->save();
}

Expand Down
34 changes: 34 additions & 0 deletions app/Http/Controllers/Staff/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use App\Models\Topic;
use App\Models\Torrent;
use App\Models\User;
use App\Models\Warning;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

Expand Down Expand Up @@ -272,4 +274,36 @@ protected function destroy($username)
return \redirect()->route('staff.dashboard.index')
->withErrors('Something Went Wrong!');
}

/**
* Manually warn a user.
*
* @param \App\Models\User $username
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function warnUser(Request $request, $username)
{
$user = User::where('username', '=', $username)->firstOrFail();
$carbon = new Carbon();
$warning = new Warning();
$warning->user_id = $user->id;
$warning->warned_by = $request->user()->id;
$warning->torrent = null;
$warning->reason = $request->input('message');
$warning->expires_on = $carbon->copy()->addDays(\config('hitrun.expire'));
$warning->active = '1';
$warning->save();

// Send Private Message
$pm = new PrivateMessage();
$pm->sender_id = 1;
$pm->receiver_id = $user->id;
$pm->subject = 'Received warning';
$pm->message = 'You have received a [b]warning[/b]. Reason: '.$request->input('message');
$pm->save();

return \redirect()->route('users.show', ['username' => $user->username])
->withSuccess('Warning issued successfully!');
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function show($username): \Illuminate\Contracts\View\Factory|\Illuminate\
$groups = Group::all();
$followers = Follow::where('target_id', '=', $user->id)->latest()->limit(25)->get();
$history = $user->history;
$warnings = Warning::where('user_id', '=', $user->id)->whereNotNull('torrent')->where('active', '=', 1)->take(\config('hitrun.max_warnings'))->get();
$hitrun = Warning::where('user_id', '=', $user->id)->latest()->paginate(10);
$warnings = Warning::where('user_id', '=', $user->id)->where('active', '=', 1)->take(\config('hitrun.max_warnings'))->get();
$hitrun = Warning::where('user_id', '=', $user->id)->whereNotNull('torrent')->latest()->paginate(10);

$bonupload = BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Upload%']])->sum('cost');
//$bondownload = BonTransactions::where('sender', '=', $user->id)->where([['name', 'like', '%Download%']])->sum('cost');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ChangeTorrentToNullableInWarning extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('warnings', function (Blueprint $table) {
$table->bigInteger('torrent')->unsigned()->nullable()->change();
});
}
}
4 changes: 4 additions & 0 deletions resources/views/Staff/warning/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@
</a>
</td>
<td>
@if(isset($warning->torrent))
<a class="text-bold"
href="{{ route('torrent', ['id' => $warning->torrenttitle->id]) }}">
{{ $warning->torrenttitle->name }}
</a>
@else
n/a
@endif
</td>
<td>
{{ $warning->reason }}
Expand Down
9 changes: 6 additions & 3 deletions resources/views/user/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ class="{{ $user->group->icon }}" data-toggle="tooltip" title=""
data-original-title="{{ $user->group->name }}"></i> {{ $user->group->name }}</span>
</h4>
<h4>@lang('user.registration-date') {{ $user->created_at === null ? "N/A" : date('M d Y', $user->created_at->getTimestamp()) }}</h4>
@if (auth()->user()->id != $user->id)
@if (auth()->user()->id != $user->id)
<span style="float:right;">
@if (auth()->user()->group->is_modo)
@if (auth()->user()->group->is_modo)
<button class="btn btn-xs btn-danger" data-toggle="modal" data-target="#modal_warn_user">
<span class="{{ config('other.font-awesome') }} fa-radiation-alt"></span> Warn User
</button>
<button class="btn btn-xs btn-warning" data-toggle="modal"
data-target="#modal_user_note"><span
class="{{ config('other.font-awesome') }} fa-sticky-note"></span> @lang('user.note') </button>
Expand Down Expand Up @@ -125,7 +128,7 @@ class="{{ config('other.font-awesome') }} fa-pencil"></span> @lang('user.edit')
<button class="btn btn-xs btn-danger" data-toggle="modal"
data-target="#modal_user_delete"><span
class="{{ config('other.font-awesome') }} fa-trash"></span> @lang('user.delete') </button>
@endif
@endif
</span>
@endif

Expand Down
36 changes: 36 additions & 0 deletions resources/views/user/user_modals.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@
</div>
</div>

<div class="modal fade" id="modal_warn_user" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog{{ \modal_style() }} modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header mx-auto">
<div class="text-center">
<p style="font-size: 27px;">Warn User: {{ $user->username }}</p>
</div>
</div>
<div class="modal-body">
<div class="py-3">
<form role="form" method="POST"
action="{{ route('user_warn', ['username' => $user->username]) }}">
@csrf
<div class="form-group">
<label for="warn_reason">Reason</label>
</div>
<div class="form-group">
<label>
<textarea name="message" class="form-control"></textarea>
</label>
</div>
<div class="form-group">
<input class="btn btn-warning" type="submit" value="Save">
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="close ml-auto" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
</div>
</div>

<div class="modal fade" id="modal_user_ban" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog{{ \modal_style() }} modal-dialog-centered" role="document">
<div class="modal-content">
Expand Down
8 changes: 8 additions & 0 deletions resources/views/user/warninglog.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@
</a>
</td>
<td>
@if(isset($warning->torrent))
<a href="{{ route('torrent', ['id' => $warning->torrenttitle->id]) }}">
{{ $warning->torrenttitle->name }}
</a>
@else
n/a
@endif
</td>
<td>
{{ $warning->reason }}
Expand Down Expand Up @@ -165,9 +169,13 @@
</a>
</td>
<td>
@if(isset($softDeletedWarning->torrent))
<a href="{{ route('torrent', ['id' => $softDeletedWarning->torrenttitle->id]) }}">
{{ $softDeletedWarning->torrenttitle->name }}
</a>
@else
n/a
@endif
</td>
<td>
{{ $softDeletedWarning->reason }}
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@
Route::post('/{username}/permissions', [App\Http\Controllers\Staff\UserController::class, 'permissions'])->name('user_permissions');
Route::post('/{username}/password', [App\Http\Controllers\Staff\UserController::class, 'password'])->name('user_password');
Route::get('/{username}/destroy', [App\Http\Controllers\Staff\UserController::class, 'destroy'])->name('user_delete');
Route::post('/{username}/warn', [App\Http\Controllers\Staff\UserController::class, 'warnUser'])->name('user_warn');
});

// Warnings Log
Expand Down