From 3a0bf1a5962d3a7a3ea1d86f5fa31a5850eeed5c Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Tue, 7 Jan 2020 16:46:50 +0100 Subject: [PATCH] Remove softDelete on 2FAccounts --- .../Controllers/TwoFAccountController.php | 23 +++++++------------ app/TwoFAccount.php | 2 -- ...05_16_162730_create_twofaccounts_table.php | 1 - routes/api.php | 1 - tests/Unit/TwoFAccountTest.php | 16 ------------- 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/TwoFAccountController.php b/app/Http/Controllers/TwoFAccountController.php index db95a0fb..4c59a6cf 100644 --- a/app/Http/Controllers/TwoFAccountController.php +++ b/app/Http/Controllers/TwoFAccountController.php @@ -7,6 +7,7 @@ use OTPHP\Factory; use Illuminate\Http\Request; use ParagonIE\ConstantTime\Base32; +use Illuminate\Support\Facades\Storage; class TwoFAccountController extends Controller { @@ -106,24 +107,16 @@ public function update(Request $request, TwoFAccount $twofaccount) */ public function destroy(TwoFAccount $twofaccount) { + // delete icon + $storedIcon = 'public/' . pathinfo($twofaccount->icon)['basename']; + + if( Storage::exists($storedIcon) ) { + Storage::delete($storedIcon); + } + $twofaccount->delete(); return response()->json(null, 204); } - - /** - * Remove the specified soft deleted resource from storage. - * - * @param \App\TwoFAccount $twofaccount - * @return \Illuminate\Http\Response - */ - public function forceDestroy($id) - { - $twofaccount = TwoFAccount::onlyTrashed()->findOrFail($id); - $twofaccount->forceDelete(); - - return response()->json(null, 204); - } - } diff --git a/app/TwoFAccount.php b/app/TwoFAccount.php index c4e5087d..fa9f95cc 100644 --- a/app/TwoFAccount.php +++ b/app/TwoFAccount.php @@ -3,11 +3,9 @@ namespace App; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\SoftDeletes; class TwoFAccount extends Model { - use SoftDeletes; protected $fillable = ['service', 'account', 'uri', 'icon']; diff --git a/database/migrations/2019_05_16_162730_create_twofaccounts_table.php b/database/migrations/2019_05_16_162730_create_twofaccounts_table.php index b10e0781..31487a50 100644 --- a/database/migrations/2019_05_16_162730_create_twofaccounts_table.php +++ b/database/migrations/2019_05_16_162730_create_twofaccounts_table.php @@ -20,7 +20,6 @@ public function up() $table->string('account'); $table->string('icon')->nullable(); $table->timestamps(); - $table->softDeletes(); }); } diff --git a/routes/api.php b/routes/api.php index aae49da0..fef95c70 100644 --- a/routes/api.php +++ b/routes/api.php @@ -23,5 +23,4 @@ Route::get('twofaccounts/{twofaccount}/totp', 'TwoFAccountController@generateTOTP')->name('twofaccounts.generateTOTP'); Route::post('qrcode/decode', 'QrCodeController@decode'); Route::post('icon/upload', 'IconController@upload'); - Route::delete('twofaccounts/force/{id}', 'TwoFAccountController@forceDestroy')->name('twofaccounts.forceDestroy'); }); \ No newline at end of file diff --git a/tests/Unit/TwoFAccountTest.php b/tests/Unit/TwoFAccountTest.php index 6c5c4d00..fd5ba6c5 100644 --- a/tests/Unit/TwoFAccountTest.php +++ b/tests/Unit/TwoFAccountTest.php @@ -135,20 +135,4 @@ public function testTwoFAccountDeletion() ->assertStatus(204); } - - /** - * test TwoFAccount permanent deletion via API - * - * @test - */ - public function testTwoFAccountPermanentDeletion() - { - $twofaccount = factory(TwoFAccount::class)->create(); - $twofaccount->delete(); - - $response = $this->actingAs($this->user, 'api') - ->json('DELETE', '/api/twofaccounts/force/' . $twofaccount->id) - ->assertStatus(204); - } - }