-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #564 from HZ-HBO-ICT/feature/555-feedback-system
Feature - Feedback system
- Loading branch information
Showing
23 changed files
with
620 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Crew; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Feedback; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\View\View; | ||
|
||
class FeedbackController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* @return View | ||
*/ | ||
public function index() : View | ||
{ | ||
if (Auth::user()->cannot('viewAny', Feedback::class)) { | ||
abort(403); | ||
} | ||
|
||
$feedbackReports = Feedback::all(); | ||
|
||
return view('crew.feedback.index', compact('feedbackReports')); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* @param Feedback $feedback | ||
* @return View | ||
*/ | ||
public function show(Feedback $feedback) : View | ||
{ | ||
if (Auth::user()->cannot('view', $feedback)) { | ||
abort(403); | ||
} | ||
|
||
return view('crew.feedback.show', compact('feedback')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Crew; | ||
|
||
use App\Models\User; | ||
use Illuminate\View\View; | ||
use LivewireUI\Modal\ModalComponent; | ||
|
||
class AddTeam extends ModalComponent | ||
{ | ||
public User $user; | ||
public $crew_team; | ||
|
||
/** | ||
* Initializes the component | ||
* @param User $user | ||
* @return void | ||
*/ | ||
public function mount(User $user) | ||
{ | ||
$this->user = $user; | ||
$this->crew_team = $user->crew_team; | ||
} | ||
|
||
/** | ||
* Saves the tag for the user | ||
*/ | ||
public function save() | ||
{ | ||
$validated = $this->validate([ | ||
'crew_team' => 'required|in:organization,website' | ||
]); | ||
|
||
$this->user->update([ | ||
'crew_team' => $this->crew_team | ||
]); | ||
|
||
return redirect()->to(route('moderator.crew.index')); | ||
} | ||
|
||
/** | ||
* Removes the set team of the crew user | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function removeTeam() | ||
{ | ||
$this->user->update([ | ||
'crew_team' => null | ||
]); | ||
|
||
return redirect()->to(route('moderator.crew.index')); | ||
} | ||
|
||
/** | ||
* Renders the component | ||
* @return View | ||
*/ | ||
public function render(): View | ||
{ | ||
return view('livewire.crew.add-team'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\Feedback; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class FeedbackReceivedMailable extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new message instance. | ||
*/ | ||
public function __construct( | ||
public Feedback $feedback | ||
) { | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
*/ | ||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
subject: "Feedback Received for team {$this->feedback->type}", | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
*/ | ||
public function content(): Content | ||
{ | ||
return new Content( | ||
markdown: 'emails.feedback-received', | ||
); | ||
} | ||
|
||
/** | ||
* Get the attachments for the message. | ||
* | ||
* @return array<int, \Illuminate\Mail\Mailables\Attachment> | ||
*/ | ||
public function attachments(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Observers\FeedbackObserver; | ||
use Illuminate\Database\Eloquent\Attributes\ObservedBy; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
#[ObservedBy([FeedbackObserver::class])] | ||
class Feedback extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = ['type', 'title', 'content', 'reported_by_id']; | ||
|
||
public static $rules = [ | ||
'type' => 'required|in:organization,website', | ||
'title' => 'required|max:255|string', | ||
'content' => 'required|max:1500|string', | ||
]; | ||
|
||
/** | ||
* Establishes connection to the user who gave the feedback | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
public function reportedBy() | ||
{ | ||
return $this->belongsTo(User::class, 'reported_by_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Observers; | ||
|
||
use App\Mail\FeedbackReceivedMailable; | ||
use App\Models\Feedback; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class FeedbackObserver | ||
{ | ||
/** | ||
* Handle the Feedback "created" event. | ||
*/ | ||
public function created(Feedback $feedback): void | ||
{ | ||
$crew = User::where('crew_team', $feedback->type)->get(); | ||
foreach ($crew as $user) { | ||
Mail::to($user->email)->send(new FeedbackReceivedMailable($feedback)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Feedback; | ||
use App\Models\User; | ||
|
||
class FeedbackPolicy | ||
{ | ||
/** | ||
* Determines whether the user can create feedback | ||
* | ||
* @param User $user | ||
* @return bool | ||
*/ | ||
public function create(User $user) | ||
{ | ||
return !$user->is_crew; | ||
} | ||
|
||
/** | ||
* Determines whether the user can view any feedback | ||
* @param User $user | ||
* @return bool | ||
*/ | ||
public function viewAny(User $user) | ||
{ | ||
return $user->can('viewAny feedback'); | ||
} | ||
|
||
/** | ||
* Determines whether the user can view specific feedback | ||
* @param User $user | ||
* @param Feedback $feedback | ||
* @return bool | ||
*/ | ||
public function view(User $user, Feedback $feedback) | ||
{ | ||
return $user->can('viewAny feedback'); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_10_16_141617_add_tag_to_users_for_crew.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->enum('crew_team', ['organization', 'website'])->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('crew_team'); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.