refactor: improve groups LiveView based on code review feedback
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3eb4cde0b7
commit
ddc8335cc0
8 changed files with 109 additions and 104 deletions
|
|
@ -186,7 +186,7 @@ defmodule MvWeb.GroupLive.Show do
|
|||
<div class="p-2 mb-2 font-mono text-lg font-bold break-all rounded bg-base-200">
|
||||
{@group.name}
|
||||
</div>
|
||||
<form phx-change="update_name_confirmation">
|
||||
<form phx-change="update_name_confirmation" phx-debounce="200">
|
||||
<input
|
||||
id="group-name-confirmation"
|
||||
name="name"
|
||||
|
|
@ -244,21 +244,29 @@ defmodule MvWeb.GroupLive.Show do
|
|||
def handle_event("confirm_delete", %{"slug" => slug}, socket) do
|
||||
actor = current_actor(socket)
|
||||
|
||||
case Membership.get_group_by_slug(slug, actor: actor) do
|
||||
{:ok, nil} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Group not found."))
|
||||
|> redirect(to: ~p"/groups")}
|
||||
# Server-side authorization check to prevent unauthorized delete attempts
|
||||
if can?(actor, :destroy, Mv.Membership.Group) do
|
||||
case Membership.get_group_by_slug(slug, actor: actor, load: []) do
|
||||
{:ok, nil} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Group not found."))
|
||||
|> redirect(to: ~p"/groups")}
|
||||
|
||||
{:ok, group} ->
|
||||
handle_delete_confirmation(socket, group, actor)
|
||||
{:ok, group} ->
|
||||
handle_delete_confirmation(socket, group, actor)
|
||||
|
||||
{:error, _error} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Failed to load group."))
|
||||
|> redirect(to: ~p"/groups")}
|
||||
{:error, _error} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Failed to load group."))
|
||||
|> redirect(to: ~p"/groups")}
|
||||
end
|
||||
else
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Not authorized."))
|
||||
|> redirect(to: ~p"/groups")}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -269,8 +277,7 @@ defmodule MvWeb.GroupLive.Show do
|
|||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Group name does not match."))
|
||||
|> assign(:show_delete_modal, false)
|
||||
|> assign(:name_confirmation, "")}
|
||||
|> assign(:show_delete_modal, true)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue