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__()
17 self.is_enabled = False
19 def get_user_attrs(self, user):
20 raise NotImplementedError
22 def enable(self, site):
28 plugins = self._site[FACILITY]
31 if self.name in plugins['config']:
32 self.set_config(plugins['config'][self.name])
34 plugins['enabled'].append(self)
35 self.is_enabled = True
36 self.debug('Info plugin enabled: %s' % self.name)
38 def disable(self, site):
39 if not self.is_enabled:
42 plugins = self._site[FACILITY]
43 plugins['enabled'].remove(self)
44 self.is_enabled = False
45 self.debug('Info plugin disabled: %s' % self.name)
48 class InfoMapping(Log):
51 self.standard_attributes = {
52 'fullname': 'Full Name',
53 'nickname': 'Nickname',
54 'surname': 'Last Name',
55 'firstname': 'First Name',
57 'dob': 'Date of Birth',
58 'email': 'E-mail Address',
60 'postcode': 'Postal Code',
61 'street': 'Street Address',
62 'state': 'State or Province',
64 'phone': 'Telephone Number',
65 'language': 'Language',
66 'timezone': 'Time Zone',
70 def set_mapping(self, attrs_map):
71 self.mapping = attrs_map
73 def display_name(self, name):
74 if name in self.standard_attributes:
75 return self.standard_attributes[name]
78 def map_attrs(self, attrs):
83 s[self.mapping[a]] = attrs[a]
90 FACILITY = 'info_config'
95 def __init__(self, site):
98 loader = PluginLoader(Info, FACILITY, 'InfoProvider')
99 self._site[FACILITY] = loader.get_plugin_data()
100 plugins = self._site[FACILITY]
102 available = plugins['available'].keys()
103 self.debug('Available info providers: %s' % str(available))
105 plugins['root'] = self
106 for item in plugins['whitelist']:
107 self.debug('Login plugin in whitelist: %s' % item)
108 if item not in plugins['available']:
109 self.debug('Info Plugin %s not found' % item)
111 plugins['available'][item].enable(self._site)
113 def get_user_attrs(self, user, requested=None):
114 plugins = self._site[FACILITY]['available']
117 for _, p in plugins.items():
118 if requested is None:
122 if requested != p.name:
124 result = p.get_user_attrs(user)
131 class InfoProviderInstaller(object):
134 self.facility = FACILITY
138 def install_args(self, group):
139 raise NotImplementedError
141 def configure(self, opts):
142 raise NotImplementedError
145 class InfoProviderInstall(object):
148 pi = PluginInstaller(InfoProviderInstall)
149 self.plugins = pi.get_plugins()