From 6fcb6562993ea4001bc0bf01d26550b99d1e979b Mon Sep 17 00:00:00 2001 From: xuwhite <73076134+xuwhite@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:19:45 +0100 Subject: [PATCH] Added important news (#1096) --- db/factories/NewsFactory.php | 11 ++--- ...dd_set_news_flag_important_permissions.php | 42 +++++++++++++++++++ ..._02_06_000000_add_is_important_to_news.php | 31 ++++++++++++++ .../public_dashboard_controller.php | 8 +++- includes/view/PublicDashboard_view.php | 19 +++++++-- resources/assets/themes/base.scss | 4 ++ resources/lang/de_DE/default.po | 3 ++ resources/lang/en_US/default.po | 3 ++ resources/views/pages/news/edit.twig | 3 +- resources/views/pages/news/overview.twig | 2 +- src/Controllers/Admin/NewsController.php | 33 +++++++++------ src/Controllers/NewsController.php | 1 + src/Models/News.php | 29 +++++++------ src/Models/UserAngelType.php | 8 ++-- .../Controllers/Admin/NewsControllerTest.php | 17 +++++--- tests/Unit/Controllers/NewsControllerTest.php | 11 ++--- tests/Unit/Models/PrivilegeTest.php | 2 +- 17 files changed, 176 insertions(+), 51 deletions(-) create mode 100644 db/migrations/2023_02_03_000000_add_set_news_flag_important_permissions.php create mode 100644 db/migrations/2023_02_06_000000_add_is_important_to_news.php diff --git a/db/factories/NewsFactory.php b/db/factories/NewsFactory.php index ae1c54b2..54b39d36 100644 --- a/db/factories/NewsFactory.php +++ b/db/factories/NewsFactory.php @@ -16,11 +16,12 @@ class NewsFactory extends Factory public function definition(): array { return [ - 'title' => $this->faker->text(50), - 'text' => $this->faker->realText(), - 'is_meeting' => $this->faker->boolean(), - 'is_pinned' => $this->faker->boolean(.1), - 'user_id' => User::factory(), + 'title' => $this->faker->text(50), + 'text' => $this->faker->realText(), + 'is_meeting' => $this->faker->boolean(), + 'is_pinned' => $this->faker->boolean(.1), + 'is_important' => $this->faker->boolean(.1), + 'user_id' => User::factory(), ]; } } diff --git a/db/migrations/2023_02_03_000000_add_set_news_flag_important_permissions.php b/db/migrations/2023_02_03_000000_add_set_news_flag_important_permissions.php new file mode 100644 index 00000000..f75747a5 --- /dev/null +++ b/db/migrations/2023_02_03_000000_add_set_news_flag_important_permissions.php @@ -0,0 +1,42 @@ +schema->getConnection(); + $db->table('privileges') + ->insert(['name' => 'news.important', 'description' => 'Make News Important']); + + $newsImportant = $db->table('privileges') + ->where('name', 'news.important') + ->get(['id']) + ->first(); + + $buerocrat = 80; + $db->table('group_privileges') + ->insertOrIgnore([ + ['group_id' => $buerocrat, 'privilege_id' => $newsImportant->id], + ]); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $db = $this->schema->getConnection(); + $db->table('privileges') + ->where(['name' => 'news.important']) + ->delete(); + } +} diff --git a/db/migrations/2023_02_06_000000_add_is_important_to_news.php b/db/migrations/2023_02_06_000000_add_is_important_to_news.php new file mode 100644 index 00000000..1d280efb --- /dev/null +++ b/db/migrations/2023_02_06_000000_add_is_important_to_news.php @@ -0,0 +1,31 @@ +schema->table('news', function (Blueprint $table): void { + $table->boolean('is_important')->default(false)->after('is_pinned'); + }); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->schema->table('news', function (Blueprint $table): void { + $table->dropColumn('is_important'); + }); + } +} diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php index 114a5fd3..47476262 100644 --- a/includes/controller/public_dashboard_controller.php +++ b/includes/controller/public_dashboard_controller.php @@ -1,6 +1,7 @@ orderBy('updated_at') + ->limit(1) + ->get(); + return [ __('Public Dashboard'), - public_dashboard_view($stats, $free_shifts), + public_dashboard_view($stats, $free_shifts, $important_news), ]; } diff --git a/includes/view/PublicDashboard_view.php b/includes/view/PublicDashboard_view.php index eaadb0e2..29837176 100644 --- a/includes/view/PublicDashboard_view.php +++ b/includes/view/PublicDashboard_view.php @@ -1,15 +1,27 @@ isNotEmpty()) { + $first_news = $important_news->first(); + $news = div('alert alert-warning text-center', [ + '' . $first_news->title . '', + ]); + } + if (count($free_shifts) > 0) { $shift_panels = [ '