Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from herpaderpaldent/warlof-fix-closure-issue
Browse files Browse the repository at this point in the history
#Version 1.0.1 - Warlof fix closure issue
  • Loading branch information
herpaderpaldent authored Oct 30, 2018
2 parents 6beb575 + 34cce7a commit 5509f52
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 189 deletions.
22 changes: 22 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
preset: laravel

risky: false

enabled:
- alpha_ordered_imports
- concat_with_spaces
- no_empty_comment

disabled:
- braces
- phpdoc_no_package
- concat_without_spaces
- length_ordered_imports
- no_blank_lines_after_class_opening
- no_blank_lines_after_throw

finder:
exclude:
- "tests"
name:
- "*.php"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 1.0.1
This version is a fix for logout job. It was bad designed as it resulted in a closure exception. This fix was provided by @warlof. Thank you very much.
* Added Style CI to repo.

# 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.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php": ">=7.1",
"cviebrock/discourse-php": "^0.9.3",
"laravel/framework": "5.5.*",
"eveseat/web": "3.0.*"
"eveseat/web": "3.0.*",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 6 additions & 12 deletions src/Action/Discourse/Groups/Attach.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Created by PhpStorm.
* User: fehu
* Date: 05.06.18
* Time: 18:01
* Time: 18:01.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Groups;


use Illuminate\Support\Collection;

class Attach
Expand All @@ -25,24 +24,19 @@ public function execute(Collection $roles, Collection $groups)
try{
$feedback = collect();

$groupnames_array = $groups->map(function ($group) {return $group->name; })->toArray();

$groupnames_array = $groups->map( function ($group){return $group->name;})->toArray();

$roles->each(function($role) use ($feedback, $groupnames_array){
if(!in_array(studly_case($role->title),$groupnames_array)){
$feedback->push( $this->create->execute(studly_case($role->title)));
$roles->each(function ($role) use ($feedback, $groupnames_array) {
if(! in_array(studly_case($role->title), $groupnames_array)){
$feedback->push($this->create->execute(studly_case($role->title)));
}
});


return $feedback;



} catch (Exception $e){
return $e;
}

}

}
}
17 changes: 7 additions & 10 deletions src/Action/Discourse/Groups/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,39 @@
* Created by PhpStorm.
* User: fehu
* Date: 05.06.18
* Time: 16:01
* Time: 16:01.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Groups;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

class Create
{
public function execute(String $groupname)
{
$client = new Client();
try {
$response = $client->request('POST', getenv('DISCOURSE_URL').'/admin/groups', [
$response = $client->request('POST', getenv('DISCOURSE_URL') . '/admin/groups', [
'form_params' => [
'api_key' => getenv('DISCOURSE_API_KEY'),
'api_username' => getenv('DISCOURSE_API_USERNAME'),
'group[name]' => $groupname
'group[name]' => $groupname,
],
]);

if (200 === $response->getStatusCode()) {

return 'Created Group: '. $groupname;
return 'Created Group: ' . $groupname;

}

abort(500,"Something went wrong at /admin/groups");
abort(500, 'Something went wrong at /admin/groups');
} catch (GuzzleException $e) {
return $e;

}



}

}
}
14 changes: 6 additions & 8 deletions src/Action/Discourse/Groups/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* Created by PhpStorm.
* User: fehu
* Date: 05.06.18
* Time: 18:44
* Time: 18:44.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Groups;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

use GuzzleHttp\Exception\GuzzleException;

class Delete
{
Expand All @@ -22,22 +21,21 @@ public function execute(int $group_id)
$response = $client->request('DELETE', getenv('DISCOURSE_URL') . '/admin/groups/' . $group_id . '.json', [
'form_params' => [
'api_key' => getenv('DISCOURSE_API_KEY'),
'api_username' => getenv('DISCOURSE_API_USERNAME')
'api_username' => getenv('DISCOURSE_API_USERNAME'),
],
]);

if (200 === $response->getStatusCode()) {

return "success";
return 'success';

}

abort(500, "Something went wrong at deleting group");
abort(500, 'Something went wrong at deleting group');
} catch (GuzzleException $e) {
return $e;

}


}
}
}
18 changes: 6 additions & 12 deletions src/Action/Discourse/Groups/Detach.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
* Created by PhpStorm.
* User: fehu
* Date: 05.06.18
* Time: 18:56
* Time: 18:56.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Groups;


use Illuminate\Support\Collection;


