Class: ForemanExpireHosts::ExpiryEditAuthorizer
- Inherits:
-
Object
- Object
- ForemanExpireHosts::ExpiryEditAuthorizer
- Defined in:
- app/services/foreman_expire_hosts/expiry_edit_authorizer.rb
Instance Attribute Summary collapse
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#initialize(opts = {}) ⇒ ExpiryEditAuthorizer
constructor
A new instance of ExpiryEditAuthorizer.
Constructor Details
#initialize(opts = {}) ⇒ ExpiryEditAuthorizer
Returns a new instance of ExpiryEditAuthorizer.
7 8 9 10 |
# File 'app/services/foreman_expire_hosts/expiry_edit_authorizer.rb', line 7 def initialize(opts = {}) self.user = opts.fetch(:user) self.hosts = opts.fetch(:hosts) end |
Instance Attribute Details
#hosts ⇒ Object
Returns the value of attribute hosts.
5 6 7 |
# File 'app/services/foreman_expire_hosts/expiry_edit_authorizer.rb', line 5 def hosts @hosts end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'app/services/foreman_expire_hosts/expiry_edit_authorizer.rb', line 5 def user @user end |
Instance Method Details
#authorized? ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 |
# File 'app/services/foreman_expire_hosts/expiry_edit_authorizer.rb', line 12 def hosts.each do |host| next unless user.can?(:edit_hosts, host) return true if user.can?(:edit_host_expiry, host) return true if Setting[:can_owner_modify_host_expiry_date] && ((host.owner_type == 'User' && host.owner == user) || (host.owner_type == 'Usergroup' && host.owner.all_users.include?(user))) end false end |