Ejemplo n.º 1
0
 def getCommandTemplate(self, command_name, dependencies=[], instance=None):
     if instance==None: instance = self.getInstanceTemplate()
     user = self.getUser()
     ct = CommandTemplate.findByName(SESSION, command_name, user)
     if ct==None:
         ct = CommandTemplate(instance, command_name, "echo hello", dependencies)
     return ct
Ejemplo n.º 2
0
def saveCommand(user, data, delete):
    workflow = WorkflowTemplate.findByID(SESSION, getID(data["workflowInCommandForm"]), user)
    if workflow == None:
        return {"updates": {}, "message": "user permissions error on workflow"}
    if delete:
        cid = getID(data["commandInCommandForm"])
        if cid != None:
            CommandTemplate.delete(SESSION, cid, user)
    else:
        instance = InstanceTemplate.findByID(SESSION, getID(data["instanceInCommandForm"]), user)
        if instance == None:
            return {"updates": {}, "message": "user permissions error on instance"}
        name = data["CommandName"]
        commandText = data["Command"]
        commandID = getID(data["commandInCommandForm"])
        dependencies = [
            CommandTemplate.findByID(SESSION, cid, user)
            for cid in list(set([getID(idname) for idname in data.getlist("commandDependenciesSelect")]))
        ]
        if None in dependencies:
            return {"updates": {}, "message": "user permissions error on command dependencies"}
        ## edit old command or make new command
        if commandID != None:
            command = CommandTemplate.findByID(SESSION, commandID, user)
            if command == None:
                return {"updates": {}, "message": "user permissions error on command"}
            command.updateValues(instance, name.lower(), commandText, dependencies)
        else:
            command = CommandTemplate(instance, name.lower(), commandText, dependencies)
            SESSION.add(command)
            SESSION.commit()

    result = {"updates": {"workflows": {str(workflow.id): workflow.dictForJSON()}}, "message": "updated command"}
    SESSION.add(workflow)
    SESSION.commit()
    return result