diff --git a/lib/backpex/live_resource.ex b/lib/backpex/live_resource.ex index f1164fc4..a2a55619 100644 --- a/lib/backpex/live_resource.ex +++ b/lib/backpex/live_resource.ex @@ -514,22 +514,14 @@ defmodule Backpex.LiveResource do defp field_active?(name, saved_fields) do case Map.get(saved_fields, Atom.to_string(name)) do - "true" -> - true - - "false" -> - false - - _other -> - true + "true" -> true + "false" -> false + _other -> true end end def assign_items(socket) do - %{ - live_resource: live_resource, - fields: fields - } = socket.assigns + %{live_resource: live_resource, fields: fields} = socket.assigns criteria = build_criteria(socket.assigns) items = Resource.list(fields, socket.assigns, live_resource, criteria) @@ -586,7 +578,7 @@ defmodule Backpex.LiveResource do end @impl Phoenix.LiveView - def render(%{live_action: action} = assigns) when action in [:show, :show_edit] do + def render(%{live_action: action} = assigns) when action in [:show] do resource_show(assigns) end @@ -619,16 +611,13 @@ defmodule Backpex.LiveResource do end defp apply_action(socket, :edit) do - %{ - live_resource: live_resource, - singular_name: singular_name - } = socket.assigns + %{live_resource: live_resource, singular_name: singular_name} = socket.assigns fields = live_resource.fields |> filtered_fields_by_action(socket.assigns, :edit) primary_value = URI.decode(socket.assigns.params["backpex_id"]) item = Resource.get!(primary_value, socket.assigns, live_resource) - unless live_resource.can?(socket.assigns, :edit, item), do: raise(Backpex.ForbiddenError) + if not live_resource.can?(socket.assigns, :edit, item), do: raise(Backpex.ForbiddenError) socket |> assign(:fields, fields) @@ -639,16 +628,13 @@ defmodule Backpex.LiveResource do end defp apply_action(socket, :show) do - %{ - live_resource: live_resource, - singular_name: singular_name - } = socket.assigns + %{live_resource: live_resource, singular_name: singular_name} = socket.assigns fields = live_resource.fields() |> filtered_fields_by_action(socket.assigns, :show) primary_value = URI.decode(socket.assigns.params["backpex_id"]) item = Resource.get!(primary_value, socket.assigns, live_resource) - unless live_resource.can?(socket.assigns, :show, item), do: raise(Backpex.ForbiddenError) + if not live_resource.can?(socket.assigns, :show, item), do: raise(Backpex.ForbiddenError) socket |> assign(:page_title, singular_name) @@ -658,13 +644,9 @@ defmodule Backpex.LiveResource do end defp apply_action(socket, :new) do - %{ - live_resource: live_resource, - schema: schema, - create_button_label: create_button_label - } = socket.assigns + %{live_resource: live_resource, schema: schema, create_button_label: create_button_label} = socket.assigns - unless live_resource.can?(socket.assigns, :new, nil), do: raise(Backpex.ForbiddenError) + if not live_resource.can?(socket.assigns, :new, nil), do: raise(Backpex.ForbiddenError) fields = live_resource.fields() |> filtered_fields_by_action(socket.assigns, :new) empty_item = schema.__struct__() @@ -687,7 +669,7 @@ defmodule Backpex.LiveResource do action = live_resource.resource_actions()[id] - unless live_resource.can?(socket.assigns, id, nil), do: raise(Backpex.ForbiddenError) + if not live_resource.can?(socket.assigns, id, nil), do: raise(Backpex.ForbiddenError) socket |> assign(:page_title, ResourceAction.name(action, :title)) @@ -730,7 +712,7 @@ defmodule Backpex.LiveResource do params: params } = socket.assigns - unless live_resource.can?(socket.assigns, :index, nil), do: raise(Backpex.ForbiddenError) + if not live_resource.can?(socket.assigns, :index, nil), do: raise(Backpex.ForbiddenError) fields = live_resource.fields() |> filtered_fields_by_action(socket.assigns, :index) @@ -788,11 +770,7 @@ defmodule Backpex.LiveResource do end defp assign_changeset(socket, fields) do - %{ - item: item, - changeset_function: changeset_function, - live_action: live_action - } = socket.assigns + %{item: item, changeset_function: changeset_function, live_action: live_action} = socket.assigns metadata = Resource.build_changeset_metadata(socket.assigns) changeset = changeset_function.(item, default_attrs(live_action, fields, socket.assigns), metadata) @@ -830,12 +808,7 @@ defmodule Backpex.LiveResource do defp default_attrs(_live_action, _fields, _assigns), do: %{} defp maybe_redirect_to_default_filters(%{assigns: %{filters_changed: false}} = socket) do - %{ - live_resource: live_resource, - query_options: query_options, - params: params, - filters: filters - } = socket.assigns + %{live_resource: live_resource, query_options: query_options, params: params, filters: filters} = socket.assigns filters_with_defaults = filters @@ -1168,10 +1141,7 @@ defmodule Backpex.LiveResource do end defp update_item(socket, item) do - %{ - live_resource: live_resource, - live_action: live_action - } = socket.assigns + %{live_resource: live_resource, live_action: live_action} = socket.assigns item_primary_value = primary_value(socket, item) item = Resource.get(item_primary_value, socket.assigns, live_resource)