Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/851
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Feb 16, 2024
1 parent 632b794 commit 28a76aa
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 87 deletions.
1 change: 0 additions & 1 deletion config/bonfire_data.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ verbs = [
"Tag"
]


#### Sentinel Data Services

# Search these apps/extensions for Pointable ecto schema definitions to index
Expand Down
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Config

import_config "config_basics.exs"
3 changes: 1 addition & 2 deletions config/config_basics.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ config :phoenix, :json_library, Jason

config :ecto_sparkles, :otp_app, :bonfire
config :ecto_sparkles, :env, config_env()
config :ecto_sparkles, :umbrella_otp_app, :bonfire_umbrella
# config :ecto_sparkles, :umbrella_otp_app, :bonfire_umbrella

# Choose password hashing backend
# Note that this corresponds with our dependencies in mix.exs
hasher = if config_env() in [:dev, :test], do: Pbkdf2, else: Argon2

config :bonfire_data_identity, Bonfire.Data.Identity.Credential, hasher_module: hasher


import_config "bonfire_data.exs"
70 changes: 70 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Config

import_config "config_basics.exs"

fake_secret =
"5KKj74dda6cEocScv+Q2zTu40/oEgQvvhcNSpTytN0AzV3o9eX7Lf9nDlcDYD2RRrOvia/Q3D0W/7u+CNoQZr+fO/93OVKUT31YBVEFuK+rAbbpoiuwXL+nFrrLTQj/H"

config :bonfire_common, :otp_app, :bonfire

config :bonfire,
otp_app: :bonfire,
env: config_env(),
signing_salt: fake_secret,
encryption_salt: fake_secret

config :bonfire, Bonfire.Web.Endpoint,
server: false,
http: [port: 4000],
adapter: Bandit.PhoenixAdapter,
secret_key_base: fake_secret,
live_view: [signing_salt: fake_secret],
render_errors: [
# view: Bonfire.UI.Common.ErrorView,
accepts: ~w(html json),
# layout: false,
layout: [html: {Bonfire.UI.Common.BasicView, :error}],
# root_layout: [html: {Bonfire.UI.Common.BasicView, :error}],
formats: [html: Bonfire.UI.Common.ErrorView, json: Bonfire.UI.Common.ErrorView]
]

# Choose password hashing backend
# Note that this corresponds with our dependencies in mix.exs
hasher = if config_env() in [:dev, :test], do: Pbkdf2, else: Argon2

config :bonfire_data_identity, Bonfire.Data.Identity.Credential, hasher_module: hasher

#### Basic configuration

# You probably won't want to touch these. You might override some in
# other config files.

config :needle, :search_path, []

config :bonfire, :endpoint_module, Bonfire.Web.Endpoint
config :phoenix_test, :endpoint, Bonfire.Web.Endpoint

# config :bonfire, :repo_module, Bonfire.Common.Repo

config :ecto_sparkles, :otp_app, :bonfire
config :ecto_sparkles, :env, config_env()

config :phoenix, :json_library, Jason

config :live_admin, :modularity, :disabled
config :orion, :modularity, :disabled

config :logger,
handle_otp_reports: true,
handle_sasl_reports: true

config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]

config :mime, :types, %{
"application/activity+json" => ["activity+json"]
}

config :hammer,
backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]}
27 changes: 17 additions & 10 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,28 @@ defmodule Bonfire.Application do
]
]}
}
] ++ Bonfire.Common.Utils.maybe_apply(Bonfire.Social.Graph, :maybe_applications, [], fallback_return: [])
] ++
Bonfire.Common.Utils.maybe_apply(Bonfire.Social.Graph, :maybe_applications, [],
fallback_return: []
)

# Stuff that depends on the Endpoint and/or the above
def apps_after,
do: [
{Tz.UpdatePeriodically, [interval_in_days: 10]}
] ++ maybe_oban()
do:
[
{Tz.UpdatePeriodically, [interval_in_days: 10]}
] ++ maybe_oban()

def maybe_oban do
case Application.get_env(:bonfire, Oban, []) do
[] -> []
config -> [
# Job Queue
{Oban, config}
]
case Application.get_env(:bonfire, Oban, []) do
[] ->
[]

