Added the responsible_id to the list of the querieable fields in query.

pull/445/head
Stefan Frank 11 years ago
parent 8f44bd1a72
commit ba76a482f2
  1. 3
      app/models/query.rb
  2. 19
      features/planning_elements/filter.feature
  3. 12
      features/step_definitions/api_steps.rb
  4. 27
      spec/models/query_spec.rb

@ -181,12 +181,15 @@ class Query < ActiveRecord::Base
author_values += user_values author_values += user_values
@available_filters["author_id"] = { :type => :list, :order => 5, :values => author_values } unless author_values.empty? @available_filters["author_id"] = { :type => :list, :order => 5, :values => author_values } unless author_values.empty?
group_values = Group.all.collect {|g| [g.name, g.id.to_s] } group_values = Group.all.collect {|g| [g.name, g.id.to_s] }
@available_filters["member_of_group"] = { :type => :list_optional, :order => 6, :values => group_values, :name => I18n.t('query_fields.member_of_group') } unless group_values.empty? @available_filters["member_of_group"] = { :type => :list_optional, :order => 6, :values => group_values, :name => I18n.t('query_fields.member_of_group') } unless group_values.empty?
role_values = Role.givable.collect {|r| [r.name, r.id.to_s] } role_values = Role.givable.collect {|r| [r.name, r.id.to_s] }
@available_filters["assigned_to_role"] = { :type => :list_optional, :order => 7, :values => role_values, :name => I18n.t('query_fields.assigned_to_role') } unless role_values.empty? @available_filters["assigned_to_role"] = { :type => :list_optional, :order => 7, :values => role_values, :name => I18n.t('query_fields.assigned_to_role') } unless role_values.empty?
@available_filters["responsible_id"] = { :type => :list_optional, :order => 8, :values => user_values } unless user_values.empty?
if User.current.logged? if User.current.logged?
# populate the watcher list with the same user list as other user filters if the user has the :view_work_package_watchers permission in at least one project # populate the watcher list with the same user list as other user filters if the user has the :view_work_package_watchers permission in at least one project
# TODO: this could be differentiated more, e.g. all users could watch issues in public projects, but won't necessarily be shown here # TODO: this could be differentiated more, e.g. all users could watch issues in public projects, but won't necessarily be shown here

@ -62,7 +62,13 @@ Feature: Filtering work packages via the api
And there is 1 user with the following: And there is 1 user with the following:
| login | bob | | login | bob |
And there is 1 user with the following:
| login | peter |
And there is 1 user with the following:
| login | pamela |
And the user "bob" is a "member" in the project "sample_project" And the user "bob" is a "member" in the project "sample_project"
And the user "peter" is a "member" in the project "sample_project"
And the user "pamela" is a "member" in the project "sample_project"
And I am already logged in as "bob" And I am already logged in as "bob"
Scenario: Call the endpoint of the api without filters Scenario: Call the endpoint of the api without filters
@ -188,3 +194,16 @@ Feature: Filtering work packages via the api
| work_package#1.2 | Story | work_package#1 | | work_package#1.2 | Story | work_package#1 |
When I call the work_package-api on project "sample_project" requesting format "json" filtering for type "Epic,Story" When I call the work_package-api on project "sample_project" requesting format "json" filtering for type "Epic,Story"
And the json-response should say that "work_package#1" has 1 child And the json-response should say that "work_package#1" has 1 child
Scenario: Filtering for responsibles
Given there are the following work packages in project "sample_project":
| subject | type | responsible |
| work_package#1 | Task | bob |
| work_package#2 | Task | peter |
| work_package#3 | Task | pamela |
When I call the work_package-api on project "sample_project" requesting format "json" filtering for responsible "peter"
Then the json-response should include 1 work package
And the json-response should not contain a work_package "work_package#1"
And the json-response should contain a work_package "work_package#2"

@ -90,6 +90,18 @@ Then(/^I call the work_package\-api on project "(.*?)" requesting format "(.*?)"
end end
When(/^I call the work_package\-api on project "(.*?)" requesting format "(.*?)" filtering for responsible "(.*?)"$/) do |project_name, format, responsible_names|
responsibles = User.where(login: responsible_names.split(','))
get_filtered_json(project_name: project_name,
format: format,
filters: [:responsible_id],
operators: {responsible_id: "="},
values: {responsible_id: responsibles.map(&:id)} )
end
And(/^there are (\d+) work packages of type "(.*?)" in project "(.*?)"$/) do |nr_of_wps, type_name, project_name| And(/^there are (\d+) work packages of type "(.*?)" in project "(.*?)"$/) do |nr_of_wps, type_name, project_name|
project = Project.find_by_identifier(project_name) project = Project.find_by_identifier(project_name)
type = project.types.find_by_name(type_name) type = project.types.find_by_name(type_name)

@ -47,4 +47,31 @@ describe Query do
query.available_columns.find {|column| column.name == :done_ratio}.should be_nil query.available_columns.find {|column| column.name == :done_ratio}.should be_nil
end end
end end
context 'filtering responsibles' do
let (:project){FactoryGirl.create(:project)}
let (:responsible_1){FactoryGirl.create(:user)}
let (:responsible_2){FactoryGirl.create(:user)}
before do
wp_1 = FactoryGirl.create(:work_package, project: project, responsible_id: responsible_1.id)
wp_2 = FactoryGirl.create(:work_package, project: project, responsible_id: responsible_2.id)
end
it "should return only the workpackage for the responsible given in the filter" do
responsible_query = Query.new
responsible_query.project = project
#responsible_query.add_filter "responsible_id", "=", responsible_1.id
puts WorkPackage.with_query(responsible_query).to_sql
result = WorkPackage.with_query(responsible_query).all
expect(result.size).to eql 1
expect(result).to include wp_1
end
end
end end

Loading…
Cancel
Save