From 7503e48591ce066fe3f15fbdecf2d6601c11f7e3 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 30 Dec 2019 18:56:29 -0500 Subject: [PATCH] show hidden links on tag page, hidden status on profile page --- lib/philomena/tags/tag.ex | 1 + lib/philomena/user_links.ex | 4 ++-- lib/philomena_web/controllers/tag_controller.ex | 4 +++- lib/philomena_web/image_loader.ex | 2 +- lib/philomena_web/templates/profile/show.html.slime | 5 +++++ .../templates/profile/user_link/_form.html.slime | 11 ++++++----- .../templates/tag/_tag_info_row.html.slime | 13 ++++++++++++- lib/philomena_web/views/tag_view.ex | 3 +++ 8 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/philomena/tags/tag.ex b/lib/philomena/tags/tag.ex index 023f329c..564c37ba 100644 --- a/lib/philomena/tags/tag.ex +++ b/lib/philomena/tags/tag.ex @@ -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 diff --git a/lib/philomena/user_links.ex b/lib/philomena/user_links.ex index c4668de4..d8e498ed 100644 --- a/lib/philomena/user_links.ex +++ b/lib/philomena/user_links.ex @@ -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(%{}) diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 3671df06..e9124be2 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -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 diff --git a/lib/philomena_web/image_loader.ex b/lib/philomena_web/image_loader.ex index 25e9d7b4..6793def6 100644 --- a/lib/philomena_web/image_loader.ex +++ b/lib/philomena_web/image_loader.ex @@ -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)) diff --git a/lib/philomena_web/templates/profile/show.html.slime b/lib/philomena_web/templates/profile/show.html.slime index b843b097..4a41f6a0 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -76,6 +76,11 @@ = if manages_links?(@conn, @user) do br + => if link.public do + ' Public + - else + ' Hidden + ' • a href=Routes.profile_user_link_path(@conn, :edit, @user, link) ' Edit diff --git a/lib/philomena_web/templates/profile/user_link/_form.html.slime b/lib/philomena_web/templates/profile/user_link/_form.html.slime index 98888d76..0fa3d608 100644 --- a/lib/philomena_web/templates/profile/user_link/_form.html.slime +++ b/lib/philomena_web/templates/profile/user_link/_form.html.slime @@ -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 diff --git a/lib/philomena_web/templates/tag/_tag_info_row.html.slime b/lib/philomena_web/templates/tag/_tag_info_row.html.slime index c3e8c373..777da850 100644 --- a/lib/philomena_web/templates/tag/_tag_info_row.html.slime +++ b/lib/philomena_web/templates/tag/_tag_info_row.html.slime @@ -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) + ' → + => 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) diff --git a/lib/philomena_web/views/tag_view.ex b/lib/philomena_web/views/tag_view.ex index cfd3dd46..b3e18793 100644 --- a/lib/philomena_web/views/tag_view.ex +++ b/lib/philomena_web/views/tag_view.ex @@ -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