generated from biigle/module
-
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.
Merge pull request #21 from biigle/edit-quota
Implement editable quota in admin area
- Loading branch information
Showing
4 changed files
with
124 additions
and
3 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,40 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\UserStorage\Http\Controllers\Api; | ||
|
||
use Biigle\Http\Controllers\Api\Controller; | ||
use Biigle\Modules\UserStorage\User; | ||
use Illuminate\Http\Request; | ||
|
||
class StorageRequestUserController extends Controller | ||
{ | ||
/** | ||
* Update the storage quota of a user | ||
* | ||
* @api {post} users/:id/storage-request-quota Update storage quota | ||
* @apiGroup UserStorage | ||
* @apiName StoreStorageQuota | ||
* @apiPermission globalAdmin | ||
* | ||
* @param Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request, $id) | ||
{ | ||
$request->validate([ | ||
'quota' => 'required|integer|min:0', | ||
]); | ||
|
||
$user = User::findOrFail($id); | ||
$user->storage_quota_available = $request->input('quota'); | ||
$user->save(); | ||
|
||
if (!$this->isAutomatedRequest()) { | ||
return $this->fuzzyRedirect('admin-users-show', ['id' => $id]) | ||
->with('message', 'Storage quota updated') | ||
->with('messageType', 'success'); | ||
} | ||
|
||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
tests/Http/Controllers/Api/StorageRequestUserControllerTest.php
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,39 @@ | ||
<?php | ||
|
||
namespace Biigle\Tests\Modules\UserStorage\Http\Controllers\Api; | ||
|
||
use ApiTestCase; | ||
use Biigle\User; | ||
use Biigle\Modules\UserStorage\User as StorageUser; | ||
|
||
class StorageRequestUserControllerTest extends ApiTestCase | ||
{ | ||
public function testStore() | ||
{ | ||
config(['user_storage.user_quota' => 100]); | ||
$user = StorageUser::convert($this->user()); | ||
|
||
$this->doTestApiRoute('POST', "/api/v1/users/{$user->id}/storage-request-quota"); | ||
|
||
$this->beAdmin(); | ||
$this->postJson("/api/v1/users/{$user->id}/storage-request-quota") | ||
->assertStatus(403); | ||
|
||
$this->be($user); | ||
$this->postJson("/api/v1/users/{$user->id}/storage-request-quota") | ||
->assertStatus(403); | ||
|
||
$this->beGlobalAdmin(); | ||
$this->postJson("/api/v1/users/{$user->id}/storage-request-quota") | ||
->assertStatus(422); | ||
|
||
$this->assertEquals(100, $user->storage_quota_available); | ||
$this | ||
->postJson("/api/v1/users/{$user->id}/storage-request-quota", [ | ||
'quota' => 200, | ||
]) | ||
->assertStatus(200); | ||
|
||
$this->assertEquals(200, $user->fresh()->storage_quota_available); | ||
} | ||
} |