Update the navbar and routes to check the User's role.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,6 +4,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyPartials.Navbar do
|
|||||||
|
|
||||||
import DecentralisedBookIndexWeb.Components.MyComponents.Buttons
|
import DecentralisedBookIndexWeb.Components.MyComponents.Buttons
|
||||||
alias Phoenix.LiveView.JS
|
alias Phoenix.LiveView.JS
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
attr :page_title, :string, required: true
|
attr :page_title, :string, required: true
|
||||||
attr :current_user, :map, default: nil
|
attr :current_user, :map, default: nil
|
||||||
@@ -28,10 +29,12 @@ defmodule DecentralisedBookIndexWeb.Components.MyPartials.Navbar do
|
|||||||
<li>
|
<li>
|
||||||
<a href={~p"/authors/"} class={selected_navbar_link_css(@page_title, "Listing Authors")} aria-current="page">Authors</a>
|
<a href={~p"/authors/"} class={selected_navbar_link_css(@page_title, "Listing Authors")} aria-current="page">Authors</a>
|
||||||
</li>
|
</li>
|
||||||
<%= if @current_user != nil do %>
|
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||||
<li>
|
<li>
|
||||||
<a href={~p"/publishers/"} class={selected_navbar_link_css(@page_title, "Listing Publishers")} aria-current="page">Publishers</a>
|
<a href={~p"/publishers/"} class={selected_navbar_link_css(@page_title, "Listing Publishers")} aria-current="page">Publishers</a>
|
||||||
</li>
|
</li>
|
||||||
|
<% end %>
|
||||||
|
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
<li>
|
<li>
|
||||||
<a href={~p"/servers/"} class={selected_navbar_link_css(@page_title, "Listing Server")} aria-current="page">Servers</a>
|
<a href={~p"/servers/"} class={selected_navbar_link_css(@page_title, "Listing Server")} aria-current="page">Servers</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ defmodule DecentralisedBookIndexWeb.Router do
|
|||||||
live "/authors/:id", AuthorLive.Show, :show
|
live "/authors/:id", AuthorLive.Show, :show
|
||||||
end
|
end
|
||||||
|
|
||||||
ash_authentication_live_session :authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :live_user_required} do
|
ash_authentication_live_session :moderator_authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
|
||||||
live "/books/new", BookLive.Edit, :new
|
live "/books/new", BookLive.Edit, :new
|
||||||
live "/books/:id/edit", BookLive.Edit, :edit
|
live "/books/:id/edit", BookLive.Edit, :edit
|
||||||
|
|
||||||
@@ -69,7 +69,9 @@ defmodule DecentralisedBookIndexWeb.Router do
|
|||||||
|
|
||||||
live "/publishers/:id", PublisherLive.Show, :show
|
live "/publishers/:id", PublisherLive.Show, :show
|
||||||
live "/publishers/:id/show/edit", PublisherLive.Show, :edit
|
live "/publishers/:id/show/edit", PublisherLive.Show, :edit
|
||||||
|
end
|
||||||
|
|
||||||
|
ash_authentication_live_session :admin_authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :admin_required} do
|
||||||
live "/servers", DbiServerLive.Index, :index
|
live "/servers", DbiServerLive.Index, :index
|
||||||
live "/servers/new", DbiServerLive.Index, :new
|
live "/servers/new", DbiServerLive.Index, :new
|
||||||
live "/servers/:id/edit", DbiServerLive.Index, :edit
|
live "/servers/:id/edit", DbiServerLive.Index, :edit
|
||||||
|
|||||||
Reference in New Issue
Block a user