summaryrefslogtreecommitdiff
path: root/rt/t/api/cf_rights.t
blob: f55214a66e2fb942248dfbfa031edc455fa1dd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
use warnings;
use strict;

use RT;
use RT::Test tests => 12;

my $q = RT::Queue->new($RT::SystemUser);
my ($id,$msg) =$q->Create(Name => "CF-Rights-".$$);
ok($id,$msg);

my $cf = RT::CustomField->new($RT::SystemUser);
($id,$msg) = $cf->Create(Name => 'CF-'.$$, Type => 'Select', MaxValues => '1', Queue => $q->id);
ok($id,$msg);


($id,$msg) =$cf->AddValue(Name => 'First');
ok($id,$msg);

my $u = RT::User->new($RT::SystemUser);
($id,$msg) = $u->Create( Name => 'User1', Privileged => 1 );
ok ($id,$msg);

($id,$msg) = $u->PrincipalObj->GrantRight( Object => $cf, Right => 'SeeCustomField' );
ok ($id,$msg);

my $ucf = RT::CustomField->new($u);
($id,$msg) = $ucf->Load( $cf->Id );
ok ($id,$msg);

my $cfv = $ucf->Values->First;

($id,$msg) = $cfv->SetName( 'First1' );
ok (!$id,$msg);

($id,$msg) = $u->PrincipalObj->GrantRight( Object => $cf, Right => 'AdminCustomFieldValues' );
ok ($id,$msg);

($id,$msg) = $cfv->SetName( 'First2' );
ok ($id,$msg);

($id,$msg) = $u->PrincipalObj->RevokeRight( Object => $cf, Right => 'AdminCustomFieldValues' );
ok ($id,$msg);

($id,$msg) = $u->PrincipalObj->GrantRight( Object => $cf, Right => 'AdminCustomField' );
ok ($id,$msg);

($id,$msg) = $cfv->SetName( 'First3' );
ok ($id,$msg);

1;