diff --git a/db/factories/NewsFactory.php b/db/factories/NewsFactory.php index 54b39d36..f2af8ccf 100644 --- a/db/factories/NewsFactory.php +++ b/db/factories/NewsFactory.php @@ -16,12 +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), - 'is_important' => $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_highlighted' => $this->faker->boolean(.1), + 'user_id' => User::factory(), ]; } } diff --git a/db/migrations/2023_09_18_000000_news_rename_important_to_highlight.php b/db/migrations/2023_09_18_000000_news_rename_important_to_highlight.php new file mode 100644 index 00000000..352ac3b6 --- /dev/null +++ b/db/migrations/2023_09_18_000000_news_rename_important_to_highlight.php @@ -0,0 +1,41 @@ +schema->table('news', function (Blueprint $table): void { + $table->renameColumn('is_important', 'is_highlighted'); + }); + + $this->schema->getConnection() + ->table('privileges') + ->where('name', 'news.important') + ->update(['name' => 'news.highlight', 'description' => 'Highlight News']); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->schema->table('news', function (Blueprint $table): void { + $table->renameColumn('is_highlighted', 'is_important'); + }); + + $this->schema->getConnection() + ->table('privileges') + ->where('name', 'news.highlight') + ->update(['name' => 'news.important', 'description' => 'Make News Important']); + } +} diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php index d4f73434..59ddc2b9 100644 --- a/includes/controller/public_dashboard_controller.php +++ b/includes/controller/public_dashboard_controller.php @@ -57,14 +57,14 @@ function public_dashboard_controller() } } - $important_news = News::whereIsImportant(true) + $highlighted_news = News::whereIsHighlighted(true) ->orderBy('updated_at') ->limit(1) ->get(); return [ __('Public Dashboard'), - public_dashboard_view($stats, $free_shifts, $important_news), + public_dashboard_view($stats, $free_shifts, $highlighted_news), ]; } diff --git a/includes/view/PublicDashboard_view.php b/includes/view/PublicDashboard_view.php index a39946bf..82510b60 100644 --- a/includes/view/PublicDashboard_view.php +++ b/includes/view/PublicDashboard_view.php @@ -9,15 +9,15 @@ use Illuminate\Support\Collection; * * @param array $stats * @param array[] $free_shifts - * @param News[]|Collection $important_news + * @param News[]|Collection $highlighted_news * @return string */ -function public_dashboard_view($stats, $free_shifts, $important_news) +function public_dashboard_view($stats, $free_shifts, $highlighted_news) { $needed_angels = ''; $news = ''; - if ($important_news->isNotEmpty()) { - $first_news = $important_news->first(); + if ($highlighted_news->isNotEmpty()) { + $first_news = $highlighted_news->first(); $news = div('alert alert-warning text-center', [ '' . $first_news->title . '', ]); diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 5b2348bf..365c2dd6 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2050,8 +2050,8 @@ msgstr "+" msgid "news.is_meeting" msgstr "[Treffen]" -msgid "news.edit.is_important" -msgstr "Wichtig" +msgid "news.edit.is_highlighted" +msgstr "Hervorgehoben" msgid "news.read_more" msgstr "Weiterlesen" diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index 980bb85f..d79e8a27 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -193,8 +193,8 @@ msgstr "Subject" msgid "news.edit.is_meeting" msgstr "Meeting" -msgid "news.edit.is_important" -msgstr "Important" +msgid "news.edit.is_highlighted" +msgstr "Highlighted" msgid "news.edit.is_pinned" msgstr "Pin to top" diff --git a/resources/views/pages/news/edit.twig b/resources/views/pages/news/edit.twig index e7e50809..dbf57965 100644 --- a/resources/views/pages/news/edit.twig +++ b/resources/views/pages/news/edit.twig @@ -49,9 +49,9 @@ {{ f.checkbox('is_pinned', __('news.edit.is_pinned'), { 'checked': is_pinned, }) }} - {% if has_permission_to('news.important') %} - {{ f.checkbox('is_important', __('news.edit.is_important'), { - 'checked': is_important, + {% if has_permission_to('news.highlight') %} + {{ f.checkbox('is_highlighted', __('news.edit.is_highlighted'), { + 'checked': is_highlighted, }) }} {% endif %} @@ -82,7 +82,7 @@

