Compare commits

..

5 Commits

Author SHA1 Message Date
CI
df66aa79b8 chore: release version v1.0.22 2024-09-25 08:24:50 +00:00
Dmitry Popov
6ea6a59ce3 fix(Map): Main map doesn't load back after refreshing/switching pages
fixes #8
2024-09-25 12:24:14 +04:00
CI
f3afa4d9d2 chore: release version v1.0.21 2024-09-24 20:21:54 +00:00
Dmitry Popov
e33d81eda1 Merge branch 'main' of github.com:wanderer-industries/wanderer 2024-09-25 00:21:17 +04:00
Dmitry Popov
0fc4863dc4 fix(Map): Main map doesn't load back after refreshing/switching pages
fixes #8
2024-09-25 00:21:14 +04:00
8 changed files with 227 additions and 167 deletions

View File

@@ -2,6 +2,24 @@
<!-- changelog -->
## [v1.0.22](https://github.com/wanderer-industries/wanderer/compare/v1.0.21...v1.0.22) (2024-09-25)
### Bug Fixes:
* Map: Main map doesn't load back after refreshing/switching pages
## [v1.0.21](https://github.com/wanderer-industries/wanderer/compare/v1.0.20...v1.0.21) (2024-09-24)
### Bug Fixes:
* Map: Main map doesn't load back after refreshing/switching pages
## [v1.0.20](https://github.com/wanderer-industries/wanderer/compare/v1.0.19...v1.0.20) (2024-09-23)

View File

@@ -78,6 +78,8 @@ config :wanderer_app,
git_sha: System.get_env("GIT_SHA", "111"),
custom_route_base_url: System.get_env("CUSTOM_ROUTE_BASE_URL"),
invites: System.get_env("WANDERER_INVITES", "false") == "true",
admin_username: System.get_env("WANDERER_ADMIN_USERNAME", "admin"),
admin_password: System.get_env("WANDERER_ADMIN_PASSWORD"),
admins: admins,
corp_id: System.get_env("WANDERER_CORP_ID", "-1") |> String.to_integer(),
corp_wallet: System.get_env("WANDERER_CORP_WALLET", ""),

View File

@@ -11,6 +11,8 @@ defmodule WandererApp.Env do
def map_subscriptions_enabled?, do: get_key(:map_subscriptions_enabled, false)
def wallet_tracking_enabled?, do: get_key(:wallet_tracking_enabled, false)
def admins, do: get_key(:admins, [])
def admin_username, do: get_key(:admin_username)
def admin_password, do: get_key(:admin_password)
def corp_wallet, do: get_key(:corp_wallet, "")
def corp_eve_id, do: get_key(:corp_id, -1)
def subscription_settings, do: get_key(:subscription_settings)

View File

@@ -0,0 +1,13 @@
defmodule WandererAppWeb.BasicAuth do
@moduledoc false
def admin_basic_auth(conn, _opts) do
admin_password = WandererApp.Env.admin_password()
if is_nil(admin_password) do
conn
else
conn
|> Plug.BasicAuth.basic_auth(username: WandererApp.Env.admin_username(), password: admin_password)
end
end
end

View File

@@ -42,8 +42,10 @@ defmodule WandererAppWeb.CharactersTrackingLive do
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: selected_map.id}) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
{:ok, settings} ->
{:ok, settings}
_ ->
{:ok, []}
end
user_id = socket.assigns.user_id

View File

