add Accounts.is_already_admin? check
This commit is contained in:
		| @@ -363,10 +363,16 @@ defmodule Memex.Accounts do | |||||||
|   """ |   """ | ||||||
|   @spec is_admin?(User.t()) :: boolean() |   @spec is_admin?(User.t()) :: boolean() | ||||||
|   def is_admin?(%User{id: user_id}) do |   def is_admin?(%User{id: user_id}) do | ||||||
|     Repo.one(from u in User, where: u.id == ^user_id and u.role == :admin) |     Repo.exists?(from u in User, where: u.id == ^user_id and u.role == :admin) | ||||||
|     |> is_nil() |  | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  |   @doc """ | ||||||
|  |   Checks to see if user has the admin role | ||||||
|  |   """ | ||||||
|  |   @spec is_already_admin?(User.t() | nil) :: boolean() | ||||||
|  |   def is_already_admin?(%User{role: :admin}), do: true | ||||||
|  |   def is_already_admin?(_invalid_user), do: false | ||||||
|  |  | ||||||
|   ## Confirmation |   ## Confirmation | ||||||
|  |  | ||||||
|   @doc """ |   @doc """ | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ defmodule MemexWeb.Components.Topbar do | |||||||
|           <li class="mx-2 my-1 border-left border border-primary-700"></li> |           <li class="mx-2 my-1 border-left border border-primary-700"></li> | ||||||
|  |  | ||||||
|           <%= if @current_user do %> |           <%= if @current_user do %> | ||||||
|             <%= if @current_user.role == :admin do %> |             <%= if @current_user |> Accounts.is_already_admin?() do %> | ||||||
|               <li class="mx-2 my-1"> |               <li class="mx-2 my-1"> | ||||||
|                 <.link |                 <.link | ||||||
|                   navigate={Routes.invite_index_path(Endpoint, :index)} |                   navigate={Routes.invite_index_path(Endpoint, :index)} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user