Skip to content

Commit

Permalink
Use new generic user settings endpoint for MAIA notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Aug 11, 2020
1 parent c37639a commit 17e0989
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 106 deletions.
36 changes: 0 additions & 36 deletions src/Http/Controllers/Api/SettingsController.php

This file was deleted.

4 changes: 0 additions & 4 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,4 @@

$router->get('maia-jobs/{id}/images/{id2}/training-proposals', 'MaiaJobImagesController@indexTrainingProposals');
$router->get('maia-jobs/{id}/images/{id2}/annotation-candidates', 'MaiaJobImagesController@indexAnnotationCandidates');

$router->post('users/my/settings/maia', [
'uses' => 'SettingsController@store',
]);
});
2 changes: 2 additions & 0 deletions src/MaiaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Biigle\Modules\Maia;

use Biigle\Http\Requests\UpdateUserSettings;
use Biigle\Modules\Maia\Events\MaiaJobContinued;
use Biigle\Modules\Maia\Events\MaiaJobCreated;
use Biigle\Modules\Maia\Events\MaiaJobDeleting;
Expand Down Expand Up @@ -53,6 +54,7 @@ public function boot(Modules $modules, Router $router)

if (config('maia.notifications.allow_user_settings')) {
$modules->registerViewMixin('maia', 'settings.notifications');
UpdateUserSettings::addRule('maia_notifications', 'filled|in:email,web');
}

Gate::policy(MaiaJob::class, Policies\MaiaJobPolicy::class);
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/settings/notifications.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
watch: {
settings: function (settings) {
this.startLoading();
this.$http.post('api/v1/users/my/settings/maia', {
this.$http.put('api/v1/users/my/settings', {
maia_notifications: this.settings,
})
.then(this.handleSuccess, this.handleError)
Expand Down
65 changes: 0 additions & 65 deletions tests/Http/Controllers/Api/SettingsControllerTest.php

This file was deleted.

27 changes: 27 additions & 0 deletions tests/Http/Requests/UpdateUserSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Biigle\Tests\Modules\Maia\Http\Requests;

use ApiTestCase;

class UpdateUserSettingsTest extends ApiTestCase
{
public function testUpdate()
{
$this->beUser();
$this->putJson("/api/v1/users/my/settings", ['maia_notifications' => 'test'])
->assertStatus(422);

$this->assertNull($this->user()->fresh()->getSettings('maia_notifications'));

$this->putJson("/api/v1/users/my/settings", ['maia_notifications' => 'email'])
->assertStatus(200);

$this->assertEquals('email', $this->user()->fresh()->getSettings('maia_notifications'));

$this->putJson("/api/v1/users/my/settings", ['maia_notifications' => 'web'])
->assertStatus(200);

$this->assertEquals('web', $this->user()->fresh()->getSettings('maia_notifications'));
}
}

0 comments on commit 17e0989

Please sign in to comment.