def userLogin(obj, event): """Redirects logged in users to personal dashboard""" # get registry where we keep our configuration registry = getUtility(IRegistry) logger.info('userlogin') # check if we need to redirect at all do_redirect = registry.get( 'collective.onlogin.interfaces.IOnloginSettings.login_redirect_enabled' ) logger.info('do_redirect {}'.format(do_redirect)) if not do_redirect: logger.info('audi5000') return # do not redirect if user initial login is set and our current event # is about User Initial Login; so First Login Redirect is always of # higher priority if registry.get('collective.onlogin.interfaces.IOnloginSettings.' \ 'first_login_redirect_enabled') and \ IUserInitialLoginInEvent.providedBy(event): logger.info('audi5000') return # get portal object portal = getSite() # check if we have an access to request object request = getattr(portal, 'REQUEST', None) logger.info('request {}'.format(len(request))) if not request: logger.info('audi5000') return # check if we need to ignore came_from variable ignore_came_from = registry.get( 'collective.onlogin.interfaces.IOnloginSettings.' \ 'login_redirect_ignore_came_from') # when we try to log from logged_out page the came_from doesn't bin canceled if not ignore_came_from and request.get('came_from'): return # check if we got redirect expression redirect_expr = registry.get( 'collective.onlogin.interfaces.IOnloginSettings.login_redirect_expr') if not redirect_expr: return # now complile and render our expression to url expr = Expression(redirect_expr) econtext = getExprContext(portal, portal) try: url = expr(econtext) except Exception, e: logException(u'Error during user login redirect') return
def userInitialLogin(obj, event): """Redirects initially logged in users to getting started wizard""" registry = getUtility(IRegistry) logger.info('initial login') # check if we need to redirect at all do_redirect = registry.get('collective.onlogin.interfaces.' \ 'IOnloginSettings.first_login_redirect_enabled') logger.info('do_redirect {}'.format(do_redirect)) if not do_redirect: logger.info('audi5000') return # get portal object portal = getSite() # check if we have an access to request object request = getattr(portal, 'REQUEST', None) logger.info('request {}'.format(len(request))) if not request: logger.info('audi5000') return # check if we need to ignore came_from variable ignore_came_from = registry.get( 'collective.onlogin.interfaces.IOnloginSettings.' \ 'first_login_redirect_ignore_came_from') # when we try to log from logged_out page the came_from doesn't bin canceled logger.info('ignore_came_from {}'.format(ignore_came_from)) if not ignore_came_from and request.get('came_from'): logger.info('audi5000') return # check if we got redirect expression redirect_expr = registry.get('collective.onlogin.interfaces.' \ 'IOnloginSettings.first_login_redirect_expr') logger.info('redirect_expr {}'.format(redirect_expr)) if not redirect_expr: logger.info('audi5000') return # now complile and render our expression to url expr = Expression(redirect_expr) econtext = getExprContext(portal, portal) try: url = expr(econtext) logger.info('url {}'.format(url)) except Exception, e: logException(u'Error during user initial login redirect') return
def _evaluateExpression(self, expr): evaluate = False if expr.startswith('path:'): expr = expr[5:] evaluate = True if expr.startswith('python:'): evaluate = True if expr.startswith('string:'): evaluate = True if evaluate: econtext = getExprContext(self, self) econtext.setGlobal('now', DateTime().ISO8601()) return Expression(expr)(econtext) return expr
def userLogin(obj, event): """Redirects logged in users to personal dashboard""" # get registry where we keep our configuration registry = getUtility(IRegistry) # check if we need to redirect at all do_redirect = registry.get("collective.onlogin.interfaces.IOnloginSettings.login_redirect_enabled") if not do_redirect: return # do not redirect if user initial login is set and our current event # is about User Initial Login; so First Login Redirect is always of # higher priority if registry.get( "collective.onlogin.interfaces.IOnloginSettings." "first_login_redirect_enabled" ) and IUserInitialLoginInEvent.providedBy(event): return # get portal object portal = getSite() # check if we have an access to request object request = getattr(portal, "REQUEST", None) if not request: return # check if we need to ignore came_from variable ignore_came_from = registry.get("collective.onlogin.interfaces.IOnloginSettings." "login_redirect_ignore_came_from") # when we try to log from logged_out page the came_from doesn't bin canceled if not ignore_came_from and request.get("came_from"): return # check if we got redirect expression redirect_expr = registry.get("collective.onlogin.interfaces.IOnloginSettings.login_redirect_expr") if not redirect_expr: return # now complile and render our expression to url expr = Expression(redirect_expr) econtext = getExprContext(portal, portal) try: url = expr(econtext) except Exception, e: logException(u"Error during user login redirect") return
def _isExecutableAdapter(self): """Check possible conditions for when an adapter is disabled. These include: 1) non-true execCondition on the adapter 2) not active within the parent form folder """ formFolder = aq_parent(self) if safe_hasattr(self, 'execCondition') and \ len(self.getRawExecCondition()): # evaluate the execCondition. # create a context for expression evaluation context = getExprContext(formFolder, self) return self.getExecCondition(expression_context=context) if self.getId() not in formFolder.getRawActionAdapter(): return False return True
def userInitialLogin(obj, event): """Redirects initially logged in users to getting started wizard""" registry = getUtility(IRegistry) # check if we need to redirect at all do_redirect = registry.get("collective.onlogin.interfaces." "IOnloginSettings.first_login_redirect_enabled") if not do_redirect: return # get portal object portal = getSite() # check if we have an access to request object request = getattr(portal, "REQUEST", None) if not request: return # check if we need to ignore came_from variable ignore_came_from = registry.get( "collective.onlogin.interfaces.IOnloginSettings." "first_login_redirect_ignore_came_from" ) # when we try to log from logged_out page the came_from doesn't bin canceled if not ignore_came_from and request.get("came_from"): return # check if we got redirect expression redirect_expr = registry.get("collective.onlogin.interfaces." "IOnloginSettings.first_login_redirect_expr") if not redirect_expr: return # now complile and render our expression to url expr = Expression(redirect_expr) econtext = getExprContext(portal, portal) try: url = expr(econtext) except Exception, e: logException(u"Error during user initial login redirect") return
def retrieveData(self): request = self.REQUEST sfbc = getToolByName(self, 'portal_salesforcebaseconnector') sObjectType = self.getSFObjectType() econtext = getExprContext(self) econtext.setGlobal('sanitize_soql', sanitize_soql) updateMatchExpression = self.getUpdateMatchExpression(expression_context = econtext) mappings = self.getFieldMap() # determine which fields to retrieve fieldList = [m['sf_field'] for m in mappings if m['sf_field']] # we always want the ID fieldList.append('Id') try: (obj_id, oldUpdateMatchExpression) = request.SESSION[(config.SESSION_KEY, self.UID())] if obj_id is None: raise ExpressionChanged if oldUpdateMatchExpression != 'CREATED' and oldUpdateMatchExpression != updateMatchExpression: raise ExpressionChanged except (AttributeError, KeyError, ExpressionChanged): # find item using expression query = 'SELECT %s FROM %s WHERE %s' % (', '.join(fieldList), sObjectType, updateMatchExpression) else: if obj_id is not None: query = "SELECT %s FROM %s WHERE Id='%s'" % (', '.join(fieldList), sObjectType, obj_id) else: request.SESSION[(config.SESSION_KEY, self.UID())] = (None, updateMatchExpression) return {} res = sfbc.query(query) error_msg = '' if not len(res['records']): if self.getActionIfNoExistingObject() == 'abort': error_msg = _(u'Could not find item to edit.') else: request.SESSION[(config.SESSION_KEY, self.UID())] = (None, updateMatchExpression) return {} if len(res['records']) > 1: error_msg = _(u'Multiple items found; unable to determine which one to edit.') # if we have an error condition, report it if error_msg: IStatusMessage(request).addStatusMessage(error_msg) mtool = getToolByName(self, 'portal_membership') if mtool.checkPermission('Modify portal content', self.aq_parent): # user needs to be able to edit form request.SESSION[(config.SESSION_KEY, self.UID())] = (None, updateMatchExpression) return {} else: # user shouldn't see form portal_url = getToolByName(self, 'portal_url')() raise Redirect(portal_url) data = {'Id':res['records'][0]['Id']} for m in mappings: if not m['sf_field']: continue value = res['records'][0][m['sf_field']] if isinstance(value, date): # make sure that the date gets interpreted as UTC value = str(value) + ' +00:00' if isinstance(value, float) and value.is_integer(): value = int(value) data[m['field_path']] = value obj_id = None if 'Id' in data: obj_id = data['Id'] request.SESSION[(config.SESSION_KEY, self.UID())] = (obj_id, updateMatchExpression) return data
def retrieveData(self): request = self.REQUEST sfbc = getToolByName(self, 'portal_salesforcebaseconnector') sObjectType = self.getSFObjectType() econtext = getExprContext(self) econtext.setGlobal('sanitize_soql', sanitize_soql) updateMatchExpression = self.getUpdateMatchExpression( expression_context=econtext) mappings = self.getFieldMap() # determine which fields to retrieve fieldList = [m['sf_field'] for m in mappings if m['sf_field']] # we always want the ID fieldList.append('Id') try: (obj_id, oldUpdateMatchExpression) = request.SESSION[(config.SESSION_KEY, self.UID())] if obj_id is None: raise ExpressionChanged if oldUpdateMatchExpression != 'CREATED' and oldUpdateMatchExpression != updateMatchExpression: raise ExpressionChanged except (AttributeError, KeyError, ExpressionChanged): # find item using expression query = 'SELECT %s FROM %s WHERE %s' % ( ', '.join(fieldList), sObjectType, updateMatchExpression) else: if obj_id is not None: query = "SELECT %s FROM %s WHERE Id='%s'" % ( ', '.join(fieldList), sObjectType, obj_id) else: request.SESSION[(config.SESSION_KEY, self.UID())] = (None, updateMatchExpression) return {} res = sfbc.query(query) error_msg = '' if not len(res['records']): if self.getActionIfNoExistingObject() == 'abort': error_msg = _(u'Could not find item to edit.') else: request.SESSION[(config.SESSION_KEY, self.UID())] = (None, updateMatchExpression) return {} if len(res['records']) > 1: error_msg = _( u'Multiple items found; unable to determine which one to edit.' ) # if we have an error condition, report it if error_msg: IStatusMessage(request).addStatusMessage(error_msg) mtool = getToolByName(self, 'portal_membership') if mtool.checkPermission('Modify portal content', self.aq_parent): # user needs to be able to edit form request.SESSION[(config.SESSION_KEY, self.UID())] = (None, updateMatchExpression) return {} else: # user shouldn't see form portal_url = getToolByName(self, 'portal_url')() raise Redirect(portal_url) data = {'Id': res['records'][0]['Id']} for m in mappings: if not m['sf_field']: continue value = res['records'][0][m['sf_field']] if isinstance(value, date): # make sure that the date gets interpreted as UTC value = str(value) + ' +00:00' if isinstance(value, float) and value.is_integer(): value = int(value) data[m['field_path']] = value obj_id = None if 'Id' in data: obj_id = data['Id'] request.SESSION[(config.SESSION_KEY, self.UID())] = (obj_id, updateMatchExpression) return data