-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): set runner image to fixed ubuntu version
See actions/runner-images#10636 Better be specific from now on
- Loading branch information
1 parent
60eafeb
commit 358cb11
Showing
13 changed files
with
239 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
defmodule Lotta.Administration.Cockpit do | ||
@moduledoc """ | ||
Interact with Cockpit for the administration of Lotta. | ||
""" | ||
use Tesla | ||
|
||
alias Lotta.Accounts.User | ||
alias LottaWeb.Urls | ||
alias Lotta.Tenants.Feedback | ||
alias Lotta.{Tenants, Repo} | ||
|
||
require Logger | ||
|
||
@doc """ | ||
Forward a feedback | ||
""" | ||
@spec send_feedback(Feedback.t()) :: :ok | {:error, any()} | ||
def send_feedback(feedback) do | ||
feedback = Repo.preload(feedback, :user) | ||
|
||
tenant = | ||
feedback | ||
|> Ecto.get_meta(:prefix) | ||
|> Tenants.get_tenant_by_prefix() | ||
|
||
create_client() | ||
|> post("/api/feedback", %{ | ||
feedback: %{ | ||
tenant_id: tenant.id, | ||
name: feedback.user.name, | ||
email: feedback.user.email, | ||
title: "FWD: #{feedback.topic}", | ||
message: """ | ||
Ein Admin hat eben Feedback für #{tenant.title} erstellt. | ||
Nutzername: #{feedback.user.name} | ||
Email: #{feedback.user.email} | ||
Kunde: #{tenant.title} (#{Urls.get_tenant_url(tenant)}) | ||
#{feedback.topic} | ||
--- | ||
#{feedback.content} | ||
""" | ||
} | ||
}) | ||
|> case do | ||
{_, %{status: status}} when status >= 200 and status < 300 -> | ||
:ok | ||
|
||
{:ok, %{status: status, body: body}} -> | ||
Logger.error("Failed to send message: #{inspect({status, body})}") | ||
{:error, status} | ||
|
||
{:error, reason} -> | ||
Logger.error("Failed to send feedback: #{inspect(reason)}") | ||
{:error, reason} | ||
end | ||
end | ||
|
||
@doc """ | ||
Send a message to Lotta | ||
""" | ||
@spec send_message(User.t(), topic :: String.t(), message :: String.t()) :: | ||
:ok | {:error, any()} | ||
def send_message(user, topic, message) do | ||
tenant = Tenants.get_tenant_by_prefix(Ecto.get_meta(user, :prefix)) | ||
|
||
create_client() | ||
|> post("/api/feedback", %{ | ||
feedback: %{ | ||
tenant_id: tenant.id, | ||
name: user.name, | ||
email: user.email, | ||
title: topic, | ||
message: message | ||
} | ||
}) | ||
|> case do | ||
{_, %{status: status}} when status >= 200 and status < 300 -> | ||
:ok | ||
|
||
{:ok, %{status: status, body: body}} -> | ||
Logger.error("Failed to send message: #{inspect({status, body})}") | ||
{:error, status} | ||
|
||
{:error, reason} -> | ||
Logger.error("Failed to send message: #{inspect(reason)}") | ||
{:error, reason} | ||
end | ||
end | ||
|
||
defp create_client() do | ||
middleware = [ | ||
Tesla.Middleware.OpenTelemetry, | ||
{Tesla.Middleware.BaseUrl, config(:endpoint)}, | ||
Tesla.Middleware.PathParams, | ||
Tesla.Middleware.JSON, | ||
{Tesla.Middleware.BasicAuth, username: config(:username), password: config(:password)} | ||
] | ||
|
||
Tesla.client(middleware) | ||
end | ||
|
||
defp config(key), do: Keyword.get(config(), key) | ||
|
||
defp config() do | ||
Application.fetch_env!(:lotta, :cockpit) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.