def save_node_to_ruleset_mappings(nid_to_rulesets, ruletype): s = db.session logg.info("saving %s ruleset mappings for %d nodes", ruletype, len(nid_to_rulesets)) node_to_access_ruleset_it = (NodeToAccessRuleset( nid=nid, ruleset_name=r, ruletype=ruletype) for nid, ruleset_names in nid_to_rulesets.items() for r in set(ruleset_names) if r is not None) s.add_all(node_to_access_ruleset_it)
def inheritWorkflowRights(name, type): w = getWorkflow(name) ac = w.access_ruleset_assocs.filter_by(ruletype=type) for step in w.children: for r in ac: if step.access_ruleset_assocs.filter_by( ruleset_name=r.ruleset_name, ruletype=type).first() is None: step.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r.ruleset_name, ruletype=type)) db.session.commit()
def show_workflow_node(self, node, req): # print req.params # set access for download same as edit (only once needed) for r in self.access_ruleset_assocs.filter_by(ruletype='write'): if self.access_ruleset_assocs.filter_by( ruleset_name=r.ruleset_name, ruletype='data').first() is None: self.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r.ruleset_name, ruletype='data')) db.session.commit() if "gotrue" in req.params: return self.forwardAndShow(node, True, req) elif "gofalse" in req.params: return self.forwardAndShow(node, False, req) if self.getTrueLabel(language=node.get( "system.wflanguage")) == "" and self.getFalseLabel( language=node.get("system.wflanguage")) == "": buttons = [] else: buttons = self.tableRowButtons(node) try: mask = q(Metadatatype).filter_by(name=node.schema).one().getMask( self.get("mask_fileatt")) maskdata = mask.getViewHTML([node], VIEW_HIDE_EMPTY, language=lang(req)) except: logg.exception( "exception in workflow step fileAttachment, getViewHTML failed, empty string" ) maskdata = "" return req.getTAL("workflow/fileattachment.html", { "buttons": buttons, "files": self.files, "wfnode": self, "pretext": self.getPreText(lang(req)), "posttext": self.getPostText(lang(req)), "sidebar": self.getSidebarText(lang(req)), 'maskdata': maskdata, "csrf": req.csrf_token.current_token, }, macro="fileattachment_show_node")
def add_remove_rulesets_from_metadatatype(mtype, new_ruleset_names): new_ruleset_names = set(new_ruleset_names) current_ruleset_assocs_by_ruleset_name = { rs.ruleset.name: rs for rs in mtype.access_ruleset_assocs.filter_by(ruletype=u"read") } current_ruleset_names = set(current_ruleset_assocs_by_ruleset_name) removed_ruleset_names = current_ruleset_names - new_ruleset_names added_ruleset_names = new_ruleset_names - current_ruleset_names for ruleset_name in removed_ruleset_names: rsa = current_ruleset_assocs_by_ruleset_name[ruleset_name] mtype.access_ruleset_assocs.remove(rsa) for ruleset_name in added_ruleset_names: mtype.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=ruleset_name, ruletype=u"read"))
def on_model_change(self, form, usergroup, is_created): if is_created: """ create ruleset for group """ existing_ruleset = q(AccessRuleset).filter_by( name=usergroup.name).scalar() if existing_ruleset is None: rule = get_or_add_access_rule(group_ids=[usergroup.id]) ruleset = AccessRuleset(name=usergroup.name, description=usergroup.name) arr = AccessRulesetToRule(rule=rule) ruleset.rule_assocs.append(arr) """ add/remove access to Metadatatypes """ for mt in q(Metadatatype): nrs_list = q(NodeToAccessRuleset).filter_by(nid=mt.id).filter_by( ruleset_name=usergroup.name).all() if mt in form.metadatatypes.data: if not nrs_list: mt.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=usergroup.name, ruletype=u'read')) else: for nrs in nrs_list: mt.access_ruleset_assocs.remove(nrs)
def updateWorkflow(name, description, nameattribute="", origname="", writeaccess=""): if origname == "": node = q(Workflows).one() if node.children.filter_by(name=name).scalar() is None: addWorkflow(name, description) w = q(Workflows).one().children.filter_by(name=name).one() else: w = q(Workflows).one().children.filter_by(name=origname).one() w.name = name w.set("description", description) w.display_name_attribute = nameattribute # TODO: is this part necessary? if not writeaccess: for r in w.access_ruleset_assocs.filter_by(ruletype=u'write'): db.session.delete(r) else: w.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=writeaccess, ruletype=u'write')) db.session.commit()
def getContent(req, ids): hidden_edit_functions_for_current_user = current_user.hidden_edit_functions if 'acls' in hidden_edit_functions_for_current_user: req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if len(ids) != 1: # should not happen req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/modules/acls.html", {}, macro="acl_editor_error") # check write access to node idstr = ids[0] nid = long(idstr) node = q(Node).get(nid) if not node.has_write_access(): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if "save" in req.params: logg.info("%r change access %r", current_user, idstr) if req.params.get("type") == "acl": for rule_type in rule_types: ruleset_names_from_request = [ rsn for rsn in req.params.get(u"left%s" % rule_type, u"").split(u";") if rsn.strip() ] inherited_ruleset_assocs, \ own_ruleset_assocs, \ special_ruleset, \ special_rule_assocs = get_access_rules_info(node, rule_type) own_ruleset_names_not_private = [ r.ruleset_name for r in own_ruleset_assocs if not r.private ] to_be_removed_rulesets = set( own_ruleset_names_not_private) - set( ruleset_names_from_request) to_be_added_rulesets = set(ruleset_names_from_request) - set( own_ruleset_names_not_private) - {'__special_rule__'} if to_be_removed_rulesets: msg = "node %r: %r removing rulesets %r" % ( node, rule_type, to_be_removed_rulesets) logg.info(msg) for ruleset_name in to_be_removed_rulesets: node.access_ruleset_assocs.filter_by( ruleset_name=ruleset_name, ruletype=rule_type).delete() if to_be_added_rulesets: msg = "node %r: %r adding rulesets %r" % ( node, rule_type, to_be_added_rulesets) logg.info(msg) for ruleset_name in to_be_added_rulesets: node.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=ruleset_name, ruletype=rule_type)) db.session.commit() if req.params.get("type") == "user": for rule_type in rule_types: user_ids_from_request = [ rsn for rsn in req.params.get(u"leftuser%s" % rule_type, u"").split(u";") if rsn.strip() ] special_ruleset = node.get_special_access_ruleset(rule_type) if special_ruleset: special_rule_assocs = special_ruleset.rule_assocs else: special_rule_assocs = [] special_access_rules = [ra.rule for ra in special_rule_assocs] user_test_results = [ decider_is_private_user_group_access_rule(ar) for ar in special_access_rules ] uids = [u.id for u in user_test_results if isinstance(u, User)] uids_to_remove = list(set(uids) - set(user_ids_from_request)) uids_to_add = list(set(user_ids_from_request) - set(uids)) if uids_to_add and not special_ruleset: # in this case uids_to_remove will be empty special_ruleset = node.get_or_add_special_access_ruleset( rule_type) special_rule_assocs = special_ruleset.rule_assocs for uid in uids_to_add: user = q(User).get(uid) access_rule = get_or_add_private_access_rule_for_user(user) rule_assoc = AccessRulesetToRule( rule=access_rule, #ruleset=special_ruleset, invert=False, blocking=False) special_rule_assocs.append(rule_assoc) # remove uids_to_remove *after* having added uids_to_add: a trigger may delete empty rulesets for uid in uids_to_remove: user = q(User).get(uid) access_rule = get_or_add_private_access_rule_for_user(user) for rule_assoc in special_rule_assocs: if rule_assoc.rule_id == access_rule.id: db.session.delete(rule_assoc) db.session.flush() db.session.commit() action = req.params.get("action", "") retacl = "" if not action: rulesetnamelist = [ t[0] for t in q(AccessRuleset.name).order_by(AccessRuleset.name).all() ] private_ruleset_names = [ t[0] for t in q(NodeToAccessRuleset.ruleset_name).filter_by( private=True).all() ] rulesetnamelist = [ rulesetname for rulesetname in rulesetnamelist if not rulesetname in private_ruleset_names ] for rule_type in rule_types: inherited_ruleset_assocs, \ own_ruleset_assocs, \ special_ruleset, special_rule_assocs = get_access_rules_info(node, rule_type) retacl += req.getTAL( "web/edit/modules/acls.html", makeList( req, own_ruleset_assocs, #not_inherited_ruleset_names[rule_type], # rights inherited_ruleset_assocs, #inherited_ruleset_names[rule_type], # readonlyrights special_ruleset, #additional_rules_inherited[rule_type], special_rule_assocs, #additional_rules_not_inherited[rule_type], rulesetnamelist, private_ruleset_names, rule_type=rule_type), macro="edit_acls_selectbox") if action == 'get_userlist': # load additional rights by ajax rulesetnamelist = [ t[0] for t in q(AccessRuleset.name).order_by(AccessRuleset.name).all() ] private_ruleset_names = [ t[0] for t in q(NodeToAccessRuleset.ruleset_name).filter_by( private=True).all() ] rulesetnamelist = [ rulesetname for rulesetname in rulesetnamelist if not rulesetname in private_ruleset_names ] retuser = "" for rule_type in rule_types: inherited_ruleset_assocs, \ own_ruleset_assocs, \ special_ruleset, special_rule_assocs = get_access_rules_info(node, rule_type) retuser += req.getTAL( "web/edit/modules/acls.html", makeUserList( req, own_ruleset_assocs, # not_inherited_ruleset_names[rule_type], # rights inherited_ruleset_assocs, # inherited_ruleset_names[rule_type], # readonlyrights special_ruleset, # additional_rules_inherited[rule_type], special_rule_assocs, # additional_rules_not_inherited[rule_type], rulesetnamelist, private_ruleset_names, rule_type=rule_type), macro="edit_acls_userselectbox") req.write(retuser) return "" runsubmit = "\nfunction runsubmit(){\n" for rule_type in rule_types: runsubmit += "\tmark(document.myform.left" + rule_type + ");\n" runsubmit += "\tmark(document.myform.leftuser" + rule_type + ");\n" runsubmit += "\tdocument.myform.submit();\n}\n" return req.getTAL("web/edit/modules/acls.html", { "runsubmit": runsubmit, "idstr": idstr, "contentacl": retacl, "adminuser": current_user.is_admin }, macro="edit_acls")
def validate(req, op): path = req.path[1:].split("/") if len(path) == 3 and path[2] == "overview": return showFieldOverview(req) if len(path) == 4 and path[3] == "editor": res = showEditor(req) return res if len(path) == 5 and path[3] == "editor" and path[4] == "show_testnodes": raise NotImplementedError("") template = req.params.get('template', '') testnodes_list = req.params.get('testnodes', '') width = req.params.get('width', '400') item_id = req.params.get('item_id', None) mdt_name = path[1] mask_name = path[2] mdt = q(Metadatatypes).one().children.filter_by(name=mdt_name).one() mask = mdt.children.filter_by(name=mask_name).one() sectionlist = [] for nid in [x.strip() for x in testnodes_list.split(',') if x.strip()]: section_descr = {} section_descr['nid'] = nid section_descr['error_flag'] = '' # in case of no error node = q(Node).get(nid) section_descr['node'] = node if node and node.has_data_access(): try: node_html = mask.getViewHTML( [node], VIEW_DEFAULT, template_from_caller=[template, mdt, mask, item_id]) section_descr['node_html'] = node_html except: logg.exception("exception while evaluating template") error_text = str(sys.exc_info()[1]) template_line = 'for node id ' + ustr( nid) + ': ' + error_text with suppress(Exception, warn=False): m = re.match( r".*line (?P<line>\d*), column (?P<column>\d*)", error_text) if m: mdict = m.groupdict() line = int(mdict.get('line', 0)) column = int(mdict.get('column', 0)) error_text = error_text.replace( 'line %d' % line, 'template line %d' % (line - 1)) template_line = 'for node id ' + ustr( nid ) + '<br/>' + error_text + '<br/><code>' + esc( template.split("\n")[line - 2][0:column - 1] ) + '<span style="color:red">' + esc( template.split("\n")[line - 2][column - 1:]) + '</span></code>' section_descr[ 'error_flag'] = 'Error while evaluating template:' section_descr['node_html'] = template_line elif node and not node.has_data_access(): section_descr['error_flag'] = 'no access' section_descr['node_html'] = '' if node is None: section_descr['node'] = None section_descr['error_flag'] = 'NoSuchNodeError' section_descr['node_html'] = 'for node id ' + ustr(nid) sectionlist.append(section_descr) # remark: error messages will be served untranslated in English # because messages from the python interpreter (in English) will be added return req.getTAL("web/admin/modules/metatype.html", { 'sectionlist': sectionlist, 'csrf': req.csrf_token.current_token }, macro="view_testnodes") if len(path) == 2 and path[1] == "info": return showInfo(req) if "file" in req.params and hasattr( req.params["file"], "filesize") and req.params["file"].filesize > 0: # import scheme from xml-file importfile = req.params.get("file") if importfile.tempname != "": xmlimport(req, importfile.tempname) if req.params.get("acttype", "schema") == "schema": # section for schema for key in req.params.keys(): # create new metadatatype if key.startswith("new"): return MetatypeDetail(req, "") # edit metadatatype elif key.startswith("edit_"): return MetatypeDetail(req, key[5:-2]) # delete metadata elif key.startswith("delete_"): deleteMetaType(key[7:-2]) break # show details for given metadatatype elif key.startswith("detaillist_"): return showDetailList(req, key[11:-2]) # show masklist for given metadatatype elif key.startswith("masks_"): return showMaskList(req, key[6:-2]) # save schema if "form_op" in req.params.keys(): if req.params.get("form_op", "") == "cancel": return view(req) if req.params.get("mname", "") == "" or req.params.get( "mlongname", "") == "" or req.params.get("mdatatypes", "") == "": return MetatypeDetail(req, req.params.get("mname_orig", ""), 1) # no name was given elif not checkString(req.params.get("mname", "")): return MetatypeDetail( req, req.params.get("mname_orig", ""), 4) # if the name contains wrong characters elif req.params.get("mname_orig", "") != req.params.get( "mname", "") and existMetaType(req.params.get("mname")): return MetatypeDetail(req, req.params.get("mname_orig", ""), 2) # metadata still existing _active = 0 if req.params.get("mactive", "") != "": _active = 1 updateMetaType(req.params.get("mname", ""), description=req.params.get("description", ""), longname=req.params.get("mlongname", ""), active=_active, datatypes=req.params.get("mdatatypes", "").replace(";", ", "), bibtexmapping=req.params.get("mbibtex", ""), citeprocmapping=req.params.get("mciteproc", ""), orig_name=req.params.get("mname_orig", "")) mtype = q(Metadatatype).filter_by( name=req.params.get("mname")).scalar() if mtype: new_ruleset_names = set(req.form.getlist("leftread")) add_remove_rulesets_from_metadatatype(mtype, new_ruleset_names) db.session.commit() elif req.params.get("acttype") == "field": # section for fields for key in req.params.keys(): # create new meta field if key.startswith("newdetail_"): return FieldDetail(req, req.params.get("parent"), "") # edit meta field elif key.startswith("editdetail_"): return FieldDetail(req, req.params.get("parent"), key[11:-2]) # delete metafield: key[13:-2] = pid | n elif key.startswith("deletedetail_"): deleteMetaField(req.params.get("parent"), key[13:-2]) return showDetailList(req, req.params.get("parent")) # change field order up if key.startswith("updetail_"): moveMetaField(req.params.get("parent"), key[9:-2], -1) return showDetailList(req, req.params.get("parent")) # change field order down elif key.startswith("downdetail_"): moveMetaField(req.params.get("parent"), key[11:-2], 1) return showDetailList(req, req.params.get("parent")) if "form_op" in req.params.keys(): if req.params.get("form_op", "") == "cancel": return showDetailList(req, req.params.get("parent")) if existMetaField(req.params.get("parent"), req.params.get("mname")) and \ (req.params.get("form_op", "") == "save_newdetail" or req.params.get("mname") != req.params.get("mname_orig")): return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 3) # field still existing elif req.params.get("mname", "") == "" or req.params.get( "mlabel", "") == "": return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 1) elif not checkString(req.params.get("mname", "")): # if the name contains wrong characters return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 4) _option = "" for o in req.params.keys(): if o.startswith("option_"): _option += o[7] _fieldvalue = "" if req.params.get("mtype", "") + "_value" in req.params.keys(): _fieldvalue = req.params.get( req.params.get("mtype") + "_value") _filenode = None if "valuesfile" in req.params.keys(): valuesfile = req.params.pop("valuesfile") _filenode = importFileToRealname(valuesfile.filename, valuesfile.tempname) _attr_dict = {} if req.params.get("mtype", "") + "_handle_attrs" in req.params.keys(): attr_names = [ s.strip() for s in req.params.get( req.params.get("mtype", "") + "_handle_attrs").split(",") ] key_prefix = req.params.get("mtype", "") + "_attr_" for attr_name in attr_names: attr_value = req.params.get(key_prefix + attr_name, "") _attr_dict[attr_name] = attr_value updateMetaField(req.params.get("parent", ""), req.params.get("mname", ""), req.params.get("mlabel", ""), req.params.get("orderpos", ""), req.params.get("mtype", ""), _option, req.params.get("mdescription", ""), _fieldvalue, fieldid=req.params.get("fieldid", ""), filenode=_filenode, attr_dict=_attr_dict) return showDetailList(req, req.params.get("parent")) elif req.params.get("acttype") == "mask": # section for masks for key in req.params.keys(): # new mask if key.startswith("newmask_"): return MaskDetails(req, req.params.get("parent"), "") # edit metatype masks elif key.startswith("editmask_"): return MaskDetails(req, req.params.get("parent"), key[9:-2], err=0) # delete mask elif key.startswith("deletemask_"): mtype = getMetaType(req.params.get("parent")) mtype.children.remove(q(Node).get(key[11:-2])) db.session.commit() return showMaskList(req, req.params.get("parent")) # create autmatic mask with all fields elif key.startswith("automask_"): generateMask(getMetaType(req.params.get("parent"))) return showMaskList(req, req.params.get("parent")) # cope selected mask if key.startswith("copymask_"): k = key[9:-2] if k.isdigit(): mask = q(Mask).get(k) else: mtype = getMetaType(req.params.get("parent")) mask = mtype.getMask(k) cloneMask(mask, u"copy_" + mask.name) return showMaskList(req, req.params.get("parent")) if "form_op" in req.params.keys(): if req.params.get("form_op", "") == "cancel": return showMaskList(req, req.params.get("parent")) if req.params.get("mname", "") == "": return MaskDetails(req, req.params.get("parent", ""), req.params.get("morig_name", ""), err=1) elif not checkString(req.params.get("mname", "")): # if the name contains wrong characters return MaskDetails(req, req.params.get("parent", ""), req.params.get("morig_name", ""), err=4) mtype = q(Metadatatype).filter_by( name=q(Node).get(req.params.get("parent", "")).name).one() if req.params.get("form_op") == "save_editmask": mask = mtype.get_mask(req.params.get("mname", "")) # in case of renaming a mask the mask cannot be detected via the new mname # then detect mask via maskid if not mask: mtype = getMetaType(req.params.get("parent")) mask = mtype.children.filter_by( id=req.params.get("maskid", "")).scalar() elif req.params.get("form_op") == "save_newmask": mask = Mask(req.params.get("mname", "")) mtype.children.append(mask) db.session.commit() mask.name = req.params.get("mname") mask.setDescription(req.params.get("mdescription")) mask.setMasktype(req.params.get("mtype")) mask.setSeparator(req.params.get("mseparator")) db.session.commit() if req.params.get("mtype") == "export": mask.setExportMapping(req.params.get("exportmapping") or "") mask.setExportHeader(req.params.get("exportheader")) mask.setExportFooter(req.params.get("exportfooter")) _opt = "" if "types" in req.params.keys(): _opt += "t" if "notlast" in req.params.keys(): _opt += "l" mask.setExportOptions(_opt) db.session.commit() mask.setLanguage(req.params.get("mlanguage", "")) mask.setDefaultMask("mdefault" in req.params.keys()) for r in mask.access_ruleset_assocs.filter_by(ruletype=u'read'): db.session.delete(r) for key in req.params.keys(): if key.startswith("left"): for r in req.params.get(key).split(';'): mask.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r, ruletype=key[4:])) break db.session.commit() return showMaskList(req, ustr(req.params.get("parent", ""))) return view(req)
def validate(req, op): path = req.path[1:].split("/") if len(path) == 3 and path[2] == "overview": return WorkflowPopup(req) if "file" in req.params and hasattr( req.params["file"], "filesize") and req.params["file"].filesize > 0: # import scheme from xml-file importfile = req.params.get("file") if importfile.tempname != "": xmlimport(req, importfile.tempname) if req.params.get("form_op", "") == "update": return WorkflowStepDetail(req, req.params.get("parent"), req.params.get("nname"), -1) try: if req.params.get("acttype", "workflow") == "workflow": # workflow section for key in req.params.keys(): if key.startswith("new_"): # create new workflow return WorkflowDetail(req, "") elif key.startswith("edit_"): # edit workflow return WorkflowDetail(req, unicode(key[5:-2])) elif key.startswith("delete_"): # delete workflow deleteWorkflow(key[7:-2]) break elif key.startswith("detaillist_"): # show nodes for given workflow #req.params["detailof"] = key[11:-2] return WorkflowStepList(req, key[11:-2]) if "form_op" in req.params.keys(): if req.params.get("form_op", "") == "cancel": return view(req) if req.params.get("name", "") == "": return WorkflowDetail(req, req.params.get("id", ""), 1) # no name was given if req.params.get("form_op") == "save_new": # save workflow values addWorkflow(req.params.get("name", ""), req.params.get("description")) elif req.params.get("form_op") == "save_edit": # save workflow values updateWorkflow(req.params.get("name", ""), req.params.get("description"), req.params.get("name_attr"), req.params.get("orig_name")) wf = getWorkflow(req.params.get("name")) if wf: if "wf_language" in req.params: wf.set('languages', req.params.get('wf_language')) else: if wf.get('languages'): del wf.attrs['languages'] for r in wf.access_ruleset_assocs.filter_by( ruletype=u'read'): db.session.delete(r) for key in req.params.keys(): if key.startswith("left_read"): for r in req.params.get(key).split(';'): wf.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r, ruletype=key[9:])) break for r in wf.access_ruleset_assocs.filter_by( ruletype=u'write'): db.session.delete(r) for key in req.params.keys(): if key.startswith("left_write"): for r in req.params.get(key).split(';'): wf.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r, ruletype=key[10:])) break # check for right inheritance if "write_inherit" in req.params: inheritWorkflowRights(req.params.get("name", ""), "write") if "read_inherit" in req.params: inheritWorkflowRights(req.params.get("name", ""), "read") db.session.commit() else: # workflowstep section for key in req.params.keys(): if key.startswith("newdetail_"): # create new workflow return WorkflowStepDetail(req, req.params.get("parent"), "") elif key.startswith("editdetail_"): # edit workflowstep return WorkflowStepDetail(req, req.params.get("parent"), key[11:-2].split("|")[1]) elif key.startswith("deletedetail_"): # delete workflow step id: deletedetail_[workflowid]|[stepid] deleteWorkflowStep(key[13:-2].split("|")[0], key[13:-2].split("|")[1]) break if "form_op" in req.params.keys(): if req.params.get("form_op", "") == "cancel": return WorkflowStepList(req, req.params.get("parent")) if req.params.get("nname", "") == "": # no Name was given return WorkflowStepDetail(req, req.params.get("parent"), req.params.get("stepid", ""), 1) if req.params.get("form_op", "") == "save_newdetail": # save workflowstep values -> create # don't create a new workflowstep if a workflowstep with the same name already exists workflowstep = getWorkflow( req.params.get("parent")).getStep(req.params.get( "nname", ""), test_only=True) if workflowstep: raise ValueError( "a workflowstep with the same name already exists") wnode = createWorkflowStep( name=req.params.get("nname", ""), type=req.params.get("ntype", ""), trueid=req.params.get("ntrueid", ""), falseid=req.params.get("nfalseid", ""), truelabel=req.params.get("ntruelabel", ""), falselabel=req.params.get("nfalselabel", ""), comment=req.params.get("ncomment", ""), adminstep=req.params.get("adminstep", "")) getWorkflow(req.params.get("parent")).addStep(wnode) elif req.params.get("form_op") == "save_editdetail": # update workflowstep wf = getWorkflow(req.params.get("parent")) # don't update a workflowstep if the name is changed and a workflowstep with the same name already exists if req.params.get("orig_name", "") != req.params.get( "nname", ""): workflowstep = wf.getStep(req.params.get("nname", ""), test_only=True) if workflowstep: raise ValueError( "a workflowstep with the same name already exists" ) truelabel = '' falselabel = '' for language in wf.getLanguages(): truelabel += '%s:%s\n' % ( language, req.params.get( '%s.ntruelabel' % language)) falselabel += '%s:%s\n' % ( language, req.params.get('%s.nfalselabel' % language)) if truelabel == '': truelabel = req.params.get("ntruelabel", "") if falselabel == '': falselabel = req.params.get("nfalselabel", "") sidebartext = '' pretext = '' posttext = '' if len(wf.getLanguages()) > 1: for language in wf.getLanguages(): sidebartext += '%s:%s\n' % ( language, req.params.get('%s.nsidebartext' % language).replace('\n', '')) pretext += '%s:%s\n' % ( language, req.params.get('%s.npretext' % language).replace('\n', '')) posttext += '%s:%s\n' % ( language, req.params.get('%s.nposttext' % language).replace('\n', '')) if sidebartext == '': sidebartext = req.params.get("nsidebartext", "").replace('\n', '') if pretext == '': pretext = req.params.get("npretext", "").replace('\n', '') if posttext == '': posttext = req.params.get("nposttext", "").replace('\n', '') wnode = updateWorkflowStep( wf, oldname=req.params.get("orig_name", ""), newname=req.params.get("nname", ""), type=req.params.get("ntype", ""), trueid=req.params.get("ntrueid", ""), falseid=req.params.get("nfalseid", ""), truelabel=truelabel, falselabel=falselabel, sidebartext=sidebartext, pretext=pretext, posttext=posttext, comment=req.params.get("ncomment", ""), adminstep=req.params.get("adminstep", "")) try: wfs = getWorkflow(req.params.get("parent")).getStep( req.params.get("orig_name", "")) except: wfs = getWorkflow(req.params.get("parent")).getStep( req.params.get("nname", "")) if wfs: for r in wfs.access_ruleset_assocs.filter_by( ruletype=u'read'): db.session.delete(r) for key in req.params.keys(): if key.startswith("left_read"): for r in req.params.get(key).split(';'): wfs.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r, ruletype=key[9:])) break for r in wfs.access_ruleset_assocs.filter_by( ruletype=u'write'): db.session.delete(r) for key in req.params.keys(): if key.startswith("left_write"): for r in req.params.get(key).split(';'): wfs.access_ruleset_assocs.append( NodeToAccessRuleset(ruleset_name=r, ruletype=key[10:])) break db.session.commit() if "metaDataEditor" in req.params.keys(): parseEditorData(req, wnode) return WorkflowStepList(req, req.params.get("parent")) return view(req) except Exception as ex: logg.exception("exception in validate") return '<h3 style="color: red">%s</h3>' % ex.message