-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 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
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
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,59 @@ | ||
<?php | ||
|
||
namespace FoF\OAuth\Query; | ||
|
||
use Flarum\Filter\FilterInterface; | ||
use Flarum\Filter\FilterState; | ||
use Flarum\Filter\ValidateFilterTrait; | ||
use Flarum\Search\AbstractRegexGambit; | ||
use Flarum\Search\SearchState; | ||
use Illuminate\Database\Query\Builder; | ||
|
||
class SsoIdFilterGambit extends AbstractRegexGambit implements FilterInterface | ||
{ | ||
use ValidateFilterTrait; | ||
|
||
public function apply(SearchState $search, $bit) | ||
{ | ||
if (! $search->getActor()->hasPermission('fof-oauth.admin.permissions.moderate_user_providers')) { | ||
return false; | ||
} | ||
|
||
return parent::apply($search, $bit); | ||
} | ||
|
||
public function getGambitPattern() | ||
{ | ||
return 'sso:(.+)'; | ||
} | ||
|
||
protected function conditions(SearchState $search, array $matches, $negate) | ||
{ | ||
$this->constrain($search->getQuery(), $matches[1], $negate); | ||
} | ||
|
||
public function getFilterKey(): string | ||
{ | ||
return 'sso'; | ||
} | ||
|
||
public function filter(FilterState $filterState, $filterValue, bool $negate) | ||
{ | ||
if (! $filterState->getActor()->hasPermission('fof-oauth.admin.permissions.moderate_user_providers')) { | ||
return; | ||
} | ||
|
||
$this->constrain($filterState->getQuery(), $filterValue, $negate); | ||
} | ||
|
||
protected function constrain(Builder $query, $rawSso, bool $negate) | ||
{ | ||
$sso = $this->asString($rawSso); | ||
|
||
$query->whereIn('id', function ($query) use ($sso) { | ||
$query->select('user_id') | ||
->from('login_providers') | ||
->where('identifier', $sso); | ||
}); | ||
} | ||
} |