Project

General

Profile

Feature #2069 ยป rm2069.patch

Mischa The Evil, 2017-09-17 02:07

View differences:

app/helpers/application_helper.rb (working copy)
818 818
  #     user:jsmith -> Link to user with login jsmith
819 819
  #     @jsmith -> Link to user with login jsmith
820 820
  #     user#2 -> Link to user with id 2
821
  #   Files:
822
  #     file#1 -> Link to file with id 1
823
  #     file:filename.ext -> Link to file with filename "filename.ext"
824
  #     file:"filename.ext" -> Link to file with filename "filename.ext"
821 825
  #
822 826
  #   Links can refer other objects from other projects, using project identifier:
823 827
  #     identifier:r52
......
908 912
            when 'user'
909 913
              u = User.visible.where(:id => oid, :type => 'User').first
910 914
              link = link_to_user(u, :only_path => only_path) if u
915
            when 'file'
916
              if project && file = Attachment.find_by_id(oid)
917
                if (file.container.is_a?(Version) && file.container.project == project) ||
918
                   (file.container.is_a?(Project) && file.container == project)
919
                  name = file.filename
920
                  link = link_to(h(name), { :only_path => only_path, :controller => 'attachments', :action => 'download', :id => file },
921
                                            :class => 'attachment')
922
                end
923
              end
911 924
            end
912 925
          elsif sep == ':'
913 926
            name = remove_double_quotes(identifier)
......
969 982
            when 'user'
970 983
              u = User.visible.where(:login => name, :type => 'User').first
971 984
              link = link_to_user(u, :only_path => only_path) if u
985
            when 'file'
986
              if project
987
                conditions = "container_type = 'Project' AND container_id = #{project.id}"
988
                if project.versions.any?
989
                  conditions = "(#{conditions}) OR "
990
                  conditions << "(container_type = 'Version' AND container_id IN (#{project.versions.collect{ |version| version.id }.join(', ')}))"
991
                end
992
                if file = Attachment.where(conditions).find_by_filename(name)
993
                  name = file.filename
994
                    link = link_to(h(name), { :only_path => only_path, :controller => 'attachments', :action => 'download', :id => file },
995
                                              :class => 'attachment')
996
                end
997
              end
972 998
            end
973 999
          elsif sep == "@"
974 1000
            name = remove_double_quotes(identifier)
......
987 1013
            (?<leading>[\s\(,\-\[\>]|^)
988 1014
            (?<esc>!)?
989 1015
            (?<project_prefix>(?<project_identifier>[a-z0-9\-_]+):)?
990
            (?<prefix>attachment|document|version|forum|news|message|project|commit|source|export|user)?
1016
            (?<prefix>attachment|document|version|forum|news|message|project|commit|source|export|user|file)?
991 1017
            (
992 1018
              (
993 1019
                (?<sep1>\#)|
    (1-1/1)