@@ -182,4 +182,64 @@ my $cf;
182182 is_deeply( JSON::from_json( $m -> content ), $result , ' Found by Content' );
183183}
184184
185+ $m -> logout;
186+
187+ # Create a user with limited rights
188+ my $user = RT::User-> new(RT-> SystemUser);
189+ my ($user_id , $user_msg ) = $user -> Create(
190+ Name => ' limited_user_' . $$ ,
191+ Password => ' password' ,
192+ Privileged => 1,
193+ );
194+ ok($user_id , " Created limited user: $user_msg " );
195+ $m -> login($user -> Name, ' password' );
196+
197+ # test articles autocomplete with rights-based filtering and max limit
198+ {
199+ # Create a second article class
200+ my $class1 = RT::Class-> new(RT-> SystemUser);
201+ my ($class1_id , $class1_msg ) = $class1 -> Create(
202+ Name => ' Visible-' . $$ ,
203+ Description => ' Visible class' ,
204+ );
205+ ok($class1_id , " Created visible class: $class1_msg " );
206+
207+ my $class2 = RT::Class-> new(RT-> SystemUser);
208+ my ($class2_id , $class2_msg ) = $class2 -> Create(
209+ Name => ' Hidden-' . $$ ,
210+ Description => ' Hidden class' ,
211+ );
212+ ok($class2_id , " Created hidden class: $class2_msg " );
213+
214+ # Grant ShowArticle right only on the visible class
215+ my ($ok , $msg ) = $user -> PrincipalObj-> GrantRight(
216+ Right => ' ShowArticle' ,
217+ Object => $class1 ,
218+ );
219+ ok($ok , " Granted ShowArticle on visible class: $msg " );
220+
221+ # Create 3 articles with the same search term
222+ # Article 1 is visible, article 2 is hidden, article 3 is visible
223+ my @articles ;
224+ my @classes = ($class1 , $class2 , $class1 );
225+ for my $i (1..3) {
226+ my $art = RT::Article-> new(RT-> SystemUser);
227+ my ($id , $art_msg ) = $art -> Create(
228+ Class => $classes [$i -1]-> Name,
229+ Name => " MaxResults Article $i " . $$ ,
230+ Summary => " MaxResults test article $i " ,
231+ );
232+ ok($id , " Created article $i : $art_msg " );
233+ push @articles , $art ;
234+ }
235+
236+ # Test with max=2: should get 2 results from the 2 visible articles
237+ $m -> get_ok(' /Helpers/Autocomplete/Articles?return=id&term=MaxResults&max=2' );
238+ my $results = JSON::from_json($m -> content);
239+
240+ is(scalar @$results , 2, ' Returns 2 results when max=2 and 2 visible articles exist' );
241+ is($results -> [0]-> {value }, $articles [0]-> id, ' First visible article is returned' );
242+ is($results -> [1]-> {value }, $articles [2]-> id, ' Third article (second visible) is returned' );
243+ }
244+
185245done_testing();
0 commit comments