Hide Backend Articles?

Post Reply
ahuppert
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sat Feb 09, 2008 5:45 am

Hide Backend Articles?

Post by ahuppert » Sat Jul 07, 2012 10:00 pm

I am new to ACL, but I think I get the concept. I have a group of editors that only need access to specific articles. I DO NOT want them even seeing that there are other articles that can be edited.

I created a new user group under Public>Manager and removed some of the permissions (like create, own, etc).

I then went into my categories and assigned that group ONLY to be able to edit the articles in the Category that I want them to.

This works completely fine, EXCEPT that I have over 100 articles. The user can see ALL OF THEM, but they are grayed out and they can only edit the ones that they are assigned to.

My question is, can I hide all of the other article titles from this user? If so, how do you do it?

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Hide Backend Articles?

Post by rcarey » Sun Jul 08, 2012 1:27 pm

I have a quick solution, but it requires you to add a line of code...

Focus on the file that displays the list of articles. The file includes logic for knowing whether or not the user has rights to edit the article. We will re-use that logic, and when we find an article that the user is unable to edit, we'll just skip that record and not display it. Here is how.

You should override the file that displays the list of article to be edited.
Copy this file: /administrator/components/com_content/views/articles/tmpl/default.php
Paste the copy here: /administrator/<admin-template>/html/com_content/articles/default.php

Now edit the copied file (which now overrides the original file). Around line 117 is a foreach statement, and around line 121 is the creation of the variagle $canEdit. This variable is true if the user can edit the article, otherwise false.

Somewhere around or shortly after line 125 (just after several variable are created) add this line of php code:

Code: Select all

if(!$canEdit){continue;}


That is it. What this does: If the user can't edit this article, don't process any more of this item and continue with the next item in the "foreach" loop.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

keithriches
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Wed May 05, 2010 4:46 pm

Re: Hide Backend Articles?

Post by keithriches » Tue Jul 10, 2012 3:24 pm

Hi i have found this post and its just what I was looking for but im not sure i follow whats happening? I can find the file:
/administrator/components/com_content/views/articles/tmpl/default.php

I can see roughly the bits youre talking about but im not sure what this path means?
Paste the copy here: /administrator/<admin-template>/html/com_content/articles/default.php

Any help would be greatly received!

keithriches
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Wed May 05, 2010 4:46 pm

Re: Hide Backend Articles?

Post by keithriches » Tue Jul 10, 2012 3:28 pm

Hi

I have added some code which seems to do the job but im not sure how safe this is?
...
<tbody>
<?php foreach ($this->items as $i => $item) :
$item->max_ordering = 0; //??
$ordering = ($listOrder == 'a.ordering');
$canCreate = $user->authorise('core.create', 'com_content.category.'.$item->catid);
$canEdit = $user->authorise('core.edit', 'com_content.article.'.$item->id);
$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
$canEditOwn = $user->authorise('core.edit.own', 'com_content.article.'.$item->id) && $item->created_by == $userId;
$canChange = $user->authorise('core.edit.state', 'com_content.article.'.$item->id) && $canCheckin;
?>
<?php if(!$canEdit){continue;}; ?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php if ($item->checked_out) : ?>
<?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'articles.', $canCheckin); ?>
<?php endif; ?>
<?php if ($canEdit || $canEditOwn) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_content&task=article.edit&id='.$item->id);?>">
<?php echo $this->escape($item->title); ?></a>
<?php else : ?>
<?php echo $this->escape($item->title); ?>
<?php endif; ?>
<p class="smallsub">
<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias));?></p>
</td>
...

Would this be ok to use do you know?

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Hide Backend Articles?

Post by rcarey » Tue Jul 10, 2012 4:34 pm

The path i listed refers to the path for overriding a "view" file. When I listed <admin-template> I meant for you to use the directory for whatever admin template you are using.

