Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
liamwhite committed Jun 23, 2024
2 parents 9607fe0 + 0f3c667 commit efb8b1a
Showing 46 changed files with 136 additions and 136 deletions.
38 changes: 19 additions & 19 deletions assets/js/burger.js → assets/js/burger.ts
Original file line number Diff line number Diff line change
@@ -2,20 +2,23 @@
* Hamburger menu.
*/

function switchClasses(element, oldClass, newClass) {
import { $, $$ } from './utils/dom';
import { assertNotNull } from './utils/assert';

function switchClasses(element: HTMLElement, oldClass: string, newClass: string) {
element.classList.remove(oldClass);
element.classList.add(newClass);
}

function open(burger, content, body, root) {
function open(burger: HTMLElement, content: HTMLElement, body: HTMLElement, root: HTMLElement) {
switchClasses(content, 'close', 'open');
switchClasses(burger, 'close', 'open');

root.classList.add('no-overflow-x');
body.classList.add('no-overflow');
}

function close(burger, content, body, root) {
function close(burger: HTMLElement, content: HTMLElement, body: HTMLElement, root: HTMLElement) {
switchClasses(content, 'open', 'close');
switchClasses(burger, 'open', 'close');

@@ -26,31 +29,29 @@ function close(burger, content, body, root) {
}, 300);
}

function copyArtistLinksTo(burger) {
const copy = links => {
function copyUserLinksTo(burger: HTMLElement) {
const copy = (links: HTMLCollection) => {
burger.appendChild(document.createElement('hr'));

[].slice.call(links).forEach(link => {
const burgerLink = link.cloneNode(true);

for (const link of links) {
const burgerLink = link.cloneNode(true) as HTMLElement;
burgerLink.className = '';
burger.appendChild(burgerLink);
});
}
};

const linksContainers = document.querySelectorAll('.js-burger-links');

[].slice.call(linksContainers).forEach(container => copy(container.children));
$$<HTMLElement>('.js-burger-links').forEach(container => copy(container.children));
}

function setupBurgerMenu() {
const burger = document.getElementById('burger');
const toggle = document.getElementById('js-burger-toggle');
const content = document.getElementById('container');
export function setupBurgerMenu() {
// Burger menu should exist on all pages.
const burger = assertNotNull($<HTMLElement>('#burger'));
const toggle = assertNotNull($<HTMLElement>('#js-burger-toggle'));
const content = assertNotNull($<HTMLElement>('#container'));
const body = document.body;
const root = document.documentElement;

copyArtistLinksTo(burger);
copyUserLinksTo(burger);

toggle.addEventListener('click', event => {
event.stopPropagation();
@@ -63,11 +64,10 @@ function setupBurgerMenu() {
open(burger, content, body, root);
}
});

content.addEventListener('click', () => {
if (content.classList.contains('open')) {
close(burger, content, body, root);
}
});
}

export { setupBurgerMenu };
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
volumes:
postgres_data: {}
opensearch_data: {}
14 changes: 7 additions & 7 deletions lib/philomena/attribution.ex
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
defprotocol Philomena.Attribution do
@doc """
Provides the "parent object" identifier for this object. This is so
that anonymous posts under the same topic id can return the same hash
for the same user.
Provides the "parent object" identifier for this object. This is so
that anonymous posts under the same topic id can return the same hash
for the same user.
"""
@spec object_identifier(struct()) :: String.t()
def object_identifier(object)

@doc """
Provides the "best" user identifier for an object. Usually this will be
the user_id, but may also be the fingerprint or IP address if other
information is unavailable.
Provides the "best" user identifier for an object. Usually this will be
the user_id, but may also be the fingerprint or IP address if other
information is unavailable.
"""
@spec best_user_identifier(struct()) :: String.t()
def best_user_identifier(object)

@doc """
Return whether this object is considered to be anonymous.
Return whether this object is considered to be anonymous.
"""
@spec anonymous?(struct()) :: true | false
def anonymous?(object)
Original file line number Diff line number Diff line change
@@ -18,11 +18,11 @@ defmodule PhilomenaWeb.Admin.ArtistLink.ContactController do

conn
|> put_flash(:info, "Artist successfully marked as contacted.")
|> moderation_log(details: &log_details/3, data: artist_link)
|> moderation_log(details: &log_details/2, data: artist_link)
|> redirect(to: ~p"/admin/artist_links")
end

defp log_details(_conn, _action, artist_link) do
defp log_details(_action, artist_link) do
%{
body: "Contacted artist #{artist_link.user.name} at #{artist_link.uri}",
subject_path: ~p"/profiles/#{artist_link.user}/artist_links/#{artist_link}"
Original file line number Diff line number Diff line change
@@ -17,11 +17,11 @@ defmodule PhilomenaWeb.Admin.ArtistLink.RejectController do

conn
|> put_flash(:info, "Artist link successfully marked as rejected.")
|> moderation_log(details: &log_details/3, data: artist_link)
|> moderation_log(details: &log_details/2, data: artist_link)
|> redirect(to: ~p"/admin/artist_links")
end

defp log_details(_conn, _action, artist_link) do
defp log_details(_action, artist_link) do
%{
body: "Rejected artist link #{artist_link.uri} created by #{artist_link.user.name}",
subject_path: ~p"/profiles/#{artist_link.user}/artist_links/#{artist_link}"
Original file line number Diff line number Diff line change
@@ -18,11 +18,11 @@ defmodule PhilomenaWeb.Admin.ArtistLink.VerificationController do

conn
|> put_flash(:info, "Artist link successfully verified.")
|> moderation_log(details: &log_details/3, data: result.artist_link)
|> moderation_log(details: &log_details/2, data: result.artist_link)
|> redirect(to: ~p"/admin/artist_links")
end

defp log_details(_conn, _action, artist_link) do
defp log_details(_action, artist_link) do
%{
body: "Verified artist link #{artist_link.uri} created by #{artist_link.user.name}",
subject_path: ~p"/profiles/#{artist_link.user}/artist_links/#{artist_link}"
9 changes: 5 additions & 4 deletions lib/philomena_web/controllers/admin/batch/tag_controller.ex
Original file line number Diff line number Diff line change
@@ -48,10 +48,11 @@ defmodule PhilomenaWeb.Admin.Batch.TagController do
{:ok, _} ->
conn
|> moderation_log(
details: &log_details/3,
details: &log_details/2,
data: %{
tag_list: tag_list,
image_count: Enum.count(image_ids)
image_count: Enum.count(image_ids),
user: conn.assigns.current_user
}
)
|> json(%{succeeded: image_ids, failed: []})
@@ -68,10 +69,10 @@ defmodule PhilomenaWeb.Admin.Batch.TagController do
end
end

defp log_details(conn, _action, data) do
defp log_details(_action, data) do
%{
body: "Batch tagged '#{data.tag_list}' on #{data.image_count} images",
subject_path: ~p"/profiles/#{conn.assigns.current_user}"
subject_path: ~p"/profiles/#{data.user}"
}
end
end
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
{:ok, fingerprint_ban} ->
conn
|> put_flash(:info, "Fingerprint was successfully banned.")
|> moderation_log(details: &log_details/3, data: fingerprint_ban)
|> moderation_log(details: &log_details/2, data: fingerprint_ban)
|> redirect(to: ~p"/admin/fingerprint_bans")

{:error, changeset} ->
@@ -70,7 +70,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
{:ok, fingerprint_ban} ->
conn
|> put_flash(:info, "Fingerprint ban successfully updated.")
|> moderation_log(details: &log_details/3, data: fingerprint_ban)
|> moderation_log(details: &log_details/2, data: fingerprint_ban)
|> redirect(to: ~p"/admin/fingerprint_bans")

{:error, changeset} ->
@@ -83,7 +83,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do

conn
|> put_flash(:info, "Fingerprint ban successfully deleted.")
|> moderation_log(details: &log_details/3, data: fingerprint_ban)
|> moderation_log(details: &log_details/2, data: fingerprint_ban)
|> redirect(to: ~p"/admin/fingerprint_bans")
end

@@ -115,7 +115,7 @@ defmodule PhilomenaWeb.Admin.FingerprintBanController do
end
end

defp log_details(_conn, action, ban) do
defp log_details(action, ban) do
body =
case action do
:create -> "Created a fingerprint ban #{ban.generated_ban_id}"
8 changes: 4 additions & 4 deletions lib/philomena_web/controllers/admin/subnet_ban_controller.ex
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ defmodule PhilomenaWeb.Admin.SubnetBanController do
{:ok, subnet_ban} ->
conn
|> put_flash(:info, "Subnet was successfully banned.")
|> moderation_log(details: &log_details/3, data: subnet_ban)
|> moderation_log(details: &log_details/2, data: subnet_ban)
|> redirect(to: ~p"/admin/subnet_bans")

{:error, changeset} ->
@@ -67,7 +67,7 @@ defmodule PhilomenaWeb.Admin.SubnetBanController do
{:ok, subnet_ban} ->
conn
|> put_flash(:info, "Subnet ban successfully updated.")
|> moderation_log(details: &log_details/3, data: subnet_ban)
|> moderation_log(details: &log_details/2, data: subnet_ban)
|> redirect(to: ~p"/admin/subnet_bans")

{:error, changeset} ->
@@ -80,7 +80,7 @@ defmodule PhilomenaWeb.Admin.SubnetBanController do

conn
|> put_flash(:info, "Subnet ban successfully deleted.")
|> moderation_log(details: &log_details/3, data: subnet_ban)
|> moderation_log(details: &log_details/2, data: subnet_ban)
|> redirect(to: ~p"/admin/subnet_bans")
end

@@ -112,7 +112,7 @@ defmodule PhilomenaWeb.Admin.SubnetBanController do
end
end

defp log_details(_conn, action, ban) do
defp log_details(action, ban) do
body =
case action do
:create -> "Created a subnet ban #{ban.generated_ban_id}"
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Admin.User.VerificationController do

conn
|> put_flash(:info, "User verification granted.")
|> moderation_log(details: &log_details/3, data: user)
|> moderation_log(details: &log_details/2, data: user)
|> redirect(to: ~p"/profiles/#{user}")
end

@@ -21,7 +21,7 @@ defmodule PhilomenaWeb.Admin.User.VerificationController do

conn
|> put_flash(:info, "User verification revoked.")
|> moderation_log(details: &log_details/3, data: user)
|> moderation_log(details: &log_details/2, data: user)
|> redirect(to: ~p"/profiles/#{user}")
end

@@ -32,7 +32,7 @@ defmodule PhilomenaWeb.Admin.User.VerificationController do
end
end

defp log_details(_conn, action, user) do
defp log_details(action, user) do
body =
case action do
:create -> "Granted verification to #{user.name}"
8 changes: 4 additions & 4 deletions lib/philomena_web/controllers/admin/user_ban_controller.ex
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ defmodule PhilomenaWeb.Admin.UserBanController do
{:ok, user_ban} ->
conn
|> put_flash(:info, "User was successfully banned.")
|> moderation_log(details: &log_details/3, data: user_ban)
|> moderation_log(details: &log_details/2, data: user_ban)
|> redirect(to: ~p"/admin/user_bans")

{:error, :user_ban, changeset, _changes} ->
@@ -71,7 +71,7 @@ defmodule PhilomenaWeb.Admin.UserBanController do
{:ok, user_ban} ->
conn
|> put_flash(:info, "User ban successfully updated.")
|> moderation_log(details: &log_details/3, data: user_ban)
|> moderation_log(details: &log_details/2, data: user_ban)
|> redirect(to: ~p"/admin/user_bans")

{:error, changeset} ->
@@ -84,7 +84,7 @@ defmodule PhilomenaWeb.Admin.UserBanController do

conn
|> put_flash(:info, "User ban successfully deleted.")
|> moderation_log(details: &log_details/3, data: user_ban)
|> moderation_log(details: &log_details/2, data: user_ban)
|> redirect(to: ~p"/admin/user_bans")
end

@@ -116,7 +116,7 @@ defmodule PhilomenaWeb.Admin.UserBanController do
end
end

defp log_details(_conn, action, ban) do
defp log_details(action, ban) do
body =
case action do
:create -> "Created a user ban #{ban.generated_ban_id}"
4 changes: 2 additions & 2 deletions lib/philomena_web/controllers/admin/user_controller.ex
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ defmodule PhilomenaWeb.Admin.UserController do
{:ok, user} ->
conn
|> put_flash(:info, "User successfully updated.")
|> moderation_log(details: &log_details/3, data: user)
|> moderation_log(details: &log_details/2, data: user)
|> redirect(to: ~p"/profiles/#{user}")

{:error, changeset} ->
@@ -81,7 +81,7 @@ defmodule PhilomenaWeb.Admin.UserController do
assign(conn, :roles, Repo.all(Role))
end

defp log_details(_conn, _action, user) do
defp log_details(_action, user) do
%{
body: "Updated user details for #{user.name}",
subject_path: ~p"/profiles/#{user}"
Original file line number Diff line number Diff line change
@@ -20,11 +20,11 @@ defmodule PhilomenaWeb.Conversation.Message.ApproveController do

conn
|> put_flash(:info, "Conversation message approved.")
|> moderation_log(details: &log_details/3, data: message)
|> moderation_log(details: &log_details/2, data: message)
|> redirect(to: "/")
end

defp log_details(_conn, _action, message) do
defp log_details(_action, message) do
%{
body: "Approved private message in conversation ##{message.conversation_id}",
subject_path: "/"
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ defmodule PhilomenaWeb.DuplicateReport.AcceptController do
{:ok, report} ->
conn
|> put_flash(:info, "Successfully accepted report.")
|> moderation_log(details: &log_details/3, data: report.duplicate_report)
|> moderation_log(details: &log_details/2, data: report.duplicate_report)
|> redirect(to: ~p"/duplicate_reports")

_error ->
@@ -30,7 +30,7 @@ defmodule PhilomenaWeb.DuplicateReport.AcceptController do
end
end

defp log_details(_conn, _action, report) do
defp log_details(_action, report) do
%{
body:
"Accepted duplicate report, merged #{report.image.id} into #{report.duplicate_of_image.id}",
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ defmodule PhilomenaWeb.DuplicateReport.AcceptReverseController do
{:ok, report} ->
conn
|> put_flash(:info, "Successfully accepted report in reverse.")
|> moderation_log(details: &log_details/3, data: report.duplicate_report)
|> moderation_log(details: &log_details/2, data: report.duplicate_report)
|> redirect(to: ~p"/duplicate_reports")

_error ->
@@ -30,7 +30,7 @@ defmodule PhilomenaWeb.DuplicateReport.AcceptReverseController do
end
end

defp log_details(_conn, _action, report) do
defp log_details(_action, report) do
%{
body:
"Reverse-accepted duplicate report, merged #{report.image.id} into #{report.duplicate_of_image.id}",
Loading

0 comments on commit efb8b1a

Please sign in to comment.