class Detach
{
protected $delete;
Expand All @@ -24,26 +22,22 @@ public function __construct(Delete $delete)
public function execute(Collection $roles, Collection $groups)
{
try{
$rolenames_array = $roles->map(function($role) {return studly_case($role->title);})->toArray();
$rolenames_array = $roles->map(function ($role) {return studly_case($role->title); })->toArray();

//Group minus Roles, what is left should be deleted
$groups_deleted = collect();
$groups->each(function ($group) use ($rolenames_array,$groups_deleted) {
if(!in_array($group->name, $rolenames_array) ){
if(! in_array($group->name, $rolenames_array)){
$groups_deleted->push($group->name);
$this->delete->execute($group->id);
};
}
});



return "Groups deleted " . $groups_deleted;

return 'Groups deleted ' . $groups_deleted;

} catch (Exception $e){
return $e;
}

}

}
}
13 changes: 6 additions & 7 deletions src/Action/Discourse/Groups/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
* Created by PhpStorm.
* User: fehu
* Date: 05.06.18
* Time: 13:13
* Time: 13:13.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Groups;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

class Get
{
public function execute()
{
$client = new Client();
try {
$response = $client->request('GET', getenv('DISCOURSE_URL').'/groups/search.json', [
$response = $client->request('GET', getenv('DISCOURSE_URL') . '/groups/search.json', [
'query' => [
'api_key' => getenv('DISCOURSE_API_KEY'),
'api_username' => getenv('DISCOURSE_API_USERNAME')
'api_username' => getenv('DISCOURSE_API_USERNAME'),
],
]);
$body = collect(json_decode($response->getBody()))->reject(function ($item){
$body = collect(json_decode($response->getBody()))->reject(function ($item) {
return $item->automatic;
});

Expand All @@ -33,5 +33,4 @@ public function execute()
}

}

}
}
15 changes: 6 additions & 9 deletions src/Action/Discourse/Groups/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Created by PhpStorm.
* * User: Herpaderp Aldent
* Date: 09.06.2018
* Time: 10:48
* Time: 10:48.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Groups;


use Seat\Web\Models\Acl\Role;

class Sync
Expand All @@ -31,17 +30,15 @@ public function execute()

$feedback = collect();


if($roles->map(function($role) {return $role->title;})->diff($groups->map( function ($group){return $group->name;}))->isNotEmpty())
if($roles->map(function ($role) {return $role->title; })->diff($groups->map(function ($group) {return $group->name; }))->isNotEmpty())
{
$feedback->push($this->attach->execute($roles,$groups));
$feedback->push($this->attach->execute($roles, $groups));
}

if($groups->map(function($group) {return $group->name;})->diff($roles->map( function ($role){return studly_case($role->title);}))->isNotEmpty()){
$feedback->push($this->detach->execute($roles,$groups));
if($groups->map(function ($group) {return $group->name; })->diff($roles->map(function ($role) {return studly_case($role->title); }))->isNotEmpty()){
$feedback->push($this->detach->execute($roles, $groups));
}

return $feedback;
}

}
}
9 changes: 4 additions & 5 deletions src/Action/Discourse/Users/GetUserByCharacterId.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
* Created by PhpStorm.
* User: felix
* Date: 21.09.2018
* Time: 21:51
* Time: 21:51.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Users;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

class GetUserByCharacterId
{
public function execute(int $id)
{
$client = new Client();
try {
$response = $client->request('GET', getenv('DISCOURSE_URL').'/users/by-external/'. $id .'.json', [
$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')
'api_username' => getenv('DISCOURSE_API_USERNAME'),
],
]);

Expand All @@ -29,5 +29,4 @@ public function execute(int $id)
return $e;
}
}

}
11 changes: 5 additions & 6 deletions src/Action/Discourse/Users/ListUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* Created by PhpStorm.
* User: fehu
* Date: 07.06.18
* Time: 09:04
* Time: 09:04.
*/

namespace Herpaderpaldent\Seat\SeatDiscourse\Action\Discourse\Users;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

use GuzzleHttp\Exception\GuzzleException;

class ListUsers
{
Expand All @@ -21,12 +20,12 @@ public function execute()
{
$client = new Client();
try {
$response = $client->request('GET', getenv('DISCOURSE_URL').'/admin/users/list/active.json', [
$response = $client->request('GET', getenv('DISCOURSE_URL') . '/admin/users/list/active.json', [
'query' => [
'api_key' => getenv('DISCOURSE_API_KEY'),
'api_username' => getenv('DISCOURSE_API_USERNAME'),
'order' => 'topics_entered',
'show_emails' => 'true'
'show_emails' => 'true',
],
]);

Expand All @@ -36,4 +35,4 @@ public function execute()
}

}
}
}
Loading

0 comments on commit 5509f52

Please sign in to comment.