-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/qr-codes
- Loading branch information
Showing
57 changed files
with
1,489 additions
and
693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.