-
- -
- <.link navigate={~p"/books/#{@book.id}/edit"}
- class="flex items-center block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
- >
-
- Edit
-
-
-
+ <%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
+
+
+
+
+
+ -
+ <.link navigate={~p"/books/#{@book.id}/edit"}
+ class="flex items-center block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
+ >
+
+ Edit
+
+
+
+
-
<.link navigate={~p"/books/#{@book.id}"}>
<%= if @book.cover_image_url != nil do %>
diff --git a/lib/decentralised_book_index_web/components/my_components/book_search.ex b/lib/decentralised_book_index_web/components/my_components/book_search.ex
index e80a158..e27d09f 100644
--- a/lib/decentralised_book_index_web/components/my_components/book_search.ex
+++ b/lib/decentralised_book_index_web/components/my_components/book_search.ex
@@ -2,12 +2,16 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
use Phoenix.Component
use DecentralisedBookIndexWeb, :verified_routes
+ alias DecentralisedBookIndex.Accounts.Role
+
attr :search_query, :string, default: ""
attr :search_mode, :string, default: "title"
attr :search_mode_options, :list, required: true
attr :select_options, :list, required: true
attr :selected_option, :string, required: true
+ attr :current_user, :map, default: nil
+
def book_search(assigns) do
~H"""
@@ -26,14 +30,16 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.BookSearch do
- <.link patch={~p"/books/new"}>
-
-
+ <%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
+ <.link patch={~p"/books/new"}>
+
+
+ <% end %>
<.dropdown_settings
search_mode={@search_mode}
search_mode_options={@search_mode_options}
diff --git a/lib/decentralised_book_index_web/live/author_live/index.ex b/lib/decentralised_book_index_web/live/author_live/index.ex
index f3bc94c..442dad4 100644
--- a/lib/decentralised_book_index_web/live/author_live/index.ex
+++ b/lib/decentralised_book_index_web/live/author_live/index.ex
@@ -14,6 +14,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
search_query={@search_query}
select_options={@select_options}
selected_option={@sort_by}
+ current_user={@current_user}
/>
<.table
@@ -58,7 +59,10 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
<% else %>
<%= for author <- @page.results do %>
- <.author_card author={author} />
+ <.author_card
+ author={author}
+ current_user={@current_user}
+ />
<% end %>
diff --git a/lib/decentralised_book_index_web/live/author_live/show.ex b/lib/decentralised_book_index_web/live/author_live/show.ex
index 6d06f14..a84abda 100644
--- a/lib/decentralised_book_index_web/live/author_live/show.ex
+++ b/lib/decentralised_book_index_web/live/author_live/show.ex
@@ -1,6 +1,8 @@
defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
use DecentralisedBookIndexWeb, :live_view
+ alias DecentralisedBookIndex.Accounts.Role
+
@impl true
def render(assigns) do
~H"""
@@ -8,11 +10,13 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
{@author.name}
<:actions>
- <.link navigate={~p"/authors/#{@author}/edit"}>
- <.edit_button>
- Edit
-
-
+ <%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
+ <.link navigate={~p"/authors/#{@author}/edit"}>
+ <.edit_button>
+ Edit
+
+
+ <% end %>
diff --git a/lib/decentralised_book_index_web/live/book_live/index.ex b/lib/decentralised_book_index_web/live/book_live/index.ex
index 2a9f102..5bcdfa8 100644
--- a/lib/decentralised_book_index_web/live/book_live/index.ex
+++ b/lib/decentralised_book_index_web/live/book_live/index.ex
@@ -16,6 +16,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
search_mode_options={@search_mode_options}
select_options={@select_options}
selected_option={@sort_by}
+ current_user={@current_user}
/>
<.table
@@ -68,7 +69,10 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
<% else %>
<%= for book <- @page.results do %>
- <.book_card book={book} />
+ <.book_card
+ book={book}
+ current_user={@current_user}
+ />
<% end %>
diff --git a/lib/decentralised_book_index_web/live/book_live/show.ex b/lib/decentralised_book_index_web/live/book_live/show.ex
index 1fedbf0..dd35ad1 100644
--- a/lib/decentralised_book_index_web/live/book_live/show.ex
+++ b/lib/decentralised_book_index_web/live/book_live/show.ex
@@ -2,6 +2,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
use DecentralisedBookIndexWeb, :live_view
alias DecentralisedBookIndex.Metadata
+ alias DecentralisedBookIndex.Accounts.Role
@impl true
def render(assigns) do
@@ -11,11 +12,13 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
<:subtitle>{@authors_string}
<:actions>
- <.link patch={~p"/books/#{@book}/edit"}>
- <.edit_button>
- Edit
-
-
+ <%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
+ <.link patch={~p"/books/#{@book}/edit"}>
+ <.edit_button>
+ Edit
+
+
+ <% end %>