Allow Users to View ONLY articles they Author

Moderators: mandville, PhilD, General Support Moderators

Locked
FieroJones
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Sep 07, 2012 4:35 pm

Allow Users to View ONLY articles they Author

Post by FieroJones » Fri Sep 07, 2012 4:41 pm

Is there a way to allow an Author (or another user group) to only see the articles that they have authored?

For Example:

I have 20 Articles, under the Category of "Category 1", 10 are Authored by User 1, 7 by Author 2, and 3 by Author 3.

When someone logs in, they are sent to the page to show all articles that are under "Catagory 1", however it shows EVERYONES articles.

How can I make it so that User 1 can only see User 1's articles?

I've been teaching myself Joomla 2.5, and this has gotten me stuck.

Thanks in advance!

-Karl

 
dmitryseliv
Joomla! Explorer
Joomla! Explorer
Posts: 320
Joined: Sun Mar 16, 2008 4:40 am

Re: Allow Users to View ONLY articles they Author

Post by dmitryseliv » Fri Sep 07, 2012 5:35 pm

I don't think you can do it by default Joomla ACL. So you will have to create an a new extension for that.

User avatar
humvee
Joomla! Master
Joomla! Master
Posts: 14713
Joined: Wed Aug 17, 2005 10:27 pm
Location: Kent, England

Re: Allow Users to View ONLY articles they Author

Post by humvee » Fri Sep 07, 2012 5:56 pm

[Mod note: Moved from General Forum to ACL Forum; Please read Which forum to post your question]

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

Re: Allow Users to View ONLY articles they Author

Post by rcarey » Sat Sep 08, 2012 1:32 pm

You can accomplish this with just a little bit of code.

Here is the short answer: Override the view file that displays the list of article in the frontend (or within the admin folder if the user will be using the backend to accessing the articles to edit). Then near the top of the foreach loop that gets and processes each article, add some code to determine if the user should see the article in the list. In your case, it will be if the user is the same as the author, and you will also want admins or some other group to be able to see every article. If the user should not see the article, simply execute "continue;" which instructs the loop to stop processing the current item and to start processing the next item.

This approach is desirable because you are adding the extra code in a file that is not overriden by upgrades (as long as you override the view file and not hack the original file).

Here are the steps:

[1] Override the view file that displays all the articles. To do this, copy
/components/com_content/views/articles/default.php
and move the copy to this folder:
/templates/<your-template>/html/com_content/articles/default.php
note: If users are to access article through the backend, then you will need to override the the similar file under the administrator folder.


[2] Edit the overriding file (the duplicate you created). In the top section, shortly after the $user object is declared, add this code

Code: Select all

<?php
   $groups = $user->get('groups');
   $canEditOthers = in_array(7,$groups) || in_array(8,$groups) ;
?>
What this does is create a variable that is true if the user belongs to a group that can edit articles by others. In my case, I make it true for '7' (admin) or '8' (the super admin). You should set these numbers to the id of the groups that you want to have access to all articles, and you might want to add more to this condition to include more groups. But what you want is the variable $canEditOthers set to true if the user belongs to any group that should allow the user to edit all articles.

[3] Move down to the lines of code in the 120's. You will see a foreach() loop starting, and some permissions variables set. Right after that block of php code, add this code

Code: Select all

<?php
         if(!$canEditOthers && $item->created_by != $userId){
            continue;
         }
?>
In this condition, if the user does not have permission to edit others, and if the particular article of this iteration was not created by the user, then continue; - which means skip the rest of the code in this loop and get the next item.

That should do it. Whoever is logged in will see only his/her articles, or if the user belongs to special/admin group the user will see all articles.
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

greg-oz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 120
Joined: Tue Jan 18, 2011 2:12 am

Re: Allow Users to View ONLY articles they Author

Post by greg-oz » Mon Sep 10, 2012 3:39 am

FieroJones wrote:Is there a way to allow an Author (or another user group) to only see the articles that they have authored?

For Example:

I have 20 Articles, under the Category of "Category 1", 10 are Authored by User 1, 7 by Author 2, and 3 by Author 3.

When someone logs in, they are sent to the page to show all articles that are under "Catagory 1", however it shows EVERYONES articles.

How can I make it so that User 1 can only see User 1's articles?

I've been teaching myself Joomla 2.5, and this has gotten me stuck.

Thanks in advance!

-Karl

Say you have 2 users each with their own article for the sake of this posting:

1) Make up a User Group based on the name of the person or their username so that it is easy to follow a year from now when you cant remember all the details.
2) Assign, to that article, the user group name that you made up for each user.
3) Assign, to the actual user, their normal Registered and also a tick in their access level for the Group level.
4) Make sure that in Viewing Access Level for those user group levels you made up, you tick only the one that applies. So if the Group name was "GeeWhilly" then under Viewing Access Level, "GeeWhilly" sees only "GeeWhilly" and no-one else sees it.

If you do that, you can put all articles under one menu and when the user logs on with the GeeWhilly level, because they also have Registered in their own settings, they see anything that you allow and also anything under GeeWhilly which other users cannot see. However they CAN see anything else on the site that you allow. If the second user is under the name John Smith and you replace all the above with JSMITH then because GeeWhilly doesnt have a tick in his user account settings for JSMITH, he literally cannot SEE any article with JSMITH user access.

Does that help? You can drop me a private message here if you need more but the only other way I can think to help if you dont get it this way is to set up the access FOR you and you can study and duplicate it.

Greg.

A PS edit - if you do it as above, even Super User cannot see it so remember to add GeeWhilly to your own access as Super User so you can see it, too.

jany137
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sun Mar 17, 2013 10:07 am

Re: Allow Users to View ONLY articles they Author

Post by jany137 » Mon Mar 25, 2013 8:01 pm

BJ Myjspace extension might be something you are looking for. Let me know if this helped.

 

Locked

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