mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
show ban list on profiles
This commit is contained in:
parent
5953264c53
commit
1dfb6f877c
5 changed files with 68 additions and 22 deletions
|
@ -5,6 +5,7 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
alias Philomena.Textile.Renderer
|
||||
alias Philomena.UserStatistics.UserStatistic
|
||||
alias Philomena.Users.User
|
||||
alias Philomena.Bans
|
||||
alias Philomena.Galleries.Gallery
|
||||
alias Philomena.Posts.Post
|
||||
alias Philomena.Comments.Comment
|
||||
|
@ -99,6 +100,11 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
interactions =
|
||||
Interactions.user_interactions([recent_uploads, recent_faves], current_user)
|
||||
|
||||
bans =
|
||||
Bans.User
|
||||
|> where(user_id: ^user.id)
|
||||
|> Repo.all()
|
||||
|
||||
render(
|
||||
conn,
|
||||
"show.html",
|
||||
|
@ -114,6 +120,7 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
statistics: statistics,
|
||||
about_me: about_me,
|
||||
tags: tags,
|
||||
bans: bans,
|
||||
layout_class: "layout--medium"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -35,6 +35,13 @@
|
|||
li = link("Tag changes", to: Routes.profile_tag_change_path(@conn, :index, @user))
|
||||
li = link("Source changes", to: Routes.profile_source_change_path(@conn, :index, @user))
|
||||
|
||||
= if (current?(@user, @conn.assigns.current_user) or can?(@conn, :index, UserBan)) and Enum.any?(@bans) do
|
||||
.block
|
||||
.block__header
|
||||
' Ban History
|
||||
.block__content
|
||||
= render PhilomenaWeb.BanView, "_bans.html", bans: @bans, conn: @conn
|
||||
|
||||
.column-layout
|
||||
.column-layout__left
|
||||
.block
|
||||
|
|
|
@ -32,35 +32,39 @@ defmodule PhilomenaWeb.AppView do
|
|||
}
|
||||
|
||||
def pretty_time(time) do
|
||||
seconds = NaiveDateTime.diff(NaiveDateTime.utc_now(), time, :second)
|
||||
now = NaiveDateTime.utc_now()
|
||||
seconds = NaiveDateTime.diff(now, time, :second)
|
||||
relation = if seconds < 0, do: "from now", else: "ago"
|
||||
time = time |> DateTime.from_naive!("Etc/UTC")
|
||||
|
||||
seconds = abs(seconds)
|
||||
minutes = abs(div(seconds, 60))
|
||||
hours = abs(div(minutes, 60))
|
||||
days = abs(div(hours, 24))
|
||||
months = abs(div(days, 30))
|
||||
years = abs(div(days, 365))
|
||||
|
||||
words =
|
||||
cond do
|
||||
seconds < 45 -> String.replace(@time_strings[:seconds], "%d", to_string(seconds))
|
||||
seconds < 90 -> String.replace(@time_strings[:minute], "%d", to_string(1))
|
||||
minutes < 45 -> String.replace(@time_strings[:minutes], "%d", to_string(minutes))
|
||||
minutes < 90 -> String.replace(@time_strings[:hour], "%d", to_string(1))
|
||||
hours < 24 -> String.replace(@time_strings[:hours], "%d", to_string(hours))
|
||||
hours < 42 -> String.replace(@time_strings[:day], "%d", to_string(1))
|
||||
days < 30 -> String.replace(@time_strings[:days], "%d", to_string(days))
|
||||
days < 45 -> String.replace(@time_strings[:month], "%d", to_string(1))
|
||||
days < 365 -> String.replace(@time_strings[:months], "%d", to_string(months))
|
||||
days < 548 -> String.replace(@time_strings[:year], "%d", to_string(1))
|
||||
true -> String.replace(@time_strings[:years], "%d", to_string(years))
|
||||
end
|
||||
words = distance_of_time_in_words(now, time)
|
||||
|
||||
content_tag(:time, "#{words} #{relation}", datetime: DateTime.to_iso8601(time), title: datetime_string(time))
|
||||
end
|
||||
|
||||
def distance_of_time_in_words(time_2, time_1) do
|
||||
seconds = abs(NaiveDateTime.diff(time_2, time_1, :second))
|
||||
minutes = div(seconds, 60)
|
||||
hours = div(minutes, 60)
|
||||
days = div(hours, 24)
|
||||
months = div(days, 30)
|
||||
years = div(days, 365)
|
||||
|
||||
cond do
|
||||
seconds < 45 -> String.replace(@time_strings[:seconds], "%d", to_string(seconds))
|
||||
seconds < 90 -> String.replace(@time_strings[:minute], "%d", to_string(1))
|
||||
minutes < 45 -> String.replace(@time_strings[:minutes], "%d", to_string(minutes))
|
||||
minutes < 90 -> String.replace(@time_strings[:hour], "%d", to_string(1))
|
||||
hours < 24 -> String.replace(@time_strings[:hours], "%d", to_string(hours))
|
||||
hours < 42 -> String.replace(@time_strings[:day], "%d", to_string(1))
|
||||
days < 30 -> String.replace(@time_strings[:days], "%d", to_string(days))
|
||||
days < 45 -> String.replace(@time_strings[:month], "%d", to_string(1))
|
||||
days < 365 -> String.replace(@time_strings[:months], "%d", to_string(months))
|
||||
days < 548 -> String.replace(@time_strings[:year], "%d", to_string(1))
|
||||
true -> String.replace(@time_strings[:years], "%d", to_string(years))
|
||||
end
|
||||
end
|
||||
|
||||
def can?(conn, action, model) do
|
||||
Canada.Can.can?(conn.assigns.current_user, action, model)
|
||||
end
|
||||
|
|
21
lib/philomena_web/views/ban/_bans.html.slime
Normal file
21
lib/philomena_web/views/ban/_bans.html.slime
Normal file
|
@ -0,0 +1,21 @@
|
|||
table.table
|
||||
thead
|
||||
tr
|
||||
th Ban Enacted
|
||||
th Ban Expires
|
||||
th Duration
|
||||
th Active?
|
||||
th Reason
|
||||
th Ban ID
|
||||
tbody
|
||||
= for b <- @bans
|
||||
tr
|
||||
td = pretty_time b.created_at
|
||||
td = pretty_time b.valid_until
|
||||
td = distance_of_time_in_words b.created_at, b.valid_until
|
||||
= if active?(b) do
|
||||
td.success Yes
|
||||
- else
|
||||
td.danger No
|
||||
td = b.reason
|
||||
td = b.generated_ban_id
|
7
lib/philomena_web/views/ban_view.ex
Normal file
7
lib/philomena_web/views/ban_view.ex
Normal file
|
@ -0,0 +1,7 @@
|
|||
defmodule PhilomenaWeb.BanView do
|
||||
use PhilomenaWeb, :view
|
||||
|
||||
def active?(ban) do
|
||||
NaiveDateTime.diff(ban.valid_until, NaiveDateTime.utc_now()) > 0
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue