From 05be46706f95d9db7121d821afc7ad028bab3102 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 2 Aug 2024 17:36:59 +0200 Subject: [PATCH] chore: deleted areas table --- app/Http/Controllers/API/EventController.php | 6 +-- app/Http/Controllers/EventController.php | 17 ++------ app/Http/Controllers/StaffingController.php | 5 +-- app/Http/Controllers/UserController.php | 32 +++++---------- app/Models/Area.php | 30 -------------- app/Models/Event.php | 11 +---- app/Models/Group.php | 2 +- app/Models/Staffing.php | 4 -- app/Models/User.php | 40 +++++-------------- app/Policies/EventPolicy.php | 6 +-- app/Policies/StaffingPolicy.php | 2 +- app/Policies/UserPolicy.php | 6 --- database/factories/StaffingFactory.php | 4 -- .../2023_05_18_165221_create_areas_table.php | 35 ---------------- ..._05_18_165642_create_permissions_table.php | 4 -- ...23_07_02_091331_create_staffings_table.php | 5 --- .../2024_07_08_215214_create_events_table.php | 2 - database/seeders/EventSeeder.php | 3 -- database/seeders/UserSeeder.php | 5 +-- resources/views/events/create.blade.php | 13 ------ resources/views/events/edit.blade.php | 13 ------ resources/views/events/show.blade.php | 3 +- resources/views/staffing/create.blade.php | 11 ----- resources/views/users/show.blade.php | 28 +++++-------- tests/Feature/Misc/APITest.php | 2 - tests/Feature/Models/CalendarTest.php | 4 +- tests/Feature/Models/EventTest.php | 14 +------ tests/Feature/Models/UserTest.php | 4 +- 28 files changed, 48 insertions(+), 263 deletions(-) delete mode 100644 app/Models/Area.php delete mode 100644 database/migrations/2023_05_18_165221_create_areas_table.php diff --git a/app/Http/Controllers/API/EventController.php b/app/Http/Controllers/API/EventController.php index 797dfdd..54d1e12 100644 --- a/app/Http/Controllers/API/EventController.php +++ b/app/Http/Controllers/API/EventController.php @@ -37,7 +37,6 @@ public function store(Request $request) { $data = $this->validate($request, [ 'calendar_id' => 'required|exists:calendars,id', - 'area' => 'required|exists:areas,id', 'title' => 'required|string|max:255', 'short_description' => 'nullable|max:280', 'long_description' => 'nullable', @@ -89,8 +88,7 @@ public function store(Request $request) 'image' => $imageName, ]); - // Ensure area and user association - $event->area()->associate($request->input('area')); + // Ensure user association $event->user()->associate($user); $event->save(); @@ -121,7 +119,6 @@ public function update(Request $request, Event $event) { $data = $this->validate($request, [ 'calendar_id' => 'required|exists:calendars,id', - 'area' => 'required|exists:areas,id', 'title' => 'required|string|max:255', 'short_description' => 'nullable|max:280', 'long_description' => 'nullable', @@ -182,7 +179,6 @@ public function update(Request $request, Event $event) 'image' => $imageURL, ]); - $event->area()->associate($request->input('area')); $event->user()->associate($user); $event->save(); diff --git a/app/Http/Controllers/EventController.php b/app/Http/Controllers/EventController.php index 1058b78..58b8769 100644 --- a/app/Http/Controllers/EventController.php +++ b/app/Http/Controllers/EventController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers; -use App\Models\Area; use App\Models\Calendar; use App\Models\Event; use Carbon\Carbon; @@ -33,11 +32,9 @@ public function create() { $this->authorize('create', Event::class); - $areas = Area::all(); - $calendars = Calendar::all(); - return view('events.create', compact('areas', 'calendars')); + return view('events.create', compact('calendars')); } /** @@ -49,7 +46,6 @@ public function store(Request $request) $this->validate($request, [ 'calendar_id' => 'required|exists:calendars,id', - 'area' => 'required|exists:areas,id', 'title' => 'required|string|max:255', 'short_description' => 'nullable|max:280', 'long_description' => 'nullable', @@ -97,8 +93,7 @@ public function store(Request $request) 'image' => $imageName, ]); - // Ensure area and user association - $event->area()->associate($request->input('area')); + // Ensure user association $event->user()->associate(\Auth::user()); $event->save(); @@ -128,11 +123,9 @@ public function edit(Event $event) { $this->authorize('update', $event); - $areas = Area::all(); - $calendars = Calendar::all(); - return view('events.edit', compact('areas', 'calendars', 'event')); + return view('events.edit', compact('calendars', 'event')); } /** @@ -144,7 +137,6 @@ public function update(Request $request, Event $event) $this->validate($request, [ 'calendar_id' => 'required|exists:calendars,id', - 'area' => 'required|exists:areas,id', 'title' => 'required|string|max:255', 'short_description' => 'nullable|max:280', 'long_description' => 'nullable', @@ -201,8 +193,7 @@ public function update(Request $request, Event $event) 'image' => $imageURL, ]); - // Ensure area and user association - $event->area()->associate($request->input('area')); + // Ensure user association $event->user()->associate(\Auth::user()); // Save the event before handling recurrences diff --git a/app/Http/Controllers/StaffingController.php b/app/Http/Controllers/StaffingController.php index 549eed7..b83de79 100644 --- a/app/Http/Controllers/StaffingController.php +++ b/app/Http/Controllers/StaffingController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers; -use App\Models\Area; use App\Models\Staffing; use Carbon\Carbon; use Illuminate\Http\Request; @@ -63,11 +62,9 @@ public function create() } } - $areas = Area::all(); - $channels = $this->getGuildChannels(); - return view('staffing.create', compact('allData', 'areas', 'channels')); + return view('staffing.create', compact('allData', 'channels')); } protected function getGuildChannels() { diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7b9d146..9525ae0 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers; -use App\Models\Area; use App\Models\Group; use App\Models\User; use Carbon\Carbon; @@ -36,11 +35,9 @@ public function show(User $user) return \Auth::user()->can('view', $event); }); - $areas = Area::all(); - $groups = Group::all(); - return view('users.show', compact('user', 'events', 'areas', 'groups')); + return view('users.show', compact('user', 'events', 'groups')); } /** @@ -53,14 +50,8 @@ public function update(Request $request, User $user) $permissions = []; // Generate a list of possible validations - foreach (Area::all() as $area) { - foreach (Group::all() as $group) { - // Only process ranks the user is allowed to change - $this->authorize('updateGroup', [$user, $group, $area]); - - $key = $area->id . '_' . $group->name; - $permissions[$key] = ''; - } + foreach (Group::all() as $group) { + $permissions[$group->name] = ''; } // Valiate and allow these fields, then loop through permissions to set the final data set @@ -69,27 +60,22 @@ public function update(Request $request, User $user) isset($data[$key]) ? $permissions[$key] = true : $permissions[$key] = false; } + //dd($permissions); + // Check and update the permissions foreach ($permissions as $key => $value) { - $str = explode('_', $key); - - $area = Area::where('id', $str[0])->get()->first(); - $group = Group::where('name', $str[1])->get()->first(); + $group = Group::where('name', $key)->get()->first(); // Check if permission is not set, and set it or other way around. - if ($user->groups()->where('area_id', $area->id)->where('group_id', $group->id)->get()->count() == 0) { + if ($user->groups()->where('group_id', $group->id)->get()->count() == 0) { if ($value == true) { - $this->authorize('updateGroup', [$user, $group, $area]); - // Attach the new permission - $user->groups()->attach($group, ['area_id' => $area->id, 'inserted_by' => \Auth::user()->id]); + $user->groups()->attach($group, ['inserted_by' => \Auth::user()->id]); } } else { if ($value == false) { - $this->authorize('updateGroup', [$user, $group, $area]); - // Detach the permission - $user->groups()->wherePivot('area_id', $area->id)->wherePivot('group_id', $group->id)->detach(); + $user->groups()->wherePivot('group_id', $group->id)->detach(); } } } diff --git a/app/Models/Area.php b/app/Models/Area.php deleted file mode 100644 index 43bebe5..0000000 --- a/app/Models/Area.php +++ /dev/null @@ -1,30 +0,0 @@ -belongsToMany(Group::class, 'permissions')->withPivot('area_id')->withTimestamps(); - } - - public function staffing() - { - return $this->hasMany(Staffing::class); - } - - public function events() - { - return $this->hasMany(Event::class); - } -} diff --git a/app/Models/Event.php b/app/Models/Event.php index be6f907..21b58a6 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -29,8 +29,7 @@ class Event extends Model 'recurrence_end_date', 'published', 'image', - 'user_id', - 'area_id' + 'user_id' ]; protected $dates = [ @@ -43,11 +42,6 @@ public function user() return $this->belongsTo(User::class); } - public function area() - { - return $this->belongsTo(Area::class); - } - public function calendar() { return $this->belongsTo(Calendar::class); @@ -124,8 +118,7 @@ public function generateRecurrences() 'recurrence_unit' => $this->recurrence_unit, 'recurrence_end_date' => $this->recurrence_end_date, 'image' => $this->image, - 'user_id' => $this->user_id, - 'area_id' => $this->area_id, + 'user_id' => $this->user_id ]); // Move to the next recurrence date diff --git a/app/Models/Group.php b/app/Models/Group.php index 235ff66..9c429df 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -11,6 +11,6 @@ class Group extends Model public function users() { - return $this->belongsToMany(User::class, 'permissions')->withPivot('area_id')->withTimestamps(); + return $this->belongsToMany(User::class, 'permissions'); } } diff --git a/app/Models/Staffing.php b/app/Models/Staffing.php index 24e0516..b8aaa21 100644 --- a/app/Models/Staffing.php +++ b/app/Models/Staffing.php @@ -18,8 +18,4 @@ class Staffing extends Model 'id', 'title', 'date', 'description', 'channel_id', 'message_id', 'week_int', 'section_1_title', 'section_2_title', 'section_3_title', 'section_4_title', 'restrict_bookings' ]; - public function area() - { - return $this->belongsTo(Area::class, 'area_id'); - } } diff --git a/app/Models/User.php b/app/Models/User.php index e9c95ce..d285e63 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -51,7 +51,7 @@ class User extends Authenticatable */ public function groups() { - return $this->belongsToMany(Group::class, 'permissions')->withPivot('area_id')->withTimestamps(); + return $this->belongsToMany(Group::class, 'permissions'); } public function events() @@ -69,39 +69,19 @@ public function getNameAttribute() * * @return bool */ - public function isModerator(?Area $area = null) + public function isModerator() { - if($area == null) { - return $this->groups->where('id', 2)->isNotEmpty(); - } - - foreach($this->groups->where('id', 2) as $group) { - if($group->pivot->area_id == $area->id) { - return true; - } - } - - return false; + return $this->groups->where('id', 2)->isNotEmpty(); } - public function isModeratorOrAbove(?Area $area = null) + /** + * Return if user is a moderator or above + * + * @return bool + */ + public function isModeratorOrAbove() { - if ($area == null) { - return $this->groups->where('id', '<=', 2)->isNotEmpty(); - } - - if ($this->isAdmin()) { - return true; - } - - // Check if user is moderator or above in the specified area - foreach ($this->groups->where('id', '<=', 2) as $group) { - if ($group->pivot->area_id == $area->id) { - return true; - } - } - - return false; + return $this->groups->where('id', '<=', 2)->isNotEmpty();; } /** diff --git a/app/Policies/EventPolicy.php b/app/Policies/EventPolicy.php index a22a2a0..c9c5f33 100644 --- a/app/Policies/EventPolicy.php +++ b/app/Policies/EventPolicy.php @@ -17,7 +17,7 @@ public function index(User $user) public function view(?User $user, Event $event) { - return $user && ($user->isModeratorOrAbove() || $user->isModerator($event->area) || $user->is($event->user)) || $event->calendar->public; + return $user && ($user->isModeratorOrAbove() || $user->isModerator() || $user->is($event->user)) || $event->calendar->public; } public function create(User $user) @@ -27,11 +27,11 @@ public function create(User $user) public function update(User $user, Event $event) { - return $user->isModerator($event->area) || $user->isAdmin(); + return $user->isModerator() || $user->isAdmin(); } public function destroy(User $user, Event $event) { - return $user->isModerator($event->area) || $user->isAdmin(); + return $user->isModerator() || $user->isAdmin(); } } diff --git a/app/Policies/StaffingPolicy.php b/app/Policies/StaffingPolicy.php index b1f2f36..c7f0685 100644 --- a/app/Policies/StaffingPolicy.php +++ b/app/Policies/StaffingPolicy.php @@ -12,6 +12,6 @@ class StaffingPolicy public function view(User $user, Staffing $staffing) { - return $user->isAdmin() || $user->isModerator($staffing->area); + return $user->isAdmin() || $user->isModerator(); } } diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index 7aaf578..a9bc88a 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -2,7 +2,6 @@ namespace App\Policies; -use App\Models\Area; use App\Models\Group; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; @@ -30,9 +29,4 @@ public function update(User $user, User $model) { return $user->isAdmin(); } - - public function updateGroup(User $user, User $model) - { - return $user->isAdmin(); - } } diff --git a/database/factories/StaffingFactory.php b/database/factories/StaffingFactory.php index 979b5c1..863b17d 100644 --- a/database/factories/StaffingFactory.php +++ b/database/factories/StaffingFactory.php @@ -2,7 +2,6 @@ namespace Database\Factories; -use App\Models\Area; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -17,8 +16,6 @@ class StaffingFactory extends Factory */ public function definition(): array { - $areas = collect(Area::all()->modelKeys()); - return [ 'title' => fake()->sentence(), 'date' => fake()->dateTimeBetween('+1 month', '+6 month'), @@ -31,7 +28,6 @@ public function definition(): array 'section_3_title' => fake()->sentence(), 'section_4_title' => fake()->sentence(), 'restrict_bookings' => rand(0, 1), - 'area_id' => $areas->random(), ]; } diff --git a/database/migrations/2023_05_18_165221_create_areas_table.php b/database/migrations/2023_05_18_165221_create_areas_table.php deleted file mode 100644 index 6522bfd..0000000 --- a/database/migrations/2023_05_18_165221_create_areas_table.php +++ /dev/null @@ -1,35 +0,0 @@ -increments('id'); - $table->string('name'); - }); - - DB::table('areas')->insert([ - ['name' => 'Denmark'], - ['name' => 'Finland'], - ['name' => 'Iceland'], - ['name' => 'Norway'], - ['name' => 'Sweden'], - ]); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('areas'); - } -}; diff --git a/database/migrations/2023_05_18_165642_create_permissions_table.php b/database/migrations/2023_05_18_165642_create_permissions_table.php index 6ba1711..0d62ef6 100644 --- a/database/migrations/2023_05_18_165642_create_permissions_table.php +++ b/database/migrations/2023_05_18_165642_create_permissions_table.php @@ -12,10 +12,7 @@ public function up(): void { Schema::create('permissions', function (Blueprint $table) { - $table->primary(['user_id', 'area_id', 'group_id']); - $table->unsignedBigInteger('user_id'); - $table->unsignedInteger('area_id'); $table->unsignedInteger('group_id'); $table->unsignedBigInteger('inserted_by')->nullable(); @@ -24,7 +21,6 @@ public function up(): void Schema::table('permissions', function (Blueprint $table) { $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('area_id')->references('id')->on('areas')->onDelete('cascade'); $table->foreign('group_id')->references('id')->on('groups')->onDelete('cascade'); $table->foreign('inserted_by')->references('id')->on('users')->onDelete('set null'); }); diff --git a/database/migrations/2023_07_02_091331_create_staffings_table.php b/database/migrations/2023_07_02_091331_create_staffings_table.php index c250aac..2c722bb 100644 --- a/database/migrations/2023_07_02_091331_create_staffings_table.php +++ b/database/migrations/2023_07_02_091331_create_staffings_table.php @@ -24,13 +24,8 @@ public function up(): void $table->text('section_3_title')->nullable(); $table->text('section_4_title')->nullable(); $table->integer('restrict_bookings'); - $table->unsignedInteger('area_id'); $table->timestamps(); }); - - Schema::table('staffings', function (Blueprint $table) { - $table->foreign('area_id')->references('id')->on('areas')->onDelete('cascade'); - }); } /** diff --git a/database/migrations/2024_07_08_215214_create_events_table.php b/database/migrations/2024_07_08_215214_create_events_table.php index cab3f03..fafaa2f 100644 --- a/database/migrations/2024_07_08_215214_create_events_table.php +++ b/database/migrations/2024_07_08_215214_create_events_table.php @@ -25,7 +25,6 @@ public function up(): void $table->tinyInteger('published')->default(0); // might do something with this $table->string('image')->nullable(); $table->unsignedBigInteger('user_id')->nullable(); - $table->unsignedInteger('area_id')->nullable(); $table->unsignedInteger('parent_id')->nullable(); $table->softDeletes(); $table->timestamps(); @@ -34,7 +33,6 @@ public function up(): void Schema::table('events', function (Blueprint $table) { $table->foreign('calendar_id')->references('id')->on('calendars')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); - $table->foreign('area_id')->references('id')->on('areas')->onDelete('cascade'); $table->foreign('parent_id')->references('id')->on('events')->onDelete('cascade'); }); } diff --git a/database/seeders/EventSeeder.php b/database/seeders/EventSeeder.php index 07a6eea..e5319f9 100644 --- a/database/seeders/EventSeeder.php +++ b/database/seeders/EventSeeder.php @@ -2,7 +2,6 @@ namespace Database\Seeders; -use App\Models\Area; use App\Models\Event; use App\Models\User; use Illuminate\Database\Seeder; @@ -19,7 +18,6 @@ public function run(): void Event::factory()->count(5)->create([ 'calendar_id' => rand(1,2), ])->each(function ($event) { - $event->area()->associate(Area::inRandomOrder()->first()->id); $event->user()->associate(User::whereHas('groups')->inRandomOrder()->first()->id); $event->save(); }); @@ -31,7 +29,6 @@ public function run(): void 'recurrence_unit' => 'week', 'recurrence_end_date' => now()->addWeeks(5)->format('Y-m-d H:i:s'), ])->each(function ($event) { - $event->area()->associate(Area::inRandomOrder()->first()->id); $event->user()->associate(User::whereHas('groups')->inRandomOrder()->first()->id); $event->save(); diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index c0e4464..d8de728 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -71,11 +71,8 @@ public function run(): void ]); // Assign groups randomly, or specific group for user 10 - if ($i == 10) { - $user->groups()->attach(Group::find($group), ['area_id' => 1]); - } else if ($i !== 11) { + if ($i !== 11) { $randomGroup = $groups->random(rand(0, $groups->count()))->pluck('id')->toArray(); - $user->groups()->attach($randomGroup, ['area_id' => 1]); } } } diff --git a/resources/views/events/create.blade.php b/resources/views/events/create.blade.php index 8cb515a..bea6c14 100644 --- a/resources/views/events/create.blade.php +++ b/resources/views/events/create.blade.php @@ -36,19 +36,6 @@ @enderror -
- - - @error('area') - {{ $errors->first('area') }} - @enderror -
-
diff --git a/resources/views/events/edit.blade.php b/resources/views/events/edit.blade.php index 496a45c..1452dd9 100644 --- a/resources/views/events/edit.blade.php +++ b/resources/views/events/edit.blade.php @@ -37,19 +37,6 @@ @enderror
-
- - - @error('area') - {{ $errors->first('area') }} - @enderror -
-
diff --git a/resources/views/events/show.blade.php b/resources/views/events/show.blade.php index 724fb4c..655446f 100644 --- a/resources/views/events/show.blade.php +++ b/resources/views/events/show.blade.php @@ -5,7 +5,7 @@

{{ $event->title }}

-

Hosted by {{ $event->area->name }} FIR in {{ $event->calendar->name }}

+

Hosted {{ $event->calendar->name }}

@@ -34,7 +34,6 @@
  • Recurrence: Every {{ $event->recurrence_interval }} {{ Str::plural($event->recurrence_unit, $event->recurrence_interval) }}
  • Recurrence End Date: {{ \Carbon\Carbon::parse($event->recurrence_end_date)->format('F j, Y, H:i') }}z
  • @endif -
  • FIR: {{ $event->area->name }}
  • diff --git a/resources/views/staffing/create.blade.php b/resources/views/staffing/create.blade.php index fb1c546..5e0fe60 100644 --- a/resources/views/staffing/create.blade.php +++ b/resources/views/staffing/create.blade.php @@ -87,17 +87,6 @@ -
    -
    - - -
    -
    diff --git a/resources/views/users/show.blade.php b/resources/views/users/show.blade.php index bc0b8d4..9d2db87 100644 --- a/resources/views/users/show.blade.php +++ b/resources/views/users/show.blade.php @@ -49,7 +49,6 @@ Title Calendar - Area Start Date End Date @@ -67,9 +66,6 @@ {{ $event->calendar->name }} @endcan - - {{ $event->area->name }} - {{ \Carbon\Carbon::parse($event->start_date)->format('d-m-Y H:i') }} @@ -101,25 +97,23 @@ - + @foreach($groups as $group) @endforeach - @foreach($areas as $area) - - - @foreach($groups as $group) - @can('updateGroup', $user) - - @else - - @endcan - @endforeach - - @endforeach + + + @foreach($groups as $group) + @can('update', $user) + + @else + + @endcan + @endforeach +
    AreaAccess{{ $group->name }}
    {{ $area->name }}groups()->where('group_id', $group->id)->where('area_id', $area->id)->count() ? "checked" : "" }}>groups()->where('group_id', $group->id)->where('area_id', $area->id)->count() ? "checked" : "" }} disabled>
    All Calendarsgroups()->where('group_id', $group->id)->count() ? "checked" : "" }}>groups()->where('group_id', $group->id)->count() ? "checked" : "" }} disabled>
    @can('update', $user) diff --git a/tests/Feature/Misc/APITest.php b/tests/Feature/Misc/APITest.php index 7699cc0..377854a 100644 --- a/tests/Feature/Misc/APITest.php +++ b/tests/Feature/Misc/APITest.php @@ -93,7 +93,6 @@ public function test_events_can_be_recieved_from_the_api() 'published', 'image', 'user_id', - 'area_id', 'parent_id', 'deleted_at', 'created_at', @@ -119,7 +118,6 @@ public function test_events_can_be_recieved_from_the_api() 'published' => 0, 'image' => $event->image, 'user_id' => $event->user_id, - 'area_id' => $event->area_id, 'parent_id' => $event->parent_id, 'deleted_at' => $event->deleted_at, 'created_at' => $event->created_at->toISOString(), diff --git a/tests/Feature/Models/CalendarTest.php b/tests/Feature/Models/CalendarTest.php index d4a53a9..450cfa3 100644 --- a/tests/Feature/Models/CalendarTest.php +++ b/tests/Feature/Models/CalendarTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Models; -use App\Models\Area; use App\Models\Calendar; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -201,9 +200,8 @@ public function test_calendar_can_be_deleted(): void protected function getUser() { - $area = Area::find(rand(1,5)); $user = User::factory()->create(); - $user->groups()->attach(1, ['area_id' => $area->id]); + $user->groups()->attach(1); return $user; } diff --git a/tests/Feature/Models/EventTest.php b/tests/Feature/Models/EventTest.php index 86da560..9deedee 100644 --- a/tests/Feature/Models/EventTest.php +++ b/tests/Feature/Models/EventTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Models; -use App\Models\Area; use App\Models\Calendar; use App\Models\Event; use App\Models\User; @@ -121,9 +120,6 @@ public function test_normal_event_can_be_created() : void // Setup user with permissions $user = $this->getUser(); - // Fetching first area as some users might only have one area - $area = Area::find(1); - // Create a test calendar $calendar = Calendar::factory()->create(); @@ -132,7 +128,6 @@ public function test_normal_event_can_be_created() : void // Post request to create a normal event $response = $this->actingAs($user)->post(route('events.store'), [ - 'area' => $area->id, 'calendar_id' => $calendar->id, 'title' => $this->faker->sentence(1), 'short_description' => $this->faker->text(280), @@ -161,8 +156,6 @@ public function test_recurrent_event_can_be_created() : void // Create a test calendar $calendar = Calendar::factory()->create(); - $area = Area::find(rand(1,5)); - // Create test event data $startDate = now()->addDays(1)->format('Y-m-d H:i'); $endDate = now()->addDays(1)->addHours(2)->format('Y-m-d H:i'); @@ -170,7 +163,6 @@ public function test_recurrent_event_can_be_created() : void // Post request to create a normal event $response = $this->actingAs($user)->post(route('events.store'), [ - 'area' => $area->id, 'calendar_id' => $calendar->id, 'title' => 'Test Event', 'short_description' => $this->faker->text(280), @@ -221,14 +213,11 @@ public function test_event_can_be_updated(): void // Create a test calendar $calendar = Calendar::factory()->create(); - $area = Area::find(rand(1,5)); - // Create a test event $event = Event::factory()->create(); // Patch request to update the calendar $response = $this->actingAs($user)->patch(route('events.update', $event), [ - 'area' => $area->id, 'calendar_id' => $calendar->id, 'title' => $this->faker->sentence(1), 'short_description' => $this->faker->text(280), @@ -263,9 +252,8 @@ public function test_event_can_be_deleted(): void protected function getUser() { - $area = Area::find(rand(1,5)); $user = User::factory()->create(); - $user->groups()->attach(1, ['area_id' => $area->id]); + $user->groups()->attach(1); return $user; } diff --git a/tests/Feature/Models/UserTest.php b/tests/Feature/Models/UserTest.php index db5e564..564382c 100644 --- a/tests/Feature/Models/UserTest.php +++ b/tests/Feature/Models/UserTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Models; -use App\Models\Area; use App\Models\Group; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -61,10 +60,9 @@ public function test_users_show_page_can_be_rendered(): void protected function getUser($group = null) { $group == null ? null : $group; - $area = Area::find(rand(1,5)); $user = User::factory()->create(); if ($group) { - $user->groups()->attach($group, ['area_id' => $area->id]); + $user->groups()->attach($group); } return $user;