config ->
[
# Job Queue
{Oban, config}
]
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/localise.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ defmodule Bonfire.Localise do

use Bonfire.Common.Localise

Bonfire.Common.Utils.maybe_apply(Bonfire.Social.Activities, :all_verb_names_extra, [], fallback_return: [])
Bonfire.Common.Utils.maybe_apply(Bonfire.Social.Activities, :all_verb_names_extra, [],
fallback_return: []
)
|> IO.inspect(label: "Making all verb names localisable")
|> localise_strings(Bonfire.Social.Activities)

Expand Down
13 changes: 7 additions & 6 deletions lib/logging.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ defmodule Bonfire.Logging do
# Only trace Oban jobs to minimize noise
if Extend.module_enabled?(OpentelemetryOban), do: OpentelemetryOban.setup(trace: [:jobs])

if repo_module && Extend.module_enabled?(OpentelemetryEcto), do: repo_module.config()
|> Keyword.fetch!(:telemetry_prefix)
|> OpentelemetryEcto.setup()

if repo_module && Extend.module_enabled?(OpentelemetryEcto),
do:
repo_module.config()
|> Keyword.fetch!(:telemetry_prefix)
|> OpentelemetryEcto.setup()
else
IO.puts("NOTE: OTLP (open telemetry) data will NOT be collected")
end
Expand All @@ -63,8 +64,8 @@ defmodule Bonfire.Logging do

defp setup_wobserver do
# if Extend.module_enabled?(Wobserver) do
# Wobserver.register(:page, {"Task Bunny", :taskbunny, &Status.page/0})
# Wobserver.register(:metric, [&Status.metrics/0])
# Wobserver.register(:page, {"Task Bunny", :taskbunny, &Status.page/0})
# Wobserver.register(:metric, [&Status.metrics/0])
# end
end

Expand Down
124 changes: 62 additions & 62 deletions lib/web/routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Bonfire.Web.Routes do
require LiveAdmin.Router

pipeline :load_current_auth do
if module_enabled?(Bonfire.UI.Me.Plugs.LoadCurrentUser) do
if module_enabled?(Bonfire.UI.Me.Plugs.LoadCurrentUser) do
# plug(Bonfire.UI.Me.Plugs.LoadCurrentAccount)
# ^ no need to call LoadCurrentAccount if also calling LoadCurrentUser
plug(Bonfire.UI.Me.Plugs.LoadCurrentUser)
Expand Down Expand Up @@ -136,7 +136,7 @@ defmodule Bonfire.Web.Routes do
pipe_through(:account_required)
end

if extension_enabled?(:bonfire_ui_me) do
if extension_enabled?(:bonfire_ui_me) do
# pages you need to view as a user
scope "/" do
pipe_through(:browser)
Expand All @@ -152,71 +152,71 @@ defmodule Bonfire.Web.Routes do
pipe_through(:admin_required)
end

scope "/" do
pipe_through(:browser_unsafe)

# if module_enabled?(Surface.Catalogue.Router) do # FIXME - getting function surface_catalogue/1 is undefined or private
# Surface.Catalogue.Router.surface_catalogue "/ui/"
# end

if Config.env() != :test do
pipe_through(:admin_required)

forward "/admin/system/wobserver", Wobserver.Web.Router

pipe_through(:browser)

if module_enabled?(OrionWeb.Router) do
OrionWeb.Router.live_orion("/admin/system/orion",
on_mount: [
Bonfire.UI.Me.LivePlugs.LoadCurrentUser,
Bonfire.UI.Me.LivePlugs.AdminRequired
]
)
scope "/" do
pipe_through(:browser_unsafe)

# if module_enabled?(Surface.Catalogue.Router) do # FIXME - getting function surface_catalogue/1 is undefined or private
# Surface.Catalogue.Router.surface_catalogue "/ui/"
# end

if Config.env() != :test do
pipe_through(:admin_required)

forward "/admin/system/wobserver", Wobserver.Web.Router

pipe_through(:browser)

if module_enabled?(OrionWeb.Router) do
OrionWeb.Router.live_orion("/admin/system/orion",
on_mount: [
Bonfire.UI.Me.LivePlugs.LoadCurrentUser,
Bonfire.UI.Me.LivePlugs.AdminRequired
]
)
end

