<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Limit Data by User with CakePHP</title>
	<atom:link href="http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/</link>
	<description>how much blog can blogchuck blog</description>
	<lastBuildDate>Fri, 16 Sep 2011 03:57:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Chuck Burgess</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-313</link>
		<dc:creator>Chuck Burgess</dc:creator>
		<pubDate>Mon, 20 Jun 2011 00:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-313</guid>
		<description>This code is designed to limit users only and allow the admin to see ALL users. If you want to limit the ADMIN to only see ADMIN information, you can remove the corresponding code from the beforeSave and beforeFind call backs (if($this-&gt;user_id = Configure::read(&#039;user_id&#039;)){).</description>
		<content:encoded><![CDATA[<p>This code is designed to limit users only and allow the admin to see ALL users. If you want to limit the ADMIN to only see ADMIN information, you can remove the corresponding code from the beforeSave and beforeFind call backs (if($this->user_id = Configure::read(&#8216;user_id&#8217;)){).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tagman</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-312</link>
		<dc:creator>tagman</dc:creator>
		<pubDate>Sun, 19 Jun 2011 11:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-312</guid>
		<description>hi chunck
I got problem when login as admin
I see data same user see
My app use acl plugin to manage 4 permission admin,mod,expert,user
can you help me to implement your code to my app
thank</description>
		<content:encoded><![CDATA[<p>hi chunck<br />
I got problem when login as admin<br />
I see data same user see<br />
My app use acl plugin to manage 4 permission admin,mod,expert,user<br />
can you help me to implement your code to my app<br />
thank</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck Burgess</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-310</link>
		<dc:creator>Chuck Burgess</dc:creator>
		<pubDate>Tue, 29 Mar 2011 23:41:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-310</guid>
		<description>They should be. If they are not, you can add the callback to your independent model with the following:

function {callback}() {
   parent::{callback}();
}

Just replace {callback} with the callback function you are performing: beforeSave, beforeFind, etc.</description>
		<content:encoded><![CDATA[<p>They should be. If they are not, you can add the callback to your independent model with the following:</p>
<p>function {callback}() {<br />
   parent::{callback}();<br />
}</p>
<p>Just replace {callback} with the callback function you are performing: beforeSave, beforeFind, etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lyba</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-309</link>
		<dc:creator>lyba</dc:creator>
		<pubDate>Tue, 29 Mar 2011 16:58:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-309</guid>
		<description>There is a major problem with this approach - it only works for the main model. Callbacks are not executed for dependent models. 

If you display dependent models on your forms they will be displayed regardless of the user_id set on them. 

I need to look for another solution or continue with updating all controllers. No quick wins so far. :(

Thanks anyway</description>
		<content:encoded><![CDATA[<p>There is a major problem with this approach &#8211; it only works for the main model. Callbacks are not executed for dependent models. </p>
<p>If you display dependent models on your forms they will be displayed regardless of the user_id set on them. </p>
<p>I need to look for another solution or continue with updating all controllers. No quick wins so far. <img src='http://blogchuck.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Thanks anyway</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck Burgess</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-304</link>
		<dc:creator>Chuck Burgess</dc:creator>
		<pubDate>Tue, 29 Mar 2011 13:12:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-304</guid>
		<description>Thank you for your feedback Iyba. I am glad you find it useful. I also appreciate the perspective of others. Your perspective helps improve this code. Thank you for posting.</description>
		<content:encoded><![CDATA[<p>Thank you for your feedback Iyba. I am glad you find it useful. I also appreciate the perspective of others. Your perspective helps improve this code. Thank you for posting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lyba</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-302</link>
		<dc:creator>lyba</dc:creator>
		<pubDate>Tue, 29 Mar 2011 06:59:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-302</guid>
		<description>This is exactly what I set to find on internet today. Took me 5 minutes, great. I like it very much.

Now, I have one concern. Above solution is assuming admin/no admin roles. And assumes authentication does not allow non users to access models in question. Although these assumptions make the solution safe, they make it limited. 

In systems where access should be restricted to owner data (e.g. medical data should not be available to admins, non doctors) and is rather role based then an admin/no admin attribute above solution is missing prevent access feature. If user_id is not set filter will return all rows. Imagine, you have not set up properly login/non login access to a certain model. The same goes for save. If user_id is not set it will allow saving any hacked id.

The simple solution is to add a line to both methods:
else (user_id not set) 
impossible to meet condition (- to return empty set)

Still the idea is great and I will expand it to my needs. I thought I will point the above out so if you intend to expand the solution you have it in mind.</description>
		<content:encoded><![CDATA[<p>This is exactly what I set to find on internet today. Took me 5 minutes, great. I like it very much.</p>
<p>Now, I have one concern. Above solution is assuming admin/no admin roles. And assumes authentication does not allow non users to access models in question. Although these assumptions make the solution safe, they make it limited. </p>
<p>In systems where access should be restricted to owner data (e.g. medical data should not be available to admins, non doctors) and is rather role based then an admin/no admin attribute above solution is missing prevent access feature. If user_id is not set filter will return all rows. Imagine, you have not set up properly login/non login access to a certain model. The same goes for save. If user_id is not set it will allow saving any hacked id.</p>
<p>The simple solution is to add a line to both methods:<br />
else (user_id not set)<br />
impossible to meet condition (- to return empty set)</p>
<p>Still the idea is great and I will expand it to my needs. I thought I will point the above out so if you intend to expand the solution you have it in mind.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck Burgess</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-300</link>
		<dc:creator>Chuck Burgess</dc:creator>
		<pubDate>Mon, 10 Jan 2011 14:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-300</guid>
		<description>The beforeFind will limit what the user will see after they log in. Keep in mind the idea behind the way this was written was to limit the user to only see their own data. If you want everyone to see ALL data, then remove the beforeFind in app_model.</description>
		<content:encoded><![CDATA[<p>The beforeFind will limit what the user will see after they log in. Keep in mind the idea behind the way this was written was to limit the user to only see their own data. If you want everyone to see ALL data, then remove the beforeFind in app_model.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-299</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Mon, 10 Jan 2011 13:25:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-299</guid>
		<description>Hi Chuck, thanks for this great explanation, the code works well. 

However, I&#039;m wondering if you could help as I&#039;m a bit confused with how the beforeFilter() works in this case.

In the Posts Controller there is, for example:
function beforeFilter() {
   parent::beforeFilter(); 
   $this-&gt;Auth-&gt;allowedActions = array(&#039;index&#039;);
}

When not logged in, a user can see all posts in the index but when logged in, they can only see their own posts. 

I&#039;d like them to still see all the posts in index but only be able to edit their own eg. $this-&gt;Auth-&gt;deny(&#039;delete&#039;,&#039;edit&#039;,&#039;add&#039;).
How does this work with this function? Should the beforeFilter be in the Model?
Sorry if I&#039;ve missed something glaringly obvious!</description>
		<content:encoded><![CDATA[<p>Hi Chuck, thanks for this great explanation, the code works well. </p>
<p>However, I&#8217;m wondering if you could help as I&#8217;m a bit confused with how the beforeFilter() works in this case.</p>
<p>In the Posts Controller there is, for example:<br />
function beforeFilter() {<br />
   parent::beforeFilter();<br />
   $this-&gt;Auth-&gt;allowedActions = array(&#8216;index&#8217;);<br />
}</p>
<p>When not logged in, a user can see all posts in the index but when logged in, they can only see their own posts. </p>
<p>I&#8217;d like them to still see all the posts in index but only be able to edit their own eg. $this-&gt;Auth-&gt;deny(&#8216;delete&#8217;,'edit&#8217;,'add&#8217;).<br />
How does this work with this function? Should the beforeFilter be in the Model?<br />
Sorry if I&#8217;ve missed something glaringly obvious!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck Burgess</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-295</link>
		<dc:creator>Chuck Burgess</dc:creator>
		<pubDate>Tue, 28 Sep 2010 20:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-295</guid>
		<description>I am still trying to put together a good solution on the UI side of things for navigation. However, I simple set up some elements and call them based on the Auth.User.role in the layout something like this:

&lt;div id=&quot;nav_bar&quot;&gt;
			&lt;?php
				if ($this-&gt;Session-&gt;read(&#039;Auth.User.role&#039;) == &#039;Admin&#039;) {
					echo $this-&gt;element(&#039;admin&#039;);
				} else {
					echo $this-&gt;element(&#039;main_nav&#039;);
					}
				}
			?&gt;	
		&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>I am still trying to put together a good solution on the UI side of things for navigation. However, I simple set up some elements and call them based on the Auth.User.role in the layout something like this:</p>
<div id="nav_bar">
			< ?php<br />
				if ($this->Session->read(&#8216;Auth.User.role&#8217;) == &#8216;Admin&#8217;) {<br />
					echo $this->element(&#8216;admin&#8217;);<br />
				} else {<br />
					echo $this->element(&#8216;main_nav&#8217;);<br />
					}<br />
				}<br />
			?>
		</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: moflint</title>
		<link>http://blogchuck.com/2010/06/limit-data-by-user-with-cakephp/comment-page-1/#comment-294</link>
		<dc:creator>moflint</dc:creator>
		<pubDate>Tue, 28 Sep 2010 10:16:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogchuck.com/?p=331#comment-294</guid>
		<description>So I&#039;ve read the whole thing (really ought to do that before commenting!) and I like your solution :-)

I&#039;m wondering what solution you have for menus/UI. What logic do you use to make visible/hide options from unauthorised users? I am thinking of a single &#039;centralized&#039; method for both the SQL limiting and the UI options.</description>
		<content:encoded><![CDATA[<p>So I&#8217;ve read the whole thing (really ought to do that before commenting!) and I like your solution <img src='http://blogchuck.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I&#8217;m wondering what solution you have for menus/UI. What logic do you use to make visible/hide options from unauthorised users? I am thinking of a single &#8216;centralized&#8217; method for both the SQL limiting and the UI options.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

