Skip to content

Commit d7b7566

Browse files
committed
Merge branch 'release/2.5.0'
2 parents 46d8ce8 + d283330 commit d7b7566

File tree

7 files changed

+124
-25
lines changed

7 files changed

+124
-25
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ matrix:
1313
- php: 7.3
1414
- php: 7.3
1515
env: SETUP=lowest
16+
- php: 7.4
17+
- php: 7.4
18+
env: SETUP=lowest
1619

1720
sudo: false
1821

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.0
1+
2.5.0

composer.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@
1414
{
1515
"name": "Jimmy Puckett",
1616
"email": "[email protected]"
17+
},
18+
{
19+
"name": "Stephen Finney",
20+
"email": "[email protected]"
1721
}
1822
],
1923
"require": {
2024
"php": ">=7.2",
2125
"ext-json": "*",
2226
"cviebrock/discourse-php": "^0.9.3",
2327
"guzzlehttp/guzzle": "^6.4",
24-
"illuminate/auth": "~5.5|~6",
25-
"illuminate/routing": "~5.5|~6",
26-
"illuminate/support": "~5.5|~6"
28+
"illuminate/auth": "~5.5|~6|~7",
29+
"illuminate/routing": "~5.5|~6|~7",
30+
"illuminate/support": "~5.5|~6|~7"
2731
},
2832
"require-dev": {
29-
"mockery/mockery": "^1",
30-
"phpunit/phpunit": "~7.0.1|~8.0",
31-
"psy/psysh": "^0.9.9",
33+
"mockery/mockery": "^1.3.1",
34+
"phpunit/phpunit": "^8.4|^9.0",
35+
"psy/psysh": "^0.10",
3236
"symfony/thanks": "^1.1",
3337
"symfony/var-dumper": "~3.0|^4.2"
3438
},

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
convertErrorsToExceptions="true"
1515
convertNoticesToExceptions="true"
1616
convertWarningsToExceptions="true"
17-
processIsolation="true"
17+
processIsolation="false"
1818
stopOnFailure="false"
1919
verbose="true">
2020

@@ -48,7 +48,7 @@
4848
showOnlySummary="true"
4949
showUncoveredFiles="false"/>
5050
<log type="coverage-clover" target="build/phpunit/logs/clover.xml"/>
51-
<log type="json" target="./build/phpunit/logs/logfile.json"/>
51+
<log type="plain" target="./build/phpunit/logs/logfile.log"/>
5252
<log type="junit" target="./build/phpunit/logs/junit.xml"/>
5353
</logging>
5454
</phpunit>

readme.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $ composer require spinen/laravel-discourse-sso
3232

