def createMAXUser(principal, event): """This subscriber will trigger when a user is created.""" pid = 'mrs5.max' installed = packages_installed() # qi_tool = plone.api.portal.get_tool(name='portal_quickinstaller') # installed = [p['id'] for p in qi_tool.listInstalledProducts()] if pid in installed: maxclient, settings = getUtility(IMAXClient)() maxclient.setActor(settings.max_restricted_username) maxclient.setToken(settings.max_restricted_token) user = principal.getId() try: maxclient.people[user].post() if maxclient.last_response_code == 201: logger.info('MAX user created for user: %s' % user) elif maxclient.last_response_code == 200: logger.info( 'MAX user already created for user: {}'.format(user)) else: logger.error( 'Error creating MAX user for user: {}. '.format(user)) logger.error(prettyResponse(maxclient.last_response)) except: logger.error('Could not contact with MAX server.') logger.error(prettyResponse(maxclient.last_response))
def update_user_properties_hook(user, event): """ This subscriber hooks on user creation and adds user properties to the soup-based catalog for later searches """ installed = packages_installed() if 'ulearn5.enginyersbcn' not in installed: add_user_to_catalog(user, event.properties, overwrite=True)
def update(self): fields = field.Fields(IDemoUserSchema) # fields['fieldset_private'].widgetFactory = FieldsetFieldWidget # fields = fields.omit('telefon') # Si queremos quitar alguno de los que hemos añadido # self.remove('home_page') # Si queremos quitar los de la base (plone.app.users) fields['check_twitter_username'].widgetFactory = VisibilityFieldWidget fields['check_ubicacio'].widgetFactory = VisibilityFieldWidget fields['check_telefon'].widgetFactory = VisibilityFieldWidget # Private policy fields['private_policy'].widgetFactory = PrivatePolicyFieldWidget fields = fields.omit('time_accepted_private_policy') registry = queryUtility(IRegistry) ulearn_tool = registry.forInterface(IUlearnControlPanelSettings) if ulearn_tool.url_private_policy == None or ulearn_tool.url_private_policy == '' or api.user.get_current( ).getProperty('private_policy', False): fields = fields.omit('private_policy') installed = packages_installed() if 'ulearn5.nomines' in installed: roles = api.user.get_roles(username=api.user.get_current().id) isAdmin = 'WebMaster' in roles or 'Manager' in roles or 'Gestor Nomines' in roles if not isAdmin: fields['dni'].field.readonly = True fields = fields.omit('user_type') else: fields['dni'].field.readonly = False else: fields = fields.omit('user_type') fields = fields.omit('dni') self.form.fields['portrait'].widgetFactory = MaxPortraitFieldWidget self.add(fields)
def UpdateUserPropertiesOnLogin(event): user = api.user.get_current() try: installed = packages_installed() if 'ulearn5.medichem' in installed: # from ulearn5.medichem.overrides import get_all_user_properties_medichem # properties = get_all_user_properties_medichem(user) # add_portrait_user(user) pass else: properties = get_all_user_properties(user) add_user_to_catalog(user, properties, overwrite=True) #Por ahora comentamos el modificar la imagen en el login porque da conflict error en el ZEO si entran a la vez #add_portrait_user(user) except: # To avoid testing test_functional code, since the # test_user doesn't have properties and stops the tests. pass
def _on_save(self, data=None): installed = packages_installed() if 'ulearn5.enginyersbcn' in installed: try: if '@@user-information' in self.request["ACTUAL_URL"]: user = api.user.get(username=self.request.form["userid"]) else: user = api.user.get_current() remove_user_from_catalog(user.id) properties = get_all_user_properties(user) add_user_to_catalog(user, properties, overwrite=True) print 'save ok' pass except: # To avoid testing test_functional code, since the # test_user doesn't have properties and stops the tests. pass pass
def UpdateUserPropertiesOnFirstLogin(event): user = api.user.get_current() if hasattr(user, 'visible_userprofile_portlet'): user.setMemberProperties({'visible_userprofile_portlet': True}) try: installed = packages_installed() if 'ulearn5.medichem' in installed: # from ulearn5.medichem.overrides import get_all_user_properties_medichem # properties = get_all_user_properties_medichem(user) pass else: properties = get_all_user_properties(user) for key, value in properties.iteritems(): if 'check_' in key: user.setMemberProperties({key: True}) except: # To avoid testing test_functional code, since the # test_user doesn't have properties and stops the tests. pass
def update(self): fields = field.Fields(IDemoUserSchema) # fields['fieldset_private'].widgetFactory = FieldsetFieldWidget fields['check_twitter_username'].widgetFactory = VisibilityFieldWidget fields['check_ubicacio'].widgetFactory = VisibilityFieldWidget fields['check_telefon'].widgetFactory = VisibilityFieldWidget fields = fields.omit('time_accepted_private_policy') fields = fields.omit('private_policy') installed = packages_installed() if 'ulearn5.nomines' in installed: roles = api.user.get_roles(username=api.user.get_current().id) isAdmin = 'WebMaster' in roles or 'Manager' in roles or 'Gestor Nomines' in roles if not isAdmin: fields['dni'].field.readonly = True fields = fields.omit('user_type') else: fields['dni'].field.readonly = False else: fields = fields.omit('user_type') fields = fields.omit('dni') self.add(fields)
def get_events(self): """Customize which properties we want to show in pt.""" installed = packages_installed() if 'ulearn5.miranza' in installed: from ulearn5.miranza.patches import get_events as get_events_miranza return get_events_miranza(self) events = [] ts = api.portal.get_tool(name='translation_service') results = self._query_events() timezone = getUserPytzTimezone() for event in results: description = abrevia(event.description, 100) if event.description else None start = event.start.astimezone(timezone) end = event.end.astimezone(timezone) location = event.location if event.location else None info = { 'url': event.getURL(), 'firstday': start.day, 'firstmonth': PLMF(ts.month_msgid(start.month)), 'abbrfirstmonth': PLMF(ts.month_msgid(start.month)), 'firstyear': start.year, 'lastday': end.day, 'lastmonth': PLMF(ts.month_msgid(end.month)), 'abbrlastmonth': PLMF(ts.month_msgid(end.month)), 'lastyear': end.year, 'title': abrevia(event.title, 60), 'descr': description, 'location': location, 'timezone': event.timezone, 'showflip': location or description } events.append(info) return events
def isUlearn(self): installed = packages_installed() if 'ulearn5.theme' in installed: return True return False