Feature #6049 ยป redmine_search_archived_aug8.patch
| app/controllers/application_controller.rb | ||
|---|---|---|
|
end
|
||
|
before_filter :user_setup, :check_if_login_required, :set_localization
|
||
|
before_filter :check_for_search_archived
|
||
|
filter_parameter_logging :password
|
||
|
protect_from_forgery
|
||
| ... | ... | |
|
User.current = find_current_user
|
||
|
end
|
||
|
def check_for_search_archived
|
||
|
if params[:search_archived]
|
||
|
flash.now[:error] = "Search Archived: suspending access checks for admin user."
|
||
|
$search_archived = params[:search_archived].present?
|
||
|
else
|
||
|
$search_archived = nil
|
||
|
end
|
||
|
end
|
||
|
# Returns the current user or nil if no user is logged in
|
||
|
# and starts a session if needed
|
||
|
def find_current_user
|
||
| app/models/project.rb | ||
|---|---|---|
|
# * :member => limit the condition to the user projects
|
||
|
def self.allowed_to_condition(user, permission, options={})
|
||
|
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||
|
if $search_archived
|
||
|
#allow admins access to search_access checkbox
|
||
|
if user.admin?
|
||
|
base_statement = "#{Project.table_name}.status IN (#{Project::STATUS_ARCHIVED},#{Project::STATUS_ACTIVE})"
|
||
|
end
|
||
|
end
|
||
|
if perm = Redmine::AccessControl.permission(permission)
|
||
|
unless perm.project_module.nil?
|
||
|
# If the permission belongs to a project module, make sure the module is enabled
|
||
| app/models/user.rb | ||
|---|---|---|
|
# * nil with options[:global] set : check if user has at least one role allowed for this action,
|
||
|
# or falls back to Non Member / Anonymous permissions depending if the user is logged
|
||
|
def allowed_to?(action, context, options={}, &block)
|
||
|
|
||
|
# allow admins full access in case of search_archived
|
||
|
if($search_archived)
|
||
|
return true if admin?
|
||
|
end
|
||
|
if context && context.is_a?(Project)
|
||
|
# No action allowed on archived projects
|
||
|
return false unless context.active?
|
||
| app/views/search/index.rhtml | ||
|---|---|---|
|
<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label>
|
||
|
<%= hidden_field_tag 'titles_only', '', :id => nil %>
|
||
|
<label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label>
|
||
|
<% # Injects search_archived checkbox, for admins only %>
|
||
|
<% if User.current.admin? %>
|
||
|
<label><%= check_box_tag 'search_archived', 1, $search_archived %> Search archived</label>
|
||
|
<% end %>
|
||
|
</p>
|
||
|
<p>
|
||
|
<% @object_types.each do |t| %>
|
||
| ... | ... | |
|
<h3><%= l(:label_result_plural) %> (<%= @results_by_type.values.sum %>)</h3>
|
||
|
<dl id="search-results">
|
||
|
<% @results.each do |e| %>
|
||
|
<dt class="<%= e.event_type %>"><%= content_tag('span', h(e.project), :class => 'project') unless @project == e.project %> <%= link_to highlight_tokens(truncate(e.event_title, :length => 255), @tokens), e.event_url %></dt>
|
||
|
<% # appends ?search_archived=1 query arg to link url if appropriate %>
|
||
|
<% search_archived_item_url = !$search_archived ? e.event_url : e.event_url.merge( {"search_archived" => "1" }) %>
|
||
|
<dt class="<%= e.event_type %>"><%= content_tag('span', h(e.project), :class => 'project') unless @project == e.project %> <%= link_to highlight_tokens(truncate(e.event_title, :length => 255), @tokens), search_archived_item_url %></dt>
|
||
|
<dd><span class="description"><%= highlight_tokens(e.event_description, @tokens) %></span>
|
||
|
<span class="author"><%= format_time(e.event_datetime) %></span></dd>
|
||
|
<% end %>
|
||