Class: ForemanExpireHosts::ExpiryEditAuthorizer

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_expire_hosts/expiry_edit_authorizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostsObject

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

#userObject

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

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'app/services/foreman_expire_hosts/expiry_edit_authorizer.rb', line 12

def authorized?
  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