Skip to content

Commit

Permalink
delete project with info throwing and real delete
Browse files Browse the repository at this point in the history
  • Loading branch information
the-last-pastafarian committed Dec 4, 2023
1 parent bb406a9 commit 850fe62
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
15 changes: 3 additions & 12 deletions server/lib/field_hub_web/controllers/api/project_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,8 @@ defmodule FieldHubWeb.Api.ProjectController do
end
end

def delete(conn, %{"project" => id}) do
project = Project.delete(id)
user = User.delete(id)

response_payload = %{
status_project: project,
status_user: user
}

conn
|> put_view(StatusView)
|> render(%{info: response_payload})
def delete(_conn, %{"project" => id}) do
Project.delete(id)
User.delete(id)
end
end
49 changes: 27 additions & 22 deletions server/lib/field_hub_web/live/project_show_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule FieldHubWeb.ProjectShowLive do
# alias FieldHubWeb.Api.ProjectController
alias FieldHubWeb.Api.ProjectController

alias FieldHubWeb.{
Router.Helpers,
UserAuth,
Expand Down Expand Up @@ -43,7 +46,7 @@ defmodule FieldHubWeb.ProjectShowLive do
|> assign(:current_user, user_name)
|> assign(:new_password, "")
|> assign(:deletion_dialog_started, false)
|> assign(:confirm_project_name,"")
|> assign(:confirm_project_name, "")
|> read_project_doc()
}

Expand Down Expand Up @@ -115,38 +118,40 @@ defmodule FieldHubWeb.ProjectShowLive do
end

def handle_event("display_delete_dialogue", _values, socket) do
{:noreply,assign(socket,:deletion_dialog_started, true)}
{:noreply, assign(socket, :deletion_dialog_started, true)}
end

# def handle_event("display_delete_dialogue", _values, socket) do
# if %{"confirm_project_name" => confirm_project_name} =_values do
# assign(socket, :confirm_project_name, confirm_project_name)
# end
# {:noreply,assign(socket,:deletion_dialog_started, true)}
# end

def handle_event("delete", %{"confirm_project_name" => confirm_project_name} = _values, socket) do
# def handle_event("update", %{"confirm_project_name" => confirm_project_name} = _values, socket) do
{:noreply, assign(socket, :confirm_project_name, confirm_project_name)}
end

def handle_event(
"delete_the_project",
_values,
%{assigns: %{project: project, current_user: user_name}} = socket
) do
socket =
case User.is_admin?(user_name) do
true ->
ProjectController.delete(socket, %{"project" => project})
{:ok, "Project `#{project}` has been deleted successfully."}

def handle_event("delete_the_project", _values, socket) do

identifier = socket.assigns.stats.name
CouchService.delete_database(identifier)

socket = put_flash(
socket,
:info,
"Project `#{identifier}` has been deleted successfully."
)
false ->
{:error, "You are not authorized to delete the project."}
end
|> case do
{:ok, msg} ->
socket
|> put_flash(:info, msg)

{:noreply,redirect(socket, to: "/")}
{:error, msg} ->
socket
|> put_flash(:error, msg)
end

{:noreply, redirect(socket, to: "/")}
end


def handle_event("generate_password", _values, socket) do
{:noreply, assign(socket, :new_password, CouchService.create_password())}
end
Expand Down

0 comments on commit 850fe62

Please sign in to comment.