{{ __('form.preview') }}

-
+
{% if news.is_meeting %}{{ __('news.is_meeting') }}{% endif %} {{ news.title }} diff --git a/resources/views/pages/news/overview.twig b/resources/views/pages/news/overview.twig index 3c4584c0..7fea140f 100644 --- a/resources/views/pages/news/overview.twig +++ b/resources/views/pages/news/overview.twig @@ -48,7 +48,7 @@ {% endblock %} {% macro news(news, show_comments_link, is_overview) %} -
+
{% if is_overview|default(false) %}
diff --git a/src/Controllers/Admin/NewsController.php b/src/Controllers/Admin/NewsController.php index d921667e..6cb974e6 100644 --- a/src/Controllers/Admin/NewsController.php +++ b/src/Controllers/Admin/NewsController.php @@ -47,10 +47,10 @@ class NewsController extends BaseController return $this->response->withView( 'pages/news/edit.twig', [ - 'news' => $news, - 'is_meeting' => $news ? $news->is_meeting : $isMeetingDefault, - 'is_pinned' => $news ? $news->is_pinned : false, - 'is_important' => $news ? $news->is_important : false, + 'news' => $news, + 'is_meeting' => $news ? $news->is_meeting : $isMeetingDefault, + 'is_pinned' => $news ? $news->is_pinned : false, + 'is_highlighted' => $news ? $news->is_highlighted : false, ], ); } @@ -63,13 +63,13 @@ class NewsController extends BaseController $news = $this->news->findOrNew($newsId); $data = $this->validate($request, [ - 'title' => 'required', - 'text' => 'required', - 'is_meeting' => 'optional|checked', - 'is_pinned' => 'optional|checked', - 'is_important' => 'optional|checked', - 'delete' => 'optional|checked', - 'preview' => 'optional|checked', + 'title' => 'required', + 'text' => 'required', + 'is_meeting' => 'optional|checked', + 'is_pinned' => 'optional|checked', + 'is_highlighted' => 'optional|checked', + 'delete' => 'optional|checked', + 'preview' => 'optional|checked', ]); if (!is_null($data['delete'])) { @@ -96,8 +96,8 @@ class NewsController extends BaseController $news->is_meeting = !is_null($data['is_meeting']); $news->is_pinned = !is_null($data['is_pinned']); - if ($this->auth->can('news.important')) { - $news->is_important = !is_null($data['is_important']); + if ($this->auth->can('news.highlight')) { + $news->is_highlighted = !is_null($data['is_highlighted']); } if (!is_null($data['preview'])) { @@ -119,7 +119,7 @@ class NewsController extends BaseController 'Updated {pinned}{type} "{news}": {text}', [ 'pinned' => $news->is_pinned ? 'pinned ' : '', - 'important' => $news->is_important ? 'important ' : '', + 'highlighted' => $news->is_highlighted ? 'highlighted ' : '', 'type' => $news->is_meeting ? 'meeting' : 'news', 'news' => $news->title, 'text' => $news->text, diff --git a/src/Controllers/NewsController.php b/src/Controllers/NewsController.php index 0b9a163c..69f35f80 100644 --- a/src/Controllers/NewsController.php +++ b/src/Controllers/NewsController.php @@ -138,7 +138,7 @@ class NewsController extends BaseController ->with('user') ->withCount('comments') ->orderByDesc('is_pinned') - ->orderByDesc('is_important') + ->orderByDesc('is_highlighted') ->orderByDesc('updated_at') ->orderByDesc('id') ->limit($perPage) diff --git a/src/Models/News.php b/src/Models/News.php index 0bcd42dc..58b54ad2 100644 --- a/src/Models/News.php +++ b/src/Models/News.php @@ -16,9 +16,9 @@ use Illuminate\Support\Str; * @property int $id * @property string $title * @property string $text + * @property bool $is_highlighted * @property bool $is_meeting * @property bool $is_pinned - * @property bool $is_important * @property Carbon|null $created_at * @property Carbon|null $updated_at * @@ -30,7 +30,7 @@ use Illuminate\Support\Str; * @method static QueryBuilder|News[] whereText($value) * @method static QueryBuilder|News[] whereIsMeeting($value) * @method static QueryBuilder|News[] whereIsPinned($value) - * @method static QueryBuilder|News[] whereIsImportant($value) + * @method static QueryBuilder|News[] whereIsHighlighted($value) * @method static QueryBuilder|News[] whereCreatedAt($value) * @method static QueryBuilder|News[] whereUpdatedAt($value) */ @@ -44,17 +44,17 @@ class News extends BaseModel /** @var array */ protected $casts = [ // phpcs:ignore - 'user_id' => 'integer', - 'is_meeting' => 'boolean', - 'is_pinned' => 'boolean', - 'is_important' => 'boolean', + 'user_id' => 'integer', + 'is_meeting' => 'boolean', + 'is_pinned' => 'boolean', + 'is_highlighted' => 'boolean', ]; /** @var array Default attributes */ protected $attributes = [ // phpcs:ignore - 'is_meeting' => false, - 'is_pinned' => false, - 'is_important' => false, + 'is_meeting' => false, + 'is_pinned' => false, + 'is_highlighted' => false, ]; /** @var array */ @@ -63,7 +63,7 @@ class News extends BaseModel 'text', 'is_meeting', 'is_pinned', - 'is_important', + 'is_highlighted', 'user_id', ]; diff --git a/tests/Unit/Controllers/Admin/NewsControllerTest.php b/tests/Unit/Controllers/Admin/NewsControllerTest.php index e367de9a..4787c572 100644 --- a/tests/Unit/Controllers/Admin/NewsControllerTest.php +++ b/tests/Unit/Controllers/Admin/NewsControllerTest.php @@ -158,12 +158,12 @@ class NewsControllerTest extends ControllerTest { $this->request->attributes->set('news_id', 1); $this->request = $this->request->withParsedBody([ - 'title' => 'New title', - 'text' => 'New text', - 'is_meeting' => '1', - 'is_pinned' => '1', - 'is_important' => '1', - 'preview' => '1', + 'title' => 'New title', + 'text' => 'New text', + 'is_meeting' => '1', + 'is_pinned' => '1', + 'is_highlighted' => '1', + 'preview' => '1', ]); $this->response->expects($this->once()) ->method('withView') @@ -175,7 +175,7 @@ class NewsControllerTest extends ControllerTest // Contains new text $this->assertTrue($news->is_meeting); $this->assertTrue($news->is_pinned); - $this->assertTrue($news->is_important); + $this->assertTrue($news->is_highlighted); $this->assertEquals('New title', $news->title); $this->assertEquals('New text', $news->text); @@ -183,7 +183,7 @@ class NewsControllerTest extends ControllerTest }); $this->auth->expects($this->atLeastOnce()) ->method('can') - ->with('news.important') + ->with('news.highlight') ->willReturn(true); /** @var NewsController $controller */ @@ -198,7 +198,7 @@ class NewsControllerTest extends ControllerTest $this->assertEquals('**foo**', $news->text); $this->assertFalse($news->is_meeting); $this->assertFalse($news->is_pinned); - $this->assertFalse($news->is_important); + $this->assertFalse($news->is_highlighted); } /** diff --git a/tests/Unit/Controllers/NewsControllerTest.php b/tests/Unit/Controllers/NewsControllerTest.php index 2dceca36..9af38e8d 100644 --- a/tests/Unit/Controllers/NewsControllerTest.php +++ b/tests/Unit/Controllers/NewsControllerTest.php @@ -39,12 +39,12 @@ class NewsControllerTest extends ControllerTest 'user_id' => 1, ], [ - 'title' => 'baz', - 'text' => 'baz', - 'is_meeting' => true, - 'is_pinned' => true, - 'is_important' => true, - 'user_id' => 1, + 'title' => 'baz', + 'text' => 'baz', + 'is_meeting' => true, + 'is_pinned' => true, + 'is_highlighted' => true, + 'user_id' => 1, ], [ 'title' => 'Lorem',