def __init__(self, name): self.tmpdir = config.settings["paths.searchstore"] self.name = name try: self.searcher = mgquery.MGSearchStore( config.settings["paths.searchstore"], self.name) except: log.info(formatException()) self.searcher = None self.s2n = None return self.searchindex2node = [None] collection = "root" if collection in collections: self.s2n = collections[collection] else: fi = open(self.tmpdir + "s2n.txt", "rb") self.s2n = [] while True: s = fi.readline() if not s: break self.s2n += [s.strip()] fi.close() collections[collection] = self.s2n
def runAction(self, node, op=""): link = "https://%s/pnode?id=%s&key=%s" % (config.get("host.name"), node.id, node.get("key")) link2 = "https://%s/node?id=%s" % (config.get("host.name"), node.id) attrs = {"node": node, "link": link, "publiclink": link2} try: if "@" in self.get('from'): node.set("system.mailtmp.from", getTALtext(self.get("from"), attrs)) elif "@" in node.get(self.get('from')): node.set("system.mailtmp.from", getTALtext(node.get(self.get("from")), attrs)) _mails = [] for m in self.get('email').split(";"): if "@" in m: _mails.append(getTALtext(m, attrs)) elif "@" in node.get(m): _mails.append(getTALtext(node.get(m), attrs)) node.set("system.mailtmp.to", ";".join(_mails)) node.set("system.mailtmp.subject", getTALtext(self.get("subject"), attrs)) node.set("system.mailtmp.text", getTALtext(self.get("text"), attrs)) db.session.commit() except: node.system_attrs['mailtmp.talerror'] = formatException() db.session.commit() return if self.get("allowedit").lower().startswith("n"): if(self.sendOut(node)): self.forward(node, True)
def __init__(self, name): self.tmpdir = config.settings["paths.searchstore"] self.name = name try: self.searcher = mgquery.MGSearchStore(config.settings["paths.searchstore"], self.name) except: log.info(formatException()) self.searcher = None self.s2n = None return self.searchindex2node = [None] collection = "root" if collection in collections: self.s2n = collections[collection] else: fi = open(self.tmpdir + "s2n.txt", "rb") self.s2n = [] while True: s = fi.readline() if not s: break self.s2n += [s.strip()] fi.close() collections[collection] = self.s2n
def addACL(username, firstname, lastname, oldusername=None): """unused function addACL?""" userrule = "( user %s )" % username userruledesc = username try: if (not (lastname == "" or firstname == "")): userruledesc = "%s, %s" % (lastname, firstname) if (oldusername is None): oldusername = username if acl.existRule(oldusername): acl.updateRule(AccessRule(username, userrule, userruledesc), oldusername, username, oldusername) else: acl.addRule(AccessRule(username, userrule, userruledesc)) except: print formatException()
def sendOut(self, node): xfrom = node.get("system.mailtmp.from") to = node.get("system.mailtmp.to") sendcondition = self.get("sendcondition") attach_pdf_form = bool(self.get("attach_pdf_form")) sendOk = 1 try: if sendcondition.startswith("attr:") and "=" in sendcondition: arrname, value = sendcondition[5:].split("=") if node.get(arrname) != value: sendOk = 0 elif (sendcondition.startswith("schema=") and node.schema not in sendcondition[7:].split(";")) or (sendcondition.startswith("type=") and not node.get("type") in sendcondition[5:].split(";")) or (sendcondition == "hasfile" and len(node.files) == 0): sendOk = 0 except: logg.exception("syntax error in email condition: %s", sendcondition) if sendOk: try: logg.info("sending mail to %s (%s)", to, self.get("email")) if not to: raise MailError("No receiver address defined") if not xfrom: raise MailError("No from address defined") attachments_paths_and_filenames = [] if attach_pdf_form: pdf_form_files = [f for f in node.files if f.filetype == 'pdf_form'] for i, f in enumerate(pdf_form_files): if not os.path.isfile(f.abspath): raise MailError("Attachment file not found: '%s'" % f.abspath) else: #attachments_paths_and_filenames.append((f.retrieveFile(), 'contract_%s_%s.pdf' %(i, node.id))) attachments_paths_and_filenames.append((f.abspath, '%s' % (f.abspath.split('_')[-1]))) pass mail.sendmail(xfrom, to, node.get("system.mailtmp.subject"), node.get( "system.mailtmp.text"), attachments_paths_and_filenames=attachments_paths_and_filenames) except: node.set("system.mailtmp.error", formatException()) db.session.commit() logg.exception("Error while sending mail- node stays in workflowstep %s %s", self.id, self.name) return else: logg.info("sending mail prevented by condition %s " % (sendcondition)) return for s in ["mailtmp.from", "mailtmp.to", "mailtmp.subject", "mailtmp.text", "mailtmp.error", "mailtmp.talerror", "mailtmp.send"]: try: del node.system_attrs[s] except KeyError: continue db.session.commit() return 1