From a97006fd9c54a2150cb711783c633c09295fe198 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 2 May 2020 12:27:50 -0400 Subject: [PATCH] fixes #109: add ability to delete channels --- lib/philomena_web/controllers/channel_controller.ex | 10 +++++++++- lib/philomena_web/router.ex | 2 +- .../templates/channel/_channel_box.html.slime | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/philomena_web/controllers/channel_controller.ex b/lib/philomena_web/controllers/channel_controller.ex index c99e49ae..7881b19b 100644 --- a/lib/philomena_web/controllers/channel_controller.ex +++ b/lib/philomena_web/controllers/channel_controller.ex @@ -6,7 +6,7 @@ defmodule PhilomenaWeb.ChannelController do alias Philomena.Repo import Ecto.Query - plug :load_and_authorize_resource, model: Channel, only: [:show, :new, :create, :edit, :update] + plug :load_and_authorize_resource, model: Channel, only: [:show, :new, :create, :edit, :update, :delete] def index(conn, params) do show_nsfw? = conn.cookies["chan_nsfw"] == "true" @@ -74,6 +74,14 @@ defmodule PhilomenaWeb.ChannelController do end end + def delete(conn, _params) do + {:ok, _channel} = Channels.delete_channel(conn.assigns.channel) + + conn + |> put_flash(:info, "Channel destroyed successfully.") + |> redirect(to: Routes.channel_path(conn, :index)) + end + defp maybe_search(query, %{"cq" => cq}) when is_binary(cq) and cq != "" do title_query = "#{cq}%" tag_query = "%#{cq}%" diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 1437b1c5..7d4fe2cc 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -393,7 +393,7 @@ defmodule PhilomenaWeb.Router do singleton: true resources "/pages", PageController, only: [:index, :new, :create, :edit, :update] - resources "/channels", ChannelController, only: [:new, :create, :edit, :update] + resources "/channels", ChannelController, only: [:new, :create, :edit, :update, :delete] end scope "/", PhilomenaWeb do diff --git a/lib/philomena_web/templates/channel/_channel_box.html.slime b/lib/philomena_web/templates/channel/_channel_box.html.slime index 2b44e794..8ca76dee 100644 --- a/lib/philomena_web/templates/channel/_channel_box.html.slime +++ b/lib/philomena_web/templates/channel/_channel_box.html.slime @@ -32,5 +32,8 @@ a href=Routes.channel_path(@conn, :edit, @channel) class=link_class i.fas.fa-fw.fa-edit> ' Edit + a href=Routes.channel_path(@conn, :delete, @channel) class=link_class data-method="delete" data-confirm="Are you really, really sure?" + i.fas.fa-fw.fa-trash> + ' Delete = render PhilomenaWeb.Channel.SubscriptionView, "_subscription.html", conn: @conn, watching: @subscriptions[@channel.id], channel: @channel