foreman_expire_hosts 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b51017605d1e78a328d639736c4fba5367f872ba
4
- data.tar.gz: 00aaff59e5242156824203423ece81d2f213f415
3
+ metadata.gz: ffe7a9b12696e0e2f492abefc63a354e46533892
4
+ data.tar.gz: 8315d516b2a6863b51df48c111093f144f6ac8ec
5
5
  SHA512:
6
- metadata.gz: a56ee4a45d47db3650f9e311a54c055fb200a84a7d6640f20532a8920660a42f39c47e702869174bf30a6462877a5583e6f5bdb5377e7f6637b51713afc20854
7
- data.tar.gz: 50bea00b635d7fa753a43b81e1f6b8402d3f331fbaca61c7eb57c6add02e6f2287f143ccb7b50d61c1e74cd4d6055746f9c9eaa144fd1fe290618da7652a893a
6
+ metadata.gz: f4cf8b79e5763299dbb22939a3f4b1128a8ecf0f8ebdb99e0474b7fc1e467a36fbad0d32dd7bec6047f6aa07f3f21bdfe4d893f317ac128a7048257770bc5725
7
+ data.tar.gz: 1a64601384e3fff010888920bc3994db9d5ab0552b198d552f36e9f31a4d5065f1adfadc6e07343725e6bcac9e158dfb22e7c712a5743c25941ee10c3086af22
@@ -72,7 +72,7 @@ module ForemanExpireHosts
72
72
  return true if new_record?
73
73
  return true if defined?(Rails::Console)
74
74
  return true unless User.current
75
- return true if User.current.admin?
75
+ return true if Authorizer.new(User.current).can?(:edit_host_expiry, self)
76
76
  return true if self.owner_type.nil? || self.owner.nil?
77
77
  Setting[:can_owner_modify_host_expiry_date] &&
78
78
  ((self.owner_type == 'User' && self.owner == User.current) ||
@@ -14,7 +14,9 @@
14
14
  },
15
15
  :autocomplete => false,
16
16
  :placeholder => 'dd/mm/yyyy',
17
- :help_inline => popover('Auto Expiry', 'Host will be deleted automatically on given expired date.
18
- <br> Leave blank to keep the host until deleted manually'),
17
+ :help_block => ('<span class="pficon-warning-triangle-o"></span> '.html_safe + _('You are not allowed to change the expiry date of this host.') unless @host.can_modify_expiry_date?),
18
+ :readonly => !@host.can_modify_expiry_date?,
19
+ :help_inline => popover('Auto Expiry', _('Host will be deleted automatically on given expiry date.') + '<br>'.html_safe +
20
+ _('Leave blank to keep the host until deleted manually')),
19
21
  :onfocus => 'append_shortcuts()'
20
22
  %>
@@ -32,6 +32,12 @@ module ForemanExpireHosts
32
32
  security_block :hosts do
33
33
  permission :edit_hosts, {:hosts => [:select_multiple_expiration, :update_multiple_expiration]}
34
34
  end
35
+
36
+ security_block :foreman_expire_hosts do
37
+ permission :edit_host_expiry,
38
+ {},
39
+ :resource_type => 'Host'
40
+ end
35
41
  end
36
42
  end
37
43
 
@@ -1,3 +1,3 @@
1
1
  module ForemanExpireHosts
2
- VERSION = '2.1.2'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  end
@@ -66,6 +66,33 @@ class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
66
66
  end
67
67
  end
68
68
 
69
+ context 'changing expiration date for user' do
70
+ let(:host) { FactoryGirl.create(:host, :managed) }
71
+
72
+ context 'with edit_host_expiry permission' do
73
+ let(:permission) { Permission.find_by_name('edit_host_expiry') }
74
+ let(:filter) { FactoryGirl.create(:filter, :permissions => [permission]) }
75
+ let(:role) { FactoryGirl.create(:role, :filters => [filter]) }
76
+ let(:user) { FactoryGirl.create(:user, :organizations => [host.organization], :locations => [host.location], :roles => [role]) }
77
+
78
+ test 'user can change expiry date' do
79
+ as_user user do
80
+ assert_equal true, host.can_modify_expiry_date?
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'without edit_host_expiry permission' do
86
+ let(:user) { FactoryGirl.build(:user, :organizations => [host.organization], :locations => [host.location]) }
87
+
88
+ test 'user can not change expiry date' do
89
+ as_user user do
90
+ assert_equal false, host.can_modify_expiry_date?
91
+ end
92
+ end
93
+ end
94
+ end
95
+
69
96
  context 'a host without expiration' do
70
97
  setup do
71
98
  @host = FactoryGirl.build(:host)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_expire_hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagarjuna Rachaneni
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-21 00:00:00.000000000 Z
12
+ date: 2017-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface