Exemplo n.º 1
0
def WorkflowStepDetail(req, wid, wnid, err=0):
    workflow = getWorkflow(wid)
    nodelist = workflow.getSteps()
    v = getAdminStdVars(req)

    if err == 0 and wnid == "":
        # new workflowstep
        workflowstep = createWorkflowStep(name="",
                                          trueid="",
                                          falseid="",
                                          truelabel="",
                                          falselabel="",
                                          comment="")
        v["orig_name"] = req.params.get("orig_name", "")

    elif err == -1:
        # update steptype
        if req.params.get("stepid", ""):
            workflowstep = updateWorkflowStep(
                workflow,
                oldname=req.params.get("nname", ""),
                newname=req.params.get("nname", ""),
                type=req.params.get("ntype", "workflowstep"),
                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", ""))
        else:
            err = 0
            workflowstep = createWorkflowStep(
                name=req.params.get("nname", ""),
                type=req.params.get("ntype", "workflowstep"),
                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", ""))
        v["orig_name"] = workflowstep.name

    elif wnid != "" and req.params.get("nname") != "":
        # edit field
        workflowstep = workflow.getStep(wnid)
        v["orig_name"] = workflowstep.name
    else:
        # error while filling values
        type = req.params.get("ntype", "workflowstep")
        if type == "":
            type = "workflowstep"
        workflowstep = createWorkflowStep(
            name=req.params.get("nname", ""),
            type=type,
            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", ""))
        v["orig_name"] = req.params.get("orig_name", "")

    if req.params.get("nytype", "") != "":
        workflowstep.setType(req.params.get("nytype", ""))

    v_part = {}
    v_part["fields"] = workflowstep.metaFields(lang(req)) or []
    v_part["node"] = workflowstep
    v_part["hiddenvalues"] = {"wnodeid": workflowstep.name}

    try:
        rule = {
            "read": [
                r.ruleset_name
                for r in workflowstep.access_ruleset_assocs.filter_by(
                    ruletype='read')
            ],
            "write": [
                r.ruleset_name
                for r in workflowstep.access_ruleset_assocs.filter_by(
                    ruletype='write')
            ]
        }
    except:
        rule = {"read": [], "write": []}

    v["acl_read"] = makeList(req,
                             "read",
                             removeEmptyStrings(rule["read"]), {},
                             overload=0,
                             type="read")
    v["acl_write"] = makeList(req,
                              "write",
                              removeEmptyStrings(rule["write"]), {},
                              overload=0,
                              type="write")
    v["editor"] = req.getTAL("web/admin/modules/workflows.html",
                             v_part,
                             macro="view_editor")
    v["workflow"] = workflow
    v["workflowstep"] = workflowstep
    v["nodelist"] = nodelist
    v["workflowtypes"] = getWorkflowTypes()
    v["error"] = err
    v["update_type"] = req.params.get("ntype", u"")
    v["actpage"] = req.params.get("actpage")
    return req.getTAL("web/admin/modules/workflows.html",
                      v,
                      macro="modify_step")
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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, str(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("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:
                        wf.removeAttribute('languages')
                    wf.setAccess("read", "")
                    for key in req.params.keys():
                        if key.startswith("left_read"):
                            wf.setAccess(key[9:],
                                         req.params.get(key).replace(";", ","))
                            break
                    wf.setAccess("write", "")
                    for key in req.params.keys():
                        if key.startswith("left_write"):
                            wf.setAccess(key[10:],
                                         req.params.get(key).replace(";", ","))
                            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")

        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
                    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"))
                    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:
                    wfs.setAccess("read", "")
                    for key in req.params.keys():
                        if key.startswith("left_read"):
                            wfs.setAccess(
                                key[9:],
                                req.params.get(key).replace(";", ","))
                            break
                    wfs.setAccess("write", "")
                    for key in req.params.keys():
                        if key.startswith("left_write"):
                            wfs.setAccess(
                                key[10:],
                                req.params.get(key).replace(";", ","))
                            break

                if "metaDataEditor" in req.params.keys():
                    parseEditorData(req, wnode)

            return WorkflowStepList(req, req.params.get("parent"))

        return view(req)
    except:
        print sys.exc_info()[0], sys.exc_info()[1]
        traceback.print_tb(sys.exc_info()[2])
Exemplo n.º 4
0
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, str(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("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:
                        wf.removeAttribute('languages')
                    wf.setAccess("read", "")
                    for key in req.params.keys():
                        if key.startswith("left_read"):
                            wf.setAccess(key[9:], req.params.get(key).replace(";", ","))
                            break
                    wf.setAccess("write", "")
                    for key in req.params.keys():
                        if key.startswith("left_write"):
                            wf.setAccess(key[10:], req.params.get(key).replace(";", ","))
                            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")

        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
                    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"))
                    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:
                    wfs.setAccess("read", "")
                    for key in req.params.keys():
                        if key.startswith("left_read"):
                            wfs.setAccess(key[9:], req.params.get(key).replace(";", ","))
                            break
                    wfs.setAccess("write", "")
                    for key in req.params.keys():
                        if key.startswith("left_write"):
                            wfs.setAccess(key[10:], req.params.get(key).replace(";", ","))
                            break

                if "metaDataEditor" in req.params.keys():
                    parseEditorData(req, wnode)

            return WorkflowStepList(req, req.params.get("parent"))

        return view(req)
    except:
        print sys.exc_info()[0], sys.exc_info()[1]
        traceback.print_tb(sys.exc_info()[2])
Exemplo n.º 5
0
def WorkflowStepDetail(req, wid, wnid, err=0):

    workflow = getWorkflow(wid)
    nodelist = workflow.getSteps()
    v = getAdminStdVars(req)

    if err == 0 and wnid == "":
        # new workflowstep
        workflowstep = createWorkflowStep(name="", trueid="", falseid="", truelabel="", falselabel="", comment="")
        workflowstep.id = ""
        v["orig_name"] = req.params.get("orig_name", "")

    elif err == -1:
        # update steptype
        if req.params.get("stepid", ""):
            workflowstep = updateWorkflowStep(
                workflow, oldname=req.params.get(
                    "nname", ""), newname=req.params.get(
                    "nname", ""), type=req.params.get(
                    "ntype", "workflowstep"), 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", ""))
        else:
            err = 0
            workflowstep = createWorkflowStep(
                name=req.params.get(
                    "nname", ""), type=req.params.get(
                    "ntype", "workflowstep"), 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", ""))
            if req.params.get("wnid", "") == "":
                workflowstep.id = ""
        v["orig_name"] = workflowstep.getName()

    elif wnid != "" and req.params.get("nname") != "":
        # edit field
        workflowstep = workflow.getStep(wnid)
        v["orig_name"] = workflowstep.getName()
    else:
        # error while filling values
        type = req.params.get("ntype", "workflowstep")
        if type == "":
            type = "workflowstep"
        workflowstep = createWorkflowStep(
            name=req.params.get(
                "nname", ""), type=type, 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", ""))
        v["orig_name"] = req.params.get("orig_name", "")

    if req.params.get("nytype", "") != "":
        workflowstep.setType(req.params.get("nytype", ""))

    v_part = {}
    v_part["fields"] = workflowstep.metaFields(lang(req)) or []
    v_part["node"] = workflowstep
    v_part["hiddenvalues"] = {"wnodeid": workflowstep.name}

    rule = {"read": str(workflowstep.getAccess("read") or "").split(","), "write": str(workflowstep.getAccess("write") or "").split(",")}
    v["acl_read"] = makeList(req, "read", removeEmptyStrings(rule["read"]), {}, overload=0, type="read")
    v["acl_write"] = makeList(req, "write", removeEmptyStrings(rule["write"]), {}, overload=0, type="write")
    v["editor"] = req.getTAL("web/admin/modules/workflows.html", v_part, macro="view_editor")
    v["workflow"] = workflow
    v["workflowstep"] = workflowstep
    v["nodelist"] = nodelist
    v["workflowtypes"] = getWorkflowTypes()
    v["error"] = err
    v["update_type"] = req.params.get("ntype", "")
    v["actpage"] = req.params.get("actpage")
    return req.getTAL("web/admin/modules/workflows.html", v, macro="modify_step")
Exemplo n.º 6
0
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