From 6da3096db175bd2bad82d5ca5be43163db7af894 Mon Sep 17 00:00:00 2001 From: Dmitry Popov Date: Thu, 13 Feb 2025 18:04:28 +0100 Subject: [PATCH] chore: release version v1.48.0 --- assets/css/app.css | 63 ++++++ lib/wanderer_app/maps.ex | 30 +++ .../live/maps/map_audit_live.ex | 65 +++--- lib/wanderer_app_web/live/maps/maps_live.ex | 195 ++++++++++-------- .../live/maps/maps_live.html.heex | 12 +- 5 files changed, 229 insertions(+), 136 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 1147c63e..7f69d660 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -936,3 +936,66 @@ body > div:first-of-type { width: 16px; height: 16px; } + +.verticalTabsContainer { + display: flex; + width: 100%; + min-height: 300px; +} +.verticalTabsContainer .p-tabview { + width: 100%; + display: flex; + align-items: flex-start; +} +.verticalTabsContainer .p-tabview-panels { + padding: 6px 1rem !important; + flex-grow: 1; + height: 100%; +} +.verticalTabsContainer .p-tabview-nav-container { + border-right: none; + height: 100%; +} +.verticalTabsContainer .p-tabview-nav { + flex-direction: column; + width: 150px; + min-height: 100%; + border: none; +} +.verticalTabsContainer .p-tabview-nav li { + width: 100%; + border-right: 4px solid var(--surface-hover); + background-color: var(--surface-card); + transition: + background-color 200ms, + border-right-color 200ms; +} +.verticalTabsContainer .p-tabview-nav li:hover { + background-color: var(--surface-hover); + border-right: 4px solid var(--surface-100); +} +.verticalTabsContainer .p-tabview-nav li .p-tabview-nav-link { + transition: color 200ms; + justify-content: flex-end; + padding: 10px; + background-color: initial; + border: none; + color: var(--gray-400); + border-radius: initial; + font-weight: 400; + margin: 0; +} +.verticalTabsContainer .p-tabview-nav li.p-tabview-selected { + background-color: var(--surface-50); + border-right: 4px solid var(--primary-color); +} +.verticalTabsContainer .p-tabview-nav li.p-tabview-selected .p-tabview-nav-link { + font-weight: 600; + color: var(--primary-color); +} +.verticalTabsContainer .p-tabview-nav li.p-tabview-selected:hover { + border-right: 4px solid var(--primary-color); +} +.verticalTabsContainer .p-tabview-panel { + flex-grow: 1; +} diff --git a/lib/wanderer_app/maps.ex b/lib/wanderer_app/maps.ex index 37d278ff..ba805ed5 100644 --- a/lib/wanderer_app/maps.ex +++ b/lib/wanderer_app/maps.ex @@ -295,4 +295,34 @@ defmodule WandererApp.Maps do character_eve_ids |> Enum.any?(fn eve_id -> eve_id in acl_roles_eve_ids end) end + + def check_user_can_delete_map(map_slug, current_user) do + map_slug + |> WandererApp.Api.Map.get_map_by_slug() + |> Ash.load([:owner, :acls, :user_permissions], actor: current_user) + |> case do + {:ok, + %{ + user_permissions: user_permissions, + owner_id: owner_id + } = map} -> + user_permissions = + WandererApp.Permissions.get_map_permissions( + user_permissions, + owner_id, + current_user.characters |> Enum.map(& &1.id) + ) + + case user_permissions.delete_map do + true -> + {:ok, map} + + _ -> + {:error, :not_authorized} + end + + error -> + {:error, error} + end + end end diff --git a/lib/wanderer_app_web/live/maps/map_audit_live.ex b/lib/wanderer_app_web/live/maps/map_audit_live.ex index de8dce29..e78d5e6c 100755 --- a/lib/wanderer_app_web/live/maps/map_audit_live.ex +++ b/lib/wanderer_app_web/live/maps/map_audit_live.ex @@ -10,57 +10,38 @@ defmodule WandererAppWeb.MapAuditLive do def mount( %{"slug" => map_slug, "period" => period, "activity" => activity} = _params, _session, - socket + %{assigns: %{current_user: current_user}} = socket ) do - current_user = socket.assigns.current_user - - map_slug - |> WandererApp.Api.Map.get_map_by_slug() - |> Ash.load([:acls, :user_permissions], actor: current_user) + WandererApp.Maps.check_user_can_delete_map(map_slug, current_user) |> case do {:ok, %{ id: map_id, - user_permissions: user_permissions, - name: map_name, - owner_id: owner_id + name: map_name } = _map} -> - user_permissions = - WandererApp.Permissions.get_map_permissions( - user_permissions, - owner_id, - current_user.characters |> Enum.map(& &1.id) - ) + {:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?() - case user_permissions.delete_map do - true -> - {:ok, is_subscription_active} = map_id |> WandererApp.Map.is_subscription_active?() - - {:ok, - socket - |> assign( - map_id: map_id, - map_name: map_name, - map_slug: map_slug, - map_subscription_active: is_subscription_active, - activity: activity, - can_undo_types: [:systems_removed], - period: period || "1H", - page: 1, - per_page: 25, - end_of_stream?: false - ) - |> stream(:activity, [])} - - _ -> - {:ok, - socket - |> put_flash(:error, "You don't have an access.") - |> push_navigate(to: ~p"/maps")} - end + {:ok, + socket + |> assign( + map_id: map_id, + map_name: map_name, + map_slug: map_slug, + map_subscription_active: is_subscription_active, + activity: activity, + can_undo_types: [:systems_removed], + period: period || "1H", + page: 1, + per_page: 25, + end_of_stream?: false + ) + |> stream(:activity, [])} _ -> - {:ok, socket} + {:ok, + socket + |> put_flash(:error, "You don't have an access.") + |> push_navigate(to: ~p"/maps")} end end diff --git a/lib/wanderer_app_web/live/maps/maps_live.ex b/lib/wanderer_app_web/live/maps/maps_live.ex index 1e2e2157..6d7ac253 100644 --- a/lib/wanderer_app_web/live/maps/maps_live.ex +++ b/lib/wanderer_app_web/live/maps/maps_live.ex @@ -37,7 +37,14 @@ defmodule WandererAppWeb.MapsLive do @impl true def mount(_params, _session, socket) do - {:ok, socket |> assign(maps: [], characters: [], location: nil)} + {:ok, + socket + |> assign( + maps: [], + characters: [], + location: nil, + map_subscriptions: [] + )} end @impl true @@ -88,99 +95,119 @@ defmodule WandererAppWeb.MapsLive do end end - defp apply_action(socket, :edit, %{"slug" => map_slug} = _params, url) do - map = - map_slug - |> WandererApp.Api.Map.get_map_by_slug!() - |> Ash.load!([:owner, :acls]) - |> map_map() + defp apply_action( + %{assigns: %{current_user: current_user}} = socket, + :edit, + %{"slug" => map_slug} = _params, + url + ) do + WandererApp.Maps.check_user_can_delete_map(map_slug, current_user) + |> case do + {:ok, map} -> + map = map |> map_map() - socket - |> assign(:active_page, :maps) - |> assign(:uri, URI.parse(url) |> Map.put(:path, ~p"/")) - |> assign(:page_title, "Maps - Edit") - |> assign(:scopes, ["wormholes", "stargates", "none", "all"]) - |> assign(:map_slug, map_slug) - |> assign( - :characters, - [map.owner |> map_character() | socket.assigns.characters] |> Enum.uniq() - ) - |> assign( - :form, - map |> AshPhoenix.Form.for_update(:update, forms: [auto?: true]) - ) - |> load_access_lists() + socket + |> assign(:active_page, :maps) + |> assign(:uri, URI.parse(url) |> Map.put(:path, ~p"/")) + |> assign(:page_title, "Maps - Edit") + |> assign(:scopes, ["wormholes", "stargates", "none", "all"]) + |> assign(:map_slug, map_slug) + |> assign( + :characters, + [map.owner |> map_character() | socket.assigns.characters] |> Enum.uniq() + ) + |> assign( + :form, + map |> AshPhoenix.Form.for_update(:update, forms: [auto?: true]) + ) + |> load_access_lists() + + _ -> + socket + |> put_flash(:error, "You don't have an access.") + |> push_navigate(to: ~p"/maps") + end end - defp apply_action(socket, :settings, %{"slug" => map_slug} = _params, _url) do - map = - map_slug - |> WandererApp.Api.Map.get_map_by_slug!() - |> Ash.load!([:owner, :acls]) + defp apply_action( + %{assigns: %{current_user: current_user}} = socket, + :settings, + %{"slug" => map_slug} = _params, + _url + ) do + WandererApp.Maps.check_user_can_delete_map(map_slug, current_user) + |> case do + {:ok, map} -> + {:ok, export_settings} = + map + |> WandererApp.Map.Server.get_export_settings() - {:ok, export_settings} = - map - |> WandererApp.Map.Server.get_export_settings() + {:ok, map_balance} = WandererApp.Map.SubscriptionManager.get_balance(map) - {:ok, map_balance} = WandererApp.Map.SubscriptionManager.get_balance(map) + {:ok, map_subscriptions} = + WandererApp.Map.SubscriptionManager.get_map_subscriptions(map.id) - {:ok, map_subscriptions} = WandererApp.Map.SubscriptionManager.get_map_subscriptions(map.id) + subscription_form = %{ + "plan" => "omega", + "period" => "1", + "characters_limit" => "100", + "hubs_limit" => "10", + "auto_renew?" => true + } - subscription_form = %{ - "plan" => "omega", - "period" => "1", - "characters_limit" => "100", - "hubs_limit" => "10", - "auto_renew?" => true - } + {:ok, options_form_data} = WandererApp.MapRepo.options_to_form_data(map) - {:ok, options_form_data} = WandererApp.MapRepo.options_to_form_data(map) + {:ok, estimated_price, discount} = + WandererApp.Map.SubscriptionManager.estimate_price(subscription_form, false) - {:ok, estimated_price, discount} = - WandererApp.Map.SubscriptionManager.estimate_price(subscription_form, false) + socket + |> assign(:active_page, :maps) + |> assign(:page_title, "Maps - Settings") + |> assign(:map_slug, map_slug) + |> assign(:map_id, map.id) + |> assign(:public_api_key, map.public_api_key) + |> assign(:map, map) + |> assign( + export_settings: export_settings |> _get_export_map_data(), + import_form: to_form(%{}), + importing: false, + show_settings?: true, + is_topping_up?: false, + active_settings_tab: "general", + is_adding_subscription?: false, + selected_subscription: nil, + options_form: options_form_data |> to_form(), + map_subscriptions: map_subscriptions, + subscription_form: subscription_form |> to_form(), + estimated_price: estimated_price, + discount: discount, + map_balance: map_balance, + topup_form: %{} |> to_form(), + subscription_plans: ["omega", "advanced"], + subscription_periods: [ + {"1 Month", "1"}, + {"3 Months", "3"}, + {"6 Months", "6"}, + {"1 Year", "12"} + ], + layout_options: [ + {"Left To Right", "left_to_right"}, + {"Top To Bottom", "top_to_bottom"} + ] + ) + |> allow_upload(:settings, + accept: ~w(.json), + max_entries: 1, + max_file_size: 10_000_000, + auto_upload: true, + progress: &handle_progress/3 + ) - socket - |> assign(:active_page, :maps) - |> assign(:page_title, "Maps - Settings") - |> assign(:map_slug, map_slug) - |> assign(:map_id, map.id) - |> assign(:public_api_key, map.public_api_key) - |> assign(:map, map) - |> assign( - export_settings: export_settings |> _get_export_map_data(), - import_form: to_form(%{}), - importing: false, - show_settings?: true, - is_topping_up?: false, - active_settings_tab: "general", - is_adding_subscription?: false, - selected_subscription: nil, - options_form: options_form_data |> to_form(), - map_subscriptions: map_subscriptions, - subscription_form: subscription_form |> to_form(), - estimated_price: estimated_price, - discount: discount, - map_balance: map_balance, - topup_form: %{} |> to_form(), - subscription_plans: ["omega", "advanced"], - subscription_periods: [ - {"1 Month", "1"}, - {"3 Months", "3"}, - {"6 Months", "6"}, - {"1 Year", "12"} - ], - layout_options: [ - {"Left To Right", "left_to_right"}, - {"Top To Bottom", "top_to_bottom"} - ] - ) - |> allow_upload(:settings, - accept: ~w(.json), - max_entries: 1, - max_file_size: 10_000_000, - auto_upload: true, - progress: &handle_progress/3 - ) + _ -> + socket + |> put_flash(:error, "You don't have an access.") + |> push_navigate(to: ~p"/maps") + end end defp allow_map_creation(), diff --git a/lib/wanderer_app_web/live/maps/maps_live.html.heex b/lib/wanderer_app_web/live/maps/maps_live.html.heex index ccc5d305..2203c804 100644 --- a/lib/wanderer_app_web/live/maps/maps_live.html.heex +++ b/lib/wanderer_app_web/live/maps/maps_live.html.heex @@ -185,7 +185,7 @@ <.modal - :if={@live_action in [:settings]} + :if={@live_action in [:settings] && not is_nil(assigns[:map])} title="Map Settings" class="!min-w-[700px]" id="map-settings-modal" @@ -194,7 +194,7 @@ >
-
+
@@ -306,14 +306,6 @@ -