class Api::ReviewsController < Api::ApiController
def index
- reviews=Review.search(params)
+ reviews=select_authorized(:user, Review.search(params), :project)
respond_to do |format|
format.json { render :json => jsonp(Review.reviews_to_json(reviews)) }
# Used for the permalink, e.g. http://localhost:9000/reviews/view/1
def view
- @review=Review.find(params[:id], :include => ['resource', 'project'])
- render 'reviews/_review', :locals => {:review => @review}
+ @review=Review.find(params[:id], :include => ['project'])
+ if has_role?(:user, @review.project)
+ render 'reviews/_review', :locals => {:review => @review}
+ else
+ render :text => "<b>Cannot access this review</b> : access denied."
+ end
end
#
def show
- @review=Review.find(params[:id], :include => ['resource', 'project'])
+ @review=Review.find(params[:id], :include => ['project'])
render :partial => 'reviews/show'
end
end
end
- @reviews = Review.search(options)
+ found_reviews = Review.search(options)
+ @reviews = select_authorized(:user, found_reviews, :project)
+ if found_reviews.size != @reviews.size
+ @security_exclusions = true
+ end
end
def is_number?(s)
result
end
+ def select_authorized(role, objects, resource_method=nil)
+ if resource_method
+ booleans=has_role?(role, objects.map{|obj| obj.send(resource_method)})
+ else
+ booleans=has_role?(role, objects)
+ end
+ result=[]
+ objects.each_with_index do |obj, index|
+ result<<obj if booleans[index]==true
+ end
+ result
+ end
+
#
# Filter method to enforce a login admin requirement.
#