webman-admin普通管理员添加数据无法自动生成admin_id

漫步者321

问题描述

webman-admin普通管理员添加限制为auth数据时无法自动生成admin_id,看Crud.php中代码好像必须要前台传admin_id参数过来,不能自动获取当前管理员ID.

程序代码或配置

/**
     * 插入前置方法
     * @param Request $request
     * @return array
     * @throws BusinessException
     */
    protected function insertInput(Request $request): array
    {
        $data = $this->inputFilter($request->post());
        $password_filed = 'password';
        if (isset($data[$password_filed])) {
            $data[$password_filed] = Util::passwordHash($data[$password_filed]);
        }

        if (!Auth::isSuperAdmin()) {
            if ($this->dataLimit === 'personal') {
                $data[$this->dataLimitField] = admin_id();
            } elseif ($this->dataLimit === 'auth') {
                if (!empty($data[$this->dataLimitField])) {
                    $admin_id = $data[$this->dataLimitField];
                    if (!in_array($admin_id, Auth::getScopeAdminIds(true))) {
                        throw new BusinessException('无数据权限');
                    }
                }
            }
        } elseif ($this->dataLimit && empty($data[$this->dataLimitField])) {
            $data[$this->dataLimitField] = admin_id();
        }
        return $data;
    }

重现问题的步骤

1、添加普通管理员
2、普通管理员登录添加限制为auth的数据提示缺少admin_id

操作系统环境及workerman/webman等具体版本

windows10 Workerman version:4.1.15

461 1 1
1个回答

walkor 打赏

发下报错,报错发全

  • 漫步者321 2024-06-05

    SQLSTATE[HY000]: General error: 1364 Field 'admin_id' doesn't have a default value (SQL: insert into wa_cars (plate, carmodel, carseries, driver_id, review, insure, mileage, status, updated_at, created_at) values (ddd, z5s, benchi, 5, ?, ?, ?, 0, 2024-06-05 14:01:43, 2024-06-05 14:01:43))

  • walkor 2024-06-05

    SQL报错的意思是向 wa_cars 表写入数据的时候没传 admin_id,传下admin_id就好了。和权限是不是auth没有关系

  • 漫步者321 2024-06-05

    admin_id不是应该自动生成吗,你看代码中如果是超级管理员就会自动生成,为什么普通管理员就不行?这是基于什么考虑吗

  • 漫步者321 2024-06-05

    if (!Auth::isSuperAdmin()) {
    if ($this->dataLimit === 'personal') {
    $data[$this->dataLimitField] = admin_id(); //personal权限会自动生成admin_id参数
    } elseif ($this->dataLimit === 'auth') { //为什么auth权限就不能自动生成admin_id参数而必须要手动传这个参数?
    if (!empty($data[$this->dataLimitField])) {
    $admin_id = $data[$this->dataLimitField];
    if (!in_array($admin_id, Auth::getScopeAdminIds(true))) {
    throw new BusinessException('无数据权限');
    }
    }
    }
    } elseif ($this->dataLimit && empty($data[$this->dataLimitField])) {
    $data[$this->dataLimitField] = admin_id();//超级管理员权限会自动生成admin_id参数
    }

  • walkor 2024-06-05
    if (!empty($data[$this->dataLimitField])) {
                        $admin_id = $data[$this->dataLimitField];
                        if (!in_array($admin_id, Auth::getScopeAdminIds(true))) {
                            throw new BusinessException('无数据权限');
                        }
                    } else {
                        $data[$this->dataLimitField] = admin_id();
                    }

    改成这样试下

×
🔝