for instance, if you are using blueStork for your admin template, you will find this directory
/administrator/templates/bluestork/html
this is the folder in which "overrides" are placed, so from this path...
...create the remaining directories and add the copied file:
/administrator/templates/bluestork/html/com_content/articles/default.php

This copied file is now used by Joomla instead of the file found under the component. This pattern is used for overriding files, and in a way so that an upgrade in the component will not overwrite your changes - because your changes should be in the override file.

If the only code change you made is the line I supplied, then the change I'm seeing appears fine. That extra line of code is placed at the same place I put it when I need something like this.

Of course, test a bit whenever you make a code change.

Let me add, if you make this change to the overriding file and leave the original as is... then in case you make a mistake and can't back out easily, you just rename or move the overriding file and the original is used again. This can be very helpful as you make code changes and test them.

One small detail to point out... You don't need the semicolon after the curly bracket - keep just the semicolon inside the brackets.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

ahuppert
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sat Feb 09, 2008 5:45 am

Re: Hide Backend Articles?

Post by ahuppert » Tue Jul 10, 2012 9:05 pm

I added the code here:

Code: Select all

      <?php foreach ($this->items as $i => $item) :
         $item->max_ordering = 0; //??
         $ordering   = ($listOrder == 'a.ordering');
         $canCreate   = $user->authorise('core.create',      'com_content.category.'.$item->catid);
         $canEdit   = $user->authorise('core.edit',         'com_content.article.'.$item->id);
         $canCheckin   = $user->authorise('core.manage',      'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
         $canEditOwn   = $user->authorise('core.edit.own',      'com_content.article.'.$item->id) && $item->created_by == $userId;
         $canChange   = $user->authorise('core.edit.state',   'com_content.article.'.$item->id) && $canCheckin;
         if(!$canEdit){continue;}?>



and it DOES in fact work. HOWEVER, is there now a way to make the default DISPLAY # (for this user) "ALL"?

I'm asking because I have 10+ pages of articles, when it is set to 20/page. With the code addition, when the person views articles, they are shown a blank page of articles unless they select DISPLAY ALL so that the 5-10 articles in the category (that they are allowed to edit) finally show up.

If that is not selected, then they have to either navigate the Display Category drop down, or select ALL to show all of the articles. To do this every time would be annoying and probably too much for a novice user.

I would love to allow them to do this from the front end, but the editing capabilities in the back end are so much cleaner and it adds a level of separation from the front end.

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Hide Backend Articles?

Post by rcarey » Tue Jul 10, 2012 9:22 pm

I am aware that this technique strips out items after the pagination is calculated - leading to the possibility of sparse-to-empty screens. But to limit the custom coding to a file you can override, this seems to be the best option. (and relatively simple to implement)

As to extending the default number of items to display, go to GlobalConfiguration->Site and you will find a field to default list limit. The highest it goes it 100, and setting this to 100 or whatever will apply this list limit to every list within the site. There might be a plugin (written or waiting to be written) that can initially set the list limit to All, but I don't know.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

ahuppert
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sat Feb 09, 2008 5:45 am

Re: Hide Backend Articles?

Post by ahuppert » Tue Jul 10, 2012 9:30 pm

Thanks for the help! It worked... I'll just have to write a more detailed HOWTO for the users...

keithriches
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Wed May 05, 2010 4:46 pm

Re: Hide Backend Articles?

Post by keithriches » Wed Jul 11, 2012 8:25 am

HI

Thanks for your response rcarey. I have looked on the server and found the directory but when i go into:

/administrator/templates/bluestork/html/

I can only see 3 files:

index.html
modules.php
pagination.php

Would i need to create a folder to get to the path:

/administrator/templates/bluestork/html/com_content/articles/default.php

Many thanks for your assistance on this

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Hide Backend Articles?

Post by rcarey » Wed Jul 11, 2012 12:18 pm

Yes. You need to create those additional directories. The "html" directory is the starting place for all overrides. Each override must be placed in additional directories that instruct the template for which component or module (and for which view) the overriding file applies. If any part of the new path (misspelled or missing folder/file) does not meet the expected naming convention, then that file will not override the corresponding "view" file from the component or module.

The overriding technique is a very important aspect of Joomla, in my opinion. It is part of the MVC model that sets Joomla apart from most of the other open source CMSs (e.g., WP, Drupal). More commonly, it is used to override the view or formatting of the frontend, but it can be very powerful in tailoring the backend that we deliver to our clients.

A discussion of overriding components and modules is found in this Joomla documentation: http://docs.joomla.org/Understanding_Output_Overrides
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

User avatar
numinousmedia
Joomla! Ace
Joomla! Ace
Posts: 1559
Joined: Fri Dec 16, 2011 6:13 pm
Location: Millersburg, OH
Contact:

Re: Hide Backend Articles?

Post by numinousmedia » Tue Jan 14, 2014 3:40 am

Thank you for posting this solution rcarey. I used it to apply the same "Hide Articles" fix to a Joomla 3.2.1 site.
Ryan
Frontend Developer and Joomla Professional
Ethode Website Development: http://www.ethode.com
Personal Site: http://www.numinousmedia.com

shawnhy
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Jan 22, 2013 3:37 am
Location: Taiwan, a democratic country

Re: Hide Backend Articles?

Post by shawnhy » Tue Sep 01, 2015 4:23 am

Hi,
Thanks for the amazing code, rcarey.
I apply the code on joomla!3.4.3 and make unauthorized items hidden. However, the td tag remains and result to the result of ugly table.

Image

Is there any way I can fix it?
Many thanks.
Shawn
You do not have the required permissions to view the files attached to this post.

shawnhy
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Tue Jan 22, 2013 3:37 am
Location: Taiwan, a democratic country

Re: Hide Backend Articles?

Post by shawnhy » Tue Sep 01, 2015 4:42 am

well. I fix if by add a

Code: Select all

style="<?php if(!$canEdit){ echo 'display: none';} ?>"


into to tr tag.

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Hide Backend Articles?

Post by rcarey » Tue Sep 01, 2015 4:49 am

@Shawnhy. You just posted as I was answering. I would expect your code to work. But I think it is better to add the code that I suggested. If I saw the page gerneated by your code, I would be able to look at the source code to see the values you intended to hide.

I assume the problem is that you placed the continue; statement too late in the code - i.e., after the <tr> so that a table row is added each time. I looked at the template file in the latest version (3.4.3), and one could place this conditional line right after line 110. And becasue the condition needs to know only the value of $canEdit, then you could place that added line of code right after the value of $canEdit is set. In other words, place it right after line 107 or this statement:

Code: Select all

$canEdit    = $user->authorise('core.edit',       'com_content.article.' . $item->id);
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

ryank1
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Jan 06, 2011 3:00 am

Re: Hide Backend Articles?

Post by ryank1 » Thu Jul 14, 2016 8:34 pm

this is great! is there a way to add it to a template so it does not get overwritten on updates?

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Hide Backend Articles?

Post by rcarey » Thu Jul 14, 2016 9:45 pm

The changes should be made to an overriding file - one that is not overwritten on upgrades. That is a common practice in Joomla. Please read earlier in this discussion to learn more about that.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

ryank1
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Jan 06, 2011 3:00 am

Re: Hide Backend Articles?

Post by ryank1 » Fri Jul 15, 2016 1:02 pm

Hey @ahuppert I did read through the comments and thought maybe since the post was so old joomla core changed a bit. I do normally work with html overides but for some reason this one wasnt working. see my screen shot of my overided in the isis theme.
Screen Shot 2016-07-15 at 7.54.19 AM.png
You do not have the required permissions to view the files attached to this post.


Post Reply

Return to “Access Control List (ACL) in Joomla! 2.5”