This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the first release with all its functionality. Since version 0.9.2 `SeAT-Discourse` was very stable and did not need a lot of refactoring or bug-fixing. However, i still had some ToDo's noted. The next few update still have some functional refactoring however functionally it does not change. Also some documentation will be added, whenever i find time and motivation to do so. These are the things changed with this version: * Logging out Job introduced ** This Job will be dispatched if a `refresh_token` in an `user group` is deleted. * Refactoring of unneeded actions * Introduction of the about-page to inform you if a new version is available. * Introduction of changelog. * Disallow login if `user group` is missing a `refresh_token`. I was looking into automatically logging out members whenever they receive a new role. Unfortunately this is not achieved easily without events dispatched whenever someone receives a role. This would need change in `SeAT` (vanilla), which i am not able to push by myself. This might be added to a later moment.
- Loading branch information
1 parent
db54ac8
commit 6beb575
Showing
14 changed files
with
417 additions
and
66 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,14 @@ | ||
# Version 1.0.0 | ||
This is the first release with all its functionality. Since version 0.9.2 `SeAT-Discourse` was very stable and did not need a lot of refactoring or bug-fixing. However, i still had some ToDo's noted. The next few update still have some functional refactoring however functionally it does not change. Also some documentation will be added, whenever i find time and motivation to do so. | ||
|
||
These are the things changed with this version: | ||
|
||
* Logging out Job introduced | ||
** This Job will be dispatched if a `refresh_token` in an `user group` is deleted. | ||
* Refactoring of unneeded actions | ||
* Introduction of the about-page to inform you if a new version is available. | ||
* Introduction of changelog. | ||
* Disallow login if `user group` is missing a `refresh_token`. | ||
|
||
I was looking into automatically logging out members whenever they receive a new role. Unfortunately this is not achieved easily without events dispatched whenever someone receives a role. This would need change in `SeAT` (vanilla), which i am not able to push by myself. This might be added to a later moment. | ||
|
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: felix | ||
* Date: 21.09.2018 | ||
* Time: 21:51 | ||
*/ | ||
|
||
namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Users; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use GuzzleHttp\Client; | ||
|
||
class GetUserByCharacterId | ||
{ | ||
public function execute(int $id) | ||
{ | ||
$client = new Client(); | ||
try { | ||
$response = $client->request('GET', getenv('DISCOURSE_URL').'/users/by-external/'. $id .'.json', [ | ||
'query' => [ | ||
'api_key' => getenv('DISCOURSE_API_KEY'), | ||
'api_username' => getenv('DISCOURSE_API_USERNAME') | ||
], | ||
]); | ||
|
||
return collect(json_decode($response->getBody())); | ||
} catch (GuzzleException $e) { | ||
return $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: felix | ||
* Date: 22.09.2018 | ||
* Time: 10:51 | ||
*/ | ||
|
||
namespace Herpaderpaldent\Seat\SeatDiscourse\Action\SeatDiscourse; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\RequestException; | ||
use Parsedown; | ||
|
||
class GetChangelog | ||
{ | ||
public function execute() | ||
{ | ||
try { | ||
$response = (new Client()) | ||
->request('GET', "https://raw.githubusercontent.com/herpaderpaldent/seat-discourse/master/CHANGELOG.md"); | ||
if ($response->getStatusCode() != 200) { | ||
return 'Error while fetching changelog'; | ||
} | ||
$parser = new Parsedown(); | ||
return $parser->parse($response->getBody()); | ||
} catch (RequestException $e) { | ||
return 'Error while fetching changelog'; | ||
} | ||
} | ||
|
||
} |
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,23 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: felix | ||
* Date: 22.09.2018 | ||
* Time: 10:47 | ||
*/ | ||
|
||
namespace Herpaderpaldent\Seat\SeatDiscourse\Http\Controllers; | ||
|
||
|
||
use Herpaderpaldent\Seat\SeatDiscourse\Action\SeatDiscourse\GetChangelog; | ||
use Seat\Web\Http\Controllers\Controller; | ||
|
||
class SeatDiscourseController extends Controller | ||
{ | ||
public function getAbout(GetChangelog $action) | ||
{ | ||
$changelog = $action->execute(); | ||
return view('seatdiscourse::about', compact('changelog')); | ||
} | ||
|
||
} |
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,113 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: felix | ||
* Date: 21.09.2018 | ||
* Time: 23:22 | ||
*/ | ||
|
||
namespace Herpaderpaldent\Seat\SeatDiscourse\Jobs; | ||
|
||
|
||
use Seat\Web\Models\Group; | ||
use Illuminate\Support\Facades\Redis; | ||
use GuzzleHttp\Client; | ||
|
||
class Logout extends SeatDiscourseJobBase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $tags = ['logout']; | ||
|
||
private $group; | ||
|
||
private $client; | ||
|
||
private $discourse_user_id; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
public $tries = 1; | ||
|
||
/** | ||
* ConversationOrchestrator constructor. | ||
* | ||
* @param \Seat\Web\Models\Group $group | ||
*/ | ||
public function __construct(Group $group) | ||
{ | ||
|
||
logger()->debug('Initialising SeAT discourse logout job for ' . $group->main_character->name); | ||
|
||
$this->group = $group; | ||
|
||
array_push($this->tags, 'main_character_id:' . $group->main_character_id); | ||
|
||
$this->client = new Client(); | ||
|
||
} | ||
|
||
public function handle() | ||
{ | ||
Redis::funnel('seat-discourse:jobs.group_logout_' . $this->group->main_character_id)->limit(1)->then(function () | ||
{ | ||
$this->beforeStart(); | ||
|
||
try { | ||
$response = $this->client->request('POST', getenv('DISCOURSE_URL').'/admin/users/' . $this->discourse_user_id . '/log_out', [ | ||
'form_params' => [ | ||
'api_key' => getenv('DISCOURSE_API_KEY'), | ||
'api_username' => getenv('DISCOURSE_API_USERNAME') | ||
], | ||
]); | ||
|
||
logger()->debug(json_decode($response->getBody())); | ||
|
||
$this->onFinish(); | ||
|
||
|
||
} catch (\Throwable $exception) { | ||
|
||
$this->onFail($exception); | ||
|
||
} | ||
|
||
}, function () | ||
{ | ||
logger()->warning('A logout job is already running for ' . $this->group->main_character->name . ' Removing the job from the queue.'); | ||
|
||
$this->delete(); | ||
}); | ||
|
||
|
||
} | ||
|
||
public function beforeStart() | ||
{ | ||
$response = $this->client->request('GET', getenv('DISCOURSE_URL').'/users/by-external/'. $this->group->main_character_id .'.json', [ | ||
'query' => [ | ||
'api_key' => getenv('DISCOURSE_API_KEY'), | ||
'api_username' => getenv('DISCOURSE_API_USERNAME') | ||
], | ||
]); | ||
|
||
$user = collect(json_decode($response->getBody())); | ||
|
||
$this->discourse_user_id = $user['user']->id; | ||
|
||
} | ||
|
||
public function onFail($exception) | ||
{ | ||
|
||
report($exception); | ||
} | ||
|
||
public function onFinish() | ||
{ | ||
|
||
} | ||
|
||
} |
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,60 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: felix | ||
* Date: 21.09.2018 | ||
* Time: 23:16 | ||
*/ | ||
|
||
namespace Herpaderpaldent\Seat\SeatDiscourse\Jobs; | ||
|
||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
abstract class SeatDiscourseJobBase implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $tags = []; | ||
|
||
/** | ||
* The number of times the job may be attempted. | ||
* | ||
* @var int | ||
*/ | ||
public $tries = 1; | ||
|
||
/** | ||
* Assign this job a tag so that Horizon can categorize and allow | ||
* for specific tags to be monitored. | ||
* | ||
* If a job specifies the tags property, that is added. | ||
* | ||
* @return array | ||
*/ | ||
public function tags(): array | ||
{ | ||
|
||
$tags = ['seatdiscourse']; | ||
|
||
if (property_exists($this, 'tags')) | ||
return array_merge($this->tags, $tags); | ||
|
||
return $tags; | ||
} | ||
|
||
/** | ||
* Execute the job | ||
* | ||
* @return void | ||
*/ | ||
public abstract function handle(); | ||
|
||
} |
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,24 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: felix | ||
* Date: 22.09.2018 | ||
* Time: 10:33 | ||
*/ | ||
|
||
namespace Herpaderpaldent\Seat\SeatDiscourse\Observers; | ||
|
||
use Herpaderpaldent\Seat\SeatDiscourse\Jobs\Logout; | ||
use Seat\Eveapi\Models\RefreshToken; | ||
|
||
class RefreshTokenObserver | ||
{ | ||
public function deleting(RefreshToken $refresh_token) | ||
{ | ||
logger()->debug('SoftDelete detected of '. $refresh_token->user->name); | ||
|
||
dispatch(new Logout($refresh_token->user->group)); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.