def comment_add(self, REQUEST): """ Add a comment for this object. """ err = [] if not self.checkPermissionSkipCaptcha(): contact_word = REQUEST.get('contact_word') captcha_errors = self.validateCaptcha(contact_word, REQUEST) if captcha_errors: err.extend(captcha_errors) if err: self.setSessionErrorsTrans(err) return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER) form_data = dict(REQUEST.form) author = REQUEST.AUTHENTICATED_USER.getUserName() comment_title = form_data.get('title') comment_body = cleanup_message(form_data.get('body')) spamstatus = self._is_spam(comment_title) if not spamstatus: spamstatus = self._is_spam(comment_body) ob = self._comment_add(title = comment_title, body = comment_body, author = author, releasedate = self.utGetTodayDate()) auth_tool = self.getAuthenticationTool() auth_tool.changeLastPost(author) self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES, date=self.utGetTodayDate()) return REQUEST.RESPONSE.redirect('%s/index_html' % self.absolute_url())
def comment_add(self, REQUEST): """ Add a comment for this object. """ err = [] if not self.checkPermissionSkipCaptcha(): recaptcha_response = REQUEST.get('g-recaptcha-response') captcha_errors = self.validateCaptcha(recaptcha_response, REQUEST) if captcha_errors: err.extend(captcha_errors) if err: self.setSessionErrorsTrans(err) return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER) form_data = dict(REQUEST.form) author = REQUEST.AUTHENTICATED_USER.getUserName() comment_title = form_data.get('title') comment_body = cleanup_message(form_data.get('body')) spamstatus = self._is_spam(comment_title) if not spamstatus: spamstatus = self._is_spam(comment_body) ob = self._comment_add(title=comment_title, body=comment_body, author=author, releasedate=self.utGetTodayDate()) auth_tool = self.getAuthenticationTool() auth_tool.changeLastPost(author) self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES, date=self.utGetTodayDate()) return REQUEST.RESPONSE.redirect('%s/index_html' % self.absolute_url())
def request_ig_access(self, REQUEST): """ Called when `request_ig_access_html` submits. Sends a mail to the portal administrator informing that the current user has requested elevated access. """ if self.portal_is_archived: raise BadRequest("You can't request access to archived IGs") role = REQUEST.form.get('role', '') location = REQUEST.form.get('location', '') location_url = REQUEST.form.get('location_url', '') explanatory_text = cleanup_message( REQUEST.form.get('explanatory_text', '').strip()) if not explanatory_text: explanatory_text = '-' if not role: return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER) if location == "/": location = '' if not location and location_url: o = urlparse(location_url.replace('/index_html', '')) location = o.path if location: location_obj = self.unrestrictedTraverse(location, None) while True: if location_obj.meta_type in ['Naaya Meeting', 'Groupware site']: break else: location_obj = location_obj.aq_parent site_id = self.getSite().getId() location = '/' + site_id + '/' + path_in_site(location_obj) location_title = location_obj.title_or_id() location_url = location_obj.absolute_url() else: location_title = self.title_or_id() location_url = self.absolute_url() user = REQUEST.AUTHENTICATED_USER member_search_link = ( "%(ig_url)s/member_search?search_string=%(userid)s" % { 'ig_url': self.absolute_url(), 'userid': user.name } ) # Create an action for the current request and include a link in the # e-mail so that the log can be viewed or passed to another # administrator key = self.utGenerateUID() log_entry_id = self.getActionLogger().create( type=ACTION_LOG_TYPES['role_request'], key=key, user=user.getUserName(), role=role, location=location, location_url=location_url, location_title=location_title ) log_entry = self.getActionLogger()[log_entry_id] user_admin_link = self._user_admin_link(log_entry) review_link = ( "%(ig_url)s/review_ig_request?key=%(key)s" % { 'ig_url': self.absolute_url(), 'key': key } ) mail_tool = self.getEmailTool() mail_to = self.administrator_email mail_from = mail_tool.get_addr_from() try: firstname = getattr(user, 'firstname', '').decode('utf-8') except UnicodeDecodeError: firstname = getattr(user, 'firstname', '').decode('latin1') try: lastname = getattr(user, 'lastname', '').decode('utf-8') except UnicodeDecodeError: lastname = getattr(user, 'lastname', '').decode('latin1') mail_data = self.request_ig_access_emailpt.render_email(**{ 'here': self, 'role': role, 'user': user, 'firstname': firstname, 'lastname': lastname, 'email': getattr(user, 'mail', ''), 'location_title': location_title, 'user_admin_link': user_admin_link, 'member_search_link': member_search_link, 'location_url': location_url, 'review_link': review_link, 'explanatory_text': explanatory_text, 'network_name': NETWORK_NAME, }) mail_tool.sendEmail(mail_data['body_text'], mail_to, mail_from, mail_data['subject']) return REQUEST.RESPONSE.redirect( '%s/request_ig_access_html?mail_sent=True' % self.absolute_url())
def request_ig_access(self, REQUEST): """ Called when `request_ig_access_html` submits. Sends a mail to the portal administrator informing that the current user has requested elevated access. """ if self.portal_is_archived: raise BadRequest, "You can't request access to archived IGs" role = REQUEST.form.get('role', '') location = REQUEST.form.get('location', '') location_url = REQUEST.form.get('location_url', '') explanatory_text = cleanup_message( REQUEST.form.get('explanatory_text', '').strip()) if not explanatory_text: explanatory_text = '-' if not role: return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER) if location == "/": location = '' if not location and location_url: o = urlparse(location_url.replace('/index_html', '')) location = o.path if location: location_obj = self.unrestrictedTraverse(location, None) while True: if location_obj.meta_type in [ 'Naaya Meeting', 'Groupware site' ]: break else: location_obj = location_obj.aq_parent site_id = self.getSite().getId() location = '/' + site_id + '/' + path_in_site(location_obj) location_title = location_obj.title_or_id() location_url = location_obj.absolute_url() else: location_title = self.title_or_id() location_url = self.absolute_url() user = REQUEST.AUTHENTICATED_USER member_search_link = ( "%(ig_url)s/member_search?search_string=%(userid)s" % { 'ig_url': self.absolute_url(), 'userid': user.name }) # Create an action for the current request and include a link in the # e-mail so that the log can be viewed or passed to another # administrator key = self.utGenerateUID() log_entry_id = self.getActionLogger().create( type=ACTION_LOG_TYPES['role_request'], key=key, user=user.getUserName(), role=role, location=location, location_url=location_url, location_title=location_title) log_entry = self.getActionLogger()[log_entry_id] user_admin_link = self._user_admin_link(log_entry) review_link = ("%(ig_url)s/review_ig_request?key=%(key)s" % { 'ig_url': self.absolute_url(), 'key': key }) mail_tool = self.getEmailTool() mail_to = self.administrator_email mail_from = mail_tool.get_addr_from() mail_data = self.request_ig_access_emailpt.render_email( **{ 'here': self, 'role': role, 'user': user, 'firstname': getattr(user, 'firstname', '').decode('utf-8'), 'lastname': getattr(user, 'lastname', '').decode('utf-8'), 'email': getattr(user, 'mail', ''), 'location_title': location_title, 'user_admin_link': user_admin_link, 'member_search_link': member_search_link, 'location_url': location_url, 'review_link': review_link, 'explanatory_text': explanatory_text, 'network_name': NETWORK_NAME, }) mail_tool.sendEmail(mail_data['body_text'], mail_to, mail_from, mail_data['subject']) return REQUEST.RESPONSE.redirect( '%s/request_ig_access_html?mail_sent=True' % self.absolute_url())
def request_ig_access(self, REQUEST): """ Called when `request_ig_access_html` submits. Sends a mail to the portal administrator informing that the current user has requested elevated access. XXX: Works only with a single source (no local users) """ if self.portal_is_archived: raise BadRequest, "You can't request access to archived IGs" role = REQUEST.form.get('role', '') location = REQUEST.form.get('location', '') explanatory_text = cleanup_message( REQUEST.form.get('explanatory_text', '').strip()) if not explanatory_text: explanatory_text = '-' sources = self.getAuthenticationTool().getSources() if not role or not sources: return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER) source_obj = sources[0] #should not be more than one if location == "/": location = '' if location: location_obj = self.unrestrictedTraverse(location, None) location_title = location_obj.title_or_id() location_url = location_obj.absolute_url() else: location_title = self.title_or_id() location_url = self.absolute_url() user = REQUEST.AUTHENTICATED_USER member_search_link = ( "%(ig_url)s/member_search?search_string=%(userid)s" % { 'ig_url': self.absolute_url(), 'userid': user.name } ) #Create an action for the current request and include a link in the #e-mail so that the log can be viewed or passed to another administrator key = self.utGenerateUID() log_entry_id = self.getActionLogger().create( type=ACTION_LOG_TYPES['role_request'], key=key, user=user.getUserName(), role=role, location=location, location_url=location_url, location_title=location_title ) log_entry = self.getActionLogger()[log_entry_id] user_admin_link = self._user_admin_link(log_entry) review_link = ( "%(ig_url)s/review_ig_request?key=%(key)s" % { 'ig_url': self.absolute_url(), 'key': key } ) mail_tool = self.getEmailTool() mail_to = self.administrator_email mail_from = mail_tool.get_addr_from() mail_data = self.request_ig_access_emailpt.render_email(**{ 'here': self, 'role': role, 'user': user, 'firstname': getattr(user, 'firstname', '').decode('latin-1'), 'lastname': getattr(user, 'lastname', '').decode('latin-1'), 'email': getattr(user, 'mail', ''), 'location_title': location_title, 'user_admin_link': user_admin_link, 'member_search_link': member_search_link, 'location_url': location_url, 'review_link': review_link, 'explanatory_text': explanatory_text, 'network_name': NETWORK_NAME, }) mail_tool.sendEmail(mail_data['body_text'], mail_to, mail_from, mail_data['subject']) return REQUEST.RESPONSE.redirect( '%s/request_ig_access_html?mail_sent=True' % self.absolute_url())