Feature #7360 » default_custom_query_trunk_r15273.patch
| app/controllers/default_custom_query_setting_controller.rb | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class DefaultCustomQuerySettingController < ApplicationController
|
||
|
before_filter :find_project_by_project_id
|
||
|
before_filter :authorize
|
||
|
helper :default_custom_query
|
||
|
def update
|
||
|
settings = params[:settings]
|
||
|
@default_query = ProjectsDefaultQuery.initialize_for(@project.id)
|
||
|
@default_query.query_id = settings[:query_id]
|
||
|
if @default_query.save
|
||
|
session[:query] = nil
|
||
|
end
|
||
|
render partial: 'form'
|
||
|
end
|
||
|
end
|
||
| app/controllers/issues_controller.rb | ||
|---|---|---|
|
before_filter :authorize, :except => [:index, :new, :create]
|
||
|
before_filter :find_optional_project, :only => [:index, :new, :create]
|
||
|
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
||
|
before_filter :with_default_query, only: [:index], if: :default_query_module_enabled?
|
||
|
accept_rss_auth :index, :show
|
||
|
accept_api_auth :index, :show, :create, :update, :destroy
|
||
| ... | ... | |
|
private
|
||
|
def with_default_query
|
||
|
case
|
||
|
when params[:query_id].present?
|
||
|
# Nothing to do
|
||
|
when api_request?
|
||
|
# Nothing to do
|
||
|
# when show_all_issues?
|
||
|
when params[:without_default]
|
||
|
params[:set_filter] = 1
|
||
|
# when filter_applied?
|
||
|
when params[:set_filter] && params.key?(:op) && params.key?(:f)
|
||
|
# Nothing to do
|
||
|
# when filter_cleared?
|
||
|
when params[:set_filter] && [:op, :f].all? {|k| !params.key?(k) }
|
||
|
apply_default_query!
|
||
|
when session[:query]
|
||
|
query_id, project_id = session[:query].values_at(:id, :project_id)
|
||
|
unless query_id && (project_id == @project.id) && IssueQuery.available_query?(@project.id, query_id)
|
||
|
apply_default_query!
|
||
|
end
|
||
|
else
|
||
|
apply_default_query!
|
||
|
end
|
||
|
end
|
||
|
def apply_default_query!
|
||
|
default_query = find_default_query
|
||
|
if default_query
|
||
|
params[:query_id] = default_query.id
|
||
|
end
|
||
|
end
|
||
|
def retrieve_previous_and_next_issue_ids
|
||
|
if params[:prev_issue_id].present? || params[:next_issue_id].present?
|
||
|
@prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
|
||
| app/controllers/projects_controller.rb | ||
|---|---|---|
|
helper :queries
|
||
|
helper :repositories
|
||
|
helper :members
|
||
|
helper :default_custom_query
|
||
|
# Lists visible projects
|
||
|
def index
|
||
| app/helpers/default_custom_query_helper.rb | ||
|---|---|---|
|
module DefaultCustomQueryHelper
|
||
|
def options_for_selectable_queries(project)
|
||
|
options_groups = []
|
||
|
queries = IssueQuery.only_public.where(project_id: nil)
|
||
|
if queries.any?
|
||
|
options_groups << [l('default_custom_query.label_queries_for_all_projects'), queries]
|
||
|
end
|
||
|
queries = project.queries.only_public
|
||
|
if queries.any?
|
||
|
options_groups << [l('default_custom_query.label_queries_for_current_project'), queries]
|
||
|
end
|
||
|
options_groups.map do |group, options|
|
||
|
[group, options.collect {|o| [o.name, o.id] }]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| app/helpers/projects_helper.rb | ||
|---|---|---|
|
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
|
||
|
{:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
|
||
|
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
|
||
|
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
|
||
|
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities},
|
||
|
{:name => 'default_custom_query', :action => :manage_default_query, :partial => 'default_custom_query_setting/form', :label => :'default_custom_query.label_setting'}
|
||
|
]
|
||
|
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||
|
tabs = tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
||
|
end
|
||
|
def parent_project_select_tag(project)
|
||
| app/helpers/queries_helper.rb | ||
|---|---|---|
|
@query.project = @project
|
||
|
end
|
||
|
@query
|
||
|
else
|
||
|
@query = find_default_query
|
||
|
end
|
||
|
end
|
||
|
private
|
||
|
def find_default_query
|
||
|
@project.default_query if @project.is_a?(Project)
|
||
|
end
|
||
|
def default_query_module_enabled?
|
||
|
@project && @project.module_enabled?(:default_custom_query)
|
||
|
end
|
||
|
# Returns the query definition as hidden field tags
|
||
|
def query_as_hidden_field_tags(query)
|
||
|
tags = hidden_field_tag("set_filter", "1", :id => nil)
|
||
| app/models/issue_query.rb | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class IssueQuery < Query
|
||
|
has_many :projects_default_queries, dependent: :nullify, foreign_key: :query_id
|
||
|
self.queried_class = Issue
|
||
| ... | ... | |
|
end
|
||
|
}
|
||
|
scope :only_public, -> {
|
||
|
where(:visibility => VISIBILITY_PUBLIC)
|
||
|
}
|
||
|
def self.available_query?(project_id, query_id)
|
||
|
self.only_public
|
||
|
.where('project_id is null or project_id = ?', project_id)
|
||
|
.where(id: query_id).exists?
|
||
|
end
|
||
|
def initialize(attributes=nil, *args)
|
||
|
super attributes
|
||
|
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
|
||
| ... | ... | |
|
!is_private?
|
||
|
end
|
||
|
def public_visibility?
|
||
|
visibility == VISIBILITY_PUBLIC
|
||
|
end
|
||
|
def draw_relations
|
||
|
r = options[:draw_relations]
|
||
|
r.nil? || r == '1'
|
||
| app/models/project.rb | ||
|---|---|---|
|
:class_name => 'IssueCustomField',
|
||
|
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||
|
:association_foreign_key => 'custom_field_id'
|
||
|
# Default Custom Queries
|
||
|
has_many :default_queries, dependent: :delete_all, :class_name => 'ProjectsDefaultQuery'
|
||
|
acts_as_attachable :view_permission => :view_files,
|
||
|
:edit_permission => :manage_files,
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def default_query
|
||
|
default_queries.first.try :query
|
||
|
end
|
||
|
def init_default_query
|
||
|
default_queries.first || default_queries.new
|
||
|
end
|
||
|
private
|
||
|
def update_inherited_members
|
||
| app/models/projects_default_query.rb | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class ProjectsDefaultQuery < ActiveRecord::Base
|
||
|
belongs_to :project
|
||
|
belongs_to :query, class_name: 'IssueQuery'
|
||
|
validates :project_id, :query_id, numericality: { allow_nil: true }
|
||
|
validates :project_id, uniqueness: true, presence: true
|
||
|
validate :query_must_be_selectable
|
||
|
def self.initialize_for(project_id)
|
||
|
default_query = where(:project_id => project_id).first
|
||
|
unless default_query
|
||
|
default_query = self.new
|
||
|
default_query.project_id = project_id
|
||
|
end
|
||
|
default_query
|
||
|
end
|
||
|
def query
|
||
|
return unless super
|
||
|
unless new_record? || selectable_query?(super)
|
||
|
update_attribute :query_id, nil
|
||
|
end
|
||
|
super
|
||
|
end
|
||
|
private
|
||
|
def query_must_be_selectable
|
||
|
return if errors.any? || query_id.blank? || !query_id_changed?
|
||
|
issue_query = IssueQuery.where(:id => query_id).first
|
||
|
unless selectable_query?(issue_query)
|
||
|
errors.add :query_id, :invalid
|
||
|
end
|
||
|
end
|
||
|
def selectable_query?(query)
|
||
|
query && query.public_visibility? &&
|
||
|
(query.project.nil? || query.project == project)
|
||
|
end
|
||
|
end
|
||
| app/views/default_custom_query_setting/_form.html.erb | ||
|---|---|---|
|
<%= labelled_form_for @default_query ||= @project.init_default_query,
|
||
|
as: :settings,
|
||
|
url: default_custom_query_setting_update_path(@project),
|
||
|
remote: true, method: :put, html: { id: 'default-query-setting' } do |f| %>
|
||
|
<%= error_messages_for @default_query %>
|
||
|
<div class="box tabular">
|
||
|
<p>
|
||
|
<%= f.select :query_id, options_for_selectable_queries(@project), include_blank: true %><br>
|
||
|
<em><%=l 'default_custom_query.text_allowed_queries' %></em>
|
||
|
</p>
|
||
|
</div>
|
||
|
<%= submit_tag l(:button_save) %>
|
||
|
<% end %>
|
||
|
<script>
|
||
|
$('#default-query-setting').on('ajax:success', function(data, result, xhr) {
|
||
|
$('#tab-content-default_custom_query').html(result);
|
||
|
});
|
||
|
</script>
|
||
| app/views/issues/_sidebar.html.erb | ||
|---|---|---|
|
<h3><%= l(:label_issue_plural) %></h3>
|
||
|
<ul>
|
||
|
<li><%= link_to l(:label_issue_view_all), _project_issues_path(@project, :set_filter => 1) %></li>
|
||
|
<% if @project && @project.module_enabled?(:default_custom_query) && @project.default_query.present? %>
|
||
|
<li><%= link_to l('default_custom_query.label_view_default_issues'), project_issues_path(@project, :set_filter => 1) %><li>
|
||
|
<% end %>
|
||
|
<li><%= link_to l(:label_issue_view_all), _project_issues_path(@project, :set_filter => 1, :without_default => 1) %></li>
|
||
|
<% if @project %>
|
||
|
<li><%= link_to l(:field_summary), project_issues_report_path(@project) %></li>
|
||
|
<% end %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
description_date_from: Enter start date
|
||
|
description_date_to: Enter end date
|
||
|
text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'
|
||
|
|
||
|
project_module_default_custom_query: Default custom query
|
||
|
permission_manage_default_query: Manage default query
|
||
|
# Labels for projects_default_queries column
|
||
|
field_query: Default custom query
|
||
|
default_custom_query:
|
||
|
label_setting: Default custom query
|
||
|
label_view_default_issues: View default issues
|
||
|
label_queries_for_all_projects: For all projects
|
||
|
label_queries_for_current_project: For current project
|
||
|
text_allowed_queries: Public (to any users) queries only selectable
|
||
| config/locales/fr.yml | ||
|---|---|---|
|
mail_body_security_notification_notify_enabled: Les notifications ont été activées pour l'adresse %{value}
|
||
|
mail_body_security_notification_notify_disabled: Les notifications ont été désactivées pour l'adresse %{value}
|
||
|
field_remote_ip: Adresse IP
|
||
|
project_module_default_custom_query: Rapport par défaut
|
||
|
permission_manage_default_query: Gérer le rapport par défaut
|
||
|
# Labels for projects_default_queries column
|
||
|
field_query: Rapport par défaut
|
||
|
default_custom_query:
|
||
|
label_setting: Rapport par défaut
|
||
|
label_view_default_issues: Voir les demandes par défaut
|
||
|
label_queries_for_all_projects: Pour tous les projets
|
||
|
label_queries_for_current_project: Pour le projet en cours
|
||
|
text_allowed_queries: Seuls les rapports publics (pour tous les utilisateurs) sont sélectionnables
|
||
| config/locales/ja.yml | ||
|---|---|---|
|
receives notifications.
|
||
|
mail_body_settings_updated: ! 'The following settings were changed:'
|
||
|
field_remote_ip: IP address
|
||
|
project_module_default_custom_query: デフォルトカスタムクエリ
|
||
|
permission_manage_default_query: デフォルトカスタムクエリの管理
|
||
|
# Labels for projects_default_queries column
|
||
|
field_query: デフォルトクエリ
|
||
|
default_custom_query:
|
||
|
label_setting: デフォルトカスタムクエリ
|
||
|
label_view_default_issues: デフォルトチケット一覧を見る
|
||
|
label_queries_for_all_projects: 全プロジェクト向け
|
||
|
label_queries_for_current_project: 現在プロジェクト
|
||
|
text_allowed_queries: 公開クエリ(すべてのユーザ)のみ選択可能
|
||
| config/locales/ru.yml | ||
|---|---|---|
|
receives notifications.
|
||
|
mail_body_settings_updated: ! 'The following settings were changed:'
|
||
|
field_remote_ip: IP address
|
||
|
project_module_default_custom_query: Выбор запроса по умолчанию (фильтр задач)
|
||
|
permission_manage_default_query: Manage default query
|
||
|
# Labels for projects_default_queries column
|
||
|
field_query: Выбор запроса по умолчанию
|
||
|
default_custom_query:
|
||
|
label_setting: Выбор запроса по умолчанию
|
||
|
label_view_default_issues: Просматривать запросы по умолчанию
|
||
|
label_queries_for_all_projects: Для всех проектов
|
||
|
label_queries_for_current_project: Для текущего прооекта
|
||
|
text_allowed_queries: Для выбора доступны только публичные запросы (фильтры задач)
|
||
| config/locales/tr.yml | ||
|---|---|---|
|
receives notifications.
|
||
|
mail_body_settings_updated: ! 'The following settings were changed:'
|
||
|
field_remote_ip: IP address
|
||
|
project_module_default_custom_query: Öntanımlı özel sorgu
|
||
|
permission_manage_default_query: Öntanımlı sorguyu yönet
|
||
|
# Labels for projects_default_queries column
|
||
|
field_query: Öntanımlı özel sorgu
|
||
|
default_custom_query:
|
||
|
label_setting: Öntanımlı özel sorgu
|
||
|
label_view_default_issues: Öntanımlı işleri gör
|
||
|
label_queries_for_all_projects: Tüm birimler için
|
||
|
label_queries_for_current_project: Simdiki birim için
|
||
|
text_allowed_queries: Herkese açık (tüm kullanıcılar) sorgular sadece seçilebilir
|
||
| config/routes.rb | ||
|---|---|---|
|
match 'uploads', :to => 'attachments#upload', :via => :post
|
||
|
controller :default_custom_query_setting, as: 'default_custom_query_setting' do
|
||
|
put ':project_id/default_custom_query/update', action: 'update', as: 'update'
|
||
|
end
|
||
|
get 'robots.txt', :to => 'welcome#robots'
|
||
|
Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir|
|
||
| config/settings.yml | ||
|---|---|---|
|
- boards
|
||
|
- calendar
|
||
|
- gantt
|
||
|
- default_custom_query
|
||
|
default_projects_tracker_ids:
|
||
|
serialized: true
|
||
|
default:
|
||
| db/migrate/20160307180800_create_projects_default_queries.rb | ||
|---|---|---|
|
class CreateProjectsDefaultQueries < ActiveRecord::Migration
|
||
|
def change
|
||
|
create_table :projects_default_queries do |t|
|
||
|
t.belongs_to :project
|
||
|
t.belongs_to :query
|
||
|
t.timestamps null: false
|
||
|
end
|
||
|
add_index :projects_default_queries, :project_id, unique: true
|
||
|
add_index :projects_default_queries, :query_id
|
||
|
end
|
||
|
end
|
||
| lib/redmine.rb | ||
|---|---|---|
|
map.project_module :gantt do |map|
|
||
|
map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true
|
||
|
end
|
||
|
map.project_module :default_custom_query do |map|
|
||
|
map.permission :manage_default_query, { :default_custom_query_setting => [:update] }, :require => :member
|
||
|
end
|
||
|
end
|
||
|
Redmine::MenuManager.map :top_menu do |menu|
|
||
| test/functional/default_custom_query_setting_controller.rb | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
class DefaultCustomQuerySettingControllerTest < ActionController::TestCase
|
||
|
fixtures :projects,
|
||
|
:users,
|
||
|
:roles,
|
||
|
:members,
|
||
|
:member_roles,
|
||
|
:issues
|
||
|
def setup
|
||
|
User.current = nil
|
||
|
@request.session[:user_id] = nil
|
||
|
@project = Project.generate_with_parent!
|
||
|
@project.enable_module!(:default_custom_query)
|
||
|
@permitted_user = User.generate!
|
||
|
User.add_to_project(@permitted_user, @project, Role.generate!(:permissions => [:edit_project, :manage_default_query]))
|
||
|
@not_permitted_user = User.generate!
|
||
|
User.add_to_project(@not_permitted_user, @project, Role.generate!(:permissions => [:edit_project, :add_subprojects]))
|
||
|
@stored_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
@session_query_value = {:id => @stored_query.id, :project_id => @project.id}
|
||
|
@request.session[:query] = @session_query_value
|
||
|
end
|
||
|
def test_update_should_success_when_module_is_enabled_on_project_and_logged_user_has_permission
|
||
|
public_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
@request.session[:user_id] = @permitted_user.id
|
||
|
xhr :put, :update, :project_id => @project.id, :settings => {:query_id => public_query.id}
|
||
|
assert_response :success
|
||
|
assert_nil @request.session[:query]
|
||
|
assert_template partial: 'default_custom_query_setting/_form'
|
||
|
assert_equal public_query, @project.default_query
|
||
|
end
|
||
|
def test_update_should_success_and_clear_query_when_module_is_enabled_on_project_and_logged_user_has_permission
|
||
|
@request.session[:user_id] = @permitted_user.id
|
||
|
xhr :put, :update, :project_id => @project.id, :settings => {:query_id => nil}
|
||
|
assert_response :success
|
||
|
assert_equal nil, @request.session[:query]
|
||
|
assert_template partial: 'default_custom_query_setting/_form'
|
||
|
assert_nil @project.default_query
|
||
|
end
|
||
|
def test_update_should_failure_when_module_is_enabled_on_project_but_logged_user_does_not_have_permission
|
||
|
public_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
@request.session[:user_id] = @not_permitted_user.id
|
||
|
xhr :put, :update, :project_id => @project.identifier, :settings => {:query_id => public_query.id}
|
||
|
assert_response :forbidden
|
||
|
assert_equal @session_query_value, @request.session[:query]
|
||
|
end
|
||
|
def test_update_should_failure_when_module_is_enabled_on_project_but_spacified_unselectable_query
|
||
|
private_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => @project)
|
||
|
@request.session[:user_id] = @permitted_user.id
|
||
|
xhr :put, :update, :project_id => @project.id, :settings => {:query_id => private_query.id}
|
||
|
assert_response :success
|
||
|
assert_equal @session_query_value, @request.session[:query]
|
||
|
assert_template partial: 'default_custom_query_setting/_form'
|
||
|
assert_select '#errorExplanation li', 1
|
||
|
end
|
||
|
def test_update_should_failure_when_module_is_disabled
|
||
|
@project.disable_module!(:default_custom_query)
|
||
|
public_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
@request.session[:user_id] = @permitted_user.id
|
||
|
xhr :put, :update, :project_id => @project.id, :settings => {:query_id => public_query.id}
|
||
|
assert_response :forbidden
|
||
|
assert_equal @session_query_value, @request.session[:query]
|
||
|
end
|
||
|
end
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
assert_response :success
|
||
|
end
|
||
|
def test_default_query_should_be_available_when_default_query_module_enabled
|
||
|
project = Project.find(1)
|
||
|
project.enable_module!(:default_custom_query)
|
||
|
q = IssueQuery.create!(:name => "default_custom_query", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
|
||
|
dq = ProjectsDefaultQuery.initialize_for(project.id)
|
||
|
dq.query = q
|
||
|
dq.save!
|
||
|
@request.session[:user_id] = 3
|
||
|
get :index, :project_id => 1
|
||
|
assert_response :success
|
||
|
assert_select 'h2', text: q.name
|
||
|
assert_select 'ul.queries a.selected', text: q.name
|
||
|
end
|
||
|
def test_default_query_should_be_unavailable_when_default_query_module_disabled
|
||
|
project = Project.find(1)
|
||
|
project.disable_module!(:default_custom_query)
|
||
|
@request.session[:user_id] = 3
|
||
|
get :index, :project_id => 1
|
||
|
assert_response :success
|
||
|
assert_select 'h2', text: l(:label_issue_plural)
|
||
|
assert_select 'ul.queries a.selected', false
|
||
|
end
|
||
|
def test_default_query_should_be_unavailable_when_param_without_default_spacified
|
||
|
project = Project.find(1)
|
||
|
project.enable_module!(:default_custom_query)
|
||
|
q = IssueQuery.create!(:name => "default_custom_query", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
|
||
|
dq = ProjectsDefaultQuery.initialize_for(project.id)
|
||
|
dq.query = q
|
||
|
dq.save!
|
||
|
@request.session[:user_id] = 3
|
||
|
get :index, :project_id => 1, :without_default => 1
|
||
|
assert_response :success
|
||
|
assert_select 'h2', text: l(:label_issue_plural)
|
||
|
assert_select 'ul.queries a.selected', false
|
||
|
end
|
||
|
def test_default_query_should_be_unavailable_when_filter_condition_op_and_f_spacified
|
||
|
project = Project.find(1)
|
||
|
project.enable_module!(:default_custom_query)
|
||
|
q = IssueQuery.create!(:name => "default_custom_query", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
|
||
|
dq = ProjectsDefaultQuery.initialize_for(project.id)
|
||
|
dq.query = q
|
||
|
dq.save!
|
||
|
@request.session[:user_id] = 3
|
||
|
get :index, :project_id => 1, :set_filter => 1, :op => 'op', :f => 'f'
|
||
|
assert_response :success
|
||
|
assert_select 'h2', text: l(:label_issue_plural)
|
||
|
assert_select 'ul.queries a.selected', false
|
||
|
end
|
||
|
def test_index_should_omit_page_param_in_export_links
|
||
|
get :index, :page => 2
|
||
|
assert_response :success
|
||
| test/unit/helpers/default_custom_query_helper_test.rb | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require File.expand_path('../../../test_helper', __FILE__)
|
||
|
class DefaultCustomQueryHelperTest < ActionView::TestCase
|
||
|
include ApplicationHelper
|
||
|
include DefaultCustomQueryHelper
|
||
|
include Redmine::I18n
|
||
|
include ERB::Util
|
||
|
include Rails.application.routes.url_helpers
|
||
|
fixtures :projects, :queries
|
||
|
def setup
|
||
|
super
|
||
|
set_language_if_valid('en')
|
||
|
end
|
||
|
def test_options_for_selectable_queries
|
||
|
project = Project.find(2)
|
||
|
options = options_for_selectable_queries(project)
|
||
|
assert_equal 2, options.count
|
||
|
assert_includes options.first, l('default_custom_query.label_queries_for_all_projects')
|
||
|
assert_includes options.first, IssueQuery.only_public.where(:project_id => nil).collect {|o| [o.name, o.id]}
|
||
|
assert_includes options.last, l('default_custom_query.label_queries_for_current_project')
|
||
|
assert_includes options.last, project.queries.only_public.collect {|o| [o.name, o.id]}
|
||
|
end
|
||
|
end
|
||
| test/unit/project_test.rb | ||
|---|---|---|
|
Project.uniq.visible.to_a
|
||
|
end
|
||
|
end
|
||
|
def test_default_query
|
||
|
project = Project.find(1)
|
||
|
query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
ProjectsDefaultQuery.create!(:project_id => project.id, :query_id => query.id)
|
||
|
default_queries = ProjectsDefaultQuery.where(:project_id => project.id)
|
||
|
assert_equal query, project.default_query
|
||
|
end
|
||
|
def test_init_default_query
|
||
|
project = Project.find(1)
|
||
|
query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
default_query = ProjectsDefaultQuery.create!(:project_id => project.id, :query_id => query.id)
|
||
|
assert_equal default_query, project.init_default_query
|
||
|
default_query.destroy!
|
||
|
assert_kind_of ProjectsDefaultQuery, project.init_default_query
|
||
|
assert project.init_default_query.new_record?
|
||
|
end
|
||
|
end
|
||
| test/unit/projects_default_query_test.rb | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
class ProjectsDefaultQueryTest < ActiveSupport::TestCase
|
||
|
include Redmine::I18n
|
||
|
fixtures :projects, :queries
|
||
|
def setup
|
||
|
User.current = nil
|
||
|
@project = Project.find(1)
|
||
|
@issue_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => @project)
|
||
|
end
|
||
|
def test_initialize_for_should_return_new_record_object
|
||
|
ProjectsDefaultQuery.where(:project_id => @project.id).destroy_all
|
||
|
default_query = ProjectsDefaultQuery.initialize_for(@project.id)
|
||
|
assert_equal ProjectsDefaultQuery, default_query.class
|
||
|
assert_equal @project.id, default_query.project_id
|
||
|
assert_equal true, default_query.new_record?
|
||
|
end
|
||
|
def test_initialize_for_should_return_presisted_object
|
||
|
ProjectsDefaultQuery.create!(:project_id => @project.id)
|
||
|
default_query = ProjectsDefaultQuery.initialize_for(@project.id)
|
||
|
assert_equal ProjectsDefaultQuery, default_query.class
|
||
|
assert_equal @project.id, default_query.project_id
|
||
|
assert_equal true, default_query.persisted?
|
||
|
end
|
||
|
def test_validate_query_must_be_selectable
|
||
|
set_language_if_valid 'en'
|
||
|
default_query = ProjectsDefaultQuery.initialize_for(@project.id)
|
||
|
|
||
|
private_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => @project)
|
||
|
default_query.query_id = private_query.id
|
||
|
assert_not default_query.valid?
|
||
|
assert_includes default_query.errors[:query_id], "is invalid"
|
||
|
|
||
|
other_project_query = IssueQuery.create!(:name => "test", :user_id => 1, :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => Project.find(2))
|
||
|
default_query.query_id = other_project_query.id
|
||
|
assert_not default_query.valid?
|
||
|
assert_includes default_query.errors[:query_id], "is invalid"
|
||
|
end
|
||
|
def test_query_should_return_issue_query_object_when_associated_query_exist_and_visibility_public
|
||
|
default_query = ProjectsDefaultQuery.create!(:project_id => @project.id, :query_id => @issue_query.id)
|
||
|
assert_equal @issue_query, default_query.query
|
||
|
@issue_query.update_attribute :project_id, nil
|
||
|
default_query.reload
|
||
|
assert_equal @issue_query, default_query.query
|
||
|
end
|
||
|
def test_query_should_return_nil_when_associated_query_exist_and_visibility_private
|
||
|
default_query = ProjectsDefaultQuery.create!(:project_id => @project.id, :query_id => @issue_query.id)
|
||
|
|
||
|
@issue_query.update_attribute :visibility, IssueQuery::VISIBILITY_PRIVATE
|
||
|
default_query.reload
|
||
|
assert_nil default_query.query
|
||
|
end
|
||
|
def test_query_should_return_nil_when_associated_query_exist_and_difarent_project_query
|
||
|
default_query = ProjectsDefaultQuery.create!(:project_id => @project.id, :query_id => @issue_query.id)
|
||
|
@issue_query.update_attribute :project_id, 2
|
||
|
default_query.reload
|
||
|
assert_nil default_query.query
|
||
|
end
|
||
|
def test_query_should_return_nil_when_associated_query_does_not_exist
|
||
|
default_query = ProjectsDefaultQuery.create!(:project_id => @project.id, :query_id => @issue_query.id)
|
||
|
@issue_query.destroy!
|
||
|
default_query.reload
|
||
|
assert_nil default_query.query
|
||
|
end
|
||
|
end
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_available_query_should_return_true_when_public_query_existed_on_project
|
||
|
project = Project.find(1)
|
||
|
IssueQuery.only_public.destroy_all
|
||
|
public_issue_query_on_project = IssueQuery.create!(:name => "q", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => project)
|
||
|
public_issue_query_nil_project = IssueQuery.create!(:name => "q", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
|
||
|
assert IssueQuery.available_query?(project.id, public_issue_query_on_project.id)
|
||
|
assert IssueQuery.available_query?(project.id, public_issue_query_nil_project.id)
|
||
|
end
|
||
|
def test_available_query_should_return_false_when_public_query_does_not_existed_on_project
|
||
|
project = Project.find(1)
|
||
|
IssueQuery.only_public.destroy_all
|
||
|
private_issue_query_on_project = IssueQuery.create!(:name => "q", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => project)
|
||
|
public_issue_query_on_other = IssueQuery.create!(:name => "q", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => Project.find(2))
|
||
|
assert_equal false, IssueQuery.available_query?(project.id, private_issue_query_on_project.id)
|
||
|
assert_equal false, IssueQuery.available_query?(project.id, public_issue_query_on_other.id)
|
||
|
end
|
||
|
def test_default_columns
|
||
|
q = IssueQuery.new
|
||
|
assert q.columns.any?
|
||