diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d4ac04..2d81e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGELOG +## v0.4.1 (2021-02-12) + +* Various bug fixes (closes #26) + * Admins can now access their draft posts without an error being thrown + * There is now a unique check in place for post slug names that now ignores the post being updated and only checks against other posts + * Fixed a development bug where data wasn't seeded correctly for categories and rollbacks wouldn't remove that data + * The dark mode theme had text the same color as the background on the admin page which has been fixed + * Reading time and categories now have visual fallbacks if they are not set properly + ## v0.4.0 (2021-02-09) * Fixed slugify integration and dependencies diff --git a/src/app/Http/Controllers/PostController.php b/src/app/Http/Controllers/PostController.php index 1d0f630..b08cbf5 100644 --- a/src/app/Http/Controllers/PostController.php +++ b/src/app/Http/Controllers/PostController.php @@ -25,18 +25,22 @@ public function readPosts(Request $request) public function create(Request $request) { + $post = new Post(); + request()->validate([ 'title' => 'required|string', - 'slug' => Rule::unique('posts')->where(function ($query) { - return $query->where('user_id', Auth::user()->id); - }), + 'slug' => [ + 'required', + Rule::unique('posts')->ignore($post->id)->where(function ($query) { + return $query->where('user_id', Auth::user()->id); + }) + ], 'reading_time' => 'nullable|numeric', 'keywords' => 'nullable|string', 'category' => 'string', 'post' => 'required|string', ]); - $post = new Post(); $post->title = request()->get('title'); $post->slug = request()->get('slug'); $post->published = request()->get('published'); @@ -54,9 +58,14 @@ public function create(Request $request) public function read($user, $slug) { - $post = Post::where('slug', '=', $slug) - // ->where('published', '=', 1) // TODO: Fix this for admins so they can still access their posts even when on "draft" - ->firstOrFail(); + if (Auth::user()->role = 1) { + $post = Post::where('slug', '=', $slug) + ->firstOrFail(); + } else { + $post = Post::where('slug', '=', $slug) + ->where('published', '=', 1) + ->firstOrFail(); + } $comments = Comment::where('post_id', '=', $post->id) ->orderBy('created_at', 'asc') ->paginate(15); @@ -82,21 +91,23 @@ public function readEdit($user, $slug) public function update(Request $request) { + $id = request()->get('id'); + $post = Post::where('id', '=', $id)->first(); + request()->validate([ 'title' => 'required|string', - /* TODO: fix validation to allow the same slug as the current one when updating - 'slug' => Rule::unique('posts')->where(function ($query) { - return $query->where('user_id', Auth::user()->id); - }), - */ + 'slug' => [ + 'required', + Rule::unique('posts')->ignore($post->id)->where(function ($query) { + return $query->where('user_id', Auth::user()->id); + }) + ], 'reading_time' => 'nullable|numeric', 'keywords' => 'nullable|string', 'category' => 'string', 'post' => 'required|string', ]); - $id = request()->get('id'); - $post = Post::where('id', '=', $id)->first(); $post->published = request()->get('published'); $post->banner_image_url = request()->get('banner_image_url'); $post->title = request()->get('title'); @@ -141,7 +152,11 @@ public function uploadPostImage(Request $request) $request->validate([ 'upload_image' => 'required|image|mimes:jpeg,jpg,png|max:2048', ]); - $id = mt_rand(100000000000, 999999999999); # TODO: This is hacky, fix down the road + + // ~1 billion possible id's, overlap potential should be small + $id_min = 1000000000; + $id_max = 9999999999; + $id = mt_rand($id_min, $id_max); if (!is_dir(storage_path("app/public/post-images"))) { mkdir(storage_path("app/public/post-images"), 0775, true); diff --git a/src/database/migrations/2020_01_27_213243_insert_admin_account.php b/src/database/migrations/2020_01_27_213243_insert_admin_account.php index 0989df4..d03b03d 100644 --- a/src/database/migrations/2020_01_27_213243_insert_admin_account.php +++ b/src/database/migrations/2020_01_27_213243_insert_admin_account.php @@ -3,6 +3,9 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; +use App\Models\User; +use App\Models\Setting; +use App\Models\Category; class InsertAdminAccount extends Migration { @@ -14,21 +17,29 @@ class InsertAdminAccount extends Migration public function up() { // Seed User's table with initial account - DB::table('users')->insert([ - 'name' => "admin", - 'email' => "admin@laraview.com", - 'email_verified_at' => now(), - 'password' => '$2y$10$P/XLoBoBIkfD6QBxhV5GB.2jXL5OZkc9E2pWAVkm9IKoAUQ0zct52', // password = "password" - 'remember_token' => Str::random(10), - 'role' => 1, - ]); + $user = new User(); + $user->id = 1; + $user->name = "admin"; + $user->email = "admin@laraview.com"; + $user->email_verified_at = now(); + $user->password = '$2y$10$P/XLoBoBIkfD6QBxhV5GB.2jXL5OZkc9E2pWAVkm9IKoAUQ0zct52'; // secret + $user->remember_token = Str::random(10); + $user->role = 1; + $user->save(); // Seed settings table with initial settings - DB::table('settings')->insert([ - 'title' => "Blog", - 'theme' => 1, - 'comments' => 1, - ]); + $setting = new Setting(); + $setting-> id = 1; + $setting->title = "Blog"; + $setting->theme = 1; + $setting->comments = 1; + $setting->save(); + + // Seed an initial category + $category = new Category(); + $category->user_id = 1; + $category->category = 'Uncategorized'; + $category->save(); } /** @@ -38,6 +49,8 @@ public function up() */ public function down() { - // TODO: Add in a way to delete this + User::truncate(); + Setting::truncate(); + Category::truncate(); } } diff --git a/src/public/css/dark-mode.css b/src/public/css/dark-mode.css index f19f17a..a22ba58 100644 --- a/src/public/css/dark-mode.css +++ b/src/public/css/dark-mode.css @@ -88,4 +88,8 @@ hr { background-color: #b20000; border-color: #b20000; } -/*# sourceMappingURL=dark-mode.css.map */ \ No newline at end of file + +.table { + color: #bbe1fa; +} +/*# sourceMappingURL=dark-mode.css.map */ diff --git a/src/public/css/dark-mode.scss b/src/public/css/dark-mode.scss index c315e0a..51da913 100644 --- a/src/public/css/dark-mode.scss +++ b/src/public/css/dark-mode.scss @@ -86,3 +86,7 @@ hr { background-color: #b20000; border-color: #b20000; } + +.table { + color: #bbe1fa; +} diff --git a/src/resources/views/admin.blade.php b/src/resources/views/admin.blade.php index 353ee08..20ce3fc 100644 --- a/src/resources/views/admin.blade.php +++ b/src/resources/views/admin.blade.php @@ -110,12 +110,12 @@