Class: PostfixAdmin::Admin

Inherits:
ApplicationRecord show all
Includes:
DovecotCramMD5Password
Defined in:
lib/postfix_admin/admin.rb

Constant Summary

Constants inherited from ApplicationRecord

PostfixAdmin::ApplicationRecord::RE_DOMAIN_NAME_LIKE, PostfixAdmin::ApplicationRecord::RE_DOMAIN_NAME_LIKE_BASE, PostfixAdmin::ApplicationRecord::RE_DOMAIN_NAME_LIKE_WITH_ANCHORS, PostfixAdmin::ApplicationRecord::RE_EMAIL_LIKE, PostfixAdmin::ApplicationRecord::RE_EMAIL_LIKE_BASE, PostfixAdmin::ApplicationRecord::RE_EMAIL_LIKE_WITH_ANCHORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DovecotCramMD5Password

#authenticate, #password_unencrypted=

Methods inherited from ApplicationRecord

#active_str, #has_timestamp_columns?, #inactive?, #set_current_time_to_timestamp_columns

Instance Attribute Details

#domain_idsObject

Returns the value of attribute domain_ids.



17
18
19
# File 'lib/postfix_admin/admin.rb', line 17

def domain_ids
  @domain_ids
end

Instance Method Details

#has_admin?(admin) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/postfix_admin/admin.rb', line 54

def has_admin?(admin)
  self == admin || super_admin?
end

#has_domain?(domain) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/postfix_admin/admin.rb', line 58

def has_domain?(domain)
  !rel_domains.where(domain: ["ALL", domain.domain]).empty?
end

#has_superadmin_column?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/postfix_admin/admin.rb', line 50

def has_superadmin_column?
  has_attribute?(:superadmin)
end

#super_admin=(value) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/postfix_admin/admin.rb', line 37

def super_admin=(value)
  if value
    domain_ids = self.rel_domain_ids.dup
    domain_ids << "ALL"
    self.rel_domain_ids = domain_ids
    self.superadmin = true if has_superadmin_column?
  else
    domain_admins.where(domain: "ALL").delete_all
    self.superadmin = false if has_superadmin_column?
  end
  save!
end

#super_admin?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/postfix_admin/admin.rb', line 25

def super_admin?
  if @super_admin.nil?
    @super_admin = if has_superadmin_column?
      self.superadmin && rel_domains.exists?("ALL")
    else
      rel_domains.exists?("ALL")
    end
  else
    @super_admin
  end
end