Restrict Categories Filter Entries

  • Paul Adamson
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
3 months 5 days ago #124220 by Paul Adamson
Restrict Categories Filter Entries was created by Paul Adamson
Hi Tuan, is it possible to restrict the categories that appear in the tickets list view filter? I have a scenario where its important that some registered users don't see some categories in the dropdown. I have it working for the New Ticket form, so I know I have the access levels correct. It would be great if I could figure how to restrict the categories filter to only show categories a user is permitted to create tickets in.

Cheers
Paul

Please Log in or Create an account to join the conversation.

  • Paul Adamson
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
3 months 4 days ago #124239 by Paul Adamson
Replied by Paul Adamson on topic Restrict Categories Filter Entries
I solved this by borrowing this code from how the ticket form displays:

$user = Factory::getUser();
$rows = HelpdeskproHelperDatabase::getAllCategories(
    'ordering',
    array('access IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')')
);

$this->lists['filter_category_id'] = HelpdeskproHelperHtml::buildCategoryDropdown(
        $this->state->filter_category_id,
        'filter_category_id',
        'class="" onchange="submit();"',
        $rows
);

And using it at the top of the template override for the tickets list view. Now this only populates the category fiilter dropdown on the list view with categories the user is eligible to view.

Please Log in or Create an account to join the conversation.

More
3 months 4 days ago #124246 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Restrict Categories Filter Entries
Thanks Paul. This is something we should fix in core package. Please get this file, unzip it, upload to components/com_helpdeskpro/View/Tickets folder on your site. Then remove the override and check result to see whether it's working as expected

Regards,

Tuan
Attachments:

Please Log in or Create an account to join the conversation.

  • Paul Adamson
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
3 months 3 days ago #124276 by Paul Adamson
Replied by Paul Adamson on topic Restrict Categories Filter Entries
It doesn't quite work. I see that the access level is now checked, but that call to return $rows still comes up empty, and so the dropdown is then built with all possible values of categories, instead of only auth'ed categories.

I'm thinking that the query needs to look like this:

(id IN (0)
OR id IN (SELECT DISTINCT category_id FROM #__helpdeskpro_tickets AS t WHERE t.staff_id =508)
OR access IN (1,1,2,17)
)

since this way you only get categories if he's a staff member assigned to thaat category OR he is given access via usergroup.

My Groups and Levels look like this:

Groups:
- Registered
-- Group 1 (22)
-- Group 2 (23)
-- Group 3 (24)

Levels:
Group 1 -> Level 1 (19)
Group 2 -> Level 2 (18)
Group 3 -> Level 3 (17)

And then in the helpdesk categories:
Cat 1 -> Level 1
Cat 2 -> Level 2
Cat 3 -> Level 3

My Test User (id=508) belongs to Group 3, but his listview category dropdown shows all categories.

I also saw that if a user is only a member of Registered, then again the listview dropdown contains all categories.

Paul

Please Log in or Create an account to join the conversation.

Moderators: Tuan Pham Ngoc