3 # Copyright (C) 2014 Ipsilon Project Contributors
5 # See the file named COPYING for the project license
7 from ipsilon.util.log import Log
8 from ipsilon.util.plugin import PluginLoader, PluginObject
9 from ipsilon.util.plugin import PluginInstaller
12 class InfoProviderBase(PluginObject, Log):
15 super(InfoProviderBase, self).__init__()
18 def get_user_attrs(self, user):
19 raise NotImplementedError
24 return self in self._site[FACILITY]['enabled']
27 def enable(self, site):
29 plugins = site[FACILITY]
30 if self in plugins['enabled']:
34 if self.name in plugins['config']:
35 self.set_config(plugins['config'][self.name])
37 plugins['enabled'].append(self)
38 self.debug('Info plugin enabled: %s' % self.name)
40 def disable(self, site):
42 plugins = site[FACILITY]
43 if self not in plugins['enabled']:
46 plugins['enabled'].remove(self)
47 self.debug('Info plugin disabled: %s' % self.name)
50 class InfoMapping(Log):
53 self.standard_attributes = {
54 'fullname': 'Full Name',
55 'nickname': 'Nickname',
56 'surname': 'Last Name',
57 'firstname': 'First Name',
59 'dob': 'Date of Birth',
60 'email': 'E-mail Address',
62 'postcode': 'Postal Code',
63 'street': 'Street Address',
64 'state': 'State or Province',
66 'phone': 'Telephone Number',
67 'language': 'Language',
68 'timezone': 'Time Zone',
72 def set_mapping(self, attrs_map):
73 self.mapping = attrs_map
75 def display_name(self, name):
76 if name in self.standard_attributes:
77 return self.standard_attributes[name]
80 def map_attrs(self, attrs):
85 s[self.mapping[a]] = attrs[a]
92 FACILITY = 'info_config'
97 def __init__(self, site):
100 loader = PluginLoader(Info, FACILITY, 'InfoProvider')
101 self._site[FACILITY] = loader.get_plugin_data()
102 plugins = self._site[FACILITY]
104 available = plugins['available'].keys()
105 self.debug('Available info providers: %s' % str(available))
107 plugins['root'] = self
108 for item in plugins['whitelist']:
109 self.debug('Login plugin in whitelist: %s' % item)
110 if item not in plugins['available']:
111 self.debug('Info Plugin %s not found' % item)
113 plugins['available'][item].enable(self._site)
115 def get_user_attrs(self, user, requested=None):
116 plugins = self._site[FACILITY]['available']
119 for _, p in plugins.items():
120 if requested is None:
124 if requested != p.name:
126 result = p.get_user_attrs(user)
133 class InfoProviderInstaller(object):
136 self.facility = FACILITY
140 def install_args(self, group):
141 raise NotImplementedError
143 def configure(self, opts):
144 raise NotImplementedError
147 class InfoProviderInstall(object):
150 pi = PluginInstaller(InfoProviderInstall)
151 self.plugins = pi.get_plugins()