Skip to content

Commit

Permalink
Merge branch 'release/6.0.19'
Browse files Browse the repository at this point in the history
* release/6.0.19:
  fixes #928
  updated layout variable
  cleanup and refactor
  Apply fixes from StyleCI (#924)
  optimize query builders
  update
  updates
  upgrade to Laravel Mix 6
  • Loading branch information
austintoddj committed Feb 1, 2021
2 parents c99d004 + ff09e4c commit be725c9
Show file tree
Hide file tree
Showing 24 changed files with 17,480 additions and 1,752 deletions.
4 changes: 4 additions & 0 deletions mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/public/js/app.js": "/public/js/app.js",
"/public/css/app.css": "/public/css/app.css"
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"dev": "mix",
"format": "prettier --write \"**/*.{scss,js,vue}\"",
"lint": "eslint --ext .js,.vue resources/js/ --fix",
"prod": "yarn format && cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "yarn dev --watch"
"prod": "yarn format && mix --production",
"watch": "mix watch"
},
"dependencies": {
"axios": "^0.21.0",
"bootstrap": "^4.5.2",
"chart.js": "^2.9.3",
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"chart.js": "^2.9.4",
"cross-env": "^7.0.3",
"filepond": "^4.25.1",
"filepond-plugin-file-validate-size": "^2.2.1",
Expand All @@ -19,7 +19,7 @@
"filepond-plugin-image-preview": "^4.6.4",
"filepond-plugin-image-validate-size": "^1.2.4",
"jquery": "^3.5.1",
"laravel-mix": "^5.0.7",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"md5": "^2.3.0",
"moment": "^2.29.1",
Expand All @@ -37,6 +37,7 @@
"vue-filepond": "^6.0.2",
"vue-fuse": "^2.2.1",
"vue-infinite-loading": "^2.4.5",
"vue-loader": "^15.9.5",
"vue-multiselect": "^2.1.6",
"vue-router": "^3.4.9",
"vue-template-compiler": "^2.6.11",
Expand All @@ -52,6 +53,7 @@
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.5.0",
"eslint-plugin-vue": "^7.3.0",
"postcss": "^8.1",
"prettier": "^2.2.1",
"webpack-bundle-analyzer": "^4.3.0"
}
Expand Down
10,669 changes: 10,666 additions & 3 deletions public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/app.css.map

Large diffs are not rendered by default.

