Remove softDelete on 2FAccounts

This commit is contained in:
Bubka 2020-01-07 16:46:50 +01:00
parent eab03e6d0c
commit 3a0bf1a596
5 changed files with 8 additions and 35 deletions

View File

@ -7,6 +7,7 @@
use OTPHP\Factory; use OTPHP\Factory;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use ParagonIE\ConstantTime\Base32; use ParagonIE\ConstantTime\Base32;
use Illuminate\Support\Facades\Storage;
class TwoFAccountController extends Controller class TwoFAccountController extends Controller
{ {
@ -106,24 +107,16 @@ public function update(Request $request, TwoFAccount $twofaccount)
*/ */
public function destroy(TwoFAccount $twofaccount) public function destroy(TwoFAccount $twofaccount)
{ {
// delete icon
$storedIcon = 'public/' . pathinfo($twofaccount->icon)['basename'];
if( Storage::exists($storedIcon) ) {
Storage::delete($storedIcon);
}
$twofaccount->delete(); $twofaccount->delete();
return response()->json(null, 204); 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);
}
} }

View File

@ -3,11 +3,9 @@
namespace App; namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class TwoFAccount extends Model class TwoFAccount extends Model
{ {
use SoftDeletes;
protected $fillable = ['service', 'account', 'uri', 'icon']; protected $fillable = ['service', 'account', 'uri', 'icon'];

View File

@ -20,7 +20,6 @@ public function up()
$table->string('account'); $table->string('account');
$table->string('icon')->nullable(); $table->string('icon')->nullable();
$table->timestamps(); $table->timestamps();
$table->softDeletes();
}); });
} }

View File

@ -23,5 +23,4 @@
Route::get('twofaccounts/{twofaccount}/totp', 'TwoFAccountController@generateTOTP')->name('twofaccounts.generateTOTP'); Route::get('twofaccounts/{twofaccount}/totp', 'TwoFAccountController@generateTOTP')->name('twofaccounts.generateTOTP');
Route::post('qrcode/decode', 'QrCodeController@decode'); Route::post('qrcode/decode', 'QrCodeController@decode');
Route::post('icon/upload', 'IconController@upload'); Route::post('icon/upload', 'IconController@upload');
Route::delete('twofaccounts/force/{id}', 'TwoFAccountController@forceDestroy')->name('twofaccounts.forceDestroy');
}); });

View File

@ -135,20 +135,4 @@ public function testTwoFAccountDeletion()
->assertStatus(204); ->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);
}
} }