-
Notifications
You must be signed in to change notification settings - Fork 6
#863 Impersonation #866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iccowan
wants to merge
24
commits into
main
Choose a base branch
from
863-impersonation-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
#863 Impersonation #866
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9195f62
#863 Fix controller dash navbar formatting
iccowan 75dcc41
#863 Lay framework for impersonation
iccowan 6e39399
#863 Add routes for impersonation and set session var
iccowan bd20657
#863 Implement impersonation
iccowan 2ba8002
#863 Add warning to users when impersonating
iccowan 6e5571a
#863 Filter out inactive users from impersonation
iccowan 7ce78ec
#863 Add visitor flag to impersonation list
iccowan 66d1c7b
#863 Put impersonation behind feature toggle
iccowan 44aa20b
#863 Fix formatting
iccowan d9bc82a
#863 Add impersonation to audit log
iccowan 1a51287
#863 Disable changing impersonation when impersonating
iccowan 99cee5c
#863 Track impersonation start/end in audit log
iccowan ec3d260
Fix formatting
iccowan 6796661
#863 Impersonation for web staff only
iccowan af90bf2
#863 Remove started impersonation message
iccowan 6bd58f5
#863 Add permanent impersonation warning banner
iccowan 1e1bfaf
#863 Remove old end impersonation button
iccowan 90a8187
Merge branch 'main' into 863-impersonation-implementation
kjporter 75307f4
Fix typo
kjporter e5603cd
Update Impersonation.php
kjporter 9d15450
Update impersonation_warning.blade.php
kjporter d6823d5
Update Impersonation.php
kjporter 681ef2c
Revert "Update Impersonation.php"
kjporter 5ca2c11
#863 Fix middleware logic for browser test
iccowan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Audit; | ||
| use App\Enums\SessionVariables; | ||
| use App\User; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class ImpersonationController extends Controller { | ||
| public function start(Request $request) { | ||
| $user = User::find($request->user_id); | ||
| $is_impersonating = session()->has(SessionVariables::IMPERSONATE->value); | ||
| if (is_null($user)) { | ||
| return redirect()->back()->with(SessionVariables::ERROR->value, 'That user does not exist'); | ||
| } | ||
|
|
||
| if ($is_impersonating) { | ||
| return redirect()->back()->with(SessionVariables::ERROR->value, 'You must first stop impersonating your current user before beginning a new session'); | ||
| } | ||
|
|
||
| session()->put(SessionVariables::IMPERSONATE->value, $user->id); | ||
| Audit::newAudit('started impersonating user ' . $user->impersonation_name . '.'); | ||
|
|
||
| return redirect('/dashboard'); | ||
| } | ||
|
|
||
| public function stop() { | ||
| Audit::newAudit('impersonation session ending...'); | ||
|
|
||
| session()->forget(SessionVariables::IMPERSONATE->value); | ||
| return redirect('/dashboard'); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,26 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Middleware; | ||
|
|
||
| use App\Enums\FeatureToggles; | ||
| use App\Enums\SessionVariables; | ||
| use Auth; | ||
| use Closure; | ||
| use Illuminate\Http\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| class Impersonation { | ||
| /** | ||
| * Handle an incoming request. | ||
| * | ||
| * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
| */ | ||
| public function handle(Request $request, Closure $next): Response { | ||
| if (toggleEnabled(FeatureToggles::IMPERSONATION) && session()->has(SessionVariables::IMPERSONATE->value) && Auth::check() && (Auth::user()->hasRole('wm') || Auth::user()->hasRole('awm'))) { | ||
| session()->put(SessionVariables::IMPERSONATING_USER->value, Auth::id()); | ||
| Auth::onceUsingId(session(SessionVariables::IMPERSONATE->value)); | ||
| } | ||
|
|
||
| return $next($request); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| <?php | ||
|
|
||
| namespace App\View\Composers; | ||
|
|
||
| use App\Enums\FeatureToggles; | ||
| use App\Enums\SessionVariables; | ||
| use App\User; | ||
| use Auth; | ||
| use Illuminate\View\View; | ||
|
|
||
| class ImpersonationComposer { | ||
| /** | ||
| * Create a new profile composer. | ||
| */ | ||
| public function __construct( | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Bind data to the view. | ||
| */ | ||
| public function compose(View $view): void { | ||
| if (toggleEnabled(FeatureToggles::IMPERSONATION)) { | ||
| $users = null; | ||
| $is_impersonating = session()->has(SessionVariables::IMPERSONATE->value); | ||
|
|
||
| if (Auth::user()->hasRole('wm') || Auth::user()->hasRole('awm')) { | ||
| $users = User::where('status', 1)->orderBy('lname', 'ASC')->get()->pluck('impersonation_name', 'id'); | ||
| } | ||
|
|
||
| $view->with('users', $users)->with('is_impersonating', $is_impersonating); | ||
| } | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
database/migrations/2026_02_23_141539_update_audits_add_impersonated_by_id_column.php
This file contains hidden or 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,27 @@ | ||
| <?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('audits', function (Blueprint $table) { | ||
| $table->integer('impersonated_by_id')->nullable(); | ||
|
|
||
| $table->foreign('impersonated_by_id')->references('id')->on('roster')->nullOnDelete(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void { | ||
| Schema::table('audits', function (Blueprint $table) { | ||
| $table->dropColumn('impersonated_by_id'); | ||
| }); | ||
| } | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,25 +1,26 @@ | ||
| <nav class="navbar navbar-expand-lg navbar-light"> | ||
| <div class="container-fluid"> | ||
| <nav class="navbar navbar-expand-lg navbar-light"> | ||
| <div class="container-fluid"> | ||
| <a class="navbar-brand" href="/dashboard"> | ||
| @include('inc.logo', ['color' => 'black']) | ||
| </a> | ||
| <div class="d-flex justify-content-start ms-5 collapse navbar-collapse"> | ||
|
|
||
| {{ html()->form()->route('searchAirport')->class(['row','row-cols-lg-auto'])->open() }} | ||
| <div class="col-12 input-group"> | ||
| {{ html()->text('apt', null)->placeholder('Search Airport ICAO')->class(['form-control']) }} | ||
| | ||
| <button class="btn btn-success" type="submit">Search</button> | ||
| </div> | ||
| <ul class="navbar-nav me-auto align-items-center"> | ||
| {{ html()->form()->route('searchAirport')->class(['form-inline'])->open() }} | ||
| <div class="col-12 input-group"> | ||
| {{ html()->text('apt', null)->placeholder('Search Airport ICAO')->class(['form-control']) }} | ||
| | ||
| <button class="btn btn-success" type="submit">Search</button> | ||
| </div> | ||
| {{ html()->form()->close() }} | ||
| </ul> | ||
| <ul class="navbar-nav ml-auto align-items-center"> | ||
| <a class="nav-link {{ Nav::isRoute('controller_dash_home') }}" href="/dashboard">Dashboard Home</a> | ||
| @if(toggleEnabled($FeatureToggles::IMPERSONATION) && (Auth::user()->hasRole('wm') || Auth::user()->hasRole('awm'))) | ||
| {{ html()->form()->route('startImpersonation')->class(['form-inline'])->open() }} | ||
| {{ html()->select('user_id', $users, Auth::id())->class(['form-select'])->attributes(['onchange' => 'this.form.submit()'])->disabled($is_impersonating) }} | ||
| {{ html()->form()->close() }} | ||
| </div> | ||
|
|
||
| <ul class="navbar-nav ms-auto"> | ||
| <a class="nav-link {{ Nav::isRoute('controller_dash_home') }}" href="/dashboard">Dashboard Home</a> | ||
| <li class="nav-item dropdown"> | ||
| <a class="nav-link" style="pointer-events:none">{{ Auth::user()->full_name }} - {{ Auth::user()->rating_short }}</a> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| @else | ||
| <a class="nav-link disabled">{{ Auth::user()->full_name }} - {{ Auth::user()->rating_short }}</a> | ||
| @endif | ||
| </ul> | ||
| </div> | ||
| </nav> |
This file contains hidden or 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,6 @@ | ||
| @if(isset($is_impersonating) && $is_impersonating && toggleEnabled($FeatureToggles::IMPERSONATION)) | ||
| <br> | ||
| <a class="d-block alert alert-warning" href="/dashboard/admin/impersonation/stop"> | ||
| WARNING: You are currently impersonating a user. Use extreme caution as any action you perform will be performed as that user, and will be tracked as so with you as the impersonator. This should be used for debugging and development only! Click this warning at any time to end impersonation. | ||
| </a> | ||
| @endif |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.