mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
fixes #76: filter public conversion route
This commit is contained in:
parent
a97006fd9c
commit
d03c1d7e5b
5 changed files with 57 additions and 2 deletions
|
@ -88,6 +88,12 @@ defmodule Philomena.Filters do
|
|||
|> Repo.update()
|
||||
end
|
||||
|
||||
def make_filter_public(%Filter{} = filter) do
|
||||
filter
|
||||
|> Filter.public_changeset()
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a Filter.
|
||||
|
||||
|
|
|
@ -68,6 +68,10 @@ defmodule Philomena.Filters.Filter do
|
|||
|> foreign_key_constraint(:id, name: :fk_rails_d2b4c2768f)
|
||||
end
|
||||
|
||||
def public_changeset(filter) do
|
||||
change(filter, public: true)
|
||||
end
|
||||
|
||||
def hidden_tags_changeset(filter, hidden_tag_ids) do
|
||||
change(filter, hidden_tag_ids: hidden_tag_ids)
|
||||
end
|
||||
|
|
23
lib/philomena_web/controllers/filter/public_controller.ex
Normal file
23
lib/philomena_web/controllers/filter/public_controller.ex
Normal file
|
@ -0,0 +1,23 @@
|
|||
defmodule PhilomenaWeb.Filter.PublicController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Filters
|
||||
alias Philomena.Filters.Filter
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :edit
|
||||
plug :load_and_authorize_resource, model: Filter, id_name: "filter_id", persisted: true
|
||||
|
||||
def create(conn, _params) do
|
||||
case Filters.make_filter_public(conn.assigns.filter) do
|
||||
{:ok, filter} ->
|
||||
conn
|
||||
|> put_flash(:info, "Successfully made filter public.")
|
||||
|> redirect(to: Routes.filter_path(conn, :show, filter))
|
||||
|
||||
_error ->
|
||||
conn
|
||||
|> put_flash(:error, "Couldn't make filter public!")
|
||||
|> redirect(to: Routes.filter_path(conn, :show, conn.assigns.filter))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -457,7 +457,9 @@ defmodule PhilomenaWeb.Router do
|
|||
resources "/current", CurrentController, only: [:update], singleton: true
|
||||
end
|
||||
|
||||
resources "/filters", FilterController
|
||||
resources "/filters", FilterController do
|
||||
resources "/public", Filter.PublicController, only: [:create], singleton: true
|
||||
end
|
||||
|
||||
resources "/profiles", ProfileController, only: [:show] do
|
||||
resources "/reports", Profile.ReportController, only: [:new, :create]
|
||||
|
|
|
@ -1,2 +1,22 @@
|
|||
h2 Editing Filter
|
||||
= render PhilomenaWeb.FilterView, "_form.html", filter: @changeset, route: Routes.filter_path(@conn, :update, @filter)
|
||||
|
||||
= if not @filter.public and not @filter.system do
|
||||
br
|
||||
br
|
||||
|
||||
input.toggle-box id="public-tools" type="checkbox" checked=false
|
||||
label for="public-tools" Advanced Options
|
||||
.toggle-box-container
|
||||
.toggle-box-container__content
|
||||
p
|
||||
' This filter is currently private and only accessible to you. If you
|
||||
' click the button below, this will make the filter public and
|
||||
' accessible to other users.
|
||||
|
||||
p
|
||||
' This process is
|
||||
strong irreversible
|
||||
' . Once you make a filter public, you cannot make it private again.
|
||||
|
||||
= button_to "Convert to Public Filter", Routes.filter_public_path(@conn, :create, @filter), class: "button", method: "create", data: [confirm: "Are you really, really sure?"]
|
||||
|
|
Loading…
Reference in a new issue