5,316 changes: 5,313 additions & 3 deletions public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"/js/app.js": "/js/app.js?id=f89b5ad51f7113df42c2",
"/css/app.css": "/css/app.css?id=773fcc9361a4f8453523",
"/js/app.js.map": "/js/app.js.map?id=7e9c339d4fd45bc95652",
"/css/app.css.map": "/css/app.css.map?id=2491b80a4a260995478c"
"/js/app.js": "/js/app.js?id=ed1f451bc0f344db4fe9",
"/css/app.css": "/css/app.css?id=264092bcb8f58a16e702"
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ Since the weekly digest runs on [Laravel's Scheduler](https://laravel.com/docs/m

## Updates

Canvas loosely follows [Semantic Versioning](https://semver.org/) and increments versions as `MAJOR.MINOR.PATCH` numbers
- Major and minor versions _can contain breaking changes_, so follow the [upgrade guide](.github/UPGRADE.md) for a
Canvas follows [Semantic Versioning](https://semver.org) and increments versions as `MAJOR.MINOR.PATCH` numbers.
- Major versions **will** contain breaking changes, so follow the [upgrade guide](.github/UPGRADE.md) for a
step-by-step breakdown
- Patch versions will remain backwards compatible, so you can safely update the package by following the steps below:
- Minor and patch versions should **never** contain breaking changes, so you can safely update the package by following the steps below:

You may update your Canvas installation using composer:

Expand Down
14 changes: 7 additions & 7 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link rel="stylesheet" href="//fonts.googleapis.com/css2?family=Karla&family=Merriweather:wght@400;700&display=swap">

@if($config['user']['darkMode'])
<link rel="stylesheet" id="highlightStylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/styles/sunburst.min.css">
@if(\Canvas\Canvas::enabledDarkMode($jsVars['user']['dark_mode']))
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.5.0/build/styles/sunburst.min.css">
@else
<link rel="stylesheet" id="highlightStylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/styles/github.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.5.0/build/styles/github.min.css">
@endif

<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/highlight.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.5.0/build/highlight.min.js"></script>
</head>
<body class="mb-5"
@if($config['user']['dark_mode']) data-theme="dark" @endif
@if(in_array($config['user']['locale'], ['ar', 'fa'])) data-lang="rtl" @endif
@if(\Canvas\Canvas::enabledDarkMode($jsVars['user']['dark_mode'])) data-theme="dark" @endif
@if(\Canvas\Canvas::usingRightToLeftLanguage($jsVars['user']['locale'])) data-lang="rtl" @endif
>

@if(!\Canvas\Canvas::assetsUpToDate())
Expand All @@ -37,7 +37,7 @@
</div>

<script>
window.Canvas = @json($config);
window.Canvas = @json($jsVars);
</script>

<script type="text/javascript" src="{{ mix('js/app.js', 'vendor/canvas') }}"></script>
Expand Down
30 changes: 12 additions & 18 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,35 @@
use Canvas\Http\Controllers\TopicController;
use Canvas\Http\Controllers\UploadsController;
use Canvas\Http\Controllers\UserController;
use Canvas\Http\Middleware\Admin;
use Canvas\Http\Middleware\Authorize;
use Canvas\Http\Middleware\AdminMiddleware;
use Canvas\Http\Middleware\AuthenticatedMiddleware;
use Illuminate\Support\Facades\Route;

// Authentication routes...
Route::namespace('Auth')->group(function () {
Route::get('login', [AuthenticatedSessionController::class, 'create'])
->middleware('guest')
->name('canvas.login');

Route::post('login', [AuthenticatedSessionController::class, 'store'])
->middleware('guest');
Route::post('login', [AuthenticatedSessionController::class, 'store']);

Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
->middleware('guest')
->name('canvas.password.request');

Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])
->middleware(['guest'])
->name('canvas.password.email');

Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
->middleware(['guest'])
->name('canvas.password.reset');

Route::post('reset-password', [NewPasswordController::class, 'store'])
->middleware(['guest'])
->name('canvas.password.update');

Route::get('logout', [AuthenticatedSessionController::class, 'destroy'])
->name('canvas.logout');
});

// API routes...
Route::middleware([Authorize::class])->group(function () {
Route::middleware([AuthenticatedMiddleware::class])->group(function () {
Route::prefix('api')->group(function () {
Route::prefix('uploads')->group(function () {
Route::post('/', [UploadsController::class, 'store']);
Expand All @@ -65,7 +59,7 @@
Route::get('{id}', [StatsController::class, 'show']);
});

Route::prefix('tags')->middleware([Admin::class])->group(function () {
Route::prefix('tags')->middleware([AdminMiddleware::class])->group(function () {
Route::get('/', [TagController::class, 'index']);
Route::get('create', [TagController::class, 'create']);
Route::get('{id}', [TagController::class, 'show']);
Expand All @@ -74,7 +68,7 @@
Route::delete('{id}', [TagController::class, 'destroy']);
});

Route::prefix('topics')->middleware([Admin::class])->group(function () {
Route::prefix('topics')->middleware([AdminMiddleware::class])->group(function () {
Route::get('/', [TopicController::class, 'index']);
Route::get('create', [TopicController::class, 'create']);
Route::get('{id}', [TopicController::class, 'show']);
Expand All @@ -84,19 +78,19 @@
});

Route::prefix('users')->group(function () {
Route::get('/', [UserController::class, 'index'])->middleware([Admin::class]);
Route::get('create', [UserController::class, 'create'])->middleware([Admin::class]);
Route::get('/', [UserController::class, 'index'])->middleware([AdminMiddleware::class]);
Route::get('create', [UserController::class, 'create'])->middleware([AdminMiddleware::class]);
Route::get('{id}', [UserController::class, 'show']);
Route::get('{id}/posts', [UserController::class, 'showPosts']);
Route::post('{id}', [UserController::class, 'store']);
Route::delete('{id}', [UserController::class, 'destroy'])->middleware([Admin::class]);
Route::delete('{id}', [UserController::class, 'destroy'])->middleware([AdminMiddleware::class]);
});

Route::prefix('search')->group(function () {
Route::get('posts', [SearchController::class, 'showPosts']);
Route::get('tags', [SearchController::class, 'showTags'])->middleware([Admin::class]);
Route::get('topics', [SearchController::class, 'showTopics'])->middleware([Admin::class]);
Route::get('users', [SearchController::class, 'showUsers'])->middleware([Admin::class]);
Route::get('tags', [SearchController::class, 'showTags'])->middleware([AdminMiddleware::class]);
Route::get('topics', [SearchController::class, 'showTopics'])->middleware([AdminMiddleware::class]);
Route::get('users', [SearchController::class, 'showUsers'])->middleware([AdminMiddleware::class]);
});
});

Expand Down
22 changes: 22 additions & 0 deletions src/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@ public static function gravatar(string $email, int $size = 200, string $default

return "https://secure.gravatar.com/avatar/{$hash}?s={$size}&d={$default}&r={$rating}";
}

/**
* Return true if dark mode is enabled.
*
* @param int $enabled
* @return bool
*/
public static function enabledDarkMode(int $enabled): bool
{
return (bool) $enabled ?: false;
}

/**
* Return true if the app is configured to use Arabic or Farsi.
*
* @param string $locale
* @return bool
*/
public static function usingRightToLeftLanguage(string $locale): bool
{
return in_array($locale, ['ar', 'fa']);
}
}
2 changes: 1 addition & 1 deletion src/Console/UiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function handle()
$this->flushNodeModules();

$this->info('Installation complete.');
$this->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
$this->comment('Please run "npm install && npm run dev" to build your assets.');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ class AuthenticatedSessionController extends Controller
/**
* Display the login view.
*
* @return Application|Factory|View
* @return Application|Factory|View|RedirectResponse
*/
public function create()
{
if (Auth::guard('canvas')->check()) {
return redirect()->route('canvas');
}

return view('canvas::auth.login');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HomeController extends Controller
public function index()
{
return view('canvas::layout')->with([
'config' => [
'jsVars' => [
'languageCodes' => Canvas::availableLanguageCodes(),
'maxUpload' => config('canvas.upload_filesize'),
'path' => Canvas::basePath(),
Expand Down
1 change: 1 addition & 0 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PostController extends Controller
public function index(): JsonResponse
{
$posts = Post::query()
->select('id', 'title', 'summary', 'featured_image', 'published_at', 'created_at', 'updated_at')
->when(request()->user('canvas')->isContributor || request()->query('scope', 'user') != 'all', function (Builder $query) {
return $query->where('user_id', request()->user('canvas')->id);
}, function (Builder $query) {
Expand Down
7 changes: 5 additions & 2 deletions src/Http/Controllers/StatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class StatsController extends Controller
public function index(): JsonResponse
{
$posts = Post::query()
->select('id')
->when(request()->query('scope', 'user') === 'all', function (Builder $query) {
return $query;
}, function (Builder $query) {
Expand All @@ -33,14 +34,16 @@ public function index(): JsonResponse
->latest()
->get();

$views = View::select('created_at')
$views = View::query()
->select('created_at')
->whereIn('post_id', $posts->pluck('id'))
->whereBetween('created_at', [
today()->subDays(30)->startOfDay()->toDateTimeString(),
today()->endOfDay()->toDateTimeString(),
])->get();

$visits = Visit::select('created_at')
$visits = Visit::query()
->select('created_at')
->whereIn('post_id', $posts->pluck('id'))
->whereBetween('created_at', [
today()->subDays(30)->startOfDay()->toDateTimeString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Closure;
use Illuminate\Http\Request;

class Admin
class AdminMiddleware
{
/**
* Handle the incoming request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Http\Request;

class Authorize
class AuthenticatedMiddleware
{
/**
* The authentication factory instance.
Expand Down
13 changes: 13 additions & 0 deletions tests/CanvasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,17 @@ public function testGravatar(): void
$this->assertStringContainsString(sprintf('d=%s', $default), $url);
$this->assertStringContainsString(sprintf('r=%s', $rating), $url);
}

public function testEnabledDarkMode(): void
{
$this->assertTrue(Canvas::enabledDarkMode(1));
$this->assertFalse(Canvas::enabledDarkMode(0));
}

public function testUsingRightToLeftLanguage(): void
{
$this->assertTrue(Canvas::usingRightToLeftLanguage('ar'));
$this->assertTrue(Canvas::usingRightToLeftLanguage('fa'));
$this->assertFalse(Canvas::usingRightToLeftLanguage('en'));
}
}
2 changes: 1 addition & 1 deletion tests/Http/Controllers/HomeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testScriptVariables(): void
->get(config('canvas.path'))
->assertSuccessful()
->assertViewIs('canvas::layout')
->assertViewHas('config')
->assertViewHas('jsVars')
->assertSee('canvas');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
/**
* Class AdminTest.
*
* @covers \Canvas\Http\Middleware\Admin
* @covers \Canvas\Http\Middleware\AdminMiddleware
*/
class AdminTest extends TestCase
class AdminMiddlewareTest extends TestCase
{
use RefreshDatabase;

Expand All @@ -24,20 +24,15 @@ public function protectedRoutesProvider(): array
['GET', 'canvas/api/tags'],
['GET', 'canvas/api/tags/create'],
['GET', 'canvas/api/tags/{id}/posts'],
['POST', 'canvas/api/tags/{id}'],
['DELETE', 'canvas/api/tags/{id}'],

// Topic routes...
['GET', 'canvas/api/topics'],
['GET', 'canvas/api/topics/create'],
['GET', 'canvas/api/topics/{id}/posts'],
['POST', 'canvas/api/topics/{id}'],
['DELETE', 'canvas/api/topics/{id}'],

// User routes...
['GET', 'canvas/api/users'],
['GET', 'canvas/api/users/create'],
['DELETE', 'canvas/api/users/{id}'],

// Search routes...
['GET', 'canvas/api/search/tags'],
Expand Down Expand Up @@ -69,4 +64,16 @@ public function testEditorAccessIsRestricted($method, $endpoint)
->call($method, $endpoint)
->assertForbidden();
}

/**
* @dataProvider protectedRoutesProvider
* @param $method
* @param $endpoint
*/
public function testAdminAccessIsGranted($method, $endpoint)
{
$this->actingAs($this->admin, 'canvas')
->call($method, $endpoint)
->assertSuccessful();
}
}
Loading

0 comments on commit be725c9

Please sign in to comment.