项目文档权限判断优化

GitlabVersion
nwb 11 years ago
parent 67dfd72845
commit cf11cac0ad

@ -29,7 +29,13 @@ class DocumentsController < ApplicationController
def index def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' @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 case @sort_by
when 'date' when 'date'
@grouped = documents.group_by {|d| d.updated_on.to_date } @grouped = documents.group_by {|d| d.updated_on.to_date }

@ -46,6 +46,10 @@ class Document < ActiveRecord::Base
!user.nil? && user.allowed_to?(:view_documents, project) !user.nil? && user.allowed_to?(:view_documents, project)
end end
def has_right?(project,user=User.current)
user.admin? || user.member_of?(project) || self.is_public==1
end
def initialize(attributes=nil, *args) def initialize(attributes=nil, *args)
super super
if new_record? if new_record?

Loading…
Cancel
Save