fixes #109: add ability to delete channels

This commit is contained in:
byte[] 2020-05-02 12:27:50 -04:00
parent 7cfb390e05
commit a97006fd9c
3 changed files with 13 additions and 2 deletions

View file

@ -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}%"

View file

@ -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

View file

@ -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