Feature #6049 ยป redmine_search_archived_aug8.patch
| app/controllers/application_controller.rb | ||
|---|---|---|
| 39 | 39 |
end |
| 40 | 40 | |
| 41 | 41 |
before_filter :user_setup, :check_if_login_required, :set_localization |
| 42 |
before_filter :check_for_search_archived |
|
| 42 | 43 |
filter_parameter_logging :password |
| 43 | 44 |
protect_from_forgery |
| 44 | 45 | |
| ... | ... | |
| 60 | 61 |
User.current = find_current_user |
| 61 | 62 |
end |
| 62 | 63 | |
| 64 |
def check_for_search_archived |
|
| 65 |
if params[:search_archived] |
|
| 66 |
flash.now[:error] = "Search Archived: suspending access checks for admin user." |
|
| 67 |
$search_archived = params[:search_archived].present? |
|
| 68 |
else |
|
| 69 |
$search_archived = nil |
|
| 70 |
end |
|
| 71 |
end |
|
| 72 | ||
| 63 | 73 |
# Returns the current user or nil if no user is logged in |
| 64 | 74 |
# and starts a session if needed |
| 65 | 75 |
def find_current_user |
| app/models/project.rb | ||
|---|---|---|
| 146 | 146 |
# * :member => limit the condition to the user projects |
| 147 | 147 |
def self.allowed_to_condition(user, permission, options={})
|
| 148 | 148 |
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
| 149 | ||
| 150 |
if $search_archived |
|
| 151 |
#allow admins access to search_access checkbox |
|
| 152 |
if user.admin? |
|
| 153 |
base_statement = "#{Project.table_name}.status IN (#{Project::STATUS_ARCHIVED},#{Project::STATUS_ACTIVE})"
|
|
| 154 |
end |
|
| 155 |
end |
|
| 156 | ||
| 149 | 157 |
if perm = Redmine::AccessControl.permission(permission) |
| 150 | 158 |
unless perm.project_module.nil? |
| 151 | 159 |
# If the permission belongs to a project module, make sure the module is enabled |
| app/models/user.rb | ||
|---|---|---|
| 398 | 398 |
# * nil with options[:global] set : check if user has at least one role allowed for this action, |
| 399 | 399 |
# or falls back to Non Member / Anonymous permissions depending if the user is logged |
| 400 | 400 |
def allowed_to?(action, context, options={}, &block)
|
| 401 |
|
|
| 402 |
# allow admins full access in case of search_archived |
|
| 403 |
if($search_archived) |
|
| 404 |
return true if admin? |
|
| 405 |
end |
|
| 406 | ||
| 401 | 407 |
if context && context.is_a?(Project) |
| 402 | 408 |
# No action allowed on archived projects |
| 403 | 409 |
return false unless context.active? |
| app/views/search/index.rhtml | ||
|---|---|---|
| 9 | 9 |
<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label> |
| 10 | 10 |
<%= hidden_field_tag 'titles_only', '', :id => nil %> |
| 11 | 11 |
<label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label> |
| 12 |
<% # Injects search_archived checkbox, for admins only %> |
|
| 13 |
<% if User.current.admin? %> |
|
| 14 |
<label><%= check_box_tag 'search_archived', 1, $search_archived %> Search archived</label> |
|
| 15 |
<% end %> |
|
| 12 | 16 |
</p> |
| 13 | 17 |
<p> |
| 14 | 18 |
<% @object_types.each do |t| %> |
| ... | ... | |
| 28 | 32 |
<h3><%= l(:label_result_plural) %> (<%= @results_by_type.values.sum %>)</h3> |
| 29 | 33 |
<dl id="search-results"> |
| 30 | 34 |
<% @results.each do |e| %> |
| 31 |
<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>
|
|
| 35 |
<% # appends ?search_archived=1 query arg to link url if appropriate %> |
|
| 36 |
<% search_archived_item_url = !$search_archived ? e.event_url : e.event_url.merge( {"search_archived" => "1" }) %>
|
|
| 37 |
<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>
|
|
| 32 | 38 |
<dd><span class="description"><%= highlight_tokens(e.event_description, @tokens) %></span> |
| 33 | 39 |
<span class="author"><%= format_time(e.event_datetime) %></span></dd> |
| 34 | 40 |
<% end %> |