Current section

Files

Jump to
step_flow lib step_flow web_controllers workflow_status.ex
Raw

lib/step_flow/web_controllers/workflow_status.ex

defmodule StepFlow.WebController.WorkflowStatus do
use StepFlow, :controller
use OpenApiSpex.ControllerSpecs
require Logger
alias OpenApiSpex.Schema
alias StepFlow.WebController.Helpers
alias StepFlow.Workflows.Status
@moduledoc false
tags ["Workflows"]
security [%{"authorization" => %OpenApiSpex.SecurityScheme{type: "http", scheme: "bearer"}}]
action_fallback(StepFlow.WebController.Fallback)
operation :list,
summary: "List workflows statuses",
description: "List workflows statuses",
type: :array,
items: %Schema{type: :string},
responses: [
ok: "Statuses",
forbidden: "Forbidden"
]
def list(%Plug.Conn{assigns: %{current_user: user}} = conn, _params) do
status =
Status.StateEnum.__valid_values__()
|> Enum.filter(fn value -> is_bitstring(value) end)
if Helpers.has_right?("workflow", user, "view") do
conn
|> json(status)
else
conn
|> put_status(:forbidden)
|> json(%{reason: "Forbidden to view workflow status with this identifier"})
end
end
end