Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. UserGroup clean-up #10585

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Add option to allow checking group with OAuth
cl8n committed Sep 23, 2023
commit 5915c82eb679501a25e12f5c893adcb37b840152
2 changes: 1 addition & 1 deletion app/Libraries/ClientCheck.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ class ClientCheck
{
public static function findBuild($user, $params): ?Build
{
$assertValid = config('osu.client.check_version') && $user->findUserGroup(app('groups')->byIdentifier('admin')) === null;
$assertValid = config('osu.client.check_version') && !$user->isGroup(app('groups')->byIdentifier('admin'), allowOAuth: true);

$clientHash = presence(get_string($params['version_hash'] ?? null));
if ($clientHash === null) {
11 changes: 5 additions & 6 deletions app/Models/User.php
Original file line number Diff line number Diff line change
@@ -653,7 +653,7 @@ public function removeFromGroup(Group $group, ?self $actor = null): void
public function setDefaultGroup(Group $group, ?self $actor = null): void
{
$this->getConnection()->transaction(function () use ($actor, $group) {
if ($this->findUserGroup($group) === null) {
if (!$this->isGroup($group, allowOAuth: true)) {
$this->addToGroup($group, null, $actor);
}

@@ -975,7 +975,7 @@ public function isAdmin()

public function isChatAnnouncer()
{
return $this->findUserGroup(app('groups')->byIdentifier('announce')) !== null;
return $this->isGroup(app('groups')->byIdentifier('announce'), allowOAuth: true);
}

public function isGMT()
@@ -1153,14 +1153,13 @@ public function findUserGroup(Group $group, bool $includePending = false): ?User
/**
* Check if the user is in a specified group.
*
* This will always return false if the user was authenticated using OAuth.
*
* @param \App\Models\Group $group
* @param string|null $ruleset Additionally check if the usergroup has a specified ruleset.
* @param bool $allowOAuth Whether to perform the check if the user was authenticated using OAuth.
*/
public function isGroup(Group $group, ?string $ruleset = null): bool
public function isGroup(Group $group, ?string $ruleset = null, bool $allowOAuth = false): bool
{
if ($this->token() !== null) {
if (!$allowOAuth && $this->token() !== null) {
return false;
}