mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
various filters fixes
This commit is contained in:
parent
b7ee2f9c50
commit
d2916e2a9b
8 changed files with 39 additions and 15 deletions
|
@ -101,7 +101,9 @@ defmodule Philomena.Filters do
|
|||
|
||||
"""
|
||||
def delete_filter(%Filter{} = filter) do
|
||||
Repo.delete(filter)
|
||||
filter
|
||||
|> Filter.deletion_changeset()
|
||||
|> Repo.delete()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -132,6 +134,9 @@ defmodule Philomena.Filters do
|
|||
|
||||
union(recent_filters, ^user_filters)
|
||||
|> Repo.all()
|
||||
|> Enum.sort_by(fn f ->
|
||||
Enum.find_index(user.recent_filter_ids, fn id -> f.id == id end)
|
||||
end)
|
||||
|> Enum.group_by(
|
||||
fn
|
||||
%{recent: "t"} -> "Recent Filters"
|
||||
|
|
|
@ -45,6 +45,12 @@ defmodule Philomena.Filters.Filter do
|
|||
|> unsafe_validate_unique([:user_id, :name], Repo)
|
||||
end
|
||||
|
||||
def deletion_changeset(filter) do
|
||||
filter
|
||||
|> change()
|
||||
|> foreign_key_constraint(:id, name: :fk_rails_d2b4c2768f)
|
||||
end
|
||||
|
||||
def hidden_tags_changeset(filter, hidden_tag_ids) do
|
||||
change(filter, hidden_tag_ids: hidden_tag_ids)
|
||||
end
|
||||
|
|
|
@ -196,13 +196,14 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
|
|||
def can?(%User{id: id}, :show, %Conversation{to_id: id}), do: true
|
||||
def can?(%User{id: id}, :show, %Conversation{from_id: id}), do: true
|
||||
|
||||
# View filters they own and system filters
|
||||
# View filters they own and public/system filters
|
||||
def can?(_user, :show, %Filter{system: true}), do: true
|
||||
def can?(_user, :show, %Filter{public: true}), do: true
|
||||
def can?(%User{}, action, Filter) when action in [:index, :new, :create], do: true
|
||||
def can?(%User{id: id}, action, %Filter{user_id: id}) when action in [:show, :edit, :update], do: true
|
||||
|
||||
# Edit filters they own
|
||||
def can?(%User{id: id}, action, %Filter{user_id: id}) when action in [:edit, :update], do: true
|
||||
def can?(%User{id: id}, action, %Filter{user_id: id}) when action in [:edit, :update, :delete], do: true
|
||||
|
||||
# View user links they've created
|
||||
def can?(%User{id: id}, :create_links, %User{id: id}), do: true
|
||||
|
|
|
@ -35,8 +35,7 @@ defmodule PhilomenaWeb.CommentController do
|
|||
)
|
||||
|
||||
rendered =
|
||||
comments.entries
|
||||
|> Renderer.render_collection(conn)
|
||||
Renderer.render_collection(comments.entries, conn)
|
||||
|
||||
comments =
|
||||
%{comments | entries: Enum.zip(rendered, comments.entries)}
|
||||
|
|
|
@ -94,10 +94,16 @@ defmodule PhilomenaWeb.FilterController do
|
|||
def delete(conn, _params) do
|
||||
filter = conn.assigns.filter
|
||||
|
||||
{:ok, _filter} = Filters.delete_filter(filter)
|
||||
case Filters.delete_filter(filter) do
|
||||
{:ok, _filter} ->
|
||||
conn
|
||||
|> put_flash(:info, "Filter deleted successfully.")
|
||||
|> redirect(to: Routes.filter_path(conn, :index))
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Filter deleted successfully.")
|
||||
|> redirect(to: Routes.filter_path(conn, :index))
|
||||
_error ->
|
||||
conn
|
||||
|> put_flash(:error, "Filter is still in use, not deleted.")
|
||||
|> redirect(to: Routes.filter_path(conn, :show, filter))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
p
|
||||
' Maintained by
|
||||
= render PhilomenaWeb.UserAttributionView, "_user.html", object: @filter, conn: @conn
|
||||
' .
|
||||
|
||||
= if @filter.system do
|
||||
p
|
||||
' Maintained by staff
|
||||
|
||||
.filter-options
|
||||
ul
|
||||
|
@ -17,7 +20,11 @@
|
|||
= length(@filter.hidden_tag_ids)
|
||||
|
||||
li
|
||||
= link("View this filter", to: Routes.filter_path(@conn, :show, @filter), class: "button")
|
||||
= link "View this filter", to: Routes.filter_path(@conn, :show, @filter), class: "button"
|
||||
|
||||
= if can?(@conn, :edit, @filter) do
|
||||
li
|
||||
= link "Edit this filter", to: Routes.filter_path(@conn, :edit, @filter), class: "button"
|
||||
|
||||
= if @filter.id == @conn.assigns.current_filter.id do
|
||||
li
|
||||
|
|
|
@ -22,10 +22,10 @@ h1
|
|||
|
||||
= if can?(@conn, :edit, @filter) do
|
||||
li
|
||||
= link("Edit this filter", to: Routes.filter_path(@conn, :edit, @filter))
|
||||
= link "Edit this filter", to: Routes.filter_path(@conn, :edit, @filter), class: "button"
|
||||
|
||||
= if can?(@conn, :delete, @filter) do
|
||||
= button_to "Destroy this filter", Routes.filter_path(@conn, :delete, @filter), method: "delete", class: "button", data: [confirm: "Are you sure?"]
|
||||
= button_to "Destroy this filter", Routes.filter_path(@conn, :delete, @filter), method: "delete", class: "button", data: [confirm: "Are you really, really sure?"]
|
||||
|
||||
= if @filter.user do
|
||||
p.filter-maintainer
|
||||
|
|
|
@ -8,7 +8,7 @@ h1 Sign in
|
|||
p = link "Forgot your password?", to: Routes.pow_reset_password_reset_password_path(@conn, :new)
|
||||
|
||||
.field
|
||||
= text_input f, :email, class: "input", required: true, placeholder: "Email"
|
||||
= text_input f, :email, class: "input", required: true, placeholder: "Email", autofocus: true
|
||||
= error_tag f, :email
|
||||
|
||||
.field
|
||||
|
@ -25,4 +25,4 @@ p
|
|||
strong
|
||||
' Haven't read the
|
||||
a<> href="/pages/rules" site rules
|
||||
' lately? Make sure you read them before posting or editing metadata!
|
||||
' lately? Make sure you read them before posting or editing metadata!
|
||||
|
|
Loading…
Reference in a new issue