You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OTRS中基于DynamicField值实现自定义客户权限模块的咨询

OTRS 客户侧审批人权限校验模块修改方案

改动核心逻辑

  • 工单查询时开启动态字段加载,获取DynamicField_ApproverList值
  • 从当前登录客户用户数据中提取邮箱字段
  • 忽略大小写比对两个值,匹配则返回权限允许标识1

修改后完整代码

# --
# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --

package Kernel::System::Ticket::CustomerPermission::CustomerUserIDCheck;

use strict;
use warnings;

our @ObjectDependencies = (
    'Kernel::System::CustomerUser',
    'Kernel::System::Log',
    'Kernel::System::Ticket',
);

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    # 校验必填入参
    for (qw(TicketID UserID)) {
        if ( !$Param{$_} ) {
            $Kernel::OM->Get('Kernel::System::Log')->Log(
                Priority => 'error',
                Message  => "Need $_!",
            );
            return;
        }
    }

    # 读取工单数据,开启动态字段加载
    my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
        TicketID      => $Param{TicketID},
        DynamicFields => 1,
    );

    return if !%Ticket;
    # 校验动态字段是否存在值
    return if !$Ticket{DynamicField_ApproverList};

    # 读取当前登录客户用户数据
    my %CustomerData = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserDataGet(
        User => $Param{UserID},
    );

    return if !%CustomerData;
    # 校验用户邮箱是否存在
    return if !$CustomerData{UserEmail};

    # 忽略大小写比对邮箱和审批人列表字段值,匹配则返回权限允许
    return 1 if lc $Ticket{DynamicField_ApproverList} eq lc $CustomerData{UserEmail};

    # 不匹配则无返回,默认无权限
    return;
}

1;

关键改动说明

  • 工单查询参数调整:将DynamicFields参数从0改为1,才能读取到工单的所有动态字段值
  • 替换了原有的客户用户ID校验逻辑,改为校验动态字段DynamicField_ApproverList和客户用户的UserEmail
  • 新增了动态字段值、用户邮箱的空值防御,避免字段为空时抛出异常
  • 若你的DynamicField_ApproverList为多值字段(存储多个邮箱用逗号/分号分隔),可将比对逻辑改为拆分字符串后循环匹配即可

内容的提问来源于stack exchange,提问作者firewill

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 05:06:03