From 71397d6b29a578d9c08ada63f677f7e7495d1d40 Mon Sep 17 00:00:00 2001 From: shibao Date: Fri, 11 Feb 2022 00:34:29 -0500 Subject: [PATCH] harden invites context --- lib/cannery/invites.ex | 60 +++++++------ .../live/ammo_group_live/form_component.ex | 4 +- .../live/invite_live/form_component.ex | 70 ++++++++------- lib/cannery_web/live/invite_live/index.ex | 88 ++++++++++++------ .../live/invite_live/index.html.leex | 2 +- priv/gettext/actions.pot | 10 +-- priv/gettext/default.pot | 90 +++++++++---------- priv/gettext/errors.pot | 22 +++-- priv/gettext/prompts.pot | 66 +++++++------- 9 files changed, 227 insertions(+), 185 deletions(-) diff --git a/lib/cannery/invites.ex b/lib/cannery/invites.ex index bd6e034b..8803af6e 100644 --- a/lib/cannery/invites.ex +++ b/lib/cannery/invites.ex @@ -4,8 +4,8 @@ defmodule Cannery.Invites do """ import Ecto.Query, warn: false - alias Ecto.Changeset alias Cannery.{Accounts.User, Invites.Invite, Repo} + alias Ecto.Changeset @invite_token_length 20 @@ -14,12 +14,14 @@ defmodule Cannery.Invites do ## Examples - iex> list_invites() + iex> list_invites(%User{id: 123, role: :admin}) [%Invite{}, ...] """ - @spec list_invites() :: [Invite.t()] - def list_invites, do: Repo.all(Invite) + @spec list_invites(User.t()) :: [Invite.t()] + def list_invites(%User{role: :admin}) do + Repo.all(Invite) + end @doc """ Gets a single invite. @@ -28,15 +30,17 @@ defmodule Cannery.Invites do ## Examples - iex> get_invite!(123) + iex> get_invite!(123, %User{id: 123, role: :admin}) %Invite{} - iex> get_invite!(456) + iex> get_invite!(456, %User{id: 123, role: :admin}) ** (Ecto.NoResultsError) """ - @spec get_invite!(Invite.id()) :: Invite.t() - def get_invite!(id), do: Repo.get!(Invite, id) + @spec get_invite!(Invite.id(), User.t()) :: Invite.t() + def get_invite!(id, %User{role: :admin}) do + Repo.get!(Invite, id) + end @doc """ Returns a valid invite or nil based on the attempted token @@ -55,8 +59,9 @@ defmodule Cannery.Invites do def get_invite_by_token(token) do Repo.one( - from i in Invite, + from(i in Invite, where: i.token == ^token and i.disabled_at |> is_nil() + ) ) end @@ -86,21 +91,16 @@ defmodule Cannery.Invites do ## Examples - iex> create_invite(%User{id: "1"}, %{field: value}) + iex> create_invite(%User{id: 123, role: :admin}, %{field: value}) {:ok, %Invite{}} - iex> create_invite("1", %{field: value}) - {:ok, %Invite{}} - - iex> create_invite(%User{id: "1"}, %{field: bad_value}) + iex> create_invite(%User{id: 123, role: :admin}, %{field: bad_value}) {:error, %Changeset{}} """ - @spec create_invite(User.t() | User.id(), attrs :: map()) :: + @spec create_invite(User.t(), attrs :: map()) :: {:ok, Invite.t()} | {:error, Changeset.t(Invite.new_invite())} - def create_invite(%{id: user_id}, attrs), do: create_invite(user_id, attrs) - - def create_invite(user_id, attrs) when not (user_id |> is_nil()) do + def create_invite(%User{id: user_id, role: :admin}, attrs) do token = :crypto.strong_rand_bytes(@invite_token_length) |> Base.url_encode64() @@ -116,43 +116,45 @@ defmodule Cannery.Invites do ## Examples - iex> update_invite(invite, %{field: new_value}) + iex> update_invite(invite, %{field: new_value}, %User{id: 123, role: :admin}) {:ok, %Invite{}} - iex> update_invite(invite, %{field: bad_value}) + iex> update_invite(invite, %{field: bad_value}, %User{id: 123, role: :admin}) {:error, %Changeset{}} """ - @spec update_invite(Invite.t(), attrs :: map()) :: + @spec update_invite(Invite.t(), attrs :: map(), User.t()) :: {:ok, Invite.t()} | {:error, Changeset.t(Invite.t())} - def update_invite(invite, attrs), do: invite |> Invite.changeset(attrs) |> Repo.update() + def update_invite(invite, attrs, %User{role: :admin}), + do: invite |> Invite.changeset(attrs) |> Repo.update() @doc """ Deletes a invite. ## Examples - iex> delete_invite(invite) + iex> delete_invite(invite, %User{id: 123, role: :admin}) {:ok, %Invite{}} - iex> delete_invite(invite) + iex> delete_invite(invite, %User{id: 123, role: :admin}) {:error, %Changeset{}} """ - @spec delete_invite(Invite.t()) :: {:ok, Invite.t()} | {:error, Changeset.t(Invite.t())} - def delete_invite(invite), do: invite |> Repo.delete() + @spec delete_invite(Invite.t(), User.t()) :: + {:ok, Invite.t()} | {:error, Changeset.t(Invite.t())} + def delete_invite(invite, %User{role: :admin}), do: invite |> Repo.delete() @doc """ Deletes a invite. ## Examples - iex> delete_invite(invite) + iex> delete_invite(invite, %User{id: 123, role: :admin}) %Invite{} """ - @spec delete_invite!(Invite.t()) :: Invite.t() - def delete_invite!(invite), do: invite |> Repo.delete!() + @spec delete_invite!(Invite.t(), User.t()) :: Invite.t() + def delete_invite!(invite, %User{role: :admin}), do: invite |> Repo.delete!() @doc """ Returns an `%Changeset{}` for tracking invite changes. diff --git a/lib/cannery_web/live/ammo_group_live/form_component.ex b/lib/cannery_web/live/ammo_group_live/form_component.ex index b6f3c119..ce8e3a24 100644 --- a/lib/cannery_web/live/ammo_group_live/form_component.ex +++ b/lib/cannery_web/live/ammo_group_live/form_component.ex @@ -4,8 +4,8 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do """ use CanneryWeb, :live_component - alias Cannery.{Ammo, Accounts.User, Containers, Containers.Container} - alias Cannery.Ammo.{AmmoType, AmmoGroup} + alias Cannery.Ammo.{AmmoGroup, AmmoType} + alias Cannery.{Accounts.User, Ammo, Containers, Containers.Container} alias Ecto.Changeset alias Phoenix.LiveView.Socket diff --git a/lib/cannery_web/live/invite_live/form_component.ex b/lib/cannery_web/live/invite_live/form_component.ex index b833af17..e20fd3d4 100644 --- a/lib/cannery_web/live/invite_live/form_component.ex +++ b/lib/cannery_web/live/invite_live/form_component.ex @@ -14,22 +14,20 @@ defmodule CanneryWeb.InviteLive.FormComponent do Socket.t() ) :: {:ok, Socket.t()} def update(%{invite: invite} = assigns, socket) do - changeset = Invites.change_invite(invite) - - {:ok, - socket - |> assign(assigns) - |> assign(:changeset, changeset)} + {:ok, socket |> assign(assigns) |> assign(:changeset, Invites.change_invite(invite))} end @impl true - def handle_event("validate", %{"invite" => invite_params}, socket) do - changeset = socket.assigns.invite |> Invites.change_invite(invite_params) - {:noreply, assign(socket, :changeset, changeset)} + def handle_event( + "validate", + %{"invite" => invite_params}, + %{assigns: %{invite: invite}} = socket + ) do + {:noreply, socket |> assign(:changeset, invite |> Invites.change_invite(invite_params))} end - def handle_event("save", %{"invite" => invite_params}, socket) do - save_invite(socket, socket.assigns.action, invite_params) + def handle_event("save", %{"invite" => invite_params}, %{assigns: %{action: action}} = socket) do + save_invite(socket, action, invite_params) end @impl true @@ -71,29 +69,39 @@ defmodule CanneryWeb.InviteLive.FormComponent do """ end - defp save_invite(socket, :edit, invite_params) do - case Invites.update_invite(socket.assigns.invite, invite_params) do - {:ok, _invite} -> - {:noreply, - socket - |> put_flash(:info, dgettext("prompts", "Invite updated successfully")) - |> push_redirect(to: socket.assigns.return_to)} + defp save_invite( + %{assigns: %{current_user: current_user, invite: invite, return_to: return_to}} = socket, + :edit, + invite_params + ) do + socket = + case invite |> Invites.update_invite(invite_params, current_user) do + {:ok, %{name: invite_name}} -> + prompt = dgettext("prompts", "%{name} updated successfully", name: invite_name) + socket |> put_flash(:info, prompt) |> push_redirect(to: return_to) - {:error, %Changeset{} = changeset} -> - {:noreply, assign(socket, :changeset, changeset)} - end + {:error, %Changeset{} = changeset} -> + socket |> assign(:changeset, changeset) + end + + {:noreply, socket} end - defp save_invite(socket, :new, invite_params) do - case Invites.create_invite(socket.assigns.current_user, invite_params) do - {:ok, _invite} -> - {:noreply, - socket - |> put_flash(:info, dgettext("prompts", "Invite created successfully")) - |> push_redirect(to: socket.assigns.return_to)} + defp save_invite( + %{assigns: %{current_user: current_user, return_to: return_to}} = socket, + :new, + invite_params + ) do + socket = + case current_user |> Invites.create_invite(invite_params) do + {:ok, %{name: invite_name}} -> + prompt = dgettext("prompts", "%{name} created successfully", name: invite_name) + socket |> put_flash(:info, prompt) |> push_redirect(to: return_to) - {:error, %Changeset{} = changeset} -> - {:noreply, assign(socket, changeset: changeset)} - end + {:error, %Changeset{} = changeset} -> + socket |> assign(changeset: changeset) + end + + {:noreply, socket} end end diff --git a/lib/cannery_web/live/invite_live/index.ex b/lib/cannery_web/live/invite_live/index.ex index 647f4eeb..85e8d95c 100644 --- a/lib/cannery_web/live/invite_live/index.ex +++ b/lib/cannery_web/live/invite_live/index.ex @@ -14,53 +14,87 @@ defmodule CanneryWeb.InviteLive.Index do end @impl true - def handle_params(params, _url, socket) do - {:noreply, socket |> apply_action(socket.assigns.live_action, params)} + def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do + {:noreply, socket |> apply_action(live_action, params)} end - defp apply_action(socket, :edit, %{"id" => id}) do + defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do socket - |> assign(page_title: gettext("Edit Invite"), invite: Invites.get_invite!(id)) + |> assign(page_title: gettext("Edit Invite"), invite: Invites.get_invite!(id, current_user)) end defp apply_action(socket, :new, _params) do - socket - |> assign(page_title: gettext("New Invite"), invite: %Invite{}) + socket |> assign(page_title: gettext("New Invite"), invite: %Invite{}) end defp apply_action(socket, :index, _params) do - socket - |> assign(page_title: gettext("Listing Invites"), invite: nil) + socket |> assign(page_title: gettext("Listing Invites"), invite: nil) end @impl true - def handle_event("delete", %{"id" => id}, socket) do - invite = Invites.get_invite!(id) - {:ok, _} = Invites.delete_invite(invite) - {:noreply, socket |> display_invites()} + def handle_event("delete", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do + %{name: invite_name} = + id |> Invites.get_invite!(current_user) |> Invites.delete_invite!(current_user) + + prompt = dgettext("prompts", "%{name} deleted succesfully", name: invite_name) + {:noreply, socket |> put_flash(:info, prompt) |> display_invites()} end - def handle_event("set_unlimited", %{"id" => id}, socket) do - id |> Invites.get_invite!() |> Invites.update_invite(%{"uses_left" => nil}) - {:noreply, socket |> display_invites()} + def handle_event( + "set_unlimited", + %{"id" => id}, + %{assigns: %{current_user: current_user}} = socket + ) do + socket = + Invites.get_invite!(id, current_user) + |> Invites.update_invite(%{"uses_left" => nil}, current_user) + |> case do + {:ok, %{name: invite_name}} -> + prompt = dgettext("prompts", "%{name} updated succesfully", name: invite_name) + socket |> put_flash(:info, prompt) |> display_invites() + + {:error, changeset} -> + socket |> put_flash(:error, changeset |> changeset_errors()) + end + + {:noreply, socket} end - def handle_event("enable", %{"id" => id}, socket) do - attrs = %{"uses_left" => nil, "disabled_at" => nil} - id |> Invites.get_invite!() |> Invites.update_invite(attrs) - {:noreply, socket |> display_invites()} + def handle_event("enable", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do + socket = + Invites.get_invite!(id, current_user) + |> Invites.update_invite(%{"uses_left" => nil, "disabled_at" => nil}, current_user) + |> case do + {:ok, %{name: invite_name}} -> + prompt = dgettext("prompts", "%{name} enabled succesfully", name: invite_name) + socket |> put_flash(:info, prompt) |> display_invites() + + {:error, changeset} -> + socket |> put_flash(:error, changeset |> changeset_errors()) + end + + {:noreply, socket} end - def handle_event("disable", %{"id" => id}, socket) do + def handle_event("disable", %{"id" => id}, %{assigns: %{current_user: current_user}} = socket) do now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) - attrs = %{"uses_left" => 0, "disabled_at" => now} - id |> Invites.get_invite!() |> Invites.update_invite(attrs) - {:noreply, socket |> display_invites()} + + socket = + Invites.get_invite!(id, current_user) + |> Invites.update_invite(%{"uses_left" => 0, "disabled_at" => now}, current_user) + |> case do + {:ok, %{name: invite_name}} -> + prompt = dgettext("prompts", "%{name} disabled succesfully", name: invite_name) + socket |> put_flash(:info, prompt) |> display_invites() + + {:error, changeset} -> + socket |> put_flash(:error, changeset |> changeset_errors()) + end + + {:noreply, socket} end - # redisplays invites to socket - defp display_invites(socket) do - invites = Invites.list_invites() - socket |> assign(:invites, invites) + defp display_invites(%{assigns: %{current_user: current_user}} = socket) do + socket |> assign(:invites, Invites.list_invites(current_user)) end end diff --git a/lib/cannery_web/live/invite_live/index.html.leex b/lib/cannery_web/live/invite_live/index.html.leex index c0990820..863121ef 100644 --- a/lib/cannery_web/live/invite_live/index.html.leex +++ b/lib/cannery_web/live/invite_live/index.html.leex @@ -69,7 +69,7 @@ <%= if invite.disabled_at |> is_nil() and not(invite.uses_left |> is_nil()) do %> + data-confirm={dgettext("prompts", "Are you sure you want to make %{name} unlimited?", name: invite.name)}> <%= gettext("Set Unlimited") %> <% end %> diff --git a/priv/gettext/actions.pot b/priv/gettext/actions.pot index 9a26d3bf..2b3edab3 100644 --- a/priv/gettext/actions.pot +++ b/priv/gettext/actions.pot @@ -91,11 +91,11 @@ msgid "New Ammo group" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:96 -#: lib/cannery_web/live/ammo_type_live/form_component.ex:156 -#: lib/cannery_web/live/container_live/form_component.ex:79 -#: lib/cannery_web/live/invite_live/form_component.ex:61 -#: lib/cannery_web/live/tag_live/form_component.ex:62 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:102 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:161 +#: lib/cannery_web/live/container_live/form_component.ex:90 +#: lib/cannery_web/live/invite_live/form_component.ex:63 +#: lib/cannery_web/live/tag_live/form_component.ex:66 msgid "Save" msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index bf375a1a..da281e0a 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -111,7 +111,7 @@ msgid "Settings" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:69 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:75 #: lib/cannery_web/live/ammo_group_live/index.html.heex:26 msgid "Count" msgstr "" @@ -144,7 +144,7 @@ msgid "No Ammo" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:83 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:89 #: lib/cannery_web/live/ammo_group_live/index.html.heex:32 msgid "Notes" msgstr "" @@ -156,7 +156,7 @@ msgid "Notes:" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:76 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:82 #: lib/cannery_web/live/ammo_group_live/index.html.heex:29 msgid "Price paid" msgstr "" @@ -183,7 +183,7 @@ msgid "This ammo group is not in a container" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:63 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:69 msgid "Ammo type" msgstr "" @@ -193,65 +193,65 @@ msgid "Average Price paid" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:140 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:145 #: lib/cannery_web/live/ammo_type_live/index.html.heex:38 msgid "Blank" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:102 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:107 msgid "Brass" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:78 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:83 #: lib/cannery_web/live/ammo_type_live/index.html.heex:28 #: lib/cannery_web/live/ammo_type_live/show.html.heex:37 msgid "Bullet core" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:71 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:76 #: lib/cannery_web/live/ammo_type_live/index.html.heex:27 #: lib/cannery_web/live/ammo_type_live/show.html.heex:36 msgid "Bullet type" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:92 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:97 #: lib/cannery_web/live/ammo_type_live/index.html.heex:30 #: lib/cannery_web/live/ammo_type_live/show.html.heex:39 msgid "Caliber" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:85 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:90 #: lib/cannery_web/live/ammo_type_live/index.html.heex:29 #: lib/cannery_web/live/ammo_type_live/show.html.heex:38 msgid "Cartridge" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:99 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:104 #: lib/cannery_web/live/ammo_type_live/index.html.heex:31 #: lib/cannery_web/live/ammo_type_live/show.html.heex:40 msgid "Case material" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:90 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:96 msgid "Container" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:144 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:149 #: lib/cannery_web/live/ammo_type_live/index.html.heex:39 msgid "Corrosive" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:58 -#: lib/cannery_web/live/container_live/form_component.ex:56 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:63 +#: lib/cannery_web/live/container_live/form_component.ex:67 msgid "Description" msgstr "" @@ -262,24 +262,24 @@ msgid "Edit Ammo type" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:69 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:74 msgid "Example bullet type abbreviations" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:74 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:79 msgid "FMJ" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:106 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:111 #: lib/cannery_web/live/ammo_type_live/index.html.heex:32 #: lib/cannery_web/live/ammo_type_live/show.html.heex:41 msgid "Grains" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:136 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:141 #: lib/cannery_web/live/ammo_type_live/index.html.heex:37 msgid "Incendiary" msgstr "" @@ -295,17 +295,17 @@ msgid "Listing Ammo types" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:148 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:153 #: lib/cannery_web/live/ammo_type_live/index.html.heex:40 msgid "Manufacturer" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:54 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:59 #: lib/cannery_web/live/ammo_type_live/index.html.heex:26 -#: lib/cannery_web/live/container_live/form_component.ex:49 -#: lib/cannery_web/live/invite_live/form_component.ex:53 -#: lib/cannery_web/live/tag_live/form_component.ex:46 +#: lib/cannery_web/live/container_live/form_component.ex:60 +#: lib/cannery_web/live/invite_live/form_component.ex:55 +#: lib/cannery_web/live/tag_live/form_component.ex:50 msgid "Name" msgstr "" @@ -325,27 +325,27 @@ msgid "No ammo for this type" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:114 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:119 #: lib/cannery_web/live/ammo_type_live/index.html.heex:33 #: lib/cannery_web/live/ammo_type_live/show.html.heex:42 msgid "Pressure" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:121 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:126 #: lib/cannery_web/live/ammo_type_live/index.html.heex:34 #: lib/cannery_web/live/ammo_type_live/show.html.heex:43 msgid "Primer type" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:128 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:133 #: lib/cannery_web/live/ammo_type_live/index.html.heex:35 msgid "Rimfire" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:152 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:157 msgid "SKU" msgstr "" @@ -360,12 +360,12 @@ msgid "Sku" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:81 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:86 msgid "Steel" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:132 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:137 #: lib/cannery_web/live/ammo_type_live/index.html.heex:36 msgid "Tracer" msgstr "" @@ -377,19 +377,19 @@ msgid "Description:" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/index.ex:22 -#: lib/cannery_web/live/container_live/show.ex:58 +#: lib/cannery_web/live/container_live/index.ex:23 +#: lib/cannery_web/live/container_live/show.ex:67 msgid "Edit Container" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/index.ex:34 +#: lib/cannery_web/live/container_live/index.ex:32 #: lib/cannery_web/live/container_live/index.html.heex:3 msgid "Listing Containers" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:71 +#: lib/cannery_web/live/container_live/form_component.ex:82 msgid "Location" msgstr "" @@ -400,17 +400,17 @@ msgid "Location:" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:67 +#: lib/cannery_web/live/container_live/form_component.ex:78 msgid "Magazine, Clip, Ammo Box, etc" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:60 +#: lib/cannery_web/live/container_live/form_component.ex:71 msgid "Metal ammo can with the anime girl sticker" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:52 +#: lib/cannery_web/live/container_live/form_component.ex:63 msgid "My cool ammo can" msgstr "" @@ -430,17 +430,17 @@ msgid "No containers" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:75 +#: lib/cannery_web/live/container_live/form_component.ex:86 msgid "On the bookshelf" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/show.ex:57 +#: lib/cannery_web/live/container_live/show.ex:66 msgid "Show Container" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:64 +#: lib/cannery_web/live/container_live/form_component.ex:75 msgid "Type" msgstr "" @@ -451,7 +451,7 @@ msgid "Type:" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/tag_live/form_component.ex:50 +#: lib/cannery_web/live/tag_live/form_component.ex:54 msgid "Background color" msgstr "" @@ -481,7 +481,7 @@ msgid "Invite Disabled" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/invite_live/index.ex:33 +#: lib/cannery_web/live/invite_live/index.ex:31 #: lib/cannery_web/live/invite_live/index.html.leex:3 msgid "Listing Invites" msgstr "" @@ -493,7 +493,7 @@ msgid "Listing Tags" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/invite_live/index.ex:28 +#: lib/cannery_web/live/invite_live/index.ex:27 msgid "New Invite" msgstr "" @@ -523,7 +523,7 @@ msgid "Tags can be added to your containers to help you organize" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/tag_live/form_component.ex:56 +#: lib/cannery_web/live/tag_live/form_component.ex:60 msgid "Text color" msgstr "" @@ -533,6 +533,6 @@ msgid "Uses Left:" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/invite_live/form_component.ex:57 +#: lib/cannery_web/live/invite_live/form_component.ex:59 msgid "Uses left" msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index be18094c..ab9ef09e 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -138,13 +138,6 @@ msgstr "" msgid "Go back home" msgstr "" -#, elixir-format, ex-autogen -#: lib/cannery/containers.ex:105 -msgid "There is still %{amount} ammo group in this container" -msgid_plural "There are still %{amount} ammo groups in this container" -msgstr[0] "" -msgstr[1] "" - #, elixir-format, ex-autogen #: lib/cannery_web/templates/user_registration/new.html.heex:13 #: lib/cannery_web/templates/user_reset_password/edit.html.heex:13 @@ -201,12 +194,17 @@ msgid "You must log in to access this page." msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/index.ex:65 -#: lib/cannery_web/live/container_live/show.ex:47 -msgid "Could not delete container: %{error}" +#: lib/cannery_web/live/container_live/index.ex:42 +msgid "Could not find that container" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/index.ex:45 -msgid "Could not find that container" +#: lib/cannery/containers.ex:105 +msgid "Container must be empty before deleting" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/container_live/index.ex:54 +#: lib/cannery_web/live/container_live/show.ex:52 +msgid "Could not delete %{name}: %{error}" msgstr "" diff --git a/priv/gettext/prompts.pot b/priv/gettext/prompts.pot index e3ef12e2..a7fc1136 100644 --- a/priv/gettext/prompts.pot +++ b/priv/gettext/prompts.pot @@ -77,12 +77,12 @@ msgid "Your account has been deleted" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:145 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:151 msgid "Ammo group created successfully" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:127 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:133 msgid "Ammo group updated successfully" msgstr "" @@ -94,11 +94,11 @@ msgid "Are you sure you want to delete this ammo?" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_group_live/form_component.ex:97 -#: lib/cannery_web/live/ammo_type_live/form_component.ex:157 -#: lib/cannery_web/live/container_live/form_component.ex:81 -#: lib/cannery_web/live/invite_live/form_component.ex:63 -#: lib/cannery_web/live/tag_live/form_component.ex:64 +#: lib/cannery_web/live/ammo_group_live/form_component.ex:103 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:162 +#: lib/cannery_web/live/container_live/form_component.ex:92 +#: lib/cannery_web/live/invite_live/form_component.ex:65 +#: lib/cannery_web/live/tag_live/form_component.ex:68 msgid "Saving..." msgstr "" @@ -111,52 +111,37 @@ msgid "Are you sure you want to delete %{name}?" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/index.ex:55 -#: lib/cannery_web/live/container_live/show.ex:37 +#: lib/cannery_web/live/container_live/index.ex:47 +#: lib/cannery_web/live/container_live/show.ex:42 msgid "%{name} has been deleted" msgstr "" -#, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:113 -msgid "Container created successfully" -msgstr "" - -#, elixir-format, ex-autogen -#: lib/cannery_web/live/container_live/form_component.ex:98 -msgid "Container updated successfully" -msgstr "" - #, elixir-format, ex-autogen #: lib/cannery_web/live/invite_live/index.html.leex:53 msgid "Are you sure you want to delete the invite for %{name}?" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/invite_live/form_component.ex:88 -msgid "Invite created successfully" -msgstr "" - -#, elixir-format, ex-autogen -#: lib/cannery_web/live/invite_live/form_component.ex:75 -msgid "Invite updated successfully" -msgstr "" - -#, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:188 -#: lib/cannery_web/live/tag_live/form_component.ex:97 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:193 +#: lib/cannery_web/live/container_live/form_component.ex:126 +#: lib/cannery_web/live/invite_live/form_component.ex:98 +#: lib/cannery_web/live/tag_live/form_component.ex:101 msgid "%{name} created successfully" msgstr "" #, elixir-format, ex-autogen #: lib/cannery_web/live/ammo_type_live/index.ex:41 #: lib/cannery_web/live/ammo_type_live/show.ex:39 +#: lib/cannery_web/live/invite_live/index.ex:39 #: lib/cannery_web/live/tag_live/index.ex:41 msgid "%{name} deleted succesfully" msgstr "" #, elixir-format, ex-autogen -#: lib/cannery_web/live/ammo_type_live/form_component.ex:174 -#: lib/cannery_web/live/tag_live/form_component.ex:79 +#: lib/cannery_web/live/ammo_type_live/form_component.ex:179 +#: lib/cannery_web/live/container_live/form_component.ex:108 +#: lib/cannery_web/live/invite_live/form_component.ex:80 +#: lib/cannery_web/live/tag_live/form_component.ex:83 msgid "%{name} updated successfully" msgstr "" @@ -165,3 +150,18 @@ msgstr "" #: lib/cannery_web/live/ammo_group_live/show.ex:33 msgid "Ammo group deleted succesfully" msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.ex:87 +msgid "%{name} disabled succesfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.ex:69 +msgid "%{name} enabled succesfully" +msgstr "" + +#, elixir-format, ex-autogen +#: lib/cannery_web/live/invite_live/index.ex:53 +msgid "%{name} updated succesfully" +msgstr ""