diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2025-03-09 23:25:12 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2025-03-09 23:25:12 +0000 |
commit | 1f46b0b236498de3cdcff4455ebb159edcd41450 (patch) | |
tree | ec4d830b2e5c4d7c7c1eedaf3122d60df11a0bac /app | |
parent | 3c5f0af44d711c356b4143cfe37f9b7091df0c67 (diff) | |
download | redmine-1f46b0b236498de3cdcff4455ebb159edcd41450.tar.gz redmine-1f46b0b236498de3cdcff4455ebb159edcd41450.zip |
Extract project query for admins to a separate ProjectAdminQuery model (#42352).
Patch by Holger Just (user:hjust).
git-svn-id: https://svn.redmine.org/redmine/trunk@23531 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/queries_controller.rb | 15 | ||||
-rw-r--r-- | app/helpers/queries_helper.rb | 2 | ||||
-rw-r--r-- | app/models/project_query.rb | 48 | ||||
-rw-r--r-- | app/models/query.rb | 2 | ||||
-rw-r--r-- | app/views/admin/projects.html.erb | 4 | ||||
-rw-r--r-- | app/views/queries/_form.html.erb | 5 | ||||
-rw-r--r-- | app/views/queries/_query_form.html.erb | 5 |
8 files changed, 24 insertions, 61 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 892629af1..9b45f9553 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -36,9 +36,7 @@ class AdminController < ApplicationController end def projects - retrieve_query(ProjectQuery, false, :defaults => @default_columns_names) - @query.admin_projects = 1 - + retrieve_query(ProjectAdminQuery, false, :defaults => @default_columns_names) @entry_count = @query.result_count @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] @projects = @query.results_scope(:limit => @entry_pages.per_page, :offset => @entry_pages.offset).to_a diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 09dc683a8..eac61ba6d 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -64,7 +64,7 @@ class QueriesController < ApplicationController if @query.save flash[:notice] = l(:notice_successful_create) - redirect_to_items(:query_id => @query, :admin_projects => params[:admin_projects]) + redirect_to_items(:query_id => @query) else render :action => 'new', :layout => !request.xhr? end @@ -78,7 +78,7 @@ class QueriesController < ApplicationController if @query.save flash[:notice] = l(:notice_successful_update) - redirect_to_items(:query_id => @query, :admin_projects => params[:admin_projects]) + redirect_to_items(:query_id => @query) else render :action => 'edit' end @@ -122,7 +122,6 @@ class QueriesController < ApplicationController def find_query @query = Query.find(params[:id]) - @query.admin_projects = params[:admin_projects] if @query.is_a?(ProjectQuery) @project = @query.project render_403 unless @query.editable_by?(User.current) rescue ActiveRecord::RecordNotFound @@ -173,11 +172,11 @@ class QueriesController < ApplicationController end def redirect_to_project_query(options) - if params[:admin_projects] - redirect_to admin_projects_path(options) - else - redirect_to projects_path(options) - end + redirect_to projects_path(options) + end + + def redirect_to_project_admin_query(options) + redirect_to admin_projects_path(options) end def redirect_to_user_query(options) diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 5e6d91a41..3775dcd3f 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -480,8 +480,6 @@ module QueriesHelper url_params = if controller_name == 'issues' {:controller => 'issues', :action => 'index', :project_id => @project} - elsif controller_name == 'admin' && action_name == 'projects' - {:admin_projects => '1'} else {} end diff --git a/app/models/project_query.rb b/app/models/project_query.rb index a43c1bc10..4464eb155 100644 --- a/app/models/project_query.rb +++ b/app/models/project_query.rb @@ -18,8 +18,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class ProjectQuery < Query - attr_accessor :admin_projects - self.queried_class = Project self.view_permission = :search_project @@ -28,6 +26,13 @@ class ProjectQuery < Query errors.add(:project_id, :exclusion) if query.project_id.present? end + # Inheriting ProjectAdminQuery from ProjectQuery introduces the problem that + # ProjectQuery.visible also yields ProjectAdminQueries, as + # well. We fix that by adding a condition on the actual class name. + def self.visible(*) + super.where type: name + end + self.available_columns = [ QueryColumn.new(:name, :sortable => "#{Project.table_name}.name"), QueryColumn.new(:status, :sortable => "#{Project.table_name}.status"), @@ -83,12 +88,6 @@ class ProjectQuery < Query add_custom_fields_filters(project_custom_fields) end - def build_from_params(params, defaults={}) - query = super - query.admin_projects = params[:admin_projects] - query - end - def available_columns return @available_columns if @available_columns @@ -99,28 +98,7 @@ class ProjectQuery < Query end def available_display_types - if self.admin_projects - ['list'] - else - ['board', 'list'] - end - end - - def display_type - if self.admin_projects - 'list' - else - super - end - end - - def project_statuses_values - values = super - if self.admin_projects - values << [l(:project_status_archived), Project::STATUS_ARCHIVED.to_s] - values << [l(:project_status_scheduled_for_deletion), Project::STATUS_SCHEDULED_FOR_DELETION.to_s] - end - values + ['board', 'list'] end def default_columns_names @@ -136,11 +114,7 @@ class ProjectQuery < Query end def base_scope - if self.admin_projects - Project.where(statement) - else - Project.visible.where(statement) - end + Project.visible.where(statement) end # Returns the project count @@ -174,8 +148,4 @@ class ProjectQuery < Query scope end - - def layout - admin_projects ? 'admin' : super - end end diff --git a/app/models/query.rb b/app/models/query.rb index 29a46f272..ebf254102 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -1006,7 +1006,7 @@ class Query < ApplicationRecord end end - if field == 'project_id' || (self.type == 'ProjectQuery' && %w[id parent_id].include?(field)) + if field == 'project_id' || (is_a?(ProjectQuery) && %w[id parent_id].include?(field)) if v.delete('mine') v += User.current.memberships.pluck(:project_id).map(&:to_s) end diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index baaf4e7d3..bb2f05677 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -6,7 +6,6 @@ <%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description, class: 'subtitle') : '' %> <%= form_tag(admin_projects_path(@project, nil), :method => :get, :id => 'query_form') do %> -<%= hidden_field_tag 'admin_projects', '1' %> <%= render :partial => 'queries/query_form' %> <% end %> @@ -19,5 +18,6 @@ <% end %> <% content_for :sidebar do %> - <%= render :partial => 'projects/sidebar' %> + <%= render_sidebar_queries(ProjectAdminQuery, @project) %> + <%= call_hook(:view_admin_projects_sidebar_queries_bottom) %> <% end %> diff --git a/app/views/queries/_form.html.erb b/app/views/queries/_form.html.erb index 213fb4890..b70ef53df 100644 --- a/app/views/queries/_form.html.erb +++ b/app/views/queries/_form.html.erb @@ -4,7 +4,6 @@ <div class="tabular"> <%= hidden_field_tag 'gantt', '1' if params[:gantt] %> <%= hidden_field_tag 'calendar', '1' if params[:calendar] %> -<%= hidden_field_tag 'admin_projects', '1' if params[:admin_projects] %> <p> <label for="query_name"> @@ -21,7 +20,7 @@ <p><label><%=l(:field_visible)%></label> <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PRIVATE %> <%= l(:label_visibility_private) %></label> <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_PUBLIC %> <%= l(:label_visibility_public) %></label> - <% unless @query.type == 'ProjectQuery' %> + <% unless @query.is_a?(ProjectQuery) %> <label class="block"><%= radio_button 'query', 'visibility', Query::VISIBILITY_ROLES %> <%= l(:label_visibility_roles) %>:</label> <% Role.givable.sorted.each do |role| %> <label class="block role-visibility"><%= check_box_tag 'query[role_ids][]', role.id, @query.roles.include?(role), :id => nil %> <%= role.name %></label> @@ -31,7 +30,7 @@ </p> <% end %> -<% unless @query.type == 'ProjectQuery' %> +<% unless @query.is_a?(ProjectQuery) %> <p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label> <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :class => (User.current.admin? ? '' : 'disable-unless-private') %></p> <% end %> diff --git a/app/views/queries/_query_form.html.erb b/app/views/queries/_query_form.html.erb index 68bc483a4..d04cd290e 100644 --- a/app/views/queries/_query_form.html.erb +++ b/app/views/queries/_query_form.html.erb @@ -69,9 +69,8 @@ <% end %> <% else %> <% if @query.editable_by?(User.current) %> - <% redirect_params = (controller_name == 'admin' && action_name == 'projects') ? {:admin_projects => 1} : {} %> - <%= link_to sprite_icon('edit', l(:button_edit_object, object_name: l(:label_query)).capitalize), edit_query_path(@query, redirect_params), :class => 'icon icon-edit' %> - <%= delete_link query_path(@query, redirect_params), {}, l(:button_delete_object, object_name: l(:label_query)).capitalize %> + <%= link_to sprite_icon('edit', l(:button_edit_object, object_name: l(:label_query)).capitalize), edit_query_path(@query), :class => 'icon icon-edit' %> + <%= delete_link query_path(@query), {}, l(:button_delete_object, object_name: l(:label_query)).capitalize %> <% end %> <% end %> </p> |