if module_enabled?(LiveAdmin.Router) do
LiveAdmin.Router.live_admin("/admin/system/data",
resources: Needle.Tables.schema_modules(),
ecto_repo: Bonfire.Common.Repo,
title: "Bonfire Data Admin",
immutable_fields: [:id, :inserted_at, :updated_at],
label_with: :name
)
end
end

if module_enabled?(LiveAdmin.Router) do
LiveAdmin.Router.live_admin("/admin/system/data",
resources: Needle.Tables.schema_modules(),
ecto_repo: Bonfire.Common.Repo,
title: "Bonfire Data Admin",
immutable_fields: [:id, :inserted_at, :updated_at],
label_with: :name
# do
# for schema <- Needle.Tables.schema_modules() do
# LiveAdmin.Router.admin_resource "/#{schema}", schema
# end
# end

# {Bonfire.UI.Common.LivePlugs, Bonfire.UI.Me.LivePlugs.UserRequired}

if module_enabled?(Phoenix.LiveDashboard.Router) do
import Phoenix.LiveDashboard.Router

live_dashboard("/admin/system",
ecto_repos: [Bonfire.Common.Repo],
ecto_psql_extras_options: [
long_running_queries: [threshold: "400 milliseconds"]
],
metrics: Bonfire.Web.Telemetry,
metrics_history:
if(Config.env() == :dev, do: {Bonfire.Telemetry.Storage, :metrics_history, []}),
# metrics: FlamegraphsWeb.Telemetry,
additional_pages: [
oban_queues: Bonfire.Web.ObanDashboard,
oban: Oban.LiveDashboard,
orion: Bonfire.Web.OrionLink,
data: Bonfire.Web.DataLink
# flame_on: FlameOn.DashboardPage
# _profiler: {PhoenixProfiler.Dashboard, []}
]
)
end
end

# do
# for schema <- Needle.Tables.schema_modules() do
# LiveAdmin.Router.admin_resource "/#{schema}", schema
# end
# end

# {Bonfire.UI.Common.LivePlugs, Bonfire.UI.Me.LivePlugs.UserRequired}

if module_enabled?(Phoenix.LiveDashboard.Router) do
import Phoenix.LiveDashboard.Router

live_dashboard("/admin/system",
ecto_repos: [Bonfire.Common.Repo],
ecto_psql_extras_options: [
long_running_queries: [threshold: "400 milliseconds"]
],
metrics: Bonfire.Web.Telemetry,
metrics_history:
if(Config.env() == :dev, do: {Bonfire.Telemetry.Storage, :metrics_history, []}),
# metrics: FlamegraphsWeb.Telemetry,
additional_pages: [
oban_queues: Bonfire.Web.ObanDashboard,
oban: Oban.LiveDashboard,
orion: Bonfire.Web.OrionLink,
data: Bonfire.Web.DataLink
# flame_on: FlameOn.DashboardPage
# _profiler: {PhoenixProfiler.Dashboard, []}
]
)
end
end
end

if Config.env() in [:dev, :test] do
Expand Down
2 changes: 1 addition & 1 deletion lib/web/views/about_live.sface
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<article class="prose max-w-max mt-3 prose-xl">{templated_or_remote_markdown(Config.get([:ui, :theme, :instance_welcome, :description], ""))}</article>
</div>
<div class="col-span-2">
<StatelessComponent module={maybe_component(Bonfire.UI.Me.SettingsViewsLive.InstanceSummaryLive , @__context__)} />
<StatelessComponent module={maybe_component(Bonfire.UI.Me.SettingsViewsLive.InstanceSummaryLive, @__context__)} />
</div>
</section>
9 changes: 5 additions & 4 deletions lib/web/views/changelog_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ defmodule Bonfire.Web.ChangelogLive do
l("Contribute") => "https://bonfirenetworks.org/contribute/"
})

changelog = case @changelog do
{:ok, changelog} -> changelog
_ -> nil
end
changelog =
case @changelog do
{:ok, changelog} -> changelog
_ -> nil
end

{:ok,
socket
Expand Down

0 comments on commit 28a76aa

Please sign in to comment.