Skip to content

Commit

Permalink
Merge pull request #544 from HZ-HBO-ICT/bugfix/high-priority-small-is…
Browse files Browse the repository at this point in the history
…suses

Bugfix - High priority issuses
  • Loading branch information
TimKardol authored Sep 27, 2024
2 parents 8d972a2 + 229e624 commit 42f5d38
Show file tree
Hide file tree
Showing 30 changed files with 530 additions and 338 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ docker run --rm \
```
4. Install the NPM packages - `npm install`
5. Set up the environment variables - `cp .env.example .env`
6. Add the app key - `./vendor/bin/sail artisan key:generate`
7. After the dependencies are installed run `./vendor/bin/sail up -d`
6. After the dependencies are installed run `./vendor/bin/sail up -d`
7. Add the app key - `./vendor/bin/sail artisan key:generate`
8. After the creation of the containers run `./vendor/bin/sail artisan migrate`
9. Run `npm run dev`

Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/Crew/BoothController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function create()
*/
public function store(Request $request)
{
// CURRENTLY NOT IN USE
abort(404);

if ($request->user()->cannot('create', Booth::class)) {
abort(403);
}
Expand Down
11 changes: 9 additions & 2 deletions app/Http/Controllers/Crew/CrewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ class CrewController extends Controller
* Returns the main page of the crew page
* @return View
*/
public function index() : View
public function index(): View
{
if (!Gate::authorize('view-crew')) {
abort(403);
}

$roles = Role::whereNotIn(
'name',
['participant', 'company representative', 'company member', 'booth owner']
[
'participant',
'company representative',
'company member',
'booth owner',
'pending booth owner',
'pending speaker'
]
)->get();

return view('crew.crew.index', compact('roles'));
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Crew/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function show(Room $room)
*/
public function destroy(Room $room): RedirectResponse // TODO: Refactor the FK constraints in the db
{
if (Auth::user()->cannot('delete', Room::class)) {
if (Auth::user()->cannot('delete', $room)) {
abort(403);
}

Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Edition;
use App\Models\Company;
use App\Models\Sponsorship;
use Illuminate\Http\Request;
use Illuminate\View\View;

Expand All @@ -16,11 +17,12 @@ class HomeController extends Controller
public function index() : View
{
$edition = Edition::current();
$anySponsorships = Sponsorship::doesntHave('companies')->count() === Sponsorship::count();
$goldSponsorCompany = Company::where('is_approved', 1)
->where('sponsorship_id', 1)
->where('is_sponsorship_approved', 1)
->first();

return view('welcome', compact(['edition', 'goldSponsorCompany']));
return view('welcome', compact(['edition', 'goldSponsorCompany', 'anySponsorships']));
}
}
9 changes: 9 additions & 0 deletions app/Http/Controllers/ProgrammeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Edition;
use App\Models\Presentation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand All @@ -16,6 +17,10 @@ class ProgrammeController extends Controller
*/
public function index(): View
{
if (!optional(Edition::current())->is_programme_released) {
abort(404);
}

$lectures = Presentation::where('type', 'lecture')
->whereNotNull('room_id')
->whereNotNull('timeslot_id')
Expand Down Expand Up @@ -47,6 +52,10 @@ public function index(): View
*/
public function show(Presentation $presentation): View
{
if (!$presentation->is_approved) {
abort(404);
}

$styles = [
1 => [
'borderColor' => 'bg-gradient-to-r from-yellow-300 to-yellow-600', // Gold
Expand Down
31 changes: 18 additions & 13 deletions app/Http/Controllers/SpeakerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@ class SpeakerController extends Controller
*/
public function index()
{
$speakers = collect();
$edition = Edition::current();
$query = UserPresentation::where('role', 'speaker');

if (!$edition) {
return redirect(route('welcome'))
->dangerBanner("Speakers are not available yet.");
}

// If the final program is released, filter by room_id and timeslot_id
if (optional(Edition::current())->is_final_programme_released) {
$speakers = UserPresentation::where('role', 'speaker')
->whereHas('presentation', function ($query) {
$query->whereNotNull('room_id')
->whereNotNull('timeslot_id');
})
->get()
->sortBy(function ($speaker) {
if ($speaker->user->company && $speaker->user->company->is_sponsorship_approved) {
return $speaker->user->company->sponsorship_id;
}
return 999; // Assign a high value to non-sponsored speakers
});
$query->whereHas('presentation', function ($query) {
$query->whereNotNull('room_id')
->whereNotNull('timeslot_id');
});
} else {
// Otherwise, filter by is_approved
$query->whereHas('presentation', function ($query) {
$query->where('is_approved', true);
});
}

$speakers = $query->get()->sortBy(function ($speaker) {
if ($speaker->user->company && $speaker->user->company->is_sponsorship_approved) {
return $speaker->user->company->sponsorship_id;
}
return 999; // Assign a high value to non-sponsored speakers
});

return view('speakers.index', compact('speakers', 'edition'));
}
}
142 changes: 142 additions & 0 deletions app/Livewire/Booth/CreateBooth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace App\Livewire\Booth;

use App\Livewire\Forms\BoothForm;
use App\Models\Booth;
use App\Models\Company;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Attributes\Validate;
use Livewire\Component;

class CreateBooth extends Component
{
#[Validate(['required', 'numeric', 'min:1', 'max:10'])]
public $width;

#[Validate(['required', 'numeric', 'min:1', 'max:10'])]
public $length;

#[Validate(['nullable', 'max:255'])]
public $additionalInformation;

public $company;
public $companies;
public $companyId;

public $searchValue;
public $isDropdownVisible;
public $users;
public $selectedUser;

/**
* Initializes the component
* @return void
*/
public function mount()
{
$this->companies = Company::whereDoesntHave('booth')->where('is_approved', '=', '1')->get();
$this->company = $this->companies->first();
$this->isDropdownVisible = false;
$this->users = optional($this->company)->users;
$this->searchValue = '';
}

/**
* Creates the entity
* @return void
*/
public function save()
{
$this->validate();

$this->validate([
'company' => 'required',
'selectedUser' => 'required'
]);

$boothData = [
'width' => $this->width,
'length' => $this->length,
'additional_information' => $this->additionalInformation,
'company_id' => $this->company->id,
'is_approved' => true
];

Booth::create($boothData);

$this->selectedUser->assignRole('booth owner');

if ($this->selectedUser->hasRole('pending booth owner')) {
$this->selectedUser->removeRole('pending booth owner');
}

$this->redirect(route('moderator.booths.index'));
}

/**
* Triggers the filtering function if the email/name is being changed
*
* @return void
*/
public function updatedSearchValue() : void
{
$this->users = $this->company->users;
if (!empty($this->searchValue)) {
$this->users = $this->users->filter(function ($user) {
$nameMatch = stripos($user->name, $this->searchValue) !== false;
$emailMatch = stripos($user->email, $this->searchValue) !== false;

return $nameMatch || $emailMatch;
});
}
}

/**
* Handles the update of the company id
* @return void
*/
public function updatedCompanyId() : void
{
$this->company = Company::find($this->companyId);
$this->users = $this->company->users;
$this->searchValue = '';
$this->updatedSearchValue();
$this->selectedUser = null;
$this->isDropdownVisible = false;
}

/**
* Triggered when the user chooses the assignee
*
* @param $id
* @return void
*/
public function selectUser($id) : void
{
$this->selectedUser = User::find($id);
$this->searchValue = $this->selectedUser->name;
$this->updatedSearchValue();
$this->isDropdownVisible = false;
}

/**
* Responsible for the visibility status of the dropdown
*
* @return void
*/
public function toggleDropdown() : void
{
$this->isDropdownVisible = !$this->isDropdownVisible;
}

/**
* Renders the component
* @return View
*/
public function render() : View
{
return view('livewire.booth.create-booth');
}
}
2 changes: 1 addition & 1 deletion app/Livewire/Company/AddMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function invite(): void
$this->validate();
if ($this->currentRole == 'speaker') {
$this->currentRole = 'pending speaker';
} else if ($this->currentRole == 'booth owner') {
} elseif ($this->currentRole == 'booth owner') {
$this->currentRole = 'pending booth owner';
}

Expand Down
2 changes: 1 addition & 1 deletion app/Mail/BoothDisapprovedMailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(Company $company)
public function envelope(): Envelope
{
return new Envelope(
subject: 'Booth Disapproved',
subject: 'Booth Refused',
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Mail/PresentationDisapprovedMailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
public function envelope(): Envelope
{
return new Envelope(
subject: 'Presentation Disapproved',
subject: 'Presentation Refused',
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Mail/SponsorshipDisapprovedMailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(Company $company)
public function envelope(): Envelope
{
return new Envelope(
subject: 'Sponsorship Disapproved',
subject: 'Sponsorship Refused',
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logAll()
->setDescriptionForEvent(fn(string $eventName) => "{$this->name} booth has been {$eventName} by " . Auth::user()->name)
->setDescriptionForEvent(fn(string $eventName) => "Presentation {$this->name} has been {$eventName} by " . Auth::user()->name)
->logOnlyDirty()
->dontLogIfAttributesChangedOnly(['is_approved']);
}
Expand Down
9 changes: 7 additions & 2 deletions app/Policies/RoomPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Policies;

use App\Models\Room;
use App\Models\User;

class RoomPolicy
Expand Down Expand Up @@ -56,8 +57,12 @@ public function update(User $user): bool
* @param User $user
* @return bool
*/
public function delete(User $user)
public function delete(User $user, Room $room)
{
return $user->can('delete room');
if (!$user->can('delete room')) {
return false;
}

return $room->presentations->count() == 0 && $room->defaultPresentations->count() == 0;
}
}
2 changes: 1 addition & 1 deletion database/factories/CompanyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function definition(): array
{
return [
'name' => $this->faker->unique()->company(),
'website' => 'www.example.com',
'website' => 'https://www.example.com',
'description' => $this->faker->paragraph(),
'motivation' => $this->faker->paragraph(),
'phone_number' => $this->faker->phoneNumber,
Expand Down
Loading

0 comments on commit 42f5d38

Please sign in to comment.