From fc75948f4cfac1afb3e4af851995f54d6f60242c Mon Sep 17 00:00:00 2001 From: shibao Date: Fri, 11 Feb 2022 00:34:02 -0500 Subject: [PATCH] add Accounts.is_admin?/1 --- lib/cannery/accounts.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/cannery/accounts.ex b/lib/cannery/accounts.ex index 9d0af06..b584ee6 100644 --- a/lib/cannery/accounts.ex +++ b/lib/cannery/accounts.ex @@ -296,6 +296,15 @@ defmodule Cannery.Accounts do list_users_by_role(:admin) |> Enum.empty?() end + @doc """ + Checks if user is an admin + """ + @spec is_admin?(User.t()) :: boolean() + def is_admin?(%User{id: user_id}) do + Repo.one(from u in User, where: u.id == ^user_id and u.role == :admin) + |> is_nil() + end + ## Confirmation @doc """