show hidden links on tag page, hidden status on profile page

This commit is contained in:
byte[] 2019-12-30 18:56:29 -05:00
parent 210aff26ab
commit 7503e48591
8 changed files with 33 additions and 10 deletions

View file

@ -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_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 :hidden_links, UserLink, where: [public: false, aasm_state: "verified"]
has_many :dnp_entries, DnpEntry, where: [aasm_state: "listed"]
field :slug, :string

View file

@ -91,8 +91,8 @@ defmodule Philomena.UserLinks do
|> Multi.run(:add_award, fn repo, _changes ->
now = DateTime.utc_now() |> DateTime.truncate(:second)
with badge when not is_nil(badge) <- repo.get_by(Badge, title: "Artist"),
nil <- repo.get_by(Award, badge_id: badge.id, user_id: user_link.user_id)
with badge when not is_nil(badge) <- repo.get_by(limit(Badge, 1), title: "Artist"),
nil <- repo.get_by(limit(Award, 1), badge_id: badge.id, user_id: user_link.user_id)
do
%Award{badge_id: badge.id, user_id: user_link.user_id, awarded_by_id: user.id, awarded_on: now}
|> Award.changeset(%{})

View file

@ -9,7 +9,9 @@ defmodule PhilomenaWeb.TagController do
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
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]
def index(conn, params) do

View file

@ -111,7 +111,7 @@ defmodule PhilomenaWeb.ImageLoader do
Tag
|> 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)
|> 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()
|> Enum.uniq_by(& &1.id)
|> Enum.filter(&is_nil(&1.aliased_tag))

View file

@ -76,6 +76,11 @@
= if manages_links?(@conn, @user) do
br
=> if link.public do
' Public
- else
' Hidden
' &bull;
a href=Routes.profile_user_link_path(@conn, :edit, @user, link)
' Edit

View file

@ -23,13 +23,14 @@
= url_input f, :uri, class: "input input--wide", placeholder: "https://www.deviantart.com/your-name", required: true
= error_tag f, :uri
.field
=> radio_button f, :public, "true"
=> label f, :public, "Visible to everyone"
elixir:
options = [
{"Visible to everyone", true},
{"Visible only to site staff", false}
]
.field
=> radio_button f, :public, "false"
=> label f, :public, "Visible only to site staff"
=> select f, :public, options, class: "input", autocomplete: "off"
h4 Instructions
p

View file

@ -37,6 +37,17 @@
= map_join(@tag.implied_tags, ", ", &link(&1.name, to: Routes.tag_path(@conn, :show, &1)))
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)
' &rarr;
=> 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
br
= link "Toggle detailed information", to: "#", data: [click_toggle: ".tag-info__more"]
@ -54,7 +65,7 @@
= if Enum.any?(@tag.public_links) do
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
=> link user.name, to: Routes.profile_path(@conn, :show, user)

View file

@ -141,6 +141,9 @@ defmodule PhilomenaWeb.TagView do
)
end
defp manages_links?(conn),
do: can?(conn, :index, Philomena.UserLinks.UserLink)
defp tag_url_root do
Application.get_env(:philomena, :tag_url_root)
end