Adds visible scope to redmine links queries.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4759 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
777ccf1328
commit
b20210e83c
|
@ -605,7 +605,8 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
if esc.nil?
|
if esc.nil?
|
||||||
if prefix.nil? && sep == 'r'
|
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},
|
link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
||||||
:class => 'changeset',
|
:class => 'changeset',
|
||||||
:title => truncate_single_line(changeset.comments, :length => 100))
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
||||||
|
@ -620,17 +621,17 @@ module ApplicationHelper
|
||||||
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
||||||
end
|
end
|
||||||
when 'document'
|
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},
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
||||||
:class => 'document'
|
:class => 'document'
|
||||||
end
|
end
|
||||||
when 'version'
|
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},
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||||
:class => 'version'
|
:class => 'version'
|
||||||
end
|
end
|
||||||
when 'message'
|
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,
|
link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
|
||||||
:controller => 'messages',
|
:controller => 'messages',
|
||||||
:action => 'show',
|
:action => 'show',
|
||||||
|
@ -649,23 +650,23 @@ module ApplicationHelper
|
||||||
name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
||||||
case prefix
|
case prefix
|
||||||
when 'document'
|
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},
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
||||||
:class => 'document'
|
:class => 'document'
|
||||||
end
|
end
|
||||||
when 'version'
|
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},
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
||||||
:class => 'version'
|
:class => 'version'
|
||||||
end
|
end
|
||||||
when 'commit'
|
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},
|
link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
|
||||||
:class => 'changeset',
|
:class => 'changeset',
|
||||||
:title => truncate_single_line(changeset.comments, :length => 100)
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
||||||
end
|
end
|
||||||
when 'source', 'export'
|
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+))?$}
|
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
||||||
path, rev, anchor = $1, $3, $5
|
path, rev, anchor = $1, $3, $5
|
||||||
link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
||||||
|
|
|
@ -29,6 +29,9 @@ class Document < ActiveRecord::Base
|
||||||
validates_presence_of :project, :title, :category
|
validates_presence_of :project, :title, :category
|
||||||
validates_length_of :title, :maximum => 60
|
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)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_documents, project)
|
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,9 @@ class Message < ActiveRecord::Base
|
||||||
|
|
||||||
after_create :add_author_as_watcher
|
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)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_messages, project)
|
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue