{
  "meta": {
    "$_GET": [
      {
        "type": "text",
        "name": "sort"
      },
      {
        "type": "text",
        "name": "dir"
      }
    ]
  },
  "exec": {
    "steps": [
      {
        "name": "identity",
        "module": "auth",
        "action": "identify",
        "options": {
          "provider": "auth"
        },
        "output": true,
        "meta": []
      },
      {
        "name": "user",
        "module": "dbconnector",
        "action": "single",
        "options": {
          "connection": "authdb",
          "sql": {
            "type": "select",
            "columns": [
              {
                "table": "users",
                "column": "id"
              },
              {
                "table": "users",
                "column": "email"
              },
              {
                "table": "users",
                "column": "regcode"
              },
              {
                "table": "users",
                "column": "validated"
              },
              {
                "table": "users",
                "column": "firstname"
              },
              {
                "table": "users",
                "column": "lastname"
              }
            ],
            "params": [
              {
                "operator": "equal",
                "type": "expression",
                "name": ":P1",
                "value": "{{identity}}",
                "test": ""
              }
            ],
            "table": {
              "name": "users"
            },
            "primary": "id",
            "joins": [],
            "query": "select `id`, `email`, `regcode`, `validated`, `firstname`, `lastname` from `users` where `users`.`id` = ?",
            "wheres": {
              "condition": "AND",
              "rules": [
                {
                  "id": "users.id",
                  "field": "users.id",
                  "type": "double",
                  "operator": "equal",
                  "value": "{{identity}}",
                  "data": {
                    "table": "users",
                    "column": "id",
                    "type": "number",
                    "columnObj": {
                      "type": "increments",
                      "primary": true,
                      "unique": false,
                      "nullable": false,
                      "name": "id"
                    }
                  },
                  "operation": "=",
                  "table": "users"
                }
              ],
              "conditional": null,
              "valid": true
            }
          }
        },
        "meta": [
          {
            "type": "number",
            "name": "id"
          },
          {
            "type": "text",
            "name": "email"
          },
          {
            "type": "text",
            "name": "regcode"
          },
          {
            "type": "boolean",
            "name": "validated"
          },
          {
            "type": "text",
            "name": "firstname"
          },
          {
            "type": "text",
            "name": "lastname"
          }
        ],
        "outputType": "object"
      },
      {
        "name": "roles",
        "module": "dbconnector",
        "action": "select",
        "options": {
          "connection": "authdb",
          "sql": {
            "type": "select",
            "columns": [
              {
                "table": "roles",
                "column": "id"
              },
              {
                "table": "roles",
                "column": "name"
              },
              {
                "table": "roles",
                "column": "isDepartment"
              }
            ],
            "params": [
              {
                "operator": "equal",
                "type": "expression",
                "name": ":P1",
                "value": "{{identity}}",
                "test": ""
              }
            ],
            "table": {
              "name": "roles"
            },
            "primary": "id",
            "joins": [
              {
                "table": "xuserrole",
                "column": "*",
                "type": "INNER",
                "clauses": {
                  "condition": "AND",
                  "rules": [
                    {
                      "table": "xuserrole",
                      "column": "roleid",
                      "operator": "equal",
                      "operation": "=",
                      "value": {
                        "table": "roles",
                        "column": "id"
                      }
                    }
                  ]
                },
                "primary": "id"
              }
            ],
            "wheres": {
              "condition": "AND",
              "rules": [
                {
                  "id": "xuserrole.userid",
                  "field": "xuserrole.userid",
                  "type": "double",
                  "operator": "equal",
                  "value": "{{identity}}",
                  "data": {
                    "table": "xuserrole",
                    "column": "userid",
                    "type": "number",
                    "columnObj": {
                      "type": "integer",
                      "primary": false,
                      "unique": false,
                      "nullable": true,
                      "name": "userid"
                    }
                  },
                  "operation": "="
                }
              ],
              "conditional": null,
              "valid": true
            },
            "query": "select `roles`.`id`, `roles`.`name`, `roles`.`isDepartment` from `roles` inner join `xuserrole` on `xuserrole`.`roleid` = `roles`.`id` where `xuserrole`.`userid` = ?"
          }
        },
        "meta": [
          {
            "type": "number",
            "name": "id"
          },
          {
            "type": "text",
            "name": "name"
          },
          {
            "type": "boolean",
            "name": "isDepartment"
          }
        ],
        "outputType": "array",
        "output": true
      },
      {
        "name": "xuserroles",
        "module": "dbconnector",
        "action": "select",
        "options": {
          "connection": "authdb",
          "sql": {
            "type": "select",
            "columns": [
              {
                "table": "xuserrole",
                "column": "userid"
              },
              {
                "table": "xuserrole",
                "column": "roleid"
              }
            ],
            "params": [
              {
                "operator": "equal",
                "type": "expression",
                "name": ":P1",
                "value": "{{identity}}",
                "test": ""
              }
            ],
            "table": {
              "name": "xuserrole"
            },
            "primary": "id",
            "joins": [],
            "wheres": {
              "condition": "AND",
              "rules": [
                {
                  "id": "xuserrole.userid",
                  "field": "xuserrole.userid",
                  "type": "double",
                  "operator": "equal",
                  "value": "{{identity}}",
                  "data": {
                    "table": "xuserrole",
                    "column": "userid",
                    "type": "number",
                    "columnObj": {
                      "type": "integer",
                      "primary": false,
                      "unique": false,
                      "nullable": true,
                      "name": "userid"
                    }
                  },
                  "operation": "="
                }
              ],
              "conditional": null,
              "valid": true
            },
            "query": "select `userid`, `roleid` from `xuserrole` where `xuserrole`.`userid` = ?"
          }
        },
        "output": true,
        "meta": [
          {
            "type": "number",
            "name": "userid"
          },
          {
            "type": "number",
            "name": "roleid"
          }
        ],
        "outputType": "array"
      },
      {
        "name": "validated",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_validated",
          "value": "{{user.validated==1}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "email",
            "type": "text"
          },
          {
            "name": "regcode",
            "type": "text"
          },
          {
            "name": "validated",
            "type": "boolean"
          },
          {
            "name": "firstname",
            "type": "text"
          },
          {
            "name": "lastname",
            "type": "text"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "associate",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_associate",
          "value": "{{roles.where('id', '==', 4).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "administrator",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_administrator",
          "value": "{{roles.where('id', '==', 1).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "manager",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_manager",
          "value": "{{roles.where('id', '==', 6).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "lead",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_lead",
          "value": "{{roles.where('id', '==', 7).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "administration_dept",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_administration_dept",
          "value": "{{roles.where('id', '==', 5).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "engineering_dept",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_engineering_dept",
          "value": "{{roles.where('id', '==', 3).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "operations_dept",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_operations_dept",
          "value": "{{roles.where('id', '==', 2).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "ops_excellence_dept",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_ops_excellence_dept",
          "value": "{{roles.where('id', '==', 8).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "business_development_dept",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_business_development_dept",
          "value": "{{roles.where('id', '==', 9).count()>0}}"
        },
        "meta": [
          {
            "name": "id",
            "type": "number"
          },
          {
            "name": "name",
            "type": "text"
          },
          {
            "name": "isDepartment",
            "type": "boolean"
          }
        ],
        "outputType": "text",
        "output": true
      },
      {
        "name": "",
        "module": "core",
        "action": "condition",
        "options": {
          "if": "{{!validated}}",
          "then": {
            "steps": {
              "name": "Forbidden",
              "module": "core",
              "action": "response",
              "options": {
                "status": 403,
                "data": "Unvalidated"
              }
            }
          }
        },
        "outputType": "boolean"
      },
      {
        "name": "",
        "module": "core",
        "action": "condition",
        "options": {
          "if": "{{!associate&&!administrator&&!manager&&!lead}}",
          "then": {
            "steps": {
              "name": "Unauthorized",
              "module": "core",
              "action": "response",
              "options": {
                "status": 401,
                "data": "Not the correct role"
              }
            }
          }
        },
        "outputType": "boolean"
      }
    ]
  }
}