@@ -8,7 +8,7 @@ defmodule WandererAppWeb.MapLive do
socket =
with %{"slug" => map_slug} <- params do
socket
|> _init_state(map_slug, false)
|> _init_state(map_slug)
else
_ ->
# redirect back to main
@@ -29,7 +29,7 @@ defmodule WandererAppWeb.MapLive do
{:ok, socket |> assign(server_online: false)}
end
defp _init_state(socket, map_slug, is_reconnect?) do
defp _init_state(socket, map_slug) do
current_user = socket.assigns.current_user
ErrorTracker.set_context(%{user_id: current_user.id})
@@ -44,7 +44,8 @@ defmodule WandererAppWeb.MapLive do
id: map_id,
deleted: false
} = map} ->
Task.async(fn -> _load_initial_data(map, is_reconnect?, current_user) end)
Process.send_after(self(), {:init_map, map}, 100)
socket
|> assign(
@@ -344,6 +345,155 @@ defmodule WandererAppWeb.MapLive do
{:noreply, socket}
end
def handle_info({:init_map, map}, %{assigns: %{current_user: current_user}} = socket) do
with %{
id: map_id,
deleted: false,
only_tracked_characters: only_tracked_characters,
user_permissions: user_permissions,
name: map_name,
owner_id: owner_id
} <- map do
user_permissions =
WandererApp.Permissions.get_map_permissions(
user_permissions,
owner_id,
current_user.characters |> Enum.map(& &1.id)
)
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
{:ok, %{characters: availaible_map_characters}} =
WandererApp.Maps.load_characters(map, character_settings, current_user.id)
can_view? = user_permissions.view_system
can_track? = user_permissions.track_character
tracked_character_ids =
availaible_map_characters |> Enum.filter(& &1.tracked) |> Enum.map(& &1.id)
all_character_tracked? = (not (availaible_map_characters |> Enum.empty?())) and availaible_map_characters |> Enum.all?(& &1.tracked)
cond do
(only_tracked_characters and can_track? and all_character_tracked?) or
(not only_tracked_characters and can_view?) ->
Process.send_after(self(), {:map_init, %{
map_id: map_id,
page_title: map_name,
user_permissions: user_permissions,
tracked_character_ids: tracked_character_ids
}}, 100)
only_tracked_characters and can_track? and not all_character_tracked? ->
Process.send_after(self(), :not_all_characters_tracked, 100)
true ->
Process.send_after(self(), :no_permissions, 100)
end
else
_ ->
Process.send_after(self(), :no_access, 100)
end
{:noreply, socket}
end
def handle_info({:map_init, %{map_id: map_id} = initial_data}, socket) do
Phoenix.PubSub.subscribe(WandererApp.PubSub, map_id)
WandererApp.Map.Manager.start_map(map_id)
{:ok, map_started} = WandererApp.Cache.lookup("map_#{map_id}:started", false)
if map_started do
Process.send_after(self(), %{event: :map_started}, 100)
end
{:noreply,
socket
|> assign(initial_data)}
end
def handle_info({:map_start,
%{
map_id: map_id,
user_characters: user_character_eve_ids,
initial_data: initial_data,
events: events
} = _started_data}, socket) do
socket =
events
|> Enum.reduce(socket, fn event, socket ->
case event do
{:track_characters, map_characters, track_character} ->
:ok = _track_characters(map_characters, map_id, track_character)
:ok = _add_characters(map_characters, map_id)
socket
:invalid_token_message ->
socket
|> put_flash(
:error,
"One of your characters has expired token. Please refresh it on characters page."
)
:empty_tracked_characters ->
socket
|> put_flash(
:info,
"You should enable tracking for at least one character to work with map."
)
:map_character_limit ->
socket
|> put_flash(
:error,
"Map reached its character limit, your characters won't be tracked. Please contact administrator."
)
_ ->
socket
end
end)
{:noreply,
socket
|> assign(
map_loaded?: true,
user_characters: user_character_eve_ids,
has_tracked_characters?: _has_tracked_characters?(user_character_eve_ids)
)
|> _push_map_event("init", initial_data)
|> push_event("js-exec", %{
to: "#map-loader",
attr: "data-loaded"
})}
end
def handle_info(:no_access, socket), do:
{:noreply,
socket
|> put_flash(:error, "You don't have an access to this map.")
|> push_navigate(to: ~p"/maps")}
def handle_info(:no_permissions, socket), do:
{:noreply,
socket
|> put_flash(:error, "You don't have permissions to use this map.")
|> push_navigate(to: ~p"/maps")}
def handle_info(:not_all_characters_tracked, socket), do:
{:noreply,
socket
|> put_flash(
:error,
"You should enable tracking for all characters that have access to this map first!"
)
|> push_navigate(to: ~p"/tracking/#{socket.assigns.map_slug}")}
@impl true
def handle_info(
{ref, result},
@@ -360,74 +510,13 @@ defmodule WandererAppWeb.MapLive do
maps: maps
)}
{:map_init_data, %{map_id: map_id} = initial_data} ->
Phoenix.PubSub.subscribe(WandererApp.PubSub, map_id)
WandererApp.Map.Manager.start_map(map_id)
{:map_started_data, started_data} ->
Process.send_after(self(), {:map_start, started_data}, 100)
{:noreply, socket}
{:ok, map_started} = WandererApp.Cache.lookup("map_#{map_id}:started", false)
if map_started do
Process.send_after(self(), %{event: :map_started}, 100)
end
{:noreply,
socket
|> assign(initial_data)}
{:map_started,
%{
map_id: map_id,
user_characters: user_character_eve_ids,
initial_data: initial_data,
events: events
} = _started_data} ->
socket =
events
|> Enum.reduce(socket, fn event, socket ->
case event do
{:track_characters, map_characters, track_character} ->
:ok = _track_characters(map_characters, map_id, track_character)
:ok = _add_characters(map_characters, map_id)
socket
:invalid_token_message ->
socket
|> put_flash(
:error,
"One of your characters has expired token. Please refresh it on characters page."
)
:empty_tracked_characters ->
socket
|> put_flash(
:info,
"You should enable tracking for at least one character to work with map."
)
:map_character_limit ->
socket
|> put_flash(
:error,
"Map reached its character limit, your characters won't be tracked. Please contact administrator."
)
_ ->
socket
end
end)
{:noreply,
socket
|> assign(
map_loaded?: true,
user_characters: user_character_eve_ids,
has_tracked_characters?: _has_tracked_characters?(user_character_eve_ids)
)
|> _push_map_event("init", initial_data)
|> push_event("js-exec", %{
to: "#map-loader",
attr: "data-loaded"
})}
{:map_error, map_error} ->
Process.send_after(self(), map_error, 100)
{:noreply, socket}
{:character_activity, character_activity} ->
{:noreply,
@@ -447,32 +536,13 @@ defmodule WandererAppWeb.MapLive do
}
)}
{:map_error, :not_all_characters_tracked} ->
{:noreply,
socket
|> put_flash(
:error,
"You should enable tracking for all characters that have access to this map first!"
)
|> push_navigate(to: ~p"/tracking/#{socket.assigns.map_slug}")}
{:map_error, :no_permissions} ->
{:noreply,
socket
|> put_flash(:error, "You don't have permissions to use this map.")
|> push_navigate(to: ~p"/maps")}
{:map_error, :no_access} ->
{:noreply,
socket
|> put_flash(:error, "You don't have an access to this map.")
|> push_navigate(to: ~p"/maps")}
_ ->
{:noreply, socket}
end
end
@impl true
def handle_info(_event, socket), do: {:noreply, socket}
@@ -1392,63 +1462,6 @@ defmodule WandererAppWeb.MapLive do
{:noreply, socket}
end
defp _load_initial_data(map, is_reconnect?, current_user) do
with %{
id: map_id,
deleted: false,
only_tracked_characters: only_tracked_characters,
user_permissions: user_permissions,
name: map_name,
owner_id: owner_id
} <- map do
user_permissions =
WandererApp.Permissions.get_map_permissions(
user_permissions,
owner_id,
current_user.characters |> Enum.map(& &1.id)
)
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
{:ok, %{characters: availaible_map_characters}} =
WandererApp.Maps.load_characters(map, character_settings, current_user.id)
can_view? = user_permissions.view_system
can_track? = user_permissions.track_character
tracked_character_ids =
availaible_map_characters |> Enum.filter(& &1.tracked) |> Enum.map(& &1.id)
all_character_tracked? = availaible_map_characters |> Enum.all?(& &1.tracked)
cond do
(only_tracked_characters and can_track? and all_character_tracked?) or
(not only_tracked_characters and can_view?) ->
{:map_init_data,
%{
map_id: map_id,
page_title: map_name,
user_permissions: user_permissions,
tracked_character_ids: tracked_character_ids,
is_reconnect?: is_reconnect?
}}
only_tracked_characters and can_track? and not all_character_tracked? ->
{:map_error, :not_all_characters_tracked}
true ->
{:map_error, :no_permissions}
end
else
_ ->
{:map_error, :no_access}
end
end
defp _on_map_started(map_id, current_user, user_permissions) do
case user_permissions do
%{view_system: true, track_character: track_character} ->
@@ -1535,7 +1548,7 @@ defmodule WandererAppWeb.MapLive do
)
|> Map.put(:reset, true)
{:map_started,
{:map_started_data,
%{
map_id: map_id,
user_characters: user_character_eve_ids,

View File

@@ -9,6 +9,10 @@ defmodule WandererAppWeb.Router do
warn: false,
only: [redirect_if_user_is_authenticated: 2]
import WandererAppWeb.BasicAuth,
warn: false,
only: [admin_basic_auth: 2]
@code_reloading Application.compile_env(
:wanderer_app,
[WandererAppWeb.Endpoint, :code_reloader],
@@ -20,6 +24,10 @@ defmodule WandererAppWeb.Router do
@font_src ~w('self' data: https://web.ccpgamescdn.com https://w.appzi.io)
@script_src ~w('self' )
pipeline :admin_bauth do
plug :admin_basic_auth
end
pipeline :browser do
plug(:accepts, ["html"])
plug(:fetch_session)
@@ -137,11 +145,9 @@ defmodule WandererAppWeb.Router do
get "/:provider/callback", AuthController, :callback
end
scope "/", WandererAppWeb do
scope "/admin", WandererAppWeb do
pipe_through(:browser)
get "/", RedirectController, :redirect_authenticated
get("/last", MapsController, :last)
pipe_through(:admin_bauth)
live_session :admin,
on_mount: [
@@ -149,9 +155,23 @@ defmodule WandererAppWeb.Router do
{WandererAppWeb.UserAuth, :ensure_admin},
WandererAppWeb.Nav
] do
live("/admin", AdminLive, :index)
live("/", AdminLive, :index)
end
error_tracker_dashboard("/errors",
on_mount: [
{WandererAppWeb.UserAuth, :ensure_authenticated},
{WandererAppWeb.UserAuth, :ensure_admin}
]
)
end
scope "/", WandererAppWeb do
pipe_through(:browser)
get "/", RedirectController, :redirect_authenticated
get("/last", MapsController, :last)
live_session :authenticated,
on_mount: [
{WandererAppWeb.UserAuth, :ensure_authenticated},
@@ -180,16 +200,7 @@ defmodule WandererAppWeb.Router do
end
end
scope "/admin" do
pipe_through(:browser)
error_tracker_dashboard("/errors",
on_mount: [
{WandererAppWeb.UserAuth, :ensure_authenticated},
{WandererAppWeb.UserAuth, :ensure_admin}
]
)
end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:wanderer_app, :dev_routes) do
@@ -206,7 +217,6 @@ defmodule WandererAppWeb.Router do
error_tracker_dashboard("/errors", as: :error_tracker_dev_dashboard)
live_dashboard("/dashboard", metrics: WandererAppWeb.Telemetry)
# forward("/mailbox", Plug.Swoosh.MailboxPreview)
end
end
end

View File

@@ -2,7 +2,7 @@ defmodule WandererApp.MixProject do
use Mix.Project
@source_url "https://github.com/wanderer-industries/wanderer"
@version "1.0.20"
@version "1.0.22"
def project do
[