aesmail / aesmail/kaffy

[FEATURE-REQUEST] Allow to {:ok, conn} on `action` in any `resource_actions` to support redirect somewhere else

Aberta
#267 2 comentários 3 reações 1 responsável Reivindicada por @aesmail Ver no GitHub
enhancement
Linguagem predominante
Elixir
Estrelas
1.4k
Forks
171
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

**Describe the problem you're proposing to solve**

So I have a action in `resource_actions` that requires redirect to some internal page after performing the action

```
def resource_actions(_conn) do
[
approve_move_to_next: %{
name: "Approve product and redirect somewhere",
action: fn conn, product ->
Product.approve(product)
redirect(conn, to: somewhere_internal_url)
end,
},
]
end
```

However `action` only accepts `{:ok, record} | {:error, changeset} | {:error, record, custom_error}` as a return value, and if you modify with the `conn` it will successfully redirect but raise an error something like

```
09:06:30.980 [error] Ranch listener SkyeWeb.Endpoint.HTTPS had connection process started with :cowboy_tls:start_link/4 at #PID<0.1179.0> exit with reason: {{:badmatch, :undefined}, [{:cow_http2_machine, :prepare_headers, 5, [file: '/Users/ryvasquez/Documents/apps/sample_app/deps/cowlib/src/cow_http2_machine.erl', line: 1119]}, {:cowboy_http2, :send_response, 5, [file: '/Users/ryvasquez/Documents/apps/sample_app/deps/cowboy/src/cowboy_http2.erl', line: 790]}, {:cowboy_http2, :commands, 3, [file: '/Users/ryvasquez/Documents/apps/sample_app/deps/cowboy/src/cowboy_http2.erl', line: 664]}, {:cowboy_http2, :loop, 2, [file: '/Users/ryvasquez/Documents/apps/sample_app/deps/cowboy/src/cowboy_http2.erl', line: 277]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}
```

**Describe the solution you'd like**

Maybe we can pattern match a `Plug.Conn` in this part
https://github.com/aesmail/kaffy/blob/c0b16cafe085638e198c7a4ad3e3afe0c31a2076/lib/kaffy_web/controllers/resource_controller.ex#L326-L337

and return as is since it was a conn.

Let me know if this is a valid solution, Im happy to work on it 👍

**Describe alternatives you've considered**

**Additional context**
Add any other context or screenshots about the feature request here.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.