diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 7bca47f36..b0ad6b109 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -29,7 +29,13 @@ class DocumentsController < ApplicationController def index @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' - documents = @project.documents.includes(:attachments, :category).all + temp = @project.documents.includes(:attachments, :category).all + documents = [] + temp.each do |doc| + if doc.has_right?(@project) + documents << doc + end + end case @sort_by when 'date' @grouped = documents.group_by {|d| d.updated_on.to_date } diff --git a/app/models/document.rb b/app/models/document.rb index 5cfce896b..1467903b0 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -46,6 +46,10 @@ class Document < ActiveRecord::Base !user.nil? && user.allowed_to?(:view_documents, project) end + def has_right?(project,user=User.current) + user.admin? || user.member_of?(project) || self.is_public==1 + end + def initialize(attributes=nil, *args) super if new_record? diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 41b2d13fd..43b0cff49 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -27,8 +27,8 @@ <% if @grouped.empty? %>
<%= l(:label_no_data) %>
<% end %> <% @grouped.keys.sort.each do |group| %> - - <%= render :partial => 'documents/document', :collection => @grouped[group] %> -<% end %> + + <%= render :partial => 'documents/document', :collection => @grouped[group] %> +<% end %> <% html_title(l(:label_document_plural)) -%>