Compare commits
7
Commits
ab3d65a899
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
045faf59a4 | ||
|
|
152bee732f | ||
|
|
99188454e9 | ||
|
|
80e99b7de8 | ||
|
|
51c584056b | ||
|
|
b70b99ba51 | ||
|
|
9c7a555dae |
+15
-1
@@ -24,6 +24,20 @@ steps:
|
||||
commands:
|
||||
- mix test
|
||||
|
||||
- name: build the image
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
username: kklochko
|
||||
password:
|
||||
from_secret: REGISTRY_PASSWORD
|
||||
repo: git.kklochko.space/kklochko/decentralised_book_index
|
||||
registry: git.kklochko.space
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_TAG}
|
||||
when:
|
||||
event: tag
|
||||
|
||||
volumes:
|
||||
- name: mix
|
||||
temp: {}
|
||||
@@ -34,4 +48,4 @@ services:
|
||||
environment:
|
||||
POSTGRES_DB: decentralised_book_index_dev
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
|
||||
@@ -64,7 +64,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SearchResources do
|
||||
|
||||
defp can_add?(current_user, role) do
|
||||
case role do
|
||||
:admin -> current_user != nil and Role.can_moderate?(current_user.role)
|
||||
:admin -> current_user != nil and Role.can_administrate?(current_user.role)
|
||||
:moderator -> current_user != nil and Role.can_moderate?(current_user.role)
|
||||
_ -> false
|
||||
end
|
||||
|
||||
@@ -20,8 +20,6 @@ defmodule DecentralisedBookIndexWeb.Components.MyComponents.SelectedAuthor do
|
||||
|
||||
errors =
|
||||
if Phoenix.Component.used_input?(assigns.author_form), do: assigns.author_form.errors, else: []
|
||||
IO.inspect("errors")
|
||||
IO.inspect(errors)
|
||||
|
||||
assigns =
|
||||
assigns
|
||||
|
||||
@@ -106,7 +106,7 @@ defmodule DecentralisedBookIndexWeb.Components.MyPartials.Navbar do
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
<%= if @current_user != nil and Role.can_administrate?(@current_user.role) do %>
|
||||
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||
<li>
|
||||
<a
|
||||
href={~p"/servers/"}
|
||||
|
||||
@@ -158,9 +158,6 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
||||
end
|
||||
|
||||
def handle_event("select-author-alias", %{"author-alias" => author_alias_id}, socket) do
|
||||
IO.inspect("book_editions_registry_id")
|
||||
IO.inspect(author_alias_id)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> update(:form, fn form ->
|
||||
|
||||
@@ -57,6 +57,25 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
|
||||
<p class="text-gray-300 leading-relaxed">
|
||||
{@author.description}
|
||||
</p>
|
||||
|
||||
<%= if not is_nil(@author.dbi_server) do %>
|
||||
<dl>
|
||||
<dt class="mt-4 mb-2 font-semibold leading-none text-gray-900 dark:text-white">
|
||||
From Server
|
||||
</dt>
|
||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||
<.link navigate={~p"/servers/#{@author.dbi_server.id}/"} class="hover:underline">
|
||||
{@author.dbi_server.name}
|
||||
</.link>
|
||||
<% else %>
|
||||
<.link navigate={@author.dbi_server.url} class="hover:underline">
|
||||
{@author.dbi_server.name}
|
||||
</.link>
|
||||
<% end %>
|
||||
</dd>
|
||||
</dl>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -74,6 +74,22 @@ defmodule DecentralisedBookIndexWeb.BookLive.Show do
|
||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{bid.type}: {bid.bid}</dd>
|
||||
<% end %>
|
||||
</dl>
|
||||
<%= if not is_nil(@book.dbi_server) do %>
|
||||
<dl>
|
||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">From Server</dt>
|
||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||
<.link navigate={~p"/servers/#{@book.dbi_server.id}/"} class="hover:underline">
|
||||
{@book.dbi_server.name}
|
||||
</.link>
|
||||
<% else %>
|
||||
<.link navigate={@book.dbi_server.url} class="hover:underline">
|
||||
{@book.dbi_server.name}
|
||||
</.link>
|
||||
<% end %>
|
||||
</dd>
|
||||
</dl>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= if not Enum.empty?(@alternative_editions) do %>
|
||||
|
||||
@@ -61,7 +61,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.FormComponent do
|
||||
socket =
|
||||
socket
|
||||
|> 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}
|
||||
|
||||
|
||||
@@ -4,26 +4,30 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
||||
alias DecentralisedBookIndex.Metadata
|
||||
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
||||
|
||||
alias DecentralisedBookIndex.Accounts.Role
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.header>
|
||||
Listing Servers
|
||||
<: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">
|
||||
<.primary_button phx-click="sync">
|
||||
Sync now
|
||||
</.primary_button>
|
||||
</div>
|
||||
<div class="flex flex-row gap-2">
|
||||
<.link patch={~p"/oban"}>
|
||||
<.primary_button>
|
||||
Task dashboard
|
||||
<div class="flex flex-row gap-2">
|
||||
<.primary_button phx-click="sync">
|
||||
Sync now
|
||||
</.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>
|
||||
<% end %>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
@@ -63,7 +67,9 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
||||
<.link navigate={~p"/servers/#{dbi_server}"}>Show</.link>
|
||||
</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>
|
||||
</.table>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
||||
use DecentralisedBookIndexWeb, :live_view
|
||||
|
||||
alias DecentralisedBookIndex.Accounts.Role
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
@@ -8,7 +10,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
||||
{@dbi_server.name}
|
||||
|
||||
<: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()}>
|
||||
<.edit_button>
|
||||
Edit
|
||||
@@ -18,7 +20,6 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
|
||||
<div>
|
||||
<dl>
|
||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Url</dt>
|
||||
@@ -28,6 +29,16 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Show do
|
||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Sync on?</dt>
|
||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{@dbi_server.sync_on?}</dd>
|
||||
</dl>
|
||||
<%= if not is_nil(@dbi_server.dbi_server) do %>
|
||||
<dl>
|
||||
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">From Server</dt>
|
||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||
<.link navigate={~p"/servers/#{@dbi_server.dbi_server.id}/"} class="hover:underline">
|
||||
{@dbi_server.dbi_server.name}
|
||||
</.link>
|
||||
</dd>
|
||||
</dl>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<.back navigate={~p"/servers"}>Back to servers</.back>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
defmodule DecentralisedBookIndexWeb.PublisherLive.Show do
|
||||
use DecentralisedBookIndexWeb, :live_view
|
||||
|
||||
alias DecentralisedBookIndex.Accounts.Role
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
@@ -18,6 +20,27 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Show do
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<%= if not is_nil(@publisher.dbi_server) do %>
|
||||
<div>
|
||||
<dl>
|
||||
<dt class="mt-4 mb-2 font-semibold leading-none text-gray-900 dark:text-white">
|
||||
From Server
|
||||
</dt>
|
||||
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
|
||||
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
|
||||
<.link navigate={~p"/servers/#{@publisher.dbi_server.id}/"} class="hover:underline">
|
||||
{@publisher.dbi_server.name}
|
||||
</.link>
|
||||
<% else %>
|
||||
<.link navigate={@publisher.dbi_server.url} class="hover:underline">
|
||||
{@publisher.dbi_server.name}
|
||||
</.link>
|
||||
<% end %>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<.back navigate={~p"/publishers"}>Back to publishers</.back>
|
||||
"""
|
||||
end
|
||||
|
||||
@@ -41,6 +41,18 @@ defmodule DecentralisedBookIndexWeb.Router do
|
||||
scope "/", DecentralisedBookIndexWeb do
|
||||
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,
|
||||
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
|
||||
live "/books/new", BookLive.Edit, :new
|
||||
@@ -56,19 +68,9 @@ defmodule DecentralisedBookIndexWeb.Router do
|
||||
live "/publishers/:id/edit", PublisherLive.Edit, :edit
|
||||
|
||||
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/new", DbiServerLive.Edit, :new
|
||||
live "/servers/:id/edit", DbiServerLive.Edit, :edit
|
||||
|
||||
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 :maybe_authenticated_routes,
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule DecentralisedBookIndex.MixProject do
|
||||
def project do
|
||||
[
|
||||
app: :decentralised_book_index,
|
||||
version: "0.1.0",
|
||||
version: "1.0.0",
|
||||
elixir: "~> 1.14",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
start_permanent: Mix.env() == :prod,
|
||||
|
||||
@@ -303,12 +303,11 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
||||
end
|
||||
|
||||
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,
|
||||
user: user,
|
||||
moderator: moderator
|
||||
user: user
|
||||
} do
|
||||
for user <- [nil, user, moderator] do
|
||||
for user <- [nil, user] do
|
||||
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
||||
conn
|
||||
|> log_in_user(user)
|
||||
@@ -316,8 +315,12 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "can be accessed by admin", %{conn: conn, admin: admin} do
|
||||
for user <- [admin] do
|
||||
test "can be accessed by moderator and admin", %{
|
||||
conn: conn,
|
||||
moderator: moderator,
|
||||
admin: admin
|
||||
} do
|
||||
for user <- [moderator, admin] do
|
||||
assert {:ok, _view, html} =
|
||||
conn
|
||||
|> log_in_user(user)
|
||||
@@ -333,13 +336,12 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
||||
%{server: generate(dbi_server())}
|
||||
end
|
||||
|
||||
test "can't be accessed by non-admin user", %{
|
||||
test "can't be accessed by non-moderator user", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
moderator: moderator,
|
||||
server: server
|
||||
} do
|
||||
for user <- [nil, user, moderator] do
|
||||
for user <- [nil, user] do
|
||||
assert {:error, {:redirect, %{flash: %{"error" => "Unauthorized!"}, to: "/"}}} =
|
||||
conn
|
||||
|> log_in_user(user)
|
||||
@@ -347,8 +349,13 @@ defmodule DecentralisedBookIndexWeb.LiveViewsPermissionsTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "can be accessed by admin", %{conn: conn, admin: admin, server: server} do
|
||||
for user <- [admin] do
|
||||
test "can be accessed by admin", %{
|
||||
conn: conn,
|
||||
moderator: moderator,
|
||||
admin: admin,
|
||||
server: server
|
||||
} do
|
||||
for user <- [moderator, admin] do
|
||||
{:ok, _view, html} =
|
||||
conn
|
||||
|> log_in_user(user)
|
||||
|
||||
Reference in New Issue
Block a user