-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* created school model. This fixes #31. * fixed school factory
- Loading branch information
1 parent
d1394ab
commit fa0f054
Showing
33 changed files
with
1,650 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace App\Events\Api\Account; | ||
|
||
use App\Http\Models\API\Account; | ||
use App\Http\Models\API\School; | ||
use Illuminate\Support\Facades\Log; | ||
use App\Events\Event; | ||
use Illuminate\Support\Facades\Redis; | ||
use Krucas\Settings\Facades\Settings; | ||
|
||
|
||
class AssignedSchool extends Event | ||
{ | ||
/** | ||
* AssignedSchool constructor. | ||
* @param Account $account | ||
* @param School $school | ||
*/ | ||
public function __construct(Account $account, School $school) | ||
{ | ||
$info = [ | ||
'account_id' => $account->id, | ||
'identifier' => $account->identifier, | ||
'username' => $account->username, | ||
'name' => $account->format_full_name(true), | ||
'school_id' => $school->id, | ||
'school_code' => $school->code, | ||
'school_label' => $school->label | ||
]; | ||
|
||
Log::info('Account assigned School:', $info); | ||
|
||
if ($user = auth()->user()) { | ||
|
||
if (Settings::get('broadcast-events', false)) { | ||
|
||
$account->primary_duty = $account->primaryDuty; | ||
$trans = $account->toArray(); | ||
$trans['name_full'] = $account->format_full_name(true); | ||
unset($trans['password']); | ||
$trans['username'] = strtolower($trans['username']); | ||
|
||
$data_to_secure = json_encode([ | ||
'data' => [ | ||
'account' => $account, | ||
'school' => $school->toArray() | ||
], | ||
'conf' => [ | ||
'ldap' => ldap_config() | ||
] | ||
]); | ||
|
||
$secure_data = encrypt_broadcast_data($data_to_secure); | ||
|
||
$message = [ | ||
'event' => 'assigned', | ||
'type' => 'school', | ||
'to' => 'account', | ||
'encrypted' => $secure_data | ||
]; | ||
|
||
Redis::publish('events', json_encode($message)); | ||
} | ||
|
||
history()->log( | ||
'Assignment', | ||
'enrolled ' . $account->format_full_name() . ' in school: "' . $school->label . '"', | ||
$account->id, | ||
'university', | ||
'bg-olive' | ||
); | ||
} | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace App\Events\Api\Account; | ||
|
||
use App\Http\Models\API\Account; | ||
use App\Http\Models\API\School; | ||
use Illuminate\Support\Facades\Log; | ||
use App\Events\Event; | ||
use Illuminate\Support\Facades\Redis; | ||
use Krucas\Settings\Facades\Settings; | ||
|
||
|
||
class UnassignedSchool extends Event | ||
{ | ||
/** | ||
* UnassignedCourse constructor. | ||
* @param Account $account | ||
* @param School $school | ||
*/ | ||
public function __construct(Account $account, School $school) | ||
{ | ||
$info = [ | ||
'account_id' => $account->id, | ||
'identifier' => $account->identifier, | ||
'username' => $account->username, | ||
'name' => $account->format_full_name(true), | ||
'school_id' => $school->id, | ||
'school_code' => $school->code, | ||
'school_label' => $school->label | ||
]; | ||
|
||
Log::info('Account removed from School:', $info); | ||
|
||
if ($user = auth()->user()) { | ||
|
||
if (Settings::get('broadcast-events', false)) { | ||
|
||
$account->primary_duty = $account->primaryDuty; | ||
$trans = $account->toArray(); | ||
$trans['name_full'] = $account->format_full_name(true); | ||
unset($trans['password']); | ||
$trans['username'] = strtolower($trans['username']); | ||
|
||
$data_to_secure = json_encode([ | ||
'data' => [ | ||
'account' => $account, | ||
'school' => $school->toArray() | ||
], | ||
'conf' => [ | ||
'ldap' => ldap_config() | ||
] | ||
]); | ||
|
||
$secure_data = encrypt_broadcast_data($data_to_secure); | ||
|
||
$message = [ | ||
'event' => 'unassigned', | ||
'type' => 'school', | ||
'to' => 'account', | ||
'encrypted' => $secure_data | ||
]; | ||
|
||
Redis::publish('events', json_encode($message)); | ||
} | ||
|
||
history()->log( | ||
'Assignment', | ||
'removed ' . $account->format_full_name() . ' from school: "' . $school->label . '"', | ||
$account->id, | ||
'university', | ||
'bg-yellow' | ||
); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Events\Api\School; | ||
|
||
use App\Http\Models\API\School; | ||
use Illuminate\Support\Facades\Log; | ||
use App\Events\Event; | ||
use Illuminate\Support\Facades\Redis; | ||
use Krucas\Settings\Facades\Settings; | ||
|
||
class SchoolCreated extends Event | ||
{ | ||
/** | ||
* SchoolCreated constructor. | ||
* @param School $school | ||
*/ | ||
public function __construct(School $school) | ||
{ | ||
Log::info('School Created:', [ | ||
'id' => $school->id, | ||
'code' => $school->code, | ||
'label' => $school->label | ||
]); | ||
|
||
if ($user = auth()->user()) { | ||
|
||
if (Settings::get('broadcast-events', false)) { | ||
|
||
$data_to_secure = json_encode([ | ||
'data' => $school->toArray(), | ||
'conf' => [ | ||
'ldap' => ldap_config() | ||
] | ||
]); | ||
|
||
$secure_data = encrypt_broadcast_data($data_to_secure); | ||
|
||
$message = [ | ||
'event' => 'created', | ||
'type' => 'school', | ||
'encrypted' => $secure_data | ||
]; | ||
|
||
Redis::publish('events', json_encode($message)); | ||
} | ||
|
||
history()->log( | ||
'School', | ||
'created a new school: ' . $school->label, | ||
$school->id, | ||
'university', | ||
'bg-green' | ||
); | ||
} | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace App\Events\Api\School; | ||
|
||
use App\Http\Models\API\School; | ||
use Krucas\Settings\Facades\Settings; | ||
use Illuminate\Support\Facades\Log; | ||
use App\Events\Event; | ||
use Illuminate\Support\Facades\Redis; | ||
|
||
class SchoolDestroyed extends Event | ||
{ | ||
/** | ||
* SchoolDestroyed constructor. | ||
* @param School $school | ||
*/ | ||
public function __construct(School $school) | ||
{ | ||
Log::info('School Destroyed:', [ | ||
'id' => $school->id, | ||
'code' => $school->code, | ||
'label' => $school->label | ||
]); | ||
|
||
if ($user = auth()->user()) { | ||
|
||
if (Settings::get('broadcast-events', false)) { | ||
|
||
$data_to_secure = json_encode([ | ||
'data' => $school->toArray(), | ||
'conf' => [ | ||
'ldap' => ldap_config() | ||
] | ||
]); | ||
|
||
$secure_data = encrypt_broadcast_data($data_to_secure); | ||
|
||
$message = [ | ||
'event' => 'deleted', | ||
'type' => 'school', | ||
'encrypted' => $secure_data | ||
]; | ||
|
||
Redis::publish('events', json_encode($message)); | ||
} | ||
|
||
history()->log( | ||
'School', | ||
'destroyed a school: ' . $school->label, | ||
$school->id, | ||
'university', | ||
'bg-red' | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.