foreman-tasks 0.16.3 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4810cb5f72cb95e222c01826c0849c45a8a098e1eb2fb5139d9bbc0abdb8823
4
- data.tar.gz: 4f53e3c82ab8a1c6b0999cb4fd99652ce3f9984e7e6a8cf5b3ee7b91d59cd808
3
+ metadata.gz: 289b729c99fef5c4047a025dd9deabfe4421ea2f5c457922f22ebababf0bf4e9
4
+ data.tar.gz: 4c571c09518c2b3ce576b4cf31be1b62e5cae4c15bc8d8401a4ce8886bd60e4f
5
5
  SHA512:
6
- metadata.gz: 7f2dd82c93ef2a26e4f1a591eb3e7778d1aa33f9dbd5971995025f7dca355b9aba7e5f8d014dc7187b152649234685af1518a7078bd4eb68242bfa8cc3f0b7f9
7
- data.tar.gz: 1278492ef015ddda14c6138655e4f2bcf50d7ce7e9fc3debeff2df5e0faf5906bf4a1159b99776370ef15a395273875a143a0068ba8b28153bf7dc4fc26107bc
6
+ metadata.gz: 5b751006f3adf4e24870a916e4ba5e13a67234d10bb977e1d66df84c626059c544179b4042d631acd50481b831eb38bfe20c6739cb3c9e1efda83e35805e2b34
7
+ data.tar.gz: cb353429cb48a625176818a3625be9da6e0c7f4deede573c2e614364d4b20d263b2476f614fa2b45813131b1cfbf113e5d736ceb7522dbd2b8dd889f02ff920b
@@ -16,8 +16,7 @@ module ForemanTasks
16
16
  end
17
17
 
18
18
  def summary
19
- scope = resource_base.search_for(current_taxonomy_search).select(:id)
20
- render json: Task::Summarizer.new(Task.where(:id => scope), params[:recent_timeframe].to_i).summary
19
+ render json: Task::Summarizer.new(resource_base, params[:recent_timeframe].to_i).summary
21
20
  end
22
21
 
23
22
  def sub_tasks
@@ -49,12 +49,10 @@ module ForemanTasks
49
49
  scoped_search :on => :user_id,
50
50
  :complete_value => true,
51
51
  :rename => 'user.id',
52
- :validator => ->(value) { ScopedSearch::Validators::INTEGER.call(value) },
53
- :value_translation => ->(value) { value == 'current_user' ? User.current.id : value },
54
- :special_values => %w[current_user],
55
- :aliases => ['owner.id'], :only_explicit => true
56
- scoped_search :relation => :user, :on => :login, :complete_value => true, :aliases => ['owner.login', 'user'], :only_explicit => true
57
- scoped_search :relation => :user, :on => :firstname, :rename => 'user.firstname', :complete_value => true, :aliases => ['owner.firstname'], :only_explicit => true
52
+ :validator => ->(value) { ScopedSearch::Validators::INTEGER.call(value) || value == 'current_user' },
53
+ :aliases => ['owner.id'], :ext_method => :search_by_owner, :only_explicit => true
54
+ scoped_search :relation => :user, :on => :login, :rename => 'user.login', :complete_value => true, :aliases => ['owner.login', 'user'], :ext_method => :search_by_owner, :only_explicit => true
55
+ scoped_search :relation => :user, :on => :firstname, :rename => 'user.firstname', :complete_value => true, :aliases => ['owner.firstname'], :ext_method => :search_by_owner, :only_explicit => true
58
56
  scoped_search :relation => :task_groups, :on => :id, :complete_value => true, :rename => 'task_group.id', :validator => ScopedSearch::Validators::INTEGER
59
57
 
60
58
  scope :active, -> { where('foreman_tasks_tasks.state != ?', :stopped) }
@@ -22,6 +22,31 @@ module ForemanTasks
22
22
  sql = "foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_id #{operator} ? OR foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_id IS NULL"
23
23
  { :conditions => sanitize_sql_for_conditions([sql, value]), :joins => joins }
24
24
  end
25
+
26
+ def search_by_owner(key, operator, value)
27
+ return { :conditions => '0 = 1' } if value == 'current_user' && User.current.nil?
28
+
29
+ key = 'owners.login' if key == 'user'
30
+ # using uniq suffix to avoid colisions when searching by two different owners via ScopedSearch
31
+ uniq_suffix = SecureRandom.hex(3)
32
+ key_name = connection.quote_column_name(key.sub(/^.*\./, ''))
33
+ value.sub!('*', '%%')
34
+ condition = if key.blank?
35
+ sanitize_sql_for_conditions(["users_#{uniq_suffix}.login #{operator} ? or users_#{uniq_suffix}.firstname #{operator} ? ", value, value])
36
+ elsif key =~ /\.id\Z/
37
+ value = User.current.id if value == 'current_user'
38
+ sanitize_sql_for_conditions(["foreman_tasks_tasks.user_id #{operator} ?", value])
39
+ else
40
+ placeholder, value = operator == 'IN' ? ['(?)', value.split(',').map(&:strip)] : ['?', value]
41
+ sanitize_sql_for_conditions(["users_#{uniq_suffix}.#{key_name} #{operator} #{placeholder}", value])
42
+ end
43
+ { :conditions => condition, :joins => joins_for_user_search(key, uniq_suffix) }
44
+ end
45
+
46
+ def joins_for_user_search(key, uniq_suffix)
47
+ return '' if key =~ /\.id\Z/
48
+ "INNER JOIN users AS users_#{uniq_suffix} ON users_#{uniq_suffix}.id = foreman_tasks_tasks.user_id"
49
+ end
25
50
  end
