Just wondering if there's a better way to do the following:
Users has_many Projects
Projects has_many lists
Lists has_many Items
Certain users only have access to certain projects. But if a user has access to a project, then the user can access all the lists and items belonging to that project.
Here's a method that I want to clean up:
def check_for_user_access(resource, resource_class, user)
case resource_class
when 'Project'
if resource.user == user
return true
end
when 'List'
if resource.project.user == user
return true
end
when 'Item'
if resource.list.project.user == user
return true
end
else
return false
end
end
I didn't want a user_id attribute in List and Item since access is really just tied to Project.
Is there a better way to do this than with a switch statement to wrap around the slightly different comparison?
Thanks in advance!