mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
show hidden links on tag page, hidden status on profile page
This commit is contained in:
parent
210aff26ab
commit
7503e48591
8 changed files with 33 additions and 10 deletions
|
@ -48,6 +48,7 @@ defmodule Philomena.Tags.Tag do
|
||||||
many_to_many :implied_tags, Tag, join_through: "tags_implied_tags", join_keys: [tag_id: :id, implied_tag_id: :id], on_replace: :delete
|
many_to_many :implied_tags, Tag, join_through: "tags_implied_tags", join_keys: [tag_id: :id, implied_tag_id: :id], on_replace: :delete
|
||||||
many_to_many :implied_by_tags, Tag, join_through: "tags_implied_tags", join_keys: [implied_tag_id: :id, tag_id: :id]
|
many_to_many :implied_by_tags, Tag, join_through: "tags_implied_tags", join_keys: [implied_tag_id: :id, tag_id: :id]
|
||||||
has_many :public_links, UserLink, where: [public: true, aasm_state: "verified"]
|
has_many :public_links, UserLink, where: [public: true, aasm_state: "verified"]
|
||||||
|
has_many :hidden_links, UserLink, where: [public: false, aasm_state: "verified"]
|
||||||
has_many :dnp_entries, DnpEntry, where: [aasm_state: "listed"]
|
has_many :dnp_entries, DnpEntry, where: [aasm_state: "listed"]
|
||||||
|
|
||||||
field :slug, :string
|
field :slug, :string
|
||||||
|
|
|
@ -91,8 +91,8 @@ defmodule Philomena.UserLinks do
|
||||||
|> Multi.run(:add_award, fn repo, _changes ->
|
|> Multi.run(:add_award, fn repo, _changes ->
|
||||||
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
||||||
|
|
||||||
with badge when not is_nil(badge) <- repo.get_by(Badge, title: "Artist"),
|
with badge when not is_nil(badge) <- repo.get_by(limit(Badge, 1), title: "Artist"),
|
||||||
nil <- repo.get_by(Award, badge_id: badge.id, user_id: user_link.user_id)
|
nil <- repo.get_by(limit(Award, 1), badge_id: badge.id, user_id: user_link.user_id)
|
||||||
do
|
do
|
||||||
%Award{badge_id: badge.id, user_id: user_link.user_id, awarded_by_id: user.id, awarded_on: now}
|
%Award{badge_id: badge.id, user_id: user_link.user_id, awarded_by_id: user.id, awarded_on: now}
|
||||||
|> Award.changeset(%{})
|
|> Award.changeset(%{})
|
||||||
|
|
|
@ -9,7 +9,9 @@ defmodule PhilomenaWeb.TagController do
|
||||||
|
|
||||||
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
||||||
plug PhilomenaWeb.CanaryMapPlug, update: :edit
|
plug PhilomenaWeb.CanaryMapPlug, update: :edit
|
||||||
plug :load_and_authorize_resource, model: Tag, id_field: "slug", only: [:show, :edit, :update, :delete], preload: [:aliases, :aliased_tag, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user]
|
plug :load_and_authorize_resource, model: Tag, id_field: "slug", only: [:show, :edit, :update, :delete], preload: [
|
||||||
|
:aliases, :aliased_tag, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user, hidden_links: :user
|
||||||
|
]
|
||||||
plug :redirect_alias when action in [:show]
|
plug :redirect_alias when action in [:show]
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
|
|
|
@ -111,7 +111,7 @@ defmodule PhilomenaWeb.ImageLoader do
|
||||||
Tag
|
Tag
|
||||||
|> join(:left, [t], at in Tag, on: t.id == at.aliased_tag_id)
|
|> join(:left, [t], at in Tag, on: t.id == at.aliased_tag_id)
|
||||||
|> where([t, at], t.name in ^tags or at.name in ^tags)
|
|> where([t, at], t.name in ^tags or at.name in ^tags)
|
||||||
|> preload([:aliases, :aliased_tag, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user])
|
|> preload([:aliases, :aliased_tag, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user, hidden_links: :user])
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.uniq_by(& &1.id)
|
|> Enum.uniq_by(& &1.id)
|
||||||
|> Enum.filter(&is_nil(&1.aliased_tag))
|
|> Enum.filter(&is_nil(&1.aliased_tag))
|
||||||
|
|
|
@ -76,6 +76,11 @@
|
||||||
|
|
||||||
= if manages_links?(@conn, @user) do
|
= if manages_links?(@conn, @user) do
|
||||||
br
|
br
|
||||||
|
=> if link.public do
|
||||||
|
' Public
|
||||||
|
- else
|
||||||
|
' Hidden
|
||||||
|
' •
|
||||||
a href=Routes.profile_user_link_path(@conn, :edit, @user, link)
|
a href=Routes.profile_user_link_path(@conn, :edit, @user, link)
|
||||||
' Edit
|
' Edit
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,14 @@
|
||||||
= url_input f, :uri, class: "input input--wide", placeholder: "https://www.deviantart.com/your-name", required: true
|
= url_input f, :uri, class: "input input--wide", placeholder: "https://www.deviantart.com/your-name", required: true
|
||||||
= error_tag f, :uri
|
= error_tag f, :uri
|
||||||
|
|
||||||
.field
|
elixir:
|
||||||
=> radio_button f, :public, "true"
|
options = [
|
||||||
=> label f, :public, "Visible to everyone"
|
{"Visible to everyone", true},
|
||||||
|
{"Visible only to site staff", false}
|
||||||
|
]
|
||||||
|
|
||||||
.field
|
.field
|
||||||
=> radio_button f, :public, "false"
|
=> select f, :public, options, class: "input", autocomplete: "off"
|
||||||
=> label f, :public, "Visible only to site staff"
|
|
||||||
|
|
||||||
h4 Instructions
|
h4 Instructions
|
||||||
p
|
p
|
||||||
|
|
|
@ -37,6 +37,17 @@
|
||||||
= map_join(@tag.implied_tags, ", ", &link(&1.name, to: Routes.tag_path(@conn, :show, &1)))
|
= map_join(@tag.implied_tags, ", ", &link(&1.name, to: Routes.tag_path(@conn, :show, &1)))
|
||||||
br
|
br
|
||||||
|
|
||||||
|
= if Enum.any?(@tag.hidden_links) and manages_links?(@conn) do
|
||||||
|
strong.comment_deleted> Hidden links:
|
||||||
|
br
|
||||||
|
|
||||||
|
= for user_link <- @tag.hidden_links do
|
||||||
|
=> link user_link.user.name, to: Routes.profile_path(@conn, :show, user_link.user)
|
||||||
|
' →
|
||||||
|
=> link user_link.uri, to: user_link.uri
|
||||||
|
br
|
||||||
|
|
||||||
|
|
||||||
= if present?(@tag.public_links) or present?(@tag.implied_by_tags) or present?(@tag.description) do
|
= if present?(@tag.public_links) or present?(@tag.implied_by_tags) or present?(@tag.description) do
|
||||||
br
|
br
|
||||||
= link "Toggle detailed information", to: "#", data: [click_toggle: ".tag-info__more"]
|
= link "Toggle detailed information", to: "#", data: [click_toggle: ".tag-info__more"]
|
||||||
|
@ -54,7 +65,7 @@
|
||||||
|
|
||||||
= if Enum.any?(@tag.public_links) do
|
= if Enum.any?(@tag.public_links) do
|
||||||
strong> Associated users:
|
strong> Associated users:
|
||||||
- users = Enum.map(@tag.public_links, & &1.user) |> Enum.uniq()
|
- users = Enum.map(@tag.public_links, & &1.user) |> Enum.uniq_by(& &1.id)
|
||||||
|
|
||||||
= for user <- users do
|
= for user <- users do
|
||||||
=> link user.name, to: Routes.profile_path(@conn, :show, user)
|
=> link user.name, to: Routes.profile_path(@conn, :show, user)
|
||||||
|
|
|
@ -141,6 +141,9 @@ defmodule PhilomenaWeb.TagView do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp manages_links?(conn),
|
||||||
|
do: can?(conn, :index, Philomena.UserLinks.UserLink)
|
||||||
|
|
||||||
defp tag_url_root do
|
defp tag_url_root do
|
||||||
Application.get_env(:philomena, :tag_url_root)
|
Application.get_env(:philomena, :tag_url_root)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue