Add Group scope to TwoFAccount model

This commit is contained in:
Bubka 2020-10-25 23:51:50 +01:00
parent 273aaa9840
commit afc2095e27
3 changed files with 22 additions and 2 deletions

View File

@ -4,6 +4,7 @@
use App\TwoFAccount;
use App\Classes\OTP;
use App\Classes\Options;
use Illuminate\Http\Request;
use ParagonIE\ConstantTime\Base32;
use Illuminate\Support\Facades\Storage;
@ -17,7 +18,8 @@ class TwoFAccountController extends Controller
*/
public function index()
{
return response()->json(TwoFAccount::ordered()->get()->toArray());
return response()->json(TwoFAccount::ofGroup(Options::get('activeGroup'))->get()->toArray());
//return response()->json(TwoFAccount::ordered()->get()->toArray());
}

View File

@ -55,6 +55,23 @@ protected static function boot()
}
/**
* Scope a query to only include TwoFAccounts of a given group.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $groupId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOfGroup($query, $groupId)
{
if( $groupId ) {
return $query->where('group_id', $groupId);
}
return $query;
}
/**
* Sortable settings
*

View File

@ -38,7 +38,8 @@
'useBasicQrcodeReader' => false,
'displayMode' => 'list',
'showAccountsIcons' => true,
'kickUserAfter' => '15'
'kickUserAfter' => '15',
'activeGroup' => 0,
],
/*