def setupSession(self): """Setup the session for the context survey. This will rebuild the session tree if the profile has changed. """ survey = aq_inner(self.context) new_profile = self.getDesiredProfile() self.session = set_session_profile(survey, self.session, new_profile) SessionManager.resume(self.session)
def _NewSurvey(self, info): """Utility method to start a new survey session.""" survey = aq_inner(self.context) title = info.get("title", u"").strip() if not title: title = survey.Title() SessionManager.start(title=title, survey=survey) self.request.response.redirect("%s/start" % survey.absolute_url())
def _start(self, link): pas = getToolByName(self.context, 'acl_users') pas.updateCredentials(self.request, self.response, link.session.account.loginname, None) newSecurityManager(None, link.session.account) SessionManager.resume(link.session) survey = self.request.client.restrictedTraverse(str(link.session.zodb_path)) v_url = urlparse.urlsplit(self.url() + '/od-resume').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect("%s/resume" % survey.absolute_url())
def _NewSurvey(self, info): """Utility method to start a new survey session.""" survey = aq_inner(self.context) title = info.get("title", u"").strip() if not title: title = survey.Title() SessionManager.start(title=title, survey=survey) v_url = urlparse.urlsplit(self.url()+'/resume').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect("%s/start" % survey.absolute_url())
def _NewSurvey(self, info): """Utility method to start a new survey session.""" survey = aq_inner(self.context) title = info.get("title", u"").strip() if not title: title = survey.Title() SessionManager.start(title=title, survey=survey) v_url = urlparse.urlsplit(self.url() + '/resume').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect("%s/start?initial_view=1" % survey.absolute_url())
def _ContinueSurvey(self, info): """Utility method to continue an existing session.""" session = Session.query(model.SurveySession).get(info["session"]) current_user = aq_base(getSecurityManager().getUser()) if session.account is not current_user: log.warn('User %s tried to hijack session from %s', getattr(current_user, 'loginname', repr(current_user)), session.account.loginname) raise Unauthorized() SessionManager.resume(session) survey = self.request.client.restrictedTraverse(str(session.zodb_path)) v_url = urlparse.urlsplit(self.url()+'/resume').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect("%s/resume" % survey.absolute_url())
def _ContinueSurvey(self, info): """Utility method to continue an existing session.""" session = Session.query(model.SurveySession).get(info["session"]) current_user = aq_base(getSecurityManager().getUser()) if session.account is not current_user: log.warn('User %s tried to hijack session from %s', getattr(current_user, 'loginname', repr(current_user)), session.account.loginname) raise Unauthorized() SessionManager.resume(session) survey = self.request.client.restrictedTraverse(str(session.zodb_path)) v_url = urlparse.urlsplit(self.url() + '/resume').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect("%s/resume?initial_view=1" % survey.absolute_url())
def handleUpload(self, action): (data, errors) = self.extractData() if errors: return input = self.parseInput(data["file"].data) if input is None: raise WidgetActionExecutionError("file", Invalid(_("error_invalid_session_file", default=u"Geen valide RI&E bestand."))) survey = self.findSurvey(input) if survey is None: raise WidgetActionExecutionError("file", Invalid(_("error_unknown_survey", default=u"De gebruikte vragenlijst bestaat niet op deze site."))) session = SessionManager.start( attr_unicode(input, "rienaam", u"RI&E import"), survey) self.updateCompany(input, session) (profile, keuzemap) = self.buildProfile(input, survey, session) BuildSurveyTree(survey, profile, session) self.updateAnswers(input, keuzemap, survey, session) question = FindFirstQuestion(dbsession=session) if question is None: transaction.get().doom() raise WidgetActionExecutionError("file", Invalid(u"Deze RI&E is helaas teveel veranderd om te kunnen gebruiken.")) self.request.response.redirect( QuestionURL(survey, question, phase="identification"))
def _newLink(self, vestigings_sleutel, webservice): session = Session() # Check if there is an account from another regelhulp for the same # vestiging. account = session.query(model.Account)\ .filter(model.Account.loginname == vestigings_sleutel)\ .first() if account is None: # Create a new account account = model.Account( loginname=vestigings_sleutel, password=None) session.add(account) session.flush() # Make sure account.id is set log.info('Created new OD account %s for %s', account.loginname, self.url()) # Login with the account newSecurityManager(None, account) pas = getToolByName(self.context, 'acl_users') pas.updateCredentials(self.request, self.response, account.loginname, None) # And start a new survey survey = aq_inner(self.context) ss = SessionManager.start(title=survey.Title(), survey=survey) Session.add(OdLink( session=ss, vestigings_sleutel=vestigings_sleutel, webservice=webservice)) v_url = urlparse.urlsplit(survey.absolute_url() + '/od-new').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect('%s/start' % survey.absolute_url())
def _NewSurvey(self, info): """Utility method to start a new survey session.""" context = aq_inner(self.context) survey = info.get("survey") survey = context.restrictedTraverse(survey) if not ISurvey.providedBy(survey): log.error('Tried to start invalid survey %r' % info.get('survey')) # Things are sufficiently messed up at this point that rendering # breaks, so trigger a redirect to the same URL again. self.request.response.redirect(context.absolute_url()) return title = info.get("title", u"").strip() if not title: title = survey.Title() SessionManager.start(title=title, survey=survey) self.request.response.redirect("%s/start" % survey.absolute_url())
def _continue(self, session_id, vestigings_sleutel, webservice): session = Session.query(model.SurveySession).get(session_id) account = aq_base(getSecurityManager().getUser()) if session.account is not account: log.warn('User %s tried to hijack session from %s', getattr(account, 'loginname', repr(account)), session.account.loginname) raise Unauthorized() Session.add(OdLink( session=session, vestigings_sleutel=vestigings_sleutel, webservice=webservice)) SessionManager.resume(session) survey = self.request.client.restrictedTraverse(str(session.zodb_path)) v_url = urlparse.urlsplit(self.url() + '/od-link').path trigger_extra_pageview(self.request, v_url) self.request.response.redirect("%s/resume" % survey.absolute_url())
def hasValidSession(self, request): """Check if the user has an active session for the survey. """ dbsession = SessionManager.session client_path = utils.RelativePath(request.client, self.context) if dbsession is None or \ dbsession.zodb_path != client_path: # Allow for alternative session ids to be hardcoded in the # euphorie.ini file for automatic browser testing with Browsera conf = getUtility(IAppConfig).get("euphorie", {}) debug_ids = conf.get('debug_sessions', '').strip().splitlines() for sid in debug_ids: session = Session.query(model.SurveySession).get(sid) if hasattr(session, 'zodb_path') and \ session.zodb_path == client_path: SessionManager.resume(session) return True return False return True
def logout(self): pas = getToolByName(self.context, "acl_users") pas.resetCredentials(self.request, self.request.response) SessionManager.stop()
def _ContinueSurvey(self, info): """Utility method to continue an existing session.""" session = Session.query(model.SurveySession).get(info["session"]) SessionManager.resume(session) survey = self.request.client.restrictedTraverse(str(session.zodb_path)) self.request.response.redirect("%s/resume" % survey.absolute_url())