xlite-dev/filament-impersonate 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

xlite-dev/filament-impersonate

Composer 安装命令:

composer require xlite-dev/filament-impersonate

包简介

This is my package filament-impersonate

README 文档

README

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require xlite-dev/filament-impersonate:^3.0

Compatibility

Package version Filament version
v2 v3
v3 v4, v5

Usage

1. Add Table action

Open the resource where you want the impersonate action to appear. This is generally going to be your UserResource class.

Go down to the table method. Inside actions or prependActions add ImpersonateAction::make as a new action for the table. Your class should look like this:

namespace App\Filament\Resources;

use Filament\Resources\Resource;
use XliteDev\FilamentImpersonate\Actions\ImpersonateAction; // <---

class UserResource extends Resource {
    // ...

    public static function table(Table $table)
    {
        return $table
            ->columns([
                // ...
            ])
            ->actions([
                ImpersonateAction::make(), // <--- 
                // ...
            ]);
    }

You should now see an action icon next to each user in your Filament UserResource list:

image

When you click on the impersonate icon you will be logged in as that user, and redirected to your main app. You will see the impersonation banner at the top of the page, with a button to leave and return to Filament:

image

2. Add Page action

Open EditUser or ViewUser class, where you want the impersonate action to appear.

Go down to the getActions method and add ImpersonateAction::make as a new action for the page. Your class should look like this:

namespace App\Filament\Resources;

use Filament\Resources\Resource;
use XliteDev\FilamentImpersonate\Actions\ImpersonateAction; // <---

class EditUser extends ViewRecord
{
    // ...

    protected function getActions(): array
    {
        return [
            ImpersonateAction::make()->record($this->getRecord()), // <---
            // ...
        ];
    }

You should now see an action icon on the EditUser or ViewUser page:

image

Configuration

You can publish the config file with:

php artisan vendor:publish --tag="filament-impersonate-config"

This is the contents of the published config file:

return [

    // This is the guard used when logging in as the impersonated user.
    'guard' => env('FILAMENT_IMPERSONATE_GUARD', 'web'),

    // After impersonating this is where we'll redirect you to.
    'redirect_to' => env('FILAMENT_IMPERSONATE_REDIRECT', '/'),

    // We wire up a route for the "leave" button. You can change the middleware stack here if needed.
    'leave_middlewares' => [
        env('FILAMENT_IMPERSONATE_LEAVE_MIDDLEWARE', 'web'),
    ],

    'banner' => [
        // Currently supports 'dark' and 'light'.
        'style' => env('FILAMENT_IMPERSONATE_BANNER_STYLE', 'dark'),

        // Turn this off if you want `absolute` positioning, so the banner scrolls out of view
        'fixed' => env('FILAMENT_IMPERSONATE_BANNER_FIXED', true),

        // Currently supports 'top' and 'bottom'.
        'position' => env('FILAMENT_IMPERSONATE_BANNER_POSITION', 'top'),
    ],
];

Authorization

By default, only Filament admins can impersonate other users. You can control this by adding a canImpersonate method to your FilamentUser class:

class User implements FilamentUser {
    
    public function canImpersonate()
    {
        return true;
    }
    
}

You can also control which targets can be impersonated. Just add a canBeImpersonated method to the user class with whatever logic you need:

class User {

    public function canBeImpersonated()
    {
        // Let's prevent impersonating other users at our own company
        return !Str::endsWith($this->email, '@mycorp.com');
    }
    
}

Customizing the banner

You can publish the views using

php artisan vendor:publish --tag="filament-impersonate-views"

The blade component has a few options you can customize.

Style

The banner is dark by default, you can set this to light:

<x-filament-impersonate::banner style='light'/>

Display name

The banner will show the name of the impersonated user, assuming there is a name attribute. You can customize this if needed:

<x-filament-impersonate::banner :display='auth()->user()->email'/>

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

xlite-dev/filament-impersonate 适用场景与选型建议

xlite-dev/filament-impersonate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59.51k 次下载、GitHub Stars 达 41, 最近一次更新时间为 2022 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「XliteDev」 「filament-impersonate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 xlite-dev/filament-impersonate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 xlite-dev/filament-impersonate 我们能提供哪些服务?
定制开发 / 二次开发

基于 xlite-dev/filament-impersonate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 59.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 41
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 41
  • Watchers: 3
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-27