Restricting access to list entries

chris.paschen

Chris Paschen
I'm trying to set-up controls for specific entries (i.e. rows in the table) for a Fabrik list. (To be able to set the access per table row)

I've tried to follow the tutorial here but it's J1.5 and doesn't apply to J3 and current fabrik. But piecing together tips from various forum posts I've been able to get this:
  1. Add a 'viewlevel' element to the list/group
  2. In the list | data | prefilter add a prefilter like this:
    1. WHERE
    2. Field: (same 'viewlevel' element added above)
    3. Condition: IN
    4. Type: Eval
    5. Apply to: Public
    6. Value: .. this is where I'm not 100% sure I have this correct:
For the Value I have tried all of these:
PHP:
$user = JFactory::getUser();
return $user->getAuthorisedViewLevels();
or
PHP:
return JFactory::getUser()->getAuthroisedViewLevels();
or
PHP:
return JAccess::getAuthroisedViewLevels(JFactory::getUser()->id);

In each case, when I try to view the front-end page displaying the list, all I get is a white screen.
(And deleting the pre-filter shows the list as it should, although without restrictions).

Have I completely missed how to do this?
Is there some documentation that is actually up-to-date?

This is a basic Joomla function so I would think that there must be SOME documentation somewhere.
(If not, please help me and I'll write-up the wiki page.)

Thanks
 
Did you try using the {$my->id} placeholder? http://fabrikar.com/forums/index.php?wiki/placeholders/#my-gt-xxx

return JAccess::getAuthorisedViewLevels ({$my->id});
should work in Joomla 3.x.
...and I'm pretty sure, since you are creating a WHERE condition in a mySQL query, you'd need to implode the array to create a string of numbers to find IN
try:
return implode( ',' , JAccess::getAuthorisedViewLevels ({$my->id}) );

If you ever need to do that where you were comparing against a string rather than a number - to make it work with the IN() function of mySql - you could use...
return '"'. implode( '","' , JAccess::getAuthorisedViewLevels ({$my->id}) ).'"';
...which would create a string of the values delimited with commas, but with double quotes around each of the array values.

And that's assuming the necessary classes are already added by fabrik - if not you'd need to include before...
jimport('joomla.access.access');
jimport('joomla.user.user');
 
Bauer,
Thanks again for coming to the rescue.
However, I still wasn't able to make this work.
(with or without including the jimport directives).
I tried all variations of the string you provided but none seem to work. But it does look like it's getting closer.

The talbe:mergeJoinedData get ids results looks like it's applying the WHERE clause to the table properly:

PHP:
SELECT DISTINCT
`cmd_webinars`.`id` AS __pk_val0,
`cmd_people`.`id` AS __pk_val1,
`cmd_webinars_104_repeat`.`id` AS __pk_val2
 
FROM `cmd_webinars`
LEFT JOIN `cmd_people` AS `cmd_people` ON `cmd_people`.`id` = `cmd_webinars`.`presenter`
LEFT JOIN `cmd_people` AS `cmd_people_0` ON `cmd_people_0`.`id` = `cmd_webinars`.`presenter`
LEFT JOIN `cmd_webinars_104_repeat` AS `cmd_webinars_104_repeat` ON `cmd_webinars_104_repeat`.`parent_id` = `cmd_webinars`.`id`
LEFT JOIN `#__users` AS `wukrp_users` ON `wukrp_users`.`id` = `cmd_people_0`.`author_id`
 
WHERE ( cmd_webinars.access_level IN
    ('1','1','2','3','4','6','7','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','38','39','41','42','43','44','45','46','47','48','49','50','51','52','54') )
ORDER BY `cmd_webinars`.`webinar_date` DESC

However, now, although I'm not getting the 'white screen' (which I'm expecting means that the syntax is at least correct), the list is empty.
And this is happening even when a couple of the items in the list are set to 'public' access.

