Class: PuavoRest::Organisation
- Inherits:
-
LdapModel
show all
- Defined in:
- resources/organisations.rb
Constant Summary
- REFRESH_LOCK =
Mutex.new
- @@organisation_cache =
nil
Constants inherited
from LdapModel
LdapModel::ESCAPES, LdapModel::ESCAPE_RE, LdapModel::KRB_LOCK, LdapModel::PROF
Instance Attribute Summary
Attributes inherited from LdapModel
#ldap_attr_store, #serialize_attrs
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods inherited from LdapModel
#[], #[]=, _class_store, #add, #add_validation_error, after, #as_json, #assert_validation, base_filter, before, by_attr, by_attr!, by_dn, by_dn!, by_dn_array, by_id, by_id!, by_ldap_attr, by_ldap_attr!, callable_from_instance, #changed?, class_store, clear_setup, computed_attr, connection, #create!, create_connection, create_filter_lambda, #dirty?, dn_bind, #empty?, escape, filter, from_ldap_hash, #get_own, #get_raw, inherited, #initialize, is_dn, is_not_found?, ldap_attrs, ldap_map, #ldap_merge!, ldap_op, #ldap_set, #link, #merge, #new?, #object_model, organisation, organisation?, pretty_attrs_to_ldap, raw_by_dn, raw_filter, sasl_bind, #save!, search, search_filters, #set, settings, settings=, setup, skip_serialize, #to_hash, #to_json, #to_ldap_hash, #transform, #update!, #validate, #validate!, #validate_unique, #write_raw
Constructor Details
This class inherits a constructor from LdapModel
Class Method Details
+ (Object) all
85
86
87
88
89
|
# File 'resources/organisations.rb', line 85
def self.all
bases.map do |base|
by_dn(base)
end
end
|
+ (Object) bases
77
78
79
80
81
82
83
|
# File 'resources/organisations.rb', line 77
def self.bases
connection.search("", LDAP::LDAP_SCOPE_BASE, "(objectClass=*)", ["namingContexts"]) do |e|
return e.get_values("namingContexts").select do |base|
base != "o=puavo"
end
end
end
|
+ (Object) by_domain(domain)
39
40
41
42
|
# File 'resources/organisations.rb', line 39
def self.by_domain(domain)
refresh if @@organisation_cache.nil?
@@organisation_cache && @@organisation_cache[domain]
end
|
+ (Object) by_domain!(domain)
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'resources/organisations.rb', line 44
def self.by_domain!(domain)
if domain.to_s.strip == ""
raise InternalError, :user => "Invalid organisation: [EMPTY]"
end
org = by_domain(domain)
if org.nil?
raise NotFound, {
:user => "Cannot find organisation for #{ domain }",
:msg => "Try Organisation.refresh"
}
end
return org
end
|
+ (Object) current(option = nil)
91
92
93
94
95
96
|
# File 'resources/organisations.rb', line 91
def self.current(option=nil)
if option == :no_cache
return Organisation.by_dn(LdapModel.organisation.dn)
end
LdapModel.organisation
end
|
+ (Boolean) current?
98
99
100
101
|
# File 'resources/organisations.rb', line 98
def self.current?
LdapModel.organisation?
end
|
+ (Object) default_organisation_domain!
60
61
62
|
# File 'resources/organisations.rb', line 60
def self.default_organisation_domain!
by_domain!(CONFIG["default_organisation_domain"])
end
|
+ (Object) ldap_base
33
34
35
|
# File 'resources/organisations.rb', line 33
def self.ldap_base
""
end
|
+ (Object) refresh
65
66
67
68
69
70
71
72
73
74
75
|
# File 'resources/organisations.rb', line 65
def self.refresh
REFRESH_LOCK.synchronize do
cache = {}
LdapModel.setup(:credentials => CONFIG["server"]) do
all.each{ |org| cache[org.domain] = org }
end
@@organisation_cache = cache
end
end
|
Instance Method Details
- (Object) organisation_key
29
30
31
|
# File 'resources/organisations.rb', line 29
def organisation_key
domain.split(".").first if domain
end
|
- (Object) owners
110
111
112
113
114
|
# File 'resources/organisations.rb', line 110
def owners
Array( get_own(:owner) ).select{ |o| o.to_s.match(/#{self.base}$/) }.map do |owner_dn|
User.by_dn(owner_dn)
end
end
|
- (Object) preferred_image
103
104
105
106
107
|
# File 'resources/organisations.rb', line 103
def preferred_image
if get_own(:preferred_image)
get_own(:preferred_image).strip
end
end
|