diff --git a/config/calendar.php b/config/calendar.php new file mode 100644 index 0000000..8767050 --- /dev/null +++ b/config/calendar.php @@ -0,0 +1,7 @@ + [ + 'roles' => ['*'], + ], +]; diff --git a/src/AppServiceProvider.php b/src/AppServiceProvider.php index 44043c1..517c44e 100644 --- a/src/AppServiceProvider.php +++ b/src/AppServiceProvider.php @@ -18,6 +18,7 @@ public function boot() ->publishProvider() ->publishFactories() ->publishMail() + ->publishConfig() ->commands(SendReminders::class); } @@ -25,6 +26,8 @@ private function load() { $this->loadRoutesFrom(__DIR__.'/../routes/api.php'); + $this->mergeConfigFrom(__DIR__.'/../config/calendar.php', 'enso.calendar'); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-enso/calendar'); @@ -68,4 +71,13 @@ private function publishMail() return $this; } + + private function publishConfig() + { + $this->publishes([ + __DIR__.'/../config' => config_path('enso'), + ], ['enso-config', 'calendar-config']); + + return $this; + } } diff --git a/src/Calendars/BirthdayCalendar.php b/src/Calendars/BirthdayCalendar.php index e8a378b..f54d22f 100644 --- a/src/Calendars/BirthdayCalendar.php +++ b/src/Calendars/BirthdayCalendar.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Config; use LaravelEnso\Calendar\Contracts\CustomCalendar; use LaravelEnso\Calendar\Enums\Colors; use LaravelEnso\People\Models\Person; @@ -42,8 +43,11 @@ public function events(Carbon $startDate, Carbon $endDate): Collection { $this->startDate = $startDate; $this->endDate = $endDate; + $roles = Config::get('enso.calendar.birthdays.roles'); return Person::query() + ->unless($roles === ['*'], fn ($query) => $query + ->whereHas('user', fn ($query) => $query->whereIn('role_id', $roles))) ->when(! $this->withinSameYear(), $this->differentYearQuery()) ->when( $this->withinSameYear() && $this->withinSameMonth(), diff --git a/tests/features/CalendarTest.php b/tests/features/CalendarTest.php new file mode 100644 index 0000000..50bc7ac --- /dev/null +++ b/tests/features/CalendarTest.php @@ -0,0 +1,51 @@ +seed(); + + $this->actingAs(User::first()); + + $this->calendar = Calendar::factory()->create(); + } + + /** @test */ + public function create_calendar() + { + $result = $this->post(route('core.calendar.store'), [ + 'name' => 'test', + 'color' => Colors::Red, + 'private' => false, + ]); + + $this->assertTrue(Calendar::whereName('test')->exists()); + } + + /** @test */ + public function can_limit_birthday_calendar_roles() + { + Config::set('enso.calendar.birthdays.roles', []); + + $this->assertEmpty((new BirthdayCalendar()) + ->events(Person::first()->birthday, Person::first()->birthday->addDay())); + } +} diff --git a/tests/features/CreateTest.php b/tests/features/CreateTest.php index 5526744..8b76572 100644 --- a/tests/features/CreateTest.php +++ b/tests/features/CreateTest.php @@ -1,7 +1,5 @@