feat(election): add access control for election details and voting options based on user permissions.

This commit is contained in:
fsociety
2024-10-25 13:30:39 +02:00
parent 3936165a0e
commit 421d60e42b
8 changed files with 1049 additions and 926 deletions

View File

@@ -1,6 +1,5 @@
export default (livewireComponent) => ({
isAllowed: livewireComponent.entangle('isAllowed', true),
signThisEvent: livewireComponent.entangle('signThisEvent'),
showLog: livewireComponent.entangle('showLog', true),

View File

@@ -162,7 +162,9 @@ $signEvent = function ($event) {
:seo="new \RalphJSmit\Laravel\SEO\Support\SEOData(title: 'Wahlen ' . $election->year, description: 'Wahlen des Vereins im Jahr ' . $election->year)"
>
@volt
<div x-cloak x-show="isAllowed" class="relative flex h-full" x-data="nostrApp(@this)"
<div>
@if($isAllowed)
<div x-cloak class="relative flex h-full" x-data="nostrApp(@this)"
wire:poll.600000ms="checkElection">
@php
@@ -245,7 +247,8 @@ $signEvent = function ($event) {
<span
class="font-semibold text-gray-800 dark:text-gray-100">2024</span>
</div>
<svg class="w-3 h-3 shrink-0 ml-1 fill-current text-gray-400 dark:text-gray-500"
<svg
class="w-3 h-3 shrink-0 ml-1 fill-current text-gray-400 dark:text-gray-500"
viewBox="0 0 12 12">
<path d="M5.9 11.4L.5 6l1.4-1.4 4 4 4-4L11.3 6z"/>
</svg>
@@ -258,7 +261,8 @@ $signEvent = function ($event) {
x-transition:enter-start="opacity-0 -translate-y-2"
x-transition:enter-end="opacity-100 translate-y-0"
x-transition:leave="transition ease-out duration-200"
x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
x-cloak>
<ul>
<li>
@@ -269,7 +273,8 @@ $signEvent = function ($event) {
<div class="grow flex items-center truncate">
<div class="truncate">2024</div>
</div>
<svg class="w-3 h-3 shrink-0 fill-current text-orange-500 ml-1"
<svg
class="w-3 h-3 shrink-0 fill-current text-orange-500 ml-1"
viewBox="0 0 12 12">
<path
d="M10.28 1.28L3.989 7.575 1.695 5.28A1 1 0 00.28 6.695l3 3a1 1 0 001.414 0l7-7A1 1 0 0010.28 1.28z"/>
@@ -295,7 +300,8 @@ $signEvent = function ($event) {
<button class="absolute inset-0 right-auto group" type="submit" aria-label="Search">
<svg
class="shrink-0 fill-current text-gray-400 dark:text-gray-500 group-hover:text-gray-500 dark:group-hover:text-gray-400 ml-3 mr-2"
width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
width="16" height="16" viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg">
<path
d="M7 14c-3.86 0-7-3.14-7-7s3.14-7 7-7 7 3.14 7 7-3.14 7-7 7zM7 2C4.243 2 2 4.243 2 7s2.243 5 5 5 5-2.243 5-5-2.243-5-5-5z"/>
<path
@@ -337,7 +343,8 @@ $signEvent = function ($event) {
@php
$votedResult = $loadedEvents->filter(fn ($e) => $e['pubkey'] === $pleb['pubkey'])->firstWhere('type', $name);
@endphp
<div class="flex space-x-2" wire:key="p_{{ $name }}">
<div class="flex space-x-2"
wire:key="p_{{ $name }}">
@if($votedResult)
<i class="fa-sharp-duotone fa-solid {{ $p['icon'] }} w-4 h-4 fill-current text-green-500"></i>
@endif
@@ -699,5 +706,19 @@ $signEvent = function ($event) {
@endif
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">Wahlen</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, die Wahlen einzusehen.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>

View File

@@ -54,14 +54,17 @@ $saveElection = function ($index) {
<x-layouts.app title="{{ __('Wahlen') }}">
@volt
<div x-cloak class="relative flex h-full" x-show="isAllowed" x-data="{isAllowed: $wire.entangle('isAllowed').live}">
<div>
@if($isAllowed)
<div class="relative flex h-full">
@foreach($elections as $election)
<div class="w-full sm:w-1/3 p-4">
<div class="shadow-lg rounded-lg overflow-hidden">
{{ $election['year'] }}
</div>
<div class="shadow-lg rounded-lg overflow-hidden">
<x-textarea wire:model="elections.{{ $loop->index }}.candidates" rows="25" label="candidates" placeholder="" />
<x-textarea wire:model="elections.{{ $loop->index }}.candidates" rows="25"
label="candidates" placeholder=""/>
</div>
<div class="py-2">
<x-button label="Speichern" wire:click="saveElection({{ $loop->index }})"/>
@@ -69,5 +72,18 @@ $saveElection = function ($index) {
</div>
@endforeach
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">Einstellungen</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, die Einstellungen zu bearbeiten.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>

View File

@@ -48,8 +48,23 @@ on([
<x-layouts.app title="{{ __('Mitglieder') }}">
@volt
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto" x-show="isAllowed" x-data="{isAllowed: $wire.entangle('isAllowed').live}" x-cloak>
<div>
@if($isAllowed)
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<livewire:einundzwanzig-pleb-table/>
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">Mitglieder</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, Mitglieder zu bearbeiten.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>

View File

@@ -112,10 +112,12 @@ $handleNotApprove = function () {
?>
<x-layouts.app :seo="new SEOData(title: 'Unterstützung für: ' . $projectProposal->name,description: str($projectProposal->description)->limit(100, '...', true), image: $projectProposal->getFirstMediaUrl('main'))">
<x-layouts.app
:seo="new SEOData(title: 'Unterstützung für: ' . $projectProposal->name,description: str($projectProposal->description)->limit(100, '...', true), image: $projectProposal->getFirstMediaUrl('main'))">
@volt
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full" x-data="nostrDefault(@this)" x-cloak
x-show="isAllowed">
<div>
@if($isAllowed)
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full">
<!-- Page content -->
<div class="max-w-5xl mx-auto flex flex-col lg:flex-row lg:space-x-8 xl:space-x-16">
@@ -150,7 +152,8 @@ $handleNotApprove = function () {
<!-- Author -->
<div class="flex items-center sm:mr-4">
<a class="block mr-2 shrink-0" href="#0">
<img class="rounded-full" src="{{ $projectProposal->einundzwanzigPleb->profile->picture }}"
<img class="rounded-full"
src="{{ $projectProposal->einundzwanzigPleb->profile->picture }}"
width="32" height="32" alt="User 04">
</a>
<div class="text-sm whitespace-nowrap">Eingereicht von
@@ -173,7 +176,8 @@ $handleNotApprove = function () {
</div>
<figure class="mb-6">
<img class="rounded-sm h-48" src="{{ $projectProposal->getFirstMediaUrl('main') }}" alt="Meetup">
<img class="rounded-sm h-48" src="{{ $projectProposal->getFirstMediaUrl('main') }}"
alt="Meetup">
</figure>
<hr class="my-6 border-t border-gray-100 dark:border-gray-700/60">
@@ -187,7 +191,8 @@ $handleNotApprove = function () {
@foreach($reasons as $reason)
<li class="flex items-start">
<a class="block mr-3 shrink-0" href="#0">
<img class="rounded-full" src="{{ $reason->einundzwanzigPleb->profile->picture }}"
<img class="rounded-full"
src="{{ $reason->einundzwanzigPleb->profile->picture }}"
width="32" height="32"
alt="{{ $reason->einundzwanzigPleb->profile->name }}">
</a>
@@ -246,8 +251,10 @@ $handleNotApprove = function () {
<div class="grow flex items-center">
<div class="relative mr-3">
<img class="w-8 h-8 rounded-full"
src="{{ $vote->einundzwanzigPleb->profile->picture }}" width="32"
height="32" alt="{{ $vote->einundzwanzigPleb->profile->name }}">
src="{{ $vote->einundzwanzigPleb->profile->picture }}"
width="32"
height="32"
alt="{{ $vote->einundzwanzigPleb->profile->name }}">
</div>
<div class="truncate">
<span class="text-sm font-medium text-gray-800 dark:text-gray-100">
@@ -275,8 +282,10 @@ $handleNotApprove = function () {
<div class="grow flex items-center">
<div class="relative mr-3">
<img class="w-8 h-8 rounded-full"
src="{{ $vote->einundzwanzigPleb->profile->picture }}" width="32"
height="32" alt="{{ $vote->einundzwanzigPleb->profile->name }}">
src="{{ $vote->einundzwanzigPleb->profile->picture }}"
width="32"
height="32"
alt="{{ $vote->einundzwanzigPleb->profile->name }}">
</div>
<div class="truncate">
<span
@@ -296,5 +305,20 @@ $handleNotApprove = function () {
</div>
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">
Projekt-Unterstützung
</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, die Projekt-Unterstützungen einzusehen.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>

View File

@@ -72,8 +72,9 @@ $save = function () {
<x-layouts.app title="{{ $projectProposal->name }}">
@volt
<div x-cloak x-show="isAllowed" class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto"
x-data="nostrDefault(@this)">
<div>
@if($isAllowed)
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<form class="space-y-8 divide-y divide-gray-700 pb-24">
<div class="space-y-8 divide-y divide-gray-700 sm:space-y-5">
<div class="mt-6 sm:mt-5 space-y-6 sm:space-y-5">
@@ -139,5 +140,18 @@ $save = function () {
</div>
</form>
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">Projekt-Unterstützung</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, die Projekt-Unterstützungen zu bearbeiten.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>

View File

@@ -64,8 +64,9 @@ $save = function () {
<x-layouts.app title="Neuer Vorschlag für eine Unterstützung">
@volt
<div x-cloak x-show="isAllowed" class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto"
x-data="nostrDefault(@this)">
<div>
@if($isAllowed)
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<form class="space-y-8 divide-y divide-gray-700 pb-24">
<div class="space-y-8 divide-y divide-gray-700 sm:space-y-5">
<div class="mt-6 sm:mt-5 space-y-6 sm:space-y-5">
@@ -78,7 +79,8 @@ $save = function () {
@endif
@if (isset($projectProposal) && $projectProposal->getFirstMediaUrl('main'))
<div class="text-gray-200">{{ __('Current picture') }}:</div>
<img class="h-48 object-contain" src="{{ $projectProposal->getFirstMediaUrl('main') }}">
<img class="h-48 object-contain"
src="{{ $projectProposal->getFirstMediaUrl('main') }}">
@endif
</div>
<input class="text-gray-200" type="file" wire:model="image">
@@ -131,5 +133,19 @@ $save = function () {
</div>
</form>
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">
Projekt-Unterstützung</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, die Projekt-Unterstützungen zu bearbeiten.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>

View File

@@ -73,8 +73,9 @@ $delete = function ($id) {
:seo="new \RalphJSmit\Laravel\SEO\Support\SEOData(title: 'Projekt Unterstützungen', description: 'Einundzwanzig Projektunterstützungen')"
>
@volt
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto" x-data="nostrDefault(@this)" x-cloak
x-show="show">
<div>
@if($isAllowed)
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<!-- Page header -->
<div class="sm:flex sm:justify-between sm:items-center mb-5">
@@ -142,7 +143,8 @@ $delete = function ($id) {
<img class="absolute object-cover object-center w-full h-full"
src="{{ $project->getFirstMediaUrl('main') }}" alt="Meetup 01">
<button class="absolute top-0 right-0 mt-4 mr-4">
<img class="rounded-full h-8 w-8" src="{{ $project->einundzwanzigPleb->profile->picture }}"
<img class="rounded-full h-8 w-8"
src="{{ $project->einundzwanzigPleb->profile->picture }}"
alt="">
</button>
</a>
@@ -176,12 +178,14 @@ $delete = function ($id) {
@if($project->votes->where('value', true)->count() > 0)
<div class="flex items-center space-x-2">
<div class="text-xs font-medium text-gray-400 dark:text-gray-300 italic">
Anzahl der Unterstützer: +{{ $project->votes->where('value', true)->count() }}
Anzahl der Unterstützer:
+{{ $project->votes->where('value', true)->count() }}
</div>
</div>
@endif
</div>
<div class="flex flex-col sm:flex-row justify-between items-center mt-3 space-y-2 sm:space-y-0">
<div
class="flex flex-col sm:flex-row justify-between items-center mt-3 space-y-2 sm:space-y-0">
@if(
($currentPleb && $currentPleb->id === $project->einundzwanzig_pleb_id)
|| ($currentPleb && in_array($currentPleb->npub, config('einundzwanzig.config.current_board'), true))
@@ -214,5 +218,19 @@ $delete = function ($id) {
</div>
</div>
@else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
<div class="bg-white dark:bg-[#1B1B1B] shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg font-medium leading-6 text-gray-900 dark:text-gray-200">
Projektunterstützungen</h3>
<p class="mt-1 max-w">
Du bist nicht berechtigt, die Projektunterstützungen einzusehen.
</p>
</div>
</div>
</div>
@endif
</div>
@endvolt
</x-layouts.app>