26
51
  end
27
52
  end
@@ -5,10 +5,8 @@ class AddUserId < ActiveRecord::Migration[5.0]
5
5
  return if User.unscoped.find_by(:login => User::ANONYMOUS_ADMIN).nil?
6
6
  User.as_anonymous_admin do
7
7
  user_locks.select(:resource_id).distinct.pluck(:resource_id).each do |owner_id|
8
- if User.exists?(:id => owner_id)
9
- tasks = ForemanTasks::Task.joins(:locks).where(:locks => user_locks.where(:resource_id => owner_id))
10
- tasks.update_all(:user_id => owner_id)
11
- end
8
+ tasks = ForemanTasks::Task.joins(:locks).where(:locks => user_locks.where(:resource_id => owner_id))
9
+ tasks.update_all(:user_id => owner_id)
12
10
  user_locks.where(:resource_id => owner_id).delete_all
13
11
  end
14
12
  end
@@ -41,7 +41,7 @@ module ForemanTasks
41
41
 
42
42
  initializer 'foreman_tasks.register_plugin', :before => :finisher_hook do |_app|
43
43
  Foreman::Plugin.register :"foreman-tasks" do
44
- requires_foreman '>= 1.16.0'
44
+ requires_foreman '>= 1.24.0'
45
45
  divider :top_menu, :parent => :monitor_menu, :last => true, :caption => N_('Foreman Tasks')
46
46
  menu :top_menu, :tasks,
47
47
  :url_hash => { :controller => 'foreman_tasks/tasks', :action => :index },
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = '0.16.3'.freeze
2
+ VERSION = '0.17.0'.freeze
3
3
  end
data/package.json CHANGED
@@ -22,8 +22,7 @@
22
22
  "url": "http://projects.theforeman.org/projects/foreman-tasks/issues"
23
23
  },
24
24
  "dependencies": {
25
- "@theforeman/vendor": "^0.1.1",
26
- "c3": "^0.4.11",
25
+ "@theforeman/vendor": "^1.4.0",
27
26
  "humanize-duration": "^3.20.1",
28
27
  "react-intl": "^2.8.0"
29
28
  },
@@ -31,7 +30,7 @@
31
30
  "@storybook/addon-actions": "^5.0.1",
32
31
  "@storybook/addon-knobs": "^5.0.1",
33
32
  "@storybook/react": "^5.0.1",
34
- "@theforeman/vendor-dev": "^0.1.1",
33
+ "@theforeman/vendor-dev": "^1.4.0",
35
34
  "babel-cli": "^6.10.1",
36
35
  "babel-core": "^6.26.3",
37
36
  "babel-eslint": "^8.2.3",
@@ -41,41 +41,6 @@ module ForemanTasks
41
41
  response = JSON.parse(@response.body)
42
42
  assert_equal 0, response['stopped']['total']
43
43
  end
44
-
45
- describe 'taxonomy scoping' do
46
- before do
47
- @organizations = [0, 0].map { FactoryBot.create(:organization) }
48
- @locations = [0, 0].map { FactoryBot.create(:location) }
49
- @tasks = [0, 0].map { FactoryBot.create(:some_task) }
50
- @tasks.zip(@organizations, @locations).each do |task, org, loc|
51
- Lock.link!(org, task.id)
52
- Lock.link!(loc, task.id)
53
- end
54
- end
55
-
56
- it 'does not limit if unset' do
57
- get(:summary, params: { recent_timeframe: 24 }, session: set_session_user)
58
- assert_response :success
59
- response = JSON.parse(@response.body)
60
- assert_equal 2, response['stopped']['total']
61
- end
62
-
63
- it 'finds only tasks with matching taxonomies' do
64
- get(:summary, params: { recent_timeframe: 24 },
65
- session: set_session_user.merge(:organization_id => @organizations.first, :location_id => @locations.first))
66
- assert_response :success
67
- response = JSON.parse(@response.body)
68
- assert_equal 1, response['stopped']['total']
69
- end
70
-
71
- it 'find no tasks when taxonomy combination contains no tasks' do
72
- get(:summary, params: { recent_timeframe: 24 },
73
- session: set_session_user.merge(:organization_id => @organizations.first, :location_id => @locations.last))
74
- assert_response :success
75
- response = JSON.parse(@response.body)
76
- assert_equal 0, response['stopped']['total']
77
- end
78
- end
79
44
  end
