diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 2daee50de..debe02162 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require 'uri' + class ApplicationController < ActionController::Base before_filter :user_setup, :check_if_login_required, :set_localization filter_parameter_logging :password @@ -77,8 +79,7 @@ class ApplicationController < ActionController::Base def require_login if !User.current.logged? - store_location - redirect_to :controller => "account", :action => "login" + redirect_to :controller => "account", :action => "login", :back_url => request.request_uri return false end true @@ -115,20 +116,16 @@ class ApplicationController < ActionController::Base end end - # store current uri in session. - # return to this location by calling redirect_back_or_default - def store_location - session[:return_to_params] = params - end - - # move to the last store_location call or to the passed default one def redirect_back_or_default(default) - if session[:return_to_params].nil? - redirect_to default - else - redirect_to session[:return_to_params] - session[:return_to_params] = nil + back_url = params[:back_url] + if !back_url.blank? + uri = URI.parse(back_url) + # do not redirect user to another host + if uri.relative? || (uri.host == request.host) + redirect_to(back_url) and return + end end + redirect_to default end def render_403 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3af77d1ac..ce4b24b8b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -226,94 +226,22 @@ class ProjectsController < ApplicationController @date_to ||= Date.today + 1 @date_from = @date_to - @days + @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') - @event_types = %w(issues news files documents changesets wiki_pages messages) - if @project - @event_types.delete('wiki_pages') unless @project.wiki - @event_types.delete('changesets') unless @project.repository - @event_types.delete('messages') unless @project.boards.any? - # only show what the user is allowed to view - @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} - @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') - end - @scope = @event_types.select {|t| params["show_#{t}"]} - # default events if none is specified in parameters - @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? - - @events = [] - - if @scope.include?('issues') - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions) - - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - cond.add("#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> ''") - @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions) - end - - if @scope.include?('news') - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions) - end - - if @scope.include?('files') - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", - :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " + - "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id", - :conditions => cond.conditions) - end - - if @scope.include?('documents') - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += Document.find(:all, :include => :project, :conditions => cond.conditions) - - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", - :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " + - "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id", - :conditions => cond.conditions) - end - - if @scope.include?('wiki_pages') - select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + - "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + - "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + - "#{WikiContent.versioned_table_name}.id" - joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + - "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + - "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id" + @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects) + @activity.scope_select {|t| !params["show_#{t}"].nil?} + @activity.default_scope! if @activity.scope.empty? - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions) - end - - if @scope.include?('changesets') - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions) - end - - if @scope.include?('messages') - cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects)) - cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) - @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions) - end - - @events_by_day = @events.group_by(&:event_date) + events = @activity.events(@date_from, @date_to) respond_to do |format| - format.html { render :layout => false if request.xhr? } + format.html { + @events_by_day = events.group_by(&:event_date) + render :layout => false if request.xhr? + } format.atom { title = (@scope.size == 1) ? l("label_#{@scope.first.singularize}_plural") : l(:label_activity) - render_feed(@events, :title => "#{@project || Setting.app_title}: #{title}") + render_feed(events, :title => "#{@project || Setting.app_title}: #{title}") } end end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 8655cfed7..5a5f3949f 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -147,6 +147,7 @@ class WikiController < ApplicationController :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", :order => 'title' @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} + @pages_by_parent_id = @pages.group_by(&:parent_id) # export wiki to a single html file when 'export' @pages = @wiki.pages.find :all, :order => 'title' @@ -164,7 +165,10 @@ class WikiController < ApplicationController page = @wiki.find_page(params[:page]) # page is nil when previewing a new page return render_403 unless page.nil? || editable?(page) - @attachements = page.attachments if page + if page + @attachements = page.attachments + @previewed = page.content + end @text = params[:content][:text] render :partial => 'common/preview' end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6e39d093f..a4102c84a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -177,7 +177,8 @@ module ApplicationHelper end def breadcrumb(*args) - content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') + elements = args.flatten + elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil end def html_title(*args) @@ -205,7 +206,7 @@ module ApplicationHelper options = args.last.is_a?(Hash) ? args.pop : {} case args.size when 1 - obj = nil + obj = options[:object] text = args.shift when 2 obj = args.shift @@ -245,12 +246,12 @@ module ApplicationHelper case options[:wiki_links] when :local # used for local links to html files - format_wiki_link = Proc.new {|project, title| "#{title}.html" } + format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" } when :anchor # used for single-file wiki export - format_wiki_link = Proc.new {|project, title| "##{title}" } + format_wiki_link = Proc.new {|project, title, anchor| "##{title}" } else - format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) } + format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) } end project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) @@ -276,9 +277,14 @@ module ApplicationHelper end if link_project && link_project.wiki + # extract anchor + anchor = nil + if page =~ /^(.+?)\#(.+)$/ + page, anchor = $1, $2 + end # check if page exists wiki_page = link_project.wiki.find_page(page) - link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), + link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor), :class => ('wiki-page' + (wiki_page ? '' : ' new'))) else # project or wiki doesn't exist @@ -451,7 +457,8 @@ module ApplicationHelper end def back_url_hidden_field_tag - hidden_field_tag 'back_url', (params[:back_url] || request.env['HTTP_REFERER']) + back_url = params[:back_url] || request.env['HTTP_REFERER'] + hidden_field_tag('back_url', back_url) unless back_url.blank? end def check_all_links(form_name) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 92f2da8a5..cd96dbd3f 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -18,7 +18,8 @@ module SearchHelper def highlight_tokens(text, tokens) return text unless text && tokens && !tokens.empty? - regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE + re_tokens = tokens.collect {|t| Regexp.escape(t)} + regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE result = '' text.split(regexp).each_with_index do |words, i| if result.length > 1200 diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index 980035bd4..0a6b810de 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -17,6 +17,22 @@ module WikiHelper + def render_page_hierarchy(pages, node=nil) + content = '' + if pages[node] + content << "
| diff --git a/app/views/common/_preview.rhtml b/app/views/common/_preview.rhtml index e3bfc3a25..fd95f1188 100644 --- a/app/views/common/_preview.rhtml +++ b/app/views/common/_preview.rhtml @@ -1,3 +1,3 @@ diff --git a/app/views/issues/context_menu.rhtml b/app/views/issues/context_menu.rhtml index af56782e8..0cdcd4733 100644 --- a/app/views/issues/context_menu.rhtml +++ b/app/views/issues/context_menu.rhtml @@ -44,6 +44,19 @@ :selected => @issue.assigned_to.nil?, :disabled => !@can[:update] %> + <% unless @project.issue_categories.empty? -%> + |