Hi Robert

I guess there's two approaches here... you'll either want to store all the user 
ids that have access to a given project:

  has project_type.project_accesses.user_id, :as => :user_ids

However, if you're going to have a lot of users, this may not be the best 
approach... I would recommend you store the project type id as an attribute 
instead:

  has project_type_id

Then, find out which project types a user has access to:

  project_type_ids = ProjectAccess.find(:all, :conditions => {:user_id => 
current_user.id}).collect { |access| access.project_type_id }

And use that as a filter in the search:

  Project.search 'foo', :with => {:project_type_id => project_type_ids}

Hope this helps.

-- 
Pat

On 29/06/2010, at 11:55 AM, rbjarnason wrote:

> Hi,
> 
> I'm trying to implement search using Thinking Sphinx for Projects that
> have access control based on Project Types.
> 
> I have 4 tables I need to work with:
> * Project (included in search)
> * Project Type (included by association in search)
> * User (the logged in user)
> * Project Access (which has project_type_id, user_id)
> 
> When logged in, I would only like to return search results for
> projects of types that a given user has access to as defined in the
> Project Access table.
> 
> I've been looking at this post: "Limiting search results depending on
> authorization level" that has given me few clues but I'm still at a
> loss how I begin implementing this sort of access control using
> Thinking Sphinx.
> http://groups.google.com/group/thinking-sphinx/browse_thread/thread/41d7a70ce75b13bb/4e7d7b2d93847d8f
> 
> Any leads would be highly appreciated.
> 
> Warm regards,
> Robert Bjarnason
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to