Any ideas on where this is going wrong?
Any help would be appreciated.
Again ... I can't believe I'm the only person who is actually trying to restrict output of Fabrik rows by access level. Someone must have made this work at SOME point.

NOTE: Attached is a full listing of the fabrik debug output.
 

Attachments

  • pre_filter_restrict_access_notworking.png
    695.2 KB · Views: 161
Progress is good.:)

You can cut and paste the fabrik debug sql statements into the query box using phpMyAdmin and see the results. (You'll have to replace any instances of #__ with your Joomla db table preface.) That might give you better details of any errors - and you can tweak the query until it works - just so you get an idea of what part is causing the problem.

Do that with the query code you provided and see what you get.

Looking at your debugging output, I'm pretty sure that the SELECT in the section "list GetData:CMD-Webimars_Display" is the one that produces the list - and looks goofy. Why is the WHERE condition at the end "WHERE 1 = -1". Where does THAT come from? Anyhow that's why you get no rows... 1 will never equal -1

Remove that WHERE condition entirely and run the query and see what you get (that will tell you if the rest of that humungous select is valid). If you get output results then it's just a matter of finding where you are getting that "WHERE 1 = -1" to begin with - and fixing it.
 
OK ...although there are days when I do think that 1 SHOULD equal -1 (esp. when I can't track down the error in code, and it would be easier to alter the rules of basic mathematics :) ... that was the key. Thanks for pointing that out (I just didn't see the little "-" there. (I think it's time for sleep).

The problem turned out to be that I have 2 elements with VERY similar names but with different functionality. And I was filtering on the wrong element.

For anyone else that runs into this problem (before this can get documented) here's what it took:

In List | Data | Pre-filter click the ADD button and set-up the following settings
  • Field: The field where you have the access level set (must be an 'access' type of element - and obviously have some access level set for your items)
  • Condition: IN
  • Value:
    PHP:
    jimport('joomla.access.access');
    jimport('joomla.user.user');
    return implode( ',' , JAccess::getAuthorisedViewLevels ({$my->id}) );
  • Type: Eval
  • Apply to: Public
  • Grouped: n/a
Bauer - thanks again for your help!
 
Believe me, I know that feeling.:rolleyes:
As I'm sure you know by now, it's always best to have a 2nd pair of eyes go over your code. Sometimes you can look at something a thousand times and it still seems right. I'm just glad you have it all working like you wanted - Congrats!:)
 
Hey Chris, Hey bauer,

I am in the middle of digging deeper into the possibilities of streamlining user-access and this little article here just exactly covers one of my first and most obvious questions - getting list-views on a user-specific basis. So thumbs up for your tip, don't think i would have made up this one in a reasonable time! Maybe this could be added to a still missing entry of the access-element in the wiki? :)

Then furthermore forgive me the impoliteness of shameless thread-hijacking :cool:, at least it's closely related:
Do you know a neat way of mass editing the access-configurations of elements/groups/lists or doing kind of pre-configuration which is then pre-filled standard for newly created objects?

Thanks and Regards,

Matthias
 
matthias - as soon as I get my head above-water with all these 'must be done before the end of the year' (yes, I'm over 4 weeks behind!) I'm going to try to add some tips to the wiki that I've compiled in these past few weeks.

As far as 'mass editing' - the only options would be to either enable list/column editing (in list view) or just using SQL to update the tables directly (or, if a 'regular' activity, create some PHP code to do it with a scheduled task).
 
matthias - as soon as I get my head above-water with all these 'must be done before the end of the year' (yes, I'm over 4 weeks behind!) I'm going to try to add some tips to the wiki that I've compiled in these past few weeks.

As far as 'mass editing' - the only options would be to either enable list/column editing (in list view) or just using SQL to update the tables directly (or, if a 'regular' activity, create some PHP code to do it with a scheduled task).


Ok, I see. Detailed Access-Levels hide somewhere in the params then. Will take a look and write some individual code than, i guess. Thanks for your efforts,

Matthias
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top