3333
The package uses the [auto registration feature](https://laravel.com/docs/5.8/packages#package-discovery) of Laravel 5.
3434

35-
## Configuration
35+
## Package Configuration
3636

3737
All of the configuration values are stored in under a `discourse` key in `config/services.php`. Here is the array to add...
3838

@@ -128,6 +128,40 @@ You can then add logic to the `User` model inside of [Accessors](https://laravel
128128
}
129129
```
130130

131+
## Discourse Configuration
132+
### Settings -> Login
133+
These are the configs we have under `Settings -> Login`. If a setting isn't listed, then ours is set to the default value.
134+
135+
| **Setting** | **Value** |
136+
|--------------------------|----------------------------------------------------------|
137+
| login required | true |
138+
| enable sso | true |
139+
| sso url | Our Laravel's SSO route (FQDN) |
140+
| sso secret | Our SSO secret key |
141+
| sso overrides bio | true |
142+
| sso overrides email | true |
143+
| sso overrides username | true |
144+
| sso overrides name | true |
145+
| sso overrides avatar | true |
146+
| sso not approved url | Our Laravel homepage (same as `url` in `config/app.php`) |
147+
| hide email address taken | true |
148+
_______________________________________________________________________
149+
150+
151+
### Settings -> Users
152+
These are the configs we have under `Settings -> Users`. If a setting isn't listed, then ours is set to the default value.
153+
154+
| **Setting** | **Value** |
155+
|-------------------------------------------|----------------------------------------------------------|
156+
| reserved usernames | We added our client's company name |
157+
| min password length | 8 |
158+
| min admin password length | 8 |
159+
| email editable | false |
160+
| logout redirect | Our Laravel homepage (same as `url` in `config/app.php`) |
161+
| purge unactivated users grace period days | 30 |
162+
| hide user profiles from public | true |
163+
_______________________________________________________________________
164+
131165
## Logging out the Discourse User
132166

133167
There's a listener in `src/Listeners/LogoutDiscourseUser.php` that will automatically log out the user from Discourse when certain events are fired. To use the Listener, [you need to register the event](https://laravel.com/docs/master/events#registering-events-and-listeners) in the `$listen` array in your `EventServiceProvider`.
@@ -149,7 +183,6 @@ When a Laravel `User` logs out, to log out their Discourse session Simply add th
149183

150184
## Left to do
151185

152-
* document Discourse configuration
153186
* badges for user
154187
* support for [`custom_fields`](https://meta.discourse.org/t/custom-user-fields-for-plugins/14956)
155188
* failed login redirect

src/Listeners/LogoutDiscourseUser.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ public function handle($event)
7070
];
7171

7272
// Get Discourse user to match this one, and send a Logout request to Discourse and get the response
73-
$user = json_decode(
74-
$this->client->get("users/by-external/{$event->user->id}.json", $configs)
75-
->getBody()
76-
)->user;
73+
$response = $this->client->get("users/by-external/{$event->user->id}.json", $configs);
7774

78-
$response = $this->client->post("admin/users/{$user->id}/log_out");
75+
if ($response->getStatusCode() !== 200) {
76+
$this->logger->warning(
77+
"When getting user {$event->user->id} Discourse returned status code {$response->getStatusCode()}",
78+
['reason' => $response->getReasonPhrase()]
79+
);
80+
return;
81+
}
82+
83+
$user = json_decode($response->getBody())->user;
84+
$response = $this->client->post("admin/users/{$user->id}/log_out", $configs);
7985

8086
if ($response->getStatusCode() !== 200) {
8187
$this->logger->notice(

tests/Listeners/LogoutDiscourseUserTest.php

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function it_logs_out_the_discourse_user_when_triggered()
129129
->andReturn(json_encode(['user' => $this->user_mock]));
130130

131131
$this->response_mock->shouldReceive('getStatusCode')
132-
->once()
132+
->twice()
133133
->andReturn(200);
134134

135135
$this->guzzle_mock->shouldReceive('get')
@@ -138,7 +138,7 @@ public function it_logs_out_the_discourse_user_when_triggered()
138138
->andReturn($this->response_mock);
139139

140140
$this->guzzle_mock->shouldReceive('post')
141-
->with('admin/users/1/log_out')
141+
->with('admin/users/1/log_out', $configs)
142142
->andReturn($this->response_mock);
143143

144144
$this->listener->handle($this->event_mock);
@@ -160,13 +160,12 @@ public function if_it_receives_no_user_it_does_nothing_and_returns()
160160
/**
161161
* @test
162162
*/
163-
public function if_discourse_response_code_is_not_200_log_a_notice_with_the_status_code()
163+
public function on_getting_user_if_discourse_response_code_is_not_200_log_a_warning_with_the_status_code()
164164
{
165165
$this->user_mock->id = 1;
166166
$this->event_mock->user = $this->user_mock;
167167

168-
$this->logger_mock->shouldReceive('notice')->once();
169-
168+
$this->logger_mock->shouldReceive('warning')->once();
170169

171170
$configs = [
172171
'base_uri' => 'http://discourse.example.com',
@@ -191,9 +190,53 @@ public function if_discourse_response_code_is_not_200_log_a_notice_with_the_stat
191190
->once()
192191
->andReturn($configs['headers']['Api-Username']);
193192

194-
$this->response_mock->shouldReceive('getBody')
193+
$this->response_mock->shouldReceive('getStatusCode')
194+
->andReturn(500);
195+
196+
$this->response_mock->shouldReceive('getReasonPhrase')
195197
->once()
196-
->andReturn(json_encode(['user' => $this->user_mock]));
198+
->andReturn('Server error');
199+
200+
$this->guzzle_mock->shouldReceive('get')
201+
->with('users/by-external/1.json', $configs)
202+
->once()
203+
->andReturn($this->response_mock);
204+
205+
$this->listener->handle($this->event_mock);
206+
}
207+
208+
/**
209+
* @test
210+
*/
211+
public function on_user_logout_if_discourse_response_code_is_not_200_log_a_notice_with_the_status_code()
212+
{
213+
$this->user_mock->id = 1;
214+
$this->event_mock->user = $this->user_mock;
215+
216+
$this->logger_mock->shouldReceive('notice')->once();
217+
218+
$configs = [
219+
'base_uri' => 'http://discourse.example.com',
220+
'headers' => [
221+
'Api-Key' => 'testkey',
222+
'Api-Username' => 'testuser',
223+
],
224+
];
225+
226+
$this->config_mock->shouldReceive('get')
227+
->with('services.discourse.url')
228+
->once()
229+
->andReturn($configs['base_uri']);
230+
231+
$this->config_mock->shouldReceive('get')
232+
->with('services.discourse.api.key')
233+
->once()
234+
->andReturn($configs['headers']['Api-Key']);
235+
236+
$this->config_mock->shouldReceive('get')
237+
->with('services.discourse.api.user')
238+
->once()
239+
->andReturn($configs['headers']['Api-Username']);
197240

198241
$this->response_mock->shouldReceive('getStatusCode')
199242
->andReturn(500);
@@ -202,13 +245,23 @@ public function if_discourse_response_code_is_not_200_log_a_notice_with_the_stat
202245
->once()
203246
->andReturn('Server error');
204247

248+
$good_response = Mockery::mock(Response::class);
249+
250+
$good_response->shouldReceive('getStatusCode')
251+
->once()
252+
->andReturn(200);
253+
254+
$good_response->shouldReceive('getBody')
255+
->once()
256+
->andReturn(json_encode(['user' => $this->user_mock]));
257+
205258
$this->guzzle_mock->shouldReceive('get')
206259
->with('users/by-external/1.json', $configs)
207260
->once()
208-
->andReturn($this->response_mock);
261+
->andReturn($good_response);
209262

210263
$this->guzzle_mock->shouldReceive('post')
211-
->with('admin/users/1/log_out')
264+
->with('admin/users/1/log_out', $configs)
212265
->andReturn($this->response_mock);
213266

214267
$this->listener->handle($this->event_mock);

0 commit comments

Comments
 (0)