• Fabrik4.5.3 for J!5.3.0 and J!4.2+is out

    You must update from Fabrik4.5.1 if you are running Joomla!5.3.0

    See Announcements

Filtering records by UserGroups

jj-pilot

Member
Hi guys,
I've been trying to figure out how I can filter records by UserGroup access-levels.

  • I have a List (of course :)
  • I publish the list through a Link on my front-page
  • How can I make sure that members of UserGroup XYZ, only see records belonging to them?
Can anyone point me to the place in the WIKI where I can read more (haven't been able to find) - or even better: tell how it is done ?

Thanks a lot :)

John
 
Thanks for your response, appreciated :)

As far as I can tell, the example in the video is based on ACCESS levels.

But my challenge is a bit different, since I'm trying to access by UserGroups.

Let say I have a UserGroup called XYZ. Members of that group can have different access levels.

So, I want the User to see ALL the records belonging to his/her related UserGroups.

I have made a UserGroup field (element), and can pick the relevant UserGroup in there.

So far, so good

But how do I make this restriction:
Show all records, where UserGroup element, relates to UserGroups, that this specific User has got access to?

Hope this makes sense...
 
Hi there

I had a similar case where I needed to filter the edit access according to a user group. Here's how I did it:

- I used a Joomla custom field in the user management to assign each user to the right group. In particular: Only members from a particular patish can edit the datasets from their parish, everybody else can only view.
- I added a hidden Calc element "can_access" to each dataset that determines whether the current user is belonging to the same parish as the dataset. Cals on Load = Yes
- Then I use the caneditrow plugin in the list section that shows the edit button only if the can_access element = 1

Obviously, you need to use the canviewrow plugin.

Here's the calculation of the can_acces element

Code:
$groups ='{$my->groups}';
if (strpos($groups, '8') !== false) {
  return '1'; // members of superuser group have always acces
}
 $parac = '';
  $parid = '{parish_members___parish_raw}';
  if (!$parid) {
  return '0';
  }
  $db =\Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
  $query = $db->createQuery(true)
      ->select($db->quoteName(array('q1.item_id')))
      ->from($db->quoteName('joskk_fields_values', 'q1'))
      ->where($db->quoteName('q1.value') . ' = ' . $db->quote($parid));
  $db->setQuery($query);
$rows = $db->loadAssocList();
$user_id = '{$my->id}';
$found = false;

foreach ($rows as $row) {
    if ($row['item_id'] == $user_id) {
        $found = true;
        break;
    }
}
$parac = $found ? '1' : '0';
return $parac;

Hope this helps!

Kindly,
Lorenz
 
Thanks :)

Meanwhile I managed to solve it pretty easily - simply by adding a filter to my LINK (FABRIK list):

WHERE
Field: my_element_name
Condition: IN
Value: {$my->groups}
Type: query
Apply to: Public

This did it - Now Users can only see records related to UserGroups to which the User has got access.
 
I was going to suggest this option, but I realized that a record can be linked to more than one user group. In that case, this won't work.
 
@startpoint - didn't see that coming :)

In this particular case it wouldn't matter so much since the records would always be related to only 1 group.

But I tested what you mentioned, relating a record to two groups, and got this error:

An error has occurred.

500 Store row failed: Incorrect integer value: '["3","10"]' for column 'owner' at row 1 ; Please inform your web-site owner

Furthermore I experience another problem: when I first relate the record to a group and hit save - everything is ok - but then, when coming back later to edit the record, the relation in the UserGroup element is gone, and I have to remember to set the group relation again.

So this didn't work at all for me - but I wonder if this is an error, or a limitation?
 
I made an assumption about the situation. It's clearly not possible. And I know about the problem with the group disappearing when editing, but I don't remember how I got around it. I think I did it with a drop-down menu instead of a list of checkboxes.
I don't use a Fabrik anymore and I can't give more precise advice.
 
Are you using a usergroup element? I'm not at my PC but I think this is the only element for setting more than one group.
 
Thanks :)

Meanwhile I managed to solve it pretty easily - simply by adding a filter to my LINK (FABRIK list):

WHERE
Field: my_element_name
Condition: IN
Value: {$my->groups}
Type: query
Apply to: Public

This did it - Now Users can only see records related to UserGroups to which the User has got access.

I use this method but in the value I insert the query using the placeholders (Example: {$my->groups} or {$my->id}. Obviously for duplicate cases I can manage with the sql language by inserting limit 1 or setting functions (if, case...) that allow the correct choice
 

Members online

No members online now.
Back
Top