mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-14 06:36:46 +00:00
feat: add Nostr profile fetcher and update election admin view
- Added a new console command `nostr:profile` which fetches a Nostr profile given a public key. - Updated the election admin view to fetch the profile if it doesn't exist in the database. - Introduced a new state variable `isAllowed` to handle authorization in the election admin view. - Redirect users with no admin access to the association profile page.
This commit is contained in:
39
app/Console/Commands/Nostr/FetchProfile.php
Normal file
39
app/Console/Commands/Nostr/FetchProfile.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Nostr;
|
||||
|
||||
use App\Traits\NostrFetcherTrait;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FetchProfile extends Command
|
||||
{
|
||||
use NostrFetcherTrait;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'nostr:pofile {--pubkey=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$pubkey = $this->option('pubkey');
|
||||
if (empty($pubkey)) {
|
||||
$this->error('Please provide a pubkey');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fetchProfile([$pubkey]);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ use function Livewire\Volt\{on};
|
||||
|
||||
name('association.election.admin');
|
||||
|
||||
state(['isAllowed' => false]);
|
||||
state(['currentPubkey' => null]);
|
||||
state(['votes' => null]);
|
||||
state(['events' => null]);
|
||||
@@ -71,6 +72,10 @@ mount(function () {
|
||||
on([
|
||||
'nostrLoggedIn' => function ($pubkey) {
|
||||
$this->currentPubkey = $pubkey;
|
||||
if ($this->currentPubkey !== '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033') {
|
||||
return redirect()->route('association.profile');
|
||||
}
|
||||
$this->isAllowed = true;
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -86,8 +91,16 @@ $loadVotes = function () {
|
||||
->map(function ($event) {
|
||||
$votedFor = \App\Models\Profile::query()
|
||||
->where('pubkey', str($event['content'])->before(',')->toString())
|
||||
->first()
|
||||
->toArray();
|
||||
->first();
|
||||
if (!$votedFor) {
|
||||
Artisan::call(\App\Console\Commands\Nostr\FetchProfile::class, [
|
||||
'--pubkey' => str($event['content'])->before(',')->toString(),
|
||||
]);
|
||||
$votedFor = \App\Models\Profile::query()
|
||||
->where('pubkey', str($event['content'])->before(',')->toString())
|
||||
->first();
|
||||
}
|
||||
$votedFor = $votedFor->toArray();
|
||||
|
||||
return [
|
||||
'created_at' => $event['created_at'],
|
||||
|
||||
Reference in New Issue
Block a user