##// END OF EJS Templates
Adds visible scope to redmine links queries....
Jean-Philippe Lang -
r4639:b20210e83c42
parent child
Show More
@@ -605,7 +605,8 module ApplicationHelper
605 end
605 end
606 if esc.nil?
606 if esc.nil?
607 if prefix.nil? && sep == 'r'
607 if prefix.nil? && sep == 'r'
608 if project && (changeset = project.changesets.find_by_revision(identifier))
608 # project.changesets.visible raises an SQL error because of a double join on repositories
609 if project && project.repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(project.repository.id, identifier))
609 link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
610 link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
610 :class => 'changeset',
611 :class => 'changeset',
611 :title => truncate_single_line(changeset.comments, :length => 100))
612 :title => truncate_single_line(changeset.comments, :length => 100))
@@ -620,17 +621,17 module ApplicationHelper
620 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
621 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
621 end
622 end
622 when 'document'
623 when 'document'
623 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
624 if document = Document.visible.find_by_id(oid)
624 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
625 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
625 :class => 'document'
626 :class => 'document'
626 end
627 end
627 when 'version'
628 when 'version'
628 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
629 if version = Version.visible.find_by_id(oid)
629 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
630 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
630 :class => 'version'
631 :class => 'version'
631 end
632 end
632 when 'message'
633 when 'message'
633 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
634 if message = Message.visible.find_by_id(oid, :include => :parent)
634 link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
635 link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
635 :controller => 'messages',
636 :controller => 'messages',
636 :action => 'show',
637 :action => 'show',
@@ -649,23 +650,23 module ApplicationHelper
649 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
650 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
650 case prefix
651 case prefix
651 when 'document'
652 when 'document'
652 if project && document = project.documents.find_by_title(name)
653 if project && document = project.documents.visible.find_by_title(name)
653 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
654 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
654 :class => 'document'
655 :class => 'document'
655 end
656 end
656 when 'version'
657 when 'version'
657 if project && version = project.versions.find_by_name(name)
658 if project && version = project.versions.visible.find_by_name(name)
658 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
659 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
659 :class => 'version'
660 :class => 'version'
660 end
661 end
661 when 'commit'
662 when 'commit'
662 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
663 if project && project.repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{name}%"]))
663 link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
664 link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
664 :class => 'changeset',
665 :class => 'changeset',
665 :title => truncate_single_line(changeset.comments, :length => 100)
666 :title => truncate_single_line(changeset.comments, :length => 100)
666 end
667 end
667 when 'source', 'export'
668 when 'source', 'export'
668 if project && project.repository
669 if project && project.repository && User.current.allowed_to?(:browse_repository, project)
669 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
670 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
670 path, rev, anchor = $1, $3, $5
671 path, rev, anchor = $1, $3, $5
671 link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
672 link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
@@ -29,6 +29,9 class Document < ActiveRecord::Base
29 validates_presence_of :project, :title, :category
29 validates_presence_of :project, :title, :category
30 validates_length_of :title, :maximum => 60
30 validates_length_of :title, :maximum => 60
31
31
32 named_scope :visible, lambda {|*args| { :include => :project,
33 :conditions => Project.allowed_to_condition(args.first || User.current, :view_documents) } }
34
32 def visible?(user=User.current)
35 def visible?(user=User.current)
33 !user.nil? && user.allowed_to?(:view_documents, project)
36 !user.nil? && user.allowed_to?(:view_documents, project)
34 end
37 end
@@ -42,6 +42,9 class Message < ActiveRecord::Base
42
42
43 after_create :add_author_as_watcher
43 after_create :add_author_as_watcher
44
44
45 named_scope :visible, lambda {|*args| { :include => {:board => :project},
46 :conditions => Project.allowed_to_condition(args.first || User.current, :view_messages) } }
47
45 def visible?(user=User.current)
48 def visible?(user=User.current)
46 !user.nil? && user.allowed_to?(:view_messages, project)
49 !user.nil? && user.allowed_to?(:view_messages, project)
47 end
50 end
General Comments 0
You need to be logged in to leave comments. Login now