chore: Upgrade credo and address issues
This commit is contained in:
		
							parent
							
								
									d8902ec569
								
							
						
					
					
						commit
						046094aa2d
					
				
					 20 changed files with 77 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,9 @@
 | 
			
		|||
defmodule Legendary.Admin.Routes do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Routes from the admin app. Use like:
 | 
			
		||||
 | 
			
		||||
      use Legendary.Admin.Routes
 | 
			
		||||
  """
 | 
			
		||||
  defmacro __using__(_opts \\ []) do
 | 
			
		||||
    quote do
 | 
			
		||||
      use Kaffy.Routes, scope: "/admin", pipe_through: [:require_admin]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Legendary.Admin.Telemetry do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Collect metrics from the admin app.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  use Supervisor
 | 
			
		||||
  import Telemetry.Metrics
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Legendary.Admin.Kaffy.Config do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Pull in the resource list for the admin from the application config.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  def create_resources(_conn) do
 | 
			
		||||
    config = Application.get_env(:admin, Legendary.Admin)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,9 @@
 | 
			
		|||
defmodule Legendary.Admin.Kaffy.EditorExtension do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Bring in additional CSS and JS for the admin interface e.g. the
 | 
			
		||||
  markdown editor library.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  def stylesheets(_conn) do
 | 
			
		||||
    [
 | 
			
		||||
      {:safe, ~s(<link rel="stylesheet" href="/css/content-editor.css" />)},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule AppWeb.Telemetry do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Collect metrics on your app.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  use Supervisor
 | 
			
		||||
  import Telemetry.Metrics
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Legendary.Content.CommentAdmin do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Custom admin logic for blog post comments.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  def index(_) do
 | 
			
		||||
    [
 | 
			
		||||
      id: nil,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Legendary.Content.MarkupField do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Custom field type definition for markdown fields. Currently uses simplemde
 | 
			
		||||
  to provide a markdown editing GUI.
 | 
			
		||||
  """
 | 
			
		||||
  use Ecto.Type
 | 
			
		||||
  def type, do: :string
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Legendary.Content.PostAdmin do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Custom admin logic for content posts and pages.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  import Ecto.Query, only: [from: 2]
 | 
			
		||||
 | 
			
		||||
  def singular_name(_) do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,11 +87,12 @@ defmodule Legendary.Content.PostsController do
 | 
			
		|||
              end
 | 
			
		||||
 | 
			
		||||
            # The static page we're looking for is missing, so this is just a 404
 | 
			
		||||
            # credo:disable-for-next-line
 | 
			
		||||
            raise Phoenix.Router.NoRouteError.exception(conn: conn, router: router)
 | 
			
		||||
          _ ->
 | 
			
		||||
            # We aren't missing the static page, we're missing a partial. This is probably
 | 
			
		||||
            # a developer error, so bubble it up
 | 
			
		||||
            raise e
 | 
			
		||||
            reraise e, System.stacktrace
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Legendary.Content.Routes do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Routes for the content engine, including blog posts, feeds, and pages.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  defmacro __using__(_opts \\ []) do
 | 
			
		||||
    quote do
 | 
			
		||||
      pipeline :feed do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,7 +52,7 @@ defmodule Legendary.Content.PostsTest do
 | 
			
		|||
  test "delete_posts/1", %{public_post: post} do
 | 
			
		||||
    assert Enum.count(Posts.list_posts()) == 1
 | 
			
		||||
    assert {:ok, _} = Posts.delete_posts(post)
 | 
			
		||||
    assert Enum.count(Posts.list_posts()) == 0
 | 
			
		||||
    assert Enum.empty?(Posts.list_posts())
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  test "change_posts/1", %{public_post: post} do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,9 @@
 | 
			
		|||
defmodule Legendary.Auth.MnesiaClusterSupervisor do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Manages the cache in Mnesia for Pow. This allows users to remain logged in
 | 
			
		||||
  even if their traffic is hitting different nodes in the cluster.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  use Supervisor
 | 
			
		||||
 | 
			
		||||
  def start_link(init_arg) do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,12 @@
 | 
			
		|||
