-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
722 additions
and
67 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
app/Console/Commands/OneTimers/createWhitelistedDomains.php
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,65 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\OneTimers; | ||
|
||
use App\WhitelistedDomain; | ||
use Exception; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class createWhitelistedDomains extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'create:whitelistedDomains'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(WhitelistedDomain $whitelistedDomain) | ||
{ | ||
try { | ||
DB::beginTransaction(); | ||
$courses = DB::table('courses') | ||
->join('users', 'courses.user_id', '=', 'users.id') | ||
->where('users.role', 2) | ||
->select('courses.id', 'email') | ||
->get(); | ||
foreach ($courses as $course) { | ||
$whitelistedDomain = new WhitelistedDomain(); | ||
$whitelistedDomain->course_id = $course->id; | ||
$whitelisted_domain = $whitelistedDomain->getWhitelistedDomainFromEmail($course->email); | ||
$whitelistedDomain->whitelisted_domain = $whitelisted_domain; | ||
$whitelistedDomain->save(); | ||
echo $whitelisted_domain . "\r\n"; | ||
} | ||
DB::commit(); | ||
} catch (Exception $e) { | ||
echo $e->getMessage(); | ||
DB::rollback(); | ||
} | ||
return 0; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Course; | ||
use App\Exceptions\Handler; | ||
use App\WhitelistedDomain; | ||
use Exception; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class WhitelistedDomainController extends Controller | ||
{ | ||
/** | ||
* @param Request $request | ||
* @param Course $course | ||
* @param WhitelistedDomain $whitelistedDomain | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function store(Request $request, | ||
Course $course, | ||
WhitelistedDomain $whitelistedDomain): array | ||
{ | ||
try { | ||
$whitelisted_domain = trim($request->whitelisted_domain); | ||
$authorized = Gate::inspect('store', [$whitelistedDomain, $course]); | ||
if (!$authorized->allowed()) { | ||
$response['message'] = $authorized->message(); | ||
return $response; | ||
} | ||
$whitelisted_domain_exists = $whitelistedDomain->where('course_id', $course->id) | ||
->where('whitelisted_domain', $whitelisted_domain) | ||
->first(); | ||
if ($whitelisted_domain_exists) { | ||
$response['type'] = 'error'; | ||
$response['message'] = "$whitelisted_domain already exists for this course."; | ||
return $response; | ||
} | ||
$whitelistedDomain->whitelisted_domain = $whitelisted_domain; | ||
$whitelistedDomain->course_id = $course->id; | ||
$whitelistedDomain->save(); | ||
$response['id'] = $whitelistedDomain->id; | ||
$response['type'] = 'success'; | ||
$response['message'] = "The whitelisted domain has been added to the course."; | ||
|
||
} catch (Exception $e) { | ||
$h = new Handler(app()); | ||
$h->report($e); | ||
$response['message'] = "There was an error storing the whitelisted domain for this course. Please try again or contact us for assistance"; | ||
} | ||
return $response; | ||
|
||
} | ||
|
||
/** | ||
* @param Course $course | ||
* @param WhitelistedDomain $whitelistedDomain | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function getByCourse(Course $course, WhitelistedDomain $whitelistedDomain): array | ||
{ | ||
try { | ||
$response['type'] = 'error'; | ||
$authorized = Gate::inspect('getByCourse', [$whitelistedDomain, $course]); | ||
if (!$authorized->allowed()) { | ||
$response['message'] = $authorized->message(); | ||
return $response; | ||
} | ||
$response['whitelisted_domains'] = $whitelistedDomain->where('course_id', $course->id)->get(); | ||
$response['type'] = 'success'; | ||
return $response; | ||
|
||
} catch (Exception $e) { | ||
$h = new Handler(app()); | ||
$h->report($e); | ||
$response['message'] = "There was an error getting the whitelisted domain for this course. Please try again or contact us for assistance"; | ||
} | ||
return $response; | ||
} | ||
|
||
/** | ||
* @param WhitelistedDomain $whitelistedDomain | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function destroy(WhitelistedDomain $whitelistedDomain): array | ||
{ | ||
try { | ||
$response['type'] = 'error'; | ||
$authorized = Gate::inspect('destroy', $whitelistedDomain); | ||
if (!$authorized->allowed()) { | ||
$response['message'] = $authorized->message(); | ||
return $response; | ||
} | ||
if (DB::table('whitelisted_domains')->where('course_id',$whitelistedDomain->course_id)->count() === 1){ | ||
$response['message'] = "You need at least one whitelisted domain."; | ||
return $response; | ||
} | ||
$whitelisted_domain = $whitelistedDomain->whitelisted_domain; | ||
$whitelistedDomain->delete(); | ||
$response['type'] = 'info'; | ||
$response['message'] = "$whitelisted_domain has been removed."; | ||
} catch (Exception $e) { | ||
$h = new Handler(app()); | ||
$h->report($e); | ||
$response['message'] = "There was an error deleting the whitelisted domain for this course. Please try again or contact us for assistance"; | ||
} | ||
return $response; | ||
|
||
|
||
|
||
} | ||
} |
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.