Revert "rector: arrrrr"

This reverts commit 16c0cd10d8.
This commit is contained in:
Andras Bacsai
2025-01-07 15:31:43 +01:00
parent da07b4fdcf
commit 1fe4dd722b
349 changed files with 3689 additions and 4184 deletions

View File

@@ -25,14 +25,12 @@ class AdminView extends Component
return redirect()->route('dashboard');
}
$this->getUsers();
return null;
}
public function submitSearch()
{
if ($this->search !== '') {
$this->users = User::query()->where(function ($query) {
$this->users = User::where(function ($query) {
$query->where('name', 'like', "%{$this->search}%")
->orWhere('email', 'like', "%{$this->search}%");
})->get()->filter(function ($user) {
@@ -45,7 +43,7 @@ class AdminView extends Component
public function getUsers()
{
$users = User::query()->where('id', '!=', auth()->id())->get();
$users = User::where('id', '!=', auth()->id())->get();
if ($users->count() > $this->number_of_users_to_show) {
$this->lots_of_users = true;
$this->users = $users->take($this->number_of_users_to_show);
@@ -79,20 +77,24 @@ class AdminView extends Component
if (! isInstanceAdmin()) {
return redirect()->route('dashboard');
}
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return null;
return;
}
}
if (! auth()->user()->isInstanceAdmin()) {
return $this->dispatch('error', 'You are not authorized to delete users');
}
$user = User::query()->find($id);
$user = User::find($id);
$teams = $user->teams;
foreach ($teams as $team) {
$user_alone_in_team = $team->members->count() === 1;
if ($team->id === 0 && $user_alone_in_team) {
return $this->dispatch('error', 'User is alone in the root team, cannot delete');
if ($team->id === 0) {
if ($user_alone_in_team) {
return $this->dispatch('error', 'User is alone in the root team, cannot delete');
}
}
if ($user_alone_in_team) {
$this->finalizeDeletion($user, $team);
@@ -108,26 +110,26 @@ class AdminView extends Component
$team->members()->detach($user->id);
continue;
}
$found_other_member_who_is_not_owner = $team->members->filter(function ($member) {
return $member->pivot->role === 'member';
})->first();
if ($found_other_member_who_is_not_owner) {
$found_other_member_who_is_not_owner->pivot->role = 'owner';
$found_other_member_who_is_not_owner->pivot->save();
$team->members()->detach($user->id);
} else {
$this->finalizeDeletion($user, $team);
}
$found_other_member_who_is_not_owner = $team->members->filter(function ($member) {
return $member->pivot->role === 'member';
})->first();
if ($found_other_member_who_is_not_owner) {
$found_other_member_who_is_not_owner->pivot->role = 'owner';
$found_other_member_who_is_not_owner->pivot->save();
$team->members()->detach($user->id);
} else {
$this->finalizeDeletion($user, $team);
}
continue;
continue;
}
} else {
$team->members()->detach($user->id);
}
$team->members()->detach($user->id);
}
$user->delete();
$this->getUsers();
return null;
}
public function render()

View File

@@ -5,7 +5,6 @@ namespace App\Livewire\Team;
use App\Models\Team;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Create extends Component
{
@@ -19,7 +18,7 @@ class Create extends Component
{
try {
$this->validate();
$team = Team::query()->create([
$team = Team::create([
'name' => $this->name,
'description' => $this->description,
'personal_team' => false,
@@ -28,7 +27,7 @@ class Create extends Component
refreshSession();
return redirect()->route('team.index');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -7,7 +7,6 @@ use App\Models\TeamInvitation;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
use Throwable;
class Index extends Component
{
@@ -46,11 +45,9 @@ class Index extends Component
$this->team->save();
refreshSession();
$this->dispatch('success', 'Team updated.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function delete()

View File

@@ -3,7 +3,6 @@
namespace App\Livewire\Team;
use App\Models\TeamInvitation;
use Exception;
use Livewire\Component;
class Invitations extends Component
@@ -19,11 +18,9 @@ class Invitations extends Component
$initiation_found->delete();
$this->refreshInvitations();
$this->dispatch('success', 'Invitation revoked.');
} catch (Exception) {
} catch (\Exception) {
return $this->dispatch('error', 'Invitation not found.');
}
return null;
}
public function refreshInvitations()

View File

@@ -4,13 +4,11 @@ namespace App\Livewire\Team;
use App\Models\TeamInvitation;
use App\Models\User;
use Exception;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Livewire\Component;
use Throwable;
use Visus\Cuid2\Cuid2;
class InviteLink extends Component
@@ -44,19 +42,19 @@ class InviteLink extends Component
try {
$this->validate();
if (auth()->user()->role() === 'admin' && $this->role === 'owner') {
throw new Exception('Admins cannot invite owners.');
throw new \Exception('Admins cannot invite owners.');
}
$member_emails = currentTeam()->members()->get()->pluck('email');
if ($member_emails->contains($this->email)) {
return handleError(livewire: $this, customErrorMessage: "$this->email is already a member of ".currentTeam()->name.'.');
}
$cuid2 = new Cuid2(32);
$link = url('/').config('constants.invitation.link.base_url').$cuid2;
$uuid = new Cuid2(32);
$link = url('/').config('constants.invitation.link.base_url').$uuid;
$user = User::whereEmail($this->email)->first();
if (is_null($user)) {
$password = Str::password();
$user = User::query()->create([
$user = User::create([
'name' => str($this->email)->before('@'),
'email' => $this->email,
'password' => Hash::make($password),
@@ -70,34 +68,36 @@ class InviteLink extends Component
$invitationValid = $invitation->isValid();
if ($invitationValid) {
return handleError(livewire: $this, customErrorMessage: "Pending invitation already exists for $this->email.");
} else {
$invitation->delete();
}
$invitation->delete();
}
$invitation = TeamInvitation::query()->firstOrCreate([
$invitation = TeamInvitation::firstOrCreate([
'team_id' => currentTeam()->id,
'uuid' => $cuid2,
'uuid' => $uuid,
'email' => $this->email,
'role' => $this->role,
'link' => $link,
'via' => $sendEmail ? 'email' : 'link',
]);
if ($sendEmail) {
$mailMessage = new MailMessage;
$mailMessage->view('emails.invitation-link', [
$mail = new MailMessage;
$mail->view('emails.invitation-link', [
'team' => currentTeam()->name,
'invitation_link' => $link,
]);
$mailMessage->subject('You have been invited to '.currentTeam()->name.' on '.config('app.name').'.');
send_user_an_email($mailMessage, $this->email);
$mail->subject('You have been invited to '.currentTeam()->name.' on '.config('app.name').'.');
send_user_an_email($mail, $this->email);
$this->dispatch('success', 'Invitation sent via email.');
$this->dispatch('refreshInvitations');
return null;
return;
} else {
$this->dispatch('success', 'Invitation link generated.');
$this->dispatch('refreshInvitations');
}
$this->dispatch('success', 'Invitation link generated.');
$this->dispatch('refreshInvitations');
} catch (Throwable $e) {
} catch (\Throwable $e) {
$error_message = $e->getMessage();
if ($e->getCode() === '23505') {
$error_message = 'Invitation already sent.';
@@ -105,7 +105,5 @@ class InviteLink extends Component
return handleError(error: $e, livewire: $this, customErrorMessage: $error_message);
}
return null;
}
}

View File

@@ -4,7 +4,6 @@ namespace App\Livewire\Team;
use App\Enums\Role;
use App\Models\User;
use Exception;
use Illuminate\Support\Facades\Cache;
use Livewire\Component;
@@ -17,11 +16,11 @@ class Member extends Component
try {
if (Role::from(auth()->user()->role())->lt(Role::ADMIN)
|| Role::from($this->getMemberRole())->gt(auth()->user()->role())) {
throw new Exception('You are not authorized to perform this action.');
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => Role::ADMIN->value]);
$this->dispatch('reloadWindow');
} catch (Exception $e) {
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
}
@@ -31,11 +30,11 @@ class Member extends Component
try {
if (Role::from(auth()->user()->role())->lt(Role::OWNER)
|| Role::from($this->getMemberRole())->gt(auth()->user()->role())) {
throw new Exception('You are not authorized to perform this action.');
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => Role::OWNER->value]);
$this->dispatch('reloadWindow');
} catch (Exception $e) {
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
}
@@ -45,11 +44,11 @@ class Member extends Component
try {
if (Role::from(auth()->user()->role())->lt(Role::ADMIN)
|| Role::from($this->getMemberRole())->gt(auth()->user()->role())) {
throw new Exception('You are not authorized to perform this action.');
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => Role::MEMBER->value]);
$this->dispatch('reloadWindow');
} catch (Exception $e) {
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
}
@@ -59,7 +58,7 @@ class Member extends Component
try {
if (Role::from(auth()->user()->role())->lt(Role::ADMIN)
|| Role::from($this->getMemberRole())->gt(auth()->user()->role())) {
throw new Exception('You are not authorized to perform this action.');
throw new \Exception('You are not authorized to perform this action.');
}
$this->member->teams()->detach(currentTeam());
Cache::forget("team:{$this->member->id}");
@@ -67,7 +66,7 @@ class Member extends Component
return $this->member->teams()->first();
});
$this->dispatch('reloadWindow');
} catch (Exception $e) {
} catch (\Exception $e) {
$this->dispatch('error', $e->getMessage());
}
}

View File

@@ -7,7 +7,7 @@ use Livewire\Component;
class Show extends Component
{
public $storage;
public $storage = null;
public function mount()
{