Hello,
I have duplicated the "New phone ticket" item in the menu bar in order to have two calls to AgentTicketPhone.
The first call has a parameter set as "full" (and is visible to admin only) and the other one set as "simple" (and visible to non-admin users only).
The goal is to allow administrator to have more control on the ticket creation than the other users.
This is working, however not in a "secure" way. The URL contains the parameter and by knowing the possible values, it is easy to access the two versions of the template.
Is there any other way to proceed ? Thank you in advance !
Hide/display fields based on user credentials
Moderator: crythias
-
- Znuny newbie
- Posts: 14
- Joined: 09 Jul 2013, 17:54
- Znuny Version: 3.2.6
-
- Znuny guru
- Posts: 5018
- Joined: 13 Mar 2011, 09:54
- Znuny Version: 6.0.x
- Real Name: Renée Bäcker
- Company: Perl-Services.de
- Contact:
Re: Hide/display fields based on user credentials
Add code to Kernel/Modules/AgentTicketPhone.pm that checks the group of the user based on the provided parameter. Something like:
Note that this code probably does not work. You have to adopt it to your system...
Code: Select all
my %Groups = $GroupObject->GroupMemberList(
UserID => $ID,
Type => 'rw',
Result => 'HASH',
);
my $VersionParam = $Self->{ParamObject}->GetParam( Param => 'xxxx' );
if ( $VersionParam eq 'full' && !grep{ $_ eq 'admin' }values %Groups ) {
die "You're not allowed to use this feature";
}
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
-
- Znuny newbie
- Posts: 14
- Joined: 09 Jul 2013, 17:54
- Znuny Version: 3.2.6
Re: Hide/display fields based on user credentials
Wow, faster than light! Thanks, I'll work on this immediately!
-
- Znuny newbie
- Posts: 14
- Joined: 09 Jul 2013, 17:54
- Znuny Version: 3.2.6
Re: Hide/display fields based on user credentials
Hi again,
I have tried with success (
) by adding the below lines into the "new" sub of AgentTicketPhone.pm.
Now the agents member of "admin" have access to the "FULL" version of the template and the other agents have access to the "SIMPLE" version of the same template.
As I'm a beginner with OTRS, could you please just take a look and tell me if it looks ok?
Thanks a lot!
I have tried with success (

Now the agents member of "admin" have access to the "FULL" version of the template and the other agents have access to the "SIMPLE" version of the same template.
Code: Select all
my $ID = $Self->{UserID};
my %Groups = $Self->{GroupObject}->GroupMemberList(
UserID => $Self->{UserID},
Type => 'rw',
Result => 'HASH',
);
my $VersionParam = $Self->{ParamObject}->GetParam( Param => 'DynamicField_AgentTemplate' );
if ( $VersionParam eq "SIMPLE" ) {
if ( grep{ $_ eq 'admin' }values %Groups ) {
die "You're not allowed to use this feature";
}
} elsif ( $VersionParam eq "FULL") {
if ( !grep{ $_ eq 'admin' }values %Groups ) {
die "You're not allowed to use this feature";
}
} else {
die "You're not allowed to use this feature";
}
Thanks a lot!
-
- Znuny newbie
- Posts: 14
- Joined: 09 Jul 2013, 17:54
- Znuny Version: 3.2.6
Re: Hide/display fields based on user credentials
Well, and there should be a way to force the parameter to FULL/SIMPLE according to the group like in the code below, right?
The above code has no effect, however I can see in a Dump that the scalar seems to be set correctly.
Code: Select all
my %Groups = $Self->{GroupObject}->GroupMemberList(
UserID => $Self->{UserID},
Type => 'rw',
Result => 'HASH',
);
if ( grep{ $_ eq 'admin' }values %Groups ) {
$Self->{'ParamObject'}->{'Query'}->{'param'}->{'DynamicField_AgentTemplate'}="FULL";
} else {
$Self->{'ParamObject'}->{'Query'}->{'param'}->{'DynamicField_AgentTemplate'}="SIMPLE";
}
-
- Znuny newbie
- Posts: 14
- Joined: 09 Jul 2013, 17:54
- Znuny Version: 3.2.6
Re: Hide/display fields based on user credentials
Ok, I'll post my solution in case someone finds it useful.
1. First step is to create a dynamic field (named AgentTemplate in my example).
2. Then, in the AgentTicketPhone.pm module, sub new, I have added the below code to provide information to the AgentTicketPhone.dtl:
3. Add the following to AgentTicketPhone.dtl (at the end, after the Core.Agent.TicketAction.Init()):
Into the "case" statement, I setup what I want to show/hide, and other settings to be applied in specific cases.
1. First step is to create a dynamic field (named AgentTemplate in my example).
2. Then, in the AgentTicketPhone.pm module, sub new, I have added the below code to provide information to the AgentTicketPhone.dtl:
Code: Select all
# provide information to the ticket template (admin=FULL, others=SIMPLE)
my %Groups = $Self->{GroupObject}->GroupMemberList(
UserID => $Self->{UserID},
Type => 'rw',
Result => 'HASH',
);
if ( grep{ $_ eq 'admin' }values %Groups ) {
push(@{$Self->{'ParamObject'}->{'Query'}->{'param'}->{'DynamicField_AgentTemplate'}},"FULL")
} else {
push(@{$Self->{'ParamObject'}->{'Query'}->{'param'}->{'DynamicField_AgentTemplate'}},"SIMPLE")
}
Code: Select all
switch($('#DynamicField_AgentTemplate').val()) {
case "FULL":
...
break;
case "SIMPLE":
...
break;
default:
}