]> source.dussan.org Git - redmine.git/commitdiff
Adds visible scope to redmine links queries.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Jan 2011 16:47:59 +0000 (16:47 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 23 Jan 2011 16:47:59 +0000 (16:47 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4759 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/models/document.rb
app/models/message.rb

index d5a658917cc4c57bc531e437d7f0bd5d4f273a64..8e973d186f55ef8aa6c5105f1799f628f2ceaf22 100644 (file)
@@ -605,7 +605,8 @@ module ApplicationHelper
       end
       if esc.nil?
         if prefix.nil? && sep == 'r'
-          if project && (changeset = project.changesets.find_by_revision(identifier))
+          # project.changesets.visible raises an SQL error because of a double join on repositories
+          if project && project.repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(project.repository.id, identifier))
             link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
                                       :class => 'changeset',
                                       :title => truncate_single_line(changeset.comments, :length => 100))
@@ -620,17 +621,17 @@ module ApplicationHelper
                                         :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
             end
           when 'document'
-            if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
+            if document = Document.visible.find_by_id(oid)
               link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
                                                 :class => 'document'
             end
           when 'version'
-            if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
+            if version = Version.visible.find_by_id(oid)
               link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
                                               :class => 'version'
             end
           when 'message'
-            if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
+            if message = Message.visible.find_by_id(oid, :include => :parent)
               link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
                                                                 :controller => 'messages',
                                                                 :action => 'show',
@@ -649,23 +650,23 @@ module ApplicationHelper
           name = identifier.gsub(%r{^"(.*)"$}, "\\1")
           case prefix
           when 'document'
-            if project && document = project.documents.find_by_title(name)
+            if project && document = project.documents.visible.find_by_title(name)
               link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
                                                 :class => 'document'
             end
           when 'version'
-            if project && version = project.versions.find_by_name(name)
+            if project && version = project.versions.visible.find_by_name(name)
               link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
                                               :class => 'version'
             end
           when 'commit'
-            if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
+            if project && project.repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{name}%"]))
               link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
                                            :class => 'changeset',
                                            :title => truncate_single_line(changeset.comments, :length => 100)
             end
           when 'source', 'export'
-            if project && project.repository
+            if project && project.repository && User.current.allowed_to?(:browse_repository, project)
               name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
               path, rev, anchor = $1, $3, $5
               link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
index 3aae3985051529359597d33bccb881886f273408..21232a2d9bed3a2de88e66564df4b5b871be083d 100644 (file)
@@ -29,6 +29,9 @@ class Document < ActiveRecord::Base
   validates_presence_of :project, :title, :category
   validates_length_of :title, :maximum => 60
   
+  named_scope :visible, lambda {|*args| { :include => :project,
+                                          :conditions => Project.allowed_to_condition(args.first || User.current, :view_documents) } }
+  
   def visible?(user=User.current)
     !user.nil? && user.allowed_to?(:view_documents, project)
   end
index 3744c239bb3aefef1e43aa1076ff193432108cbf..77c9ff55076424bec1b9bff7d488764fade4c953 100644 (file)
@@ -42,6 +42,9 @@ class Message < ActiveRecord::Base
   
   after_create :add_author_as_watcher
   
+  named_scope :visible, lambda {|*args| { :include => {:board => :project},
+                                          :conditions => Project.allowed_to_condition(args.first || User.current, :view_messages) } }
+  
   def visible?(user=User.current)
     !user.nil? && user.allowed_to?(:view_messages, project)
   end