Update DBIServer's Index and Show to allow moderators to read.
This commit is contained in:
@@ -61,7 +61,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.FormComponent do
|
|||||||
socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|> put_flash(:info, "Server #{socket.assigns.form.source.type}d successfully")
|
|> put_flash(:info, "Server #{socket.assigns.form.source.type}d successfully")
|
||||||
|> push_navigate(to: patch_url(socket.assigns.action, dbi_server.id))
|
|> redirect(to: patch_url(socket.assigns.action, dbi_server.id))
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,30 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
|||||||
alias DecentralisedBookIndex.Metadata
|
alias DecentralisedBookIndex.Metadata
|
||||||
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.header>
|
<.header>
|
||||||
Listing Servers
|
Listing Servers
|
||||||
<:actions>
|
<:actions>
|
||||||
<div class="flex flex-row gap-2">
|
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
<.primary_button phx-click="sync">
|
<div class="flex flex-row gap-2">
|
||||||
Sync now
|
<.primary_button phx-click="sync">
|
||||||
</.primary_button>
|
Sync now
|
||||||
</div>
|
|
||||||
<div class="flex flex-row gap-2">
|
|
||||||
<.link patch={~p"/oban"}>
|
|
||||||
<.primary_button>
|
|
||||||
Task dashboard
|
|
||||||
</.primary_button>
|
</.primary_button>
|
||||||
</.link>
|
</div>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<.link patch={~p"/oban"}>
|
||||||
|
<.primary_button>
|
||||||
|
Task dashboard
|
||||||
|
</.primary_button>
|
||||||
|
</.link>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<% end %>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
@@ -63,7 +67,9 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
|||||||
<.link navigate={~p"/servers/#{dbi_server}"}>Show</.link>
|
<.link navigate={~p"/servers/#{dbi_server}"}>Show</.link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.link patch={~p"/servers/#{dbi_server}/edit"}>Edit</.link>
|
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
|
<.link patch={~p"/servers/#{dbi_server}/edit"}>Edit</.link>
|
||||||
|
<% end %>
|
||||||
</:action>
|
</:action>
|
||||||
</.table>
|
</.table>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
||||||
use DecentralisedBookIndexWeb, :live_view
|
use DecentralisedBookIndexWeb, :live_view
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.Accounts.Role
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -8,7 +10,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
|||||||
{@dbi_server.name}
|
{@dbi_server.name}
|
||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
<%= if is_nil(@dbi_server.dbi_server) do %>
|
<%= if is_nil(@dbi_server.dbi_server) and @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||||
<.link patch={~p"/servers/#{@dbi_server}/edit"} phx-click={JS.push_focus()}>
|
<.link patch={~p"/servers/#{@dbi_server}/edit"} phx-click={JS.push_focus()}>
|
||||||
<.edit_button>
|
<.edit_button>
|
||||||
Edit
|
Edit
|
||||||
@@ -18,7 +20,6 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
|||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<dl>
|
<dl>
|
||||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Url</dt>
|
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Url</dt>
|
||||||
|
|||||||
@@ -41,6 +41,18 @@ defmodule DecentralisedBookIndexWeb.Router do
|
|||||||
scope "/", DecentralisedBookIndexWeb do
|
scope "/", DecentralisedBookIndexWeb do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
|
ash_authentication_live_session :admin_authenticated_routes,
|
||||||
|
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :admin_required} do
|
||||||
|
live "/servers/new", DbiServerLive.Edit, :new
|
||||||
|
live "/servers/:id/edit", DbiServerLive.Edit, :edit
|
||||||
|
#live "/servers", DbiServerLive.Index, :index
|
||||||
|
#live "/servers/:id", DbiServerLive.Show, :show
|
||||||
|
|
||||||
|
live "/users", UserLive.Index, :index
|
||||||
|
live "/users/:id", UserLive.Show, :show
|
||||||
|
live "/users/:id/edit", UserLive.Edit, :edit
|
||||||
|
end
|
||||||
|
|
||||||
ash_authentication_live_session :moderator_authenticated_routes,
|
ash_authentication_live_session :moderator_authenticated_routes,
|
||||||
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
|
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
|
||||||
live "/books/new", BookLive.Edit, :new
|
live "/books/new", BookLive.Edit, :new
|
||||||
@@ -56,19 +68,9 @@ defmodule DecentralisedBookIndexWeb.Router do
|
|||||||
live "/publishers/:id/edit", PublisherLive.Edit, :edit
|
live "/publishers/:id/edit", PublisherLive.Edit, :edit
|
||||||
|
|
||||||
live "/publishers/:id", PublisherLive.Show, :show
|
live "/publishers/:id", PublisherLive.Show, :show
|
||||||
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.Edit, :new
|
|
||||||
live "/servers/:id/edit", DbiServerLive.Edit, :edit
|
|
||||||
|
|
||||||
live "/servers/:id", DbiServerLive.Show, :show
|
live "/servers/:id", DbiServerLive.Show, :show
|
||||||
|
|
||||||
live "/users", UserLive.Index, :index
|
|
||||||
live "/users/:id", UserLive.Show, :show
|
|
||||||
live "/users/:id/edit", UserLive.Edit, :edit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ash_authentication_live_session :maybe_authenticated_routes,
|
ash_authentication_live_session :maybe_authenticated_routes,
|
||||||
|
|||||||
@@ -303,12 +303,11 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "Server Index /servers" do
|
describe "Server Index /servers" do
|
||||||
test "can't be accessed by regular user and moderator", %{
|
test "can't be accessed by regular user", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
user: user,
|
user: user
|
||||||
moderator: moderator
|
|
||||||
} do
|
} do
|
||||||
for user <- [nil, user, moderator] do
|
for user <- [nil, user] do
|
||||||
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
@@ -316,8 +315,12 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "can be accessed by admin", %{conn: conn, admin: admin} do
|
test "can be accessed by moderator and admin", %{
|
||||||
for user <- [admin] do
|
conn: conn,
|
||||||
|
moderator: moderator,
|
||||||
|
admin: admin
|
||||||
|
} do
|
||||||
|
for user <- [moderator, admin] do
|
||||||
assert {:ok, _view, html} =
|
assert {:ok, _view, html} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
@@ -333,13 +336,12 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
%{server: generate(dbi_server())}
|
%{server: generate(dbi_server())}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "can't be accessed by non-admin user", %{
|
test "can't be accessed by non-moderator user", %{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
user: user,
|
user: user,
|
||||||
moderator: moderator,
|
|
||||||
server: server
|
server: server
|
||||||
} do
|
} do
|
||||||
for user <- [nil, user, moderator] do
|
for user <- [nil, user] do
|
||||||
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
@@ -347,8 +349,13 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "can be accessed by admin", %{conn: conn, admin: admin, server: server} do
|
test "can be accessed by admin", %{
|
||||||
for user <- [admin] do
|
conn: conn,
|
||||||
|
moderator: moderator,
|
||||||
|
admin: admin,
|
||||||
|
server: server
|
||||||
|
} do
|
||||||
|
for user <- [moderator, admin] do
|
||||||
{:ok, _view, html} =
|
{:ok, _view, html} =
|
||||||
conn
|
conn
|
||||||
|> log_in_user(user)
|
|> log_in_user(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user