-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manager role means read-only access to all devices within the application. It's meant for network operators, becase they might find it useful while debugging network issues.
- Loading branch information
1 parent
80b46e5
commit a4d4d18
Showing
21 changed files
with
442 additions
and
7 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
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,42 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Mail\UserSubroleChanged; | ||
use App\Mail\YourSubroleChanged; | ||
use App\Models\User; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class UserSubroleController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
} | ||
|
||
public function update(Request $request, User $user): RedirectResponse | ||
{ | ||
$this->authorize('do-everything'); | ||
|
||
if ($request->user()->is($user)) { | ||
return to_route('users.show', $user) | ||
->with('status', __('users.cannot_toggle_your_role')) | ||
->with('color', 'red'); | ||
} | ||
|
||
$user->manager = $user->manager ? false : true; | ||
$user->update(); | ||
|
||
Mail::send(new UserSubroleChanged($user)); | ||
Mail::send(new YourSubroleChanged($user)); | ||
|
||
$role = $user->manager ? 'managered' : 'demanagered'; | ||
$color = $user->manager ? 'indigo' : 'yellow'; | ||
|
||
return to_route('users.show', $user) | ||
->with('status', __("users.{$role}", ['name' => $user->name])) | ||
->with('color', $color); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class UserSubroleChanged extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new message instance. | ||
*/ | ||
public function __construct(public User $user) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
*/ | ||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
to: User::activeAdminsEmails(), | ||
subject: __('emails.user_subrole_changed_subject', ['name' => $this->user->name]), | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
*/ | ||
public function content(): Content | ||
{ | ||
return new Content( | ||
markdown: 'emails.user_subrole_changed', | ||
); | ||
} | ||
|
||
/** | ||
* 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,54 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Address; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class YourSubroleChanged extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new message instance. | ||
*/ | ||
public function __construct(public User $user) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
*/ | ||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
to: [new Address($this->user->email, $this->user->name)], | ||
subject: __('emails.your_subrole_changed_subject'), | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
*/ | ||
public function content(): Content | ||
{ | ||
return new Content( | ||
markdown: 'emails.your_subrole_changed', | ||
); | ||
} | ||
|
||
/** | ||
* 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
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
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_02_06_191541_add_manager_to_users_table.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->boolean('manager')->default(false)->after('admin'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('manager'); | ||
}); | ||
} | ||
}; |
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
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
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,8 @@ | ||
<x-mail::message> | ||
|
||
# {{ __('emails.user_subrole_changed_header') }} | ||
|
||
{{ $user->manager ? __('emails.user_subrole_changed_body_granted', ['name' => $user->name]) : __('emails.user_subrole_changed_body_revoked', ['name' => $user->name]) }} | ||
|
||
{{ config('app.name') }} | ||
</x-mail::message> |
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,8 @@ | ||
<x-mail::message> | ||
|
||
# {{ __('emails.your_subrole_changed_subject') }} | ||
|
||
{{ $user->manager ? __('emails.your_subrole_changed_body_granted') : __('emails.your_subrole_changed_body_revoked') }} | ||
|
||
{{ config('app.name') }} | ||
</x-mail::message> |
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,25 @@ | ||
<form x-data="{ open: false }" class="inline-block" action="{{ route('users.subrole', $user) }}" method="POST"> | ||
@csrf | ||
@method('patch') | ||
|
||
@if ($user->manager) | ||
<x-button @click.prevent="open = !open" color="blue">{{ __('common.manager_revoke') }}</x-button> | ||
@else | ||
<x-button @click.prevent="open = !open" color="red">{{ __('common.manager_grant') }}</x-button> | ||
@endif | ||
|
||
<x-modal> | ||
<x-slot:title> | ||
@if ($user->manager) | ||
{{ __('common.manager_revoke_rights') }} | ||
@else | ||
{{ __('common.manager_grant_rights') }} | ||
@endif | ||
</x-slot:title> | ||
@if ($user->manager) | ||
{{ __('common.manager_revoke_rights_body', ['name' => $user->name]) }} | ||
@else | ||
{{ __('common.manager_grant_rights_body', ['name' => $user->name]) }} | ||
@endif | ||
</x-modal> | ||
</form> |
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
Oops, something went wrong.