fix credo warning for is_owner_or_admin?

This commit is contained in:
shibao 2024-02-23 22:17:56 -05:00
parent 53d0dcfb15
commit 2a87037f06
9 changed files with 18 additions and 18 deletions

View File

@ -229,10 +229,10 @@ defmodule Memex.Contexts do
context |> Context.update_changeset(attrs, user)
end
@spec is_owner_or_admin?(Context.t(), User.t()) :: boolean()
def is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner_or_admin?(_context, %{role: :admin}), do: true
def is_owner_or_admin?(_context, _other_user), do: false
@spec owner_or_admin?(Context.t(), User.t()) :: boolean()
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def owner_or_admin?(_context, %{role: :admin}), do: true
def owner_or_admin?(_context, _other_user), do: false
@spec is_owner?(Context.t(), User.t()) :: boolean()
def is_owner?(%{user_id: user_id}, %{id: user_id}), do: true

View File

@ -229,10 +229,10 @@ defmodule Memex.Notes do
note |> Note.update_changeset(attrs, user)
end
@spec is_owner_or_admin?(Note.t(), User.t()) :: boolean()
def is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner_or_admin?(_context, %{role: :admin}), do: true
def is_owner_or_admin?(_context, _other_user), do: false
@spec owner_or_admin?(Note.t(), User.t()) :: boolean()
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def owner_or_admin?(_context, %{role: :admin}), do: true
def owner_or_admin?(_context, _other_user), do: false
@spec is_owner?(Note.t(), User.t()) :: boolean()
def is_owner?(%{user_id: user_id}, %{id: user_id}), do: true

View File

@ -231,10 +231,10 @@ defmodule Memex.Pipelines do
pipeline |> Pipeline.update_changeset(attrs, user)
end
@spec is_owner_or_admin?(Pipeline.t(), User.t()) :: boolean()
def is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def is_owner_or_admin?(_context, %{role: :admin}), do: true
def is_owner_or_admin?(_context, _other_user), do: false
@spec owner_or_admin?(Pipeline.t(), User.t()) :: boolean()
def owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true
def owner_or_admin?(_context, %{role: :admin}), do: true
def owner_or_admin?(_context, _other_user), do: false
@spec is_owner?(Pipeline.t(), User.t()) :: boolean()
def is_owner?(%{user_id: user_id}, %{id: user_id}), do: true

View File

@ -40,7 +40,7 @@
<%= dgettext("actions", "edit") %>
</.link>
<.link
:if={Contexts.is_owner_or_admin?(context, @current_user)}
:if={Contexts.owner_or_admin?(context, @current_user)}
href="#"
phx-click="delete"
phx-value-id={context.id}

View File

@ -24,7 +24,7 @@
<%= dgettext("actions", "edit") %>
</.link>
<button
:if={Contexts.is_owner_or_admin?(@context, @current_user)}
:if={Contexts.owner_or_admin?(@context, @current_user)}
type="button"
class="btn btn-primary"
phx-click="delete"

View File

@ -40,7 +40,7 @@
<%= dgettext("actions", "edit") %>
</.link>
<.link
:if={Notes.is_owner_or_admin?(note, @current_user)}
:if={Notes.owner_or_admin?(note, @current_user)}
href="#"
phx-click="delete"
phx-value-id={note.id}

View File

@ -24,7 +24,7 @@
<%= dgettext("actions", "edit") %>
</.link>
<button
:if={Notes.is_owner_or_admin?(@note, @current_user)}
:if={Notes.owner_or_admin?(@note, @current_user)}
type="button"
class="btn btn-primary"
phx-click="delete"

View File

@ -40,7 +40,7 @@
<%= dgettext("actions", "edit") %>
</.link>
<.link
:if={Pipelines.is_owner_or_admin?(pipeline, @current_user)}
:if={Pipelines.owner_or_admin?(pipeline, @current_user)}
href="#"
phx-click="delete"
phx-value-id={pipeline.id}

View File

@ -24,7 +24,7 @@
<%= dgettext("actions", "edit") %>
</.link>
<button
:if={Pipelines.is_owner_or_admin?(@pipeline, @current_user)}
:if={Pipelines.owner_or_admin?(@pipeline, @current_user)}
type="button"
class="btn btn-primary"
phx-click="delete"