80
45
 
81
46
  it 'supports csv export' do
@@ -30,66 +30,20 @@ class TasksTest < ActiveSupport::TestCase
30
30
  assert_equal [@task_one], ForemanTasks::Task.search_for("user = #{@user_one.login}")
31
31
  end
32
32
 
33
- test 'cannot search by arbitrary key' do
34
- proc { ForemanTasks::Task.search_for('user.my_key ~ 5') }.must_raise(ScopedSearch::QueryNotSupported)
35
- proc { ForemanTasks::Task.search_for('user. = 5') }.must_raise(ScopedSearch::QueryNotSupported)
36
- end
37
-
38
- test 'can search the tasks by negated user' do
39
- assert_equal [@task_one], ForemanTasks::Task.search_for("user != #{@user_two.login}")
40
- assert_equal [@task_one], ForemanTasks::Task.search_for("user <> #{@user_two.login}")
41
- SecureRandom.stubs(:hex).returns('abc')
42
- assert_equal ForemanTasks::Task.search_for("user != #{@user_two.login}").to_sql,
43
- ForemanTasks::Task.search_for("user <> #{@user_two.login}").to_sql
44
- end
45
-
46
33
  test 'can search the tasks by user\'s id' do
47
34
  assert_equal [@task_one], ForemanTasks::Task.search_for("user.id = #{@user_one.id}")
48
35
  assert_equal [@task_one], ForemanTasks::Task.search_for("owner.id = #{@user_one.id}")
49
- assert_equal [@task_one], ForemanTasks::Task.search_for("user.id != #{@user_two.id}")
50
- assert_equal [@task_one], ForemanTasks::Task.search_for("owner.id != #{@user_two.id}")
51
- end
52
-
53
- test 'can search by array of user ids' do
54
- assert_equal [@task_one], ForemanTasks::Task.search_for("user.id ^ (#{@user_one.id})")
55
- assert_equal [@task_one], ForemanTasks::Task.search_for("owner.id ^ (#{@user_one.id})")
56
- assert_equal [@task_one], ForemanTasks::Task.search_for("user.id !^ (#{@user_two.id})")
57
- assert_equal [@task_one], ForemanTasks::Task.search_for("owner.id !^ (#{@user_two.id})")
58
- end
59
-
60
- test 'cannot glob on user\'s id' do
61
- proc { ForemanTasks::Task.search_for("user.id ~ something") }.must_raise(ScopedSearch::QueryNotSupported)
62
- proc { ForemanTasks::Task.search_for("user.id ~ 5") }.must_raise(ScopedSearch::QueryNotSupported)
63
36
  end
64
37
 
65
38
  test 'can search the tasks by user with wildcards' do
66
- part = @user_one.login[1..-1] # search for '*ser1' if login is 'user1'
67
- # The following two should be equivalent
68
- assert_equal [@task_one], ForemanTasks::Task.search_for("user ~ #{part}")
69
- assert_equal [@task_one], ForemanTasks::Task.search_for("user ~ *#{part}*")
70
- SecureRandom.stubs(:hex).returns('abc')
71
- assert_equal ForemanTasks::Task.search_for("user ~ #{part}").to_sql,
72
- ForemanTasks::Task.search_for("user ~ *#{part}*").to_sql
73
- end
74
-
75
- test 'can search the tasks by user with negated wildcards' do
76
- part = @user_two.login[1..-1] # search for '*ser1' if login is 'user1'
77
- # The following two should be equivalent
78
- assert_equal [@task_one], ForemanTasks::Task.search_for("user !~ #{part}")
79
- assert_equal [@task_one], ForemanTasks::Task.search_for("user !~ *#{part}*")
80
- SecureRandom.stubs(:hex).returns('abc')
81
- assert_equal ForemanTasks::Task.search_for("user !~ #{part}").to_sql,
82
- ForemanTasks::Task.search_for("user !~ *#{part}*").to_sql
39
+ glob = '*' + @user_one.login[1..-1] # search for '*ser1' if login is 'user1'
40
+ assert_equal [@task_one], ForemanTasks::Task.search_for("user ~ #{glob}")
83
41
  end
84
42
 
85
43
  test 'can search the tasks by array' do
86
44
  assert_equal [@task_one], ForemanTasks::Task.search_for("user ^ (this_user, #{@user_one.login}, that_user)")
87
45
  end
88
46
 
89
- test 'can search the tasks by negated array' do
90
- assert_equal [@task_one], ForemanTasks::Task.search_for("user !^ (this_user, #{@user_two.login}, that_user)")
91
- end
92
-
93
47
  test 'properly returns username' do
94
48
  assert_equal @task_one.username, @user_one.login
95
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.3
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks-core