mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-05-20 10:04:53 +00:00
🚀 Refactor: Centralize isBoardMember logic in EinundzwanzigPleb model and replace redundant checks
This commit is contained in:
@@ -38,28 +38,27 @@ class extends Component {
|
||||
#[Locked]
|
||||
public bool $canEdit = false;
|
||||
|
||||
#[Locked]
|
||||
public ?\App\Models\EinundzwanzigPleb $currentPleb = null;
|
||||
|
||||
public ?int $confirmDeleteId = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
if (NostrAuth::check()) {
|
||||
$currentPubkey = NostrAuth::pubkey();
|
||||
$currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $currentPubkey)->first();
|
||||
$this->currentPleb = NostrAuth::user()?->getPleb();
|
||||
|
||||
if (
|
||||
$currentPleb
|
||||
&& $currentPleb->association_status->value > 1
|
||||
&& $currentPleb->paymentEvents()->where('year', date('Y'))->where('paid', true)->exists()
|
||||
) {
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
|
||||
if ($currentPleb && in_array($currentPleb->npub, config('einundzwanzig.config.current_board'))) {
|
||||
$this->canEdit = true;
|
||||
}
|
||||
|
||||
$this->loadNews();
|
||||
if (! $this->currentPleb) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->currentPleb->isBoardMember()) {
|
||||
$this->isAllowed = true;
|
||||
$this->canEdit = true;
|
||||
} elseif ($this->currentPleb->hasPaidMembership()) {
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
|
||||
$this->loadNews();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
@@ -101,13 +100,11 @@ class extends Component {
|
||||
'form.description' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', NostrAuth::pubkey())->first();
|
||||
|
||||
$news = new Notification;
|
||||
$news->name = $this->form['name'];
|
||||
$news->description = $this->form['description'] ?? null;
|
||||
$news->category = $this->form['category'];
|
||||
$news->einundzwanzig_pleb_id = $currentPleb->id;
|
||||
$news->einundzwanzig_pleb_id = $this->currentPleb->id;
|
||||
$news->save();
|
||||
|
||||
if ($this->file) {
|
||||
@@ -340,20 +337,15 @@ class extends Component {
|
||||
</button>
|
||||
|
||||
<!-- User badge -->
|
||||
@if(NostrAuth::check())
|
||||
@php
|
||||
$currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', NostrAuth::pubkey())->first();
|
||||
@endphp
|
||||
@if($currentPleb)
|
||||
<div class="flex items-center gap-2.5 rounded-xl bg-bg-surface border border-border-subtle px-4 py-2.5">
|
||||
<img
|
||||
src="{{ $currentPleb->profile?->picture ?? asset('einundzwanzig-alpha.jpg') }}"
|
||||
alt="{{ $currentPleb->profile?->name ?? 'Anonym' }}"
|
||||
class="w-8 h-8 rounded-full bg-bg-elevated object-cover shrink-0"
|
||||
/>
|
||||
<span class="text-[13px] font-medium text-text-primary">{{ $currentPleb->profile?->name ?? str($currentPleb->npub)->limit(32) }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@if($currentPleb)
|
||||
<div class="flex items-center gap-2.5 rounded-xl bg-bg-surface border border-border-subtle px-4 py-2.5">
|
||||
<img
|
||||
src="{{ $currentPleb->profile?->picture ?? asset('einundzwanzig-alpha.jpg') }}"
|
||||
alt="{{ $currentPleb->profile?->name ?? 'Anonym' }}"
|
||||
class="w-8 h-8 rounded-full bg-bg-elevated object-cover shrink-0"
|
||||
/>
|
||||
<span class="text-[13px] font-medium text-text-primary">{{ $currentPleb->profile?->name ?? str($currentPleb->npub)->limit(32) }}</span>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -43,11 +43,8 @@ class extends Component
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
|
||||
if ($nostrUser) {
|
||||
$pleb = $nostrUser->getPleb();
|
||||
if ($pleb && in_array($pleb->npub, config('einundzwanzig.config.current_board'), true)) {
|
||||
$this->isAdmin = true;
|
||||
}
|
||||
if ($nostrUser && $nostrUser->isBoardMember()) {
|
||||
$this->isAdmin = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ new class extends Component {
|
||||
$this->projects = ProjectProposal::query()
|
||||
->with([
|
||||
'einundzwanzigPleb.profile',
|
||||
'votes',
|
||||
'votes.einundzwanzigPleb',
|
||||
])
|
||||
->where(function ($query) {
|
||||
$query
|
||||
|
||||
@@ -45,7 +45,7 @@ new class extends Component {
|
||||
{
|
||||
return Vote::query()
|
||||
->where('project_proposal_id', $this->projectProposal->id)
|
||||
->whereHas('einundzwanzigPleb', fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board')))
|
||||
->whereHas('einundzwanzigPleb', fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board', [])))
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ new class extends Component {
|
||||
->where('project_proposal_id', $this->projectProposal->id)
|
||||
->whereDoesntHave(
|
||||
'einundzwanzigPleb',
|
||||
fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board'))
|
||||
fn($q) => $q->whereIn('npub', config('einundzwanzig.config.current_board', []))
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user