defmodule Legendary.Auth.Roles do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Functions for working with roles on users, such as testing whether a user has
 | 
			
		||||
  a role.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  def has_role?(userlike, role) when is_atom(role), do: has_role?(userlike, Atom.to_string(role))
 | 
			
		||||
  def has_role?(nil, _), do: false
 | 
			
		||||
  def has_role?(user = %Legendary.Auth.User{}, role) do
 | 
			
		||||
  def has_role?(%Legendary.Auth.User{} = user, role) do
 | 
			
		||||
    Enum.any?(user.roles || [], & &1 == role)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,7 +40,7 @@ defmodule Legendary.Auth.User do
 | 
			
		|||
    |> pow_extension_changeset(attrs)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def reset_password_changeset(user = %Legendary.Auth.User{}, params) do
 | 
			
		||||
  def reset_password_changeset(%Legendary.Auth.User{} = user, params) do
 | 
			
		||||
    user
 | 
			
		||||
    |> new_password_changeset(params, @pow_config)
 | 
			
		||||
    |> Changeset.validate_required([:password])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,15 @@
 | 
			
		|||
defmodule Legendary.Auth.UserAdmin do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Custom admin login for user records.
 | 
			
		||||
  """
 | 
			
		||||
  import Ecto.Query, only: [from: 2]
 | 
			
		||||
  alias Legendary.Auth.User
 | 
			
		||||
  alias Legendary.Core.Repo
 | 
			
		||||
 | 
			
		||||
  def custom_links(_schema) do
 | 
			
		||||
    # We add the funwithflags admin URL under this custom admin because kaffy
 | 
			
		||||
    #   doesn't have global custom links that work in this way and user is the
 | 
			
		||||
    #   closest fit.
 | 
			
		||||
    [
 | 
			
		||||
      %{name: "Feature Flags", url: "/admin/feature-flags", order: 2, location: :top, icon: "flag"},
 | 
			
		||||
    ]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,10 @@
 | 
			
		|||
defmodule Legendary.AuthWeb.Helpers do
 | 
			
		||||
  def current_user(socket = %Phoenix.LiveView.Socket{assigns: %{current_user: user}}), do: user
 | 
			
		||||
  def current_user(socket = %Phoenix.LiveView.Socket{assigns: %{__assigns__: %{current_user: user}}}), do: user
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Utility functions for working with users and roles.
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  def current_user(%Phoenix.LiveView.Socket{assigns: %{current_user: user}}), do: user
 | 
			
		||||
  def current_user(%Phoenix.LiveView.Socket{assigns: %{__assigns__: %{current_user: user}}}), do: user
 | 
			
		||||
  def current_user(%Phoenix.LiveView.Socket{}), do: nil
 | 
			
		||||
  def current_user(conn), do: Pow.Plug.current_user(conn)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ defmodule Legendary.Core.MapUtils do
 | 
			
		|||
    Map.merge(base, override, &deep_value/3)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp deep_value(_key, base = %{}, override = %{}) do
 | 
			
		||||
  defp deep_value(_key, %{} = base, %{} = override) do
 | 
			
		||||
    deep_merge(base, override)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,10 @@
 | 
			
		|||
defmodule Legendary.Core.Routes do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Router module that brings in core framework routes, such as the feature flag
 | 
			
		||||
  admin interface. Can be included like:
 | 
			
		||||
 | 
			
		||||
      use Legendary.Core.Routes
 | 
			
		||||
  """
 | 
			
		||||
  defmacro __using__(_opts \\ []) do
 | 
			
		||||
    quote do
 | 
			
		||||
      scope path: "/admin/feature-flags" do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
defmodule Mix.Legendary do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Parent module for all Legendary framework mix tasks. Provides some helpers
 | 
			
		||||
  used by tasks and generators.
 | 
			
		||||
  """
 | 
			
		||||
  alias Mix.Phoenix.{Schema}
 | 
			
		||||
 | 
			
		||||
  @doc false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								mix.lock
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								mix.lock
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -11,7 +11,7 @@
 | 
			
		|||
  "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
 | 
			
		||||
  "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
 | 
			
		||||
  "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
 | 
			
		||||
  "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"},
 | 
			
		||||
  "credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"},
 | 
			
		||||
  "crontab": {:hex, :crontab, "1.1.10", "dc9bb1f4299138d47bce38341f5dcbee0aa6c205e864fba7bc847f3b5cb48241", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "1347d889d1a0eda997990876b4894359e34bfbbd688acbb0ba28a2795ca40685"},
 | 
			
		||||
  "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"},
 | 
			
		||||
  "decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue