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

Laravel 8 upgrade #285

Merged
merged 24 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5565b16
Start updating to Laravel 8
supertassu Sep 10, 2020
1731bf3
Fix tests, update laravel-socialite-mediawiki
supertassu Sep 10, 2020
577f1ed
Only search oldappeals table if it exists in AppealController::appeal()
supertassu Sep 10, 2020
f8be9fa
Merge branch 'appeal-oldappeal-check' into laravel-8
supertassu Sep 10, 2020
474325a
Properly throw exception
supertassu Sep 10, 2020
ac2a2b7
Merge branch 'appeal-oldappeal-check' into laravel-8
supertassu Sep 10, 2020
ed42869
Fix class name in test
supertassu Sep 10, 2020
6f2b90d
Apply non-model-moving changes made between L6 and 8
supertassu Sep 10, 2020
3b42cf5
Rename database/seeds/ to database/seeders/
supertassu Sep 10, 2020
0aca5a4
Manually apply namespace to routes, comments on variable seem wrong
supertassu Sep 10, 2020
6f4bef0
Update dependencies again
supertassu Sep 11, 2020
a796cb1
Class name fixes
supertassu Sep 11, 2020
01b866e
Merge branch 'master' into laravel-8
dqwiki Oct 22, 2020
c3f40dd
Push latest updates
dqwiki Oct 22, 2020
31845be
Upgrade Guzzle to 6.5.5 to avoid https://github.com/guzzle/guzzle/iss…
dqwiki Oct 22, 2020
be55f8a
factory helper is no longer available in laravel 8
dqwiki Oct 22, 2020
129d04e
Disable buttons that haven't worked in ages
dqwiki Oct 22, 2020
bee4015
Modify per be55f8a comments
dqwiki Oct 22, 2020
f5487c0
Upgrade Factory changes in Laravel 8
dqwiki Oct 22, 2020
1a9bfbf
Upgrade factory for dusk
dqwiki Oct 22, 2020
64670ce
Fix System comments via old appeal comments causing 404
dqwiki Oct 22, 2020
c0b741e
Cleanup DQ's fix
supertassu Oct 23, 2020
4b7958d
Clean up even more
supertassu Oct 23, 2020
36ee22d
Re-add missing middleware, run composer update, fix ip ban factory
supertassu Oct 23, 2020
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/laravel-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Build assets
run: npm run production
- name: Run PHPUnit
run: vendor/bin/phpunit
run: php artisan test
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
- name: Start chromedriver
Expand Down
3 changes: 3 additions & 0 deletions app/Appeal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use RuntimeException;
use App\MwApi\MwApiUrls;
use Illuminate\Database\Eloquent\Model;

class Appeal extends Model
{
use HasFactory;

const REPLY_STATUS_CHANGE_OPTIONS = [
self::STATUS_OPEN => self::STATUS_OPEN,
self::STATUS_AWAITING_REPLY => self::STATUS_AWAITING_REPLY,
Expand Down
3 changes: 3 additions & 0 deletions app/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Ban extends Model
{
use HasFactory;

protected $primaryKey = 'id';
public $timestamps = false;
protected $guarded = ['id'];
Expand Down
20 changes: 3 additions & 17 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
Expand All @@ -27,25 +26,12 @@ class Handler extends ExceptionHandler
];

/**
* Report or log an exception.
* Register the exception handling callbacks for the application.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
public function register()
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
//
}
}
45 changes: 26 additions & 19 deletions app/Http/Controllers/AppealController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App;
use App\Appeal;
use App\Jobs\GetBlockDetailsJob;
use App\Log;
Expand All @@ -15,6 +14,7 @@
use App\Template;
use App\User;
use Auth;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
Expand All @@ -31,25 +31,9 @@ public function __construct()
public function appeal($id)
{
$info = Appeal::find($id);
if (is_null($info)) {
$info = Oldappeal::findOrFail($id);
$this->authorize('view', $info);

$comments = $info->comments;
$userlist = [];

foreach ($comments as $comment) {
if (!is_null($comment->commentUser) && !in_array($comment->commentUser, $userlist)) {
$userlist[$comment->commentUser] = Olduser::findOrFail($comment->commentUser)->username;
}
}

if ($info['status'] === "UNVERIFIED") {
return view('appeals.unverifiedappeal');
}

return view('appeals.oldappeal', ['info' => $info, 'comments' => $comments, 'userlist' => $userlist]);
} else {
// UTRS 2 appeal exists
if ($info) {
$this->authorize('view', $info);
$isDeveloper = Permission::checkSecurity(Auth::id(), "DEVELOPER","*");

Expand Down Expand Up @@ -93,6 +77,29 @@ public function appeal($id)
'previousAppeals' => $previousAppeals,
]);
}

// if UTRS 1 table exists, let's check there as well
if (Schema::hasTable('oldappeals')) {
$info = Oldappeal::findOrFail($id);
$this->authorize('view', $info);

$comments = $info->comments;
$userlist = [];

foreach ($comments as $comment) {
if (!is_null($comment->commentUser) && !in_array($comment->commentUser, $userlist)) {
$userlist[$comment->commentUser] = Olduser::findOrFail($comment->commentUser)->username;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a sufficient catch. With Oldappeals, Oldcomments has a zero equivalency being the system. Uploading a patch.

}

if ($info['status'] === "UNVERIFIED") {
return view('appeals.unverifiedappeal');
}

return view('appeals.oldappeal', ['info' => $info, 'comments' => $comments, 'userlist' => $userlist]);
}

throw (new ModelNotFoundException)->setModel(Appeal::class, $id);
}

public function appeallist()
Expand Down
32 changes: 6 additions & 26 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http;

use App\Http\Middleware\ForceHttps;
use App\Http\Middleware\AddHstsHeader;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
Expand All @@ -16,14 +14,13 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,

ForceHttps::class,
AddHstsHeader::class,
];

/**
Expand All @@ -43,8 +40,8 @@ class Kernel extends HttpKernel
],

'api' => [
'throttle:60,1',
'bindings',
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

Expand All @@ -58,29 +55,12 @@ class Kernel extends HttpKernel
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];

/**
* The priority-sorted list of middleware.
*
* This forces non-global middleware to always be in the given order.
*
* @var array
*/
protected $middlewarePriority = [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\Authenticate::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;

class CheckForMaintenanceMode extends Middleware
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
Expand Down
14 changes: 9 additions & 5 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ class RedirectIfAuthenticated
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @param string|null ...$guards
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle($request, Closure $next, ...$guards)
{
if (Auth::guard($guard)->check()) {
return redirect('/')
->with('message', 'This action can only be performed by users who are not logged in.');
$guards = empty($guards) ? [null] : $guards;

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect('/')
->with('message', 'This action can only be performed by users who are not logged in.');
}
}

return $next($request);
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}

2 changes: 1 addition & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TrustProxies extends Middleware
/**
* The trusted proxies for this application.
*
* @var array|string
* @var array|string|null
*/
protected $proxies = [
// https://openstack-browser.toolforge.org/project/project-proxy
Expand Down
7 changes: 0 additions & 7 deletions app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;

/**
* The URIs that should be excluded from CSRF verification.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Oldappeal.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Oldappeal extends Model

public function comments()
{
return $this->hasMany('App\Oldcomment', 'appealID','appealID');
return $this->hasMany(Oldcomment::class, 'appealID','appealID');
}

/** hack: add read-only 'id' attribute even thru it's appealID in database. ref #236 */
Expand Down
2 changes: 1 addition & 1 deletion app/Oldcomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Database\Eloquent\Model;

class oldcomment extends Model
class Oldcomment extends Model
{
//
}
Loading