Skip to content

Commit

Permalink
Merge branch 'development' into feature/qr-codes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimKardol authored Oct 23, 2024
2 parents 67e0f71 + 9d84971 commit 35334fe
Show file tree
Hide file tree
Showing 57 changed files with 1,489 additions and 693 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
54 changes: 54 additions & 0 deletions app/Actions/Users/AddParticipantToCompanyHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Actions\Users;

use App\Models\Company;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Mockery\Exception;
use Spatie\Permission\Models\Role;

class AddParticipantToCompanyHandler
{
/**
* Handles the adding of a user who registered as a participant to
* their company. The default role is company member, which is going to be assigned unless
* the user has a presentation or another role is passed
*
* @param User $user
* @param Company $company
* @param string $role
* @return void
*/
public function execute(User $user, Company $company, string $role = 'company member'): void
{
// Making sure, if something fails, everything will roll back
DB::transaction(function () use ($user, $company, $role) {
if ($user->company) {
throw new Exception('The user is already a member of a company. Are you sure this is the right user?');
}

$user->update([
'company_id' => $company->id
]);

if ($user->presenter_of) {
if (!$company->has_presentations_left) {
throw new Exception('The company has reached their presentation limit. Contact them to resolve this.');
}

$presentation = $user->presenter_of;
$presentation->update([
'company_id' => $company->id
]);
} else {
if (!Role::findByName($role, 'web')) {
throw new Exception('The role cannot be found');
}

$role = Role::findByName($role, 'web');
$user->assignRole($role);
}
});
}
}
46 changes: 46 additions & 0 deletions app/Console/Commands/AddParticipantToCompany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Console\Commands;

use App\Actions\Users\AddParticipantToCompanyHandler;
use App\Models\Company;
use App\Models\User;
use Illuminate\Console\Command;

class AddParticipantToCompany extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:add-participant-to-company {email} {company_id} {role=company member}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Adds a participant as a part of a company in case the user registered as stand alone
even though they are attending with a company.';

/**
* Execute the console command.
*/
public function handle()
{
activity()->withoutLogs(function () {
try {
$user = User::where('email', $this->argument('email'))->firstOrFail();
$company = Company::findOrFail($this->argument('company_id'));

(new AddParticipantToCompanyHandler())->execute($user, $company, $this->argument('role'));

$user->refresh();
$this->info("You successfully added {$user->email} as part of the {$user->company->name}");
} catch (\Exception $e) {
$this->error($e);
}
});
}
}
11 changes: 5 additions & 6 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 Expand Up @@ -77,17 +80,13 @@ public function show(Booth $booth)
/**
* Approve or reject the specified resource in storage.
*/
public function approve(Request $request, Booth $booth)
public function approve(Booth $booth, bool $isApproved)
{
if (Auth::user()->cannot('approveRequest', $booth)) {
abort(403);
}

$validated = $request->validate([
'approved' => 'required|boolean'
]);

$isApproved = $validated['approved'];
$isApproved = filter_var($isApproved, FILTER_VALIDATE_BOOLEAN);
$booth->handleApproval($isApproved);

$template = $isApproved ? 'You approved the booth of :company!'
Expand Down
9 changes: 3 additions & 6 deletions app/Http/Controllers/Crew/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,14 @@ public function show(Company $company): View
/**
* Approve or reject the specified resource in storage.
*/
public function approve(Request $request, Company $company)
public function approve(Company $company, bool $isApproved)
{
if (Auth::user()->cannot('approveRequest', $company)) {
abort(403);
}

$validated = $request->validate([
'approved' => 'required|boolean'
]);

$isApproved = $validated['approved'];
$isApproved = filter_var($isApproved, FILTER_VALIDATE_BOOLEAN);
if (!$isApproved) {
if ($company->representative->receive_emails) {
Mail::to($company->representative->email)->send(new CompanyDisapprovedMailable($company));
Expand Down Expand Up @@ -203,7 +200,7 @@ private function createCompanyWithNewUser($input)
'email' => $input['rep_new_email'],
'role' => 'company representative',
]);

Mail::to($input['rep_new_email'])->send(new CompanyRepInvitation($invitation));

return $company;
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
8 changes: 2 additions & 6 deletions app/Http/Controllers/Crew/PresentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,13 @@ public function show(Presentation $presentation): View
/**
* Approve or reject the specified resource in storage.
*/
public function approve(Request $request, Presentation $presentation)
public function approve(Presentation $presentation, bool $isApproved)
{
if (Auth::user()->cannot('approve', $presentation)) {
abort(403);
}

$validated = $request->validate([
'approved' => 'required|boolean'
]);

$isApproved = $validated['approved'];
$isApproved = filter_var($isApproved, FILTER_VALIDATE_BOOLEAN);
if (!$isApproved) {
foreach ($presentation->speakers as $speaker) {
if ($speaker->receive_emails) {
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
8 changes: 2 additions & 6 deletions app/Http/Controllers/Crew/SponsorshipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ public function show(Company $company): View
* @param Company $company
* @return mixed
*/
public function approve(Request $request, Company $company)
public function approve(Company $company, bool $isApproved)
{
if (Auth::user()->cannot('approve', Sponsorship::class)) {
abort(403);
}

$validated = $request->validate([
'approved' => 'required|boolean'
]);

$isApproved = $validated['approved'];
$isApproved = filter_var($isApproved, FILTER_VALIDATE_BOOLEAN);
$company->handleSponsorshipApproval($isApproved);

$template = $isApproved ? 'You approved the sponsorship of :company!'
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'));
}
}
Loading

0 comments on commit 35334fe

Please sign in to comment.