From c99041372653db83d208b03c924dfc5d78655627 Mon Sep 17 00:00:00 2001 From: Micah Woods Date: Tue, 24 Nov 2026 21:38:01 -0600 Subject: [PATCH 1/3] feat(api): report or block huddl organizers and group owners --- GLOSSARY.md | 4 + lib/huddlz/accounts.ex | 9 + lib/huddlz/accounts/account_report.ex | 49 +++ .../account_report/actions/report_group.ex | 37 +++ .../actions/report_organizer.ex | 37 +++ .../checks/reporter_can_see_account.ex | 12 +- lib/huddlz/accounts/group_owner.ex | 26 ++ lib/huddlz/accounts/huddl_organizer.ex | 26 ++ lib/huddlz/accounts/user_block.ex | 159 +++++++++ .../user_block/changes/block_group_owner.ex | 30 ++ .../changes/block_huddl_organizer.ex | 30 ++ lib/huddlz/communities/group.ex | 6 + lib/huddlz/communities/huddl.ex | 16 + .../preparations/hide_blocked_organizers.ex | 19 ++ .../20261125033612_add_user_blocks.exs | 59 ++++ .../repo/user_blocks/20261125033613.json | 154 +++++++++ .../huddl_organizer_moderation.feature | 107 ++++++ .../account_reports_steps.exs | 6 +- .../huddl_organizer_moderation_steps.exs | 311 ++++++++++++++++++ 19 files changed, 1094 insertions(+), 3 deletions(-) create mode 100644 lib/huddlz/accounts/account_report/actions/report_group.ex create mode 100644 lib/huddlz/accounts/account_report/actions/report_organizer.ex create mode 100644 lib/huddlz/accounts/group_owner.ex create mode 100644 lib/huddlz/accounts/huddl_organizer.ex create mode 100644 lib/huddlz/accounts/user_block.ex create mode 100644 lib/huddlz/accounts/user_block/changes/block_group_owner.ex create mode 100644 lib/huddlz/accounts/user_block/changes/block_huddl_organizer.ex create mode 100644 lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex create mode 100644 priv/repo/migrations/20261125033612_add_user_blocks.exs create mode 100644 priv/resource_snapshots/repo/user_blocks/20261125033613.json create mode 100644 test/features/huddl_organizer_moderation.feature create mode 100644 test/features/step_definitions/huddl_organizer_moderation_steps.exs diff --git a/GLOSSARY.md b/GLOSSARY.md index 52ad02762..f92f6093e 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -58,6 +58,10 @@ _Avoid_: Bot, integration, app **Account report**: A confirmed member's request for administrators to review an account they can already see, including the organizer of a public huddl without joining its group or RSVPing, for spam or another concern. A report does not itself suspend the account; its details and the reporter's identity are available only to huddlz staff for review. +**Block**: +A person's private choice to stop seeing huddlz someone else organizes, made from a huddl whose organizer they can see. Blocked organizers' huddlz leave that person's discovery and group lists; huddlz they already RSVPed to and links they open still work. The blocked person is not told and loses nothing they could see before. A block is not a report. +_Avoid_: Mute, ban + ## Communities and places **Group**: diff --git a/lib/huddlz/accounts.ex b/lib/huddlz/accounts.ex index 2982a6b02..9a116dbe9 100644 --- a/lib/huddlz/accounts.ex +++ b/lib/huddlz/accounts.ex @@ -59,11 +59,20 @@ defmodule Huddlz.Accounts do resource Huddlz.Accounts.AccountReport do define :report_account, action: :report + define :report_huddl_organizer, action: :report_organizer, args: [:huddl_id] + define :report_group_owner, action: :report_group, args: [:group_id] define :get_account_report, action: :read, get_by: [:id] define :count_account_reports, action: :count_queue, args: [:handled] define :list_account_reports, action: :queue, args: [{:optional, :handled}] define :mark_report_handled, action: :mark_handled define :reopen_report, action: :reopen end + + resource Huddlz.Accounts.UserBlock do + define :block_huddl_organizer, action: :block_organizer, args: [:huddl_id] + define :block_group_owner, action: :block_group_owner, args: [:group_id] + define :list_blocks, action: :mine + define :unblock, action: :unblock + end end end diff --git a/lib/huddlz/accounts/account_report.ex b/lib/huddlz/accounts/account_report.ex index b3e16483d..f31a08cd8 100644 --- a/lib/huddlz/accounts/account_report.ex +++ b/lib/huddlz/accounts/account_report.ex @@ -37,6 +37,8 @@ defmodule Huddlz.Accounts.AccountReport do routes do base "/account_reports" post :report + route :post, "/organizer", :report_organizer + route :post, "/group", :report_group end end @@ -84,6 +86,48 @@ defmodule Huddlz.Accounts.AccountReport do return_skipped_upsert? true end + action :report_organizer do + description """ + Report the organizer of a huddl the actor can see, by naming the + huddl. It follows the same rules as reporting the account directly + and returns nothing about the account. + """ + + argument :huddl_id, :uuid do + description "The huddl whose organizer to report" + allow_nil? false + end + + argument :reason, Huddlz.Accounts.AccountReport.Reason + + argument :details, :string do + constraints max_length: 1000, trim?: true + end + + run Huddlz.Accounts.AccountReport.Actions.ReportOrganizer + end + + action :report_group do + description """ + Report the owner of a group the actor can see, by naming the group. + It follows the same rules as reporting the account directly and + returns nothing about the account. + """ + + argument :group_id, :uuid do + description "The group whose owner to report" + allow_nil? false + end + + argument :reason, Huddlz.Accounts.AccountReport.Reason + + argument :details, :string do + constraints max_length: 1000, trim?: true + end + + run Huddlz.Accounts.AccountReport.Actions.ReportGroup + end + read :queue do description "The administrators' queue: open reports, or handled ones, newest first, expired ones gone" @@ -137,6 +181,11 @@ defmodule Huddlz.Accounts.AccountReport do end policies do + policy action([:report_organizer, :report_group]) do + description "Signed-in people may ask; reporting the account itself decides the rest" + authorize_if actor_present() + end + policy action(:report) do description "Confirmed members report accounts they can already see, never themselves" forbid_unless Huddlz.Accounts.Checks.ConfirmedActor diff --git a/lib/huddlz/accounts/account_report/actions/report_group.ex b/lib/huddlz/accounts/account_report/actions/report_group.ex new file mode 100644 index 000000000..9cf684d5e --- /dev/null +++ b/lib/huddlz/accounts/account_report/actions/report_group.ex @@ -0,0 +1,37 @@ +defmodule Huddlz.Accounts.AccountReport.Actions.ReportGroup do + @moduledoc """ + Reports the owner of a group through the ordinary `:report` action, + so the same rules decide who may report whom. The reporter names only + the group and learns nothing about the account: the action returns no + report. + """ + + use Ash.Resource.Actions.Implementation + + alias Huddlz.Accounts + alias Huddlz.Accounts.GroupOwner + alias Huddlz.Communities.Group + + @impl true + def run(input, _opts, %{actor: actor}) do + group_id = input.arguments.group_id + + with {:ok, owner_id} <- GroupOwner.fetch(group_id, actor), + {:ok, _report} <- + Accounts.report_account( + %{ + reported_user_id: owner_id, + reason: Map.get(input.arguments, :reason), + details: Map.get(input.arguments, :details), + source_type: :group, + source_id: group_id + }, + actor: actor + ) do + :ok + else + :error -> {:error, Ash.Error.Query.NotFound.exception(resource: Group)} + {:error, error} -> {:error, error} + end + end +end diff --git a/lib/huddlz/accounts/account_report/actions/report_organizer.ex b/lib/huddlz/accounts/account_report/actions/report_organizer.ex new file mode 100644 index 000000000..04e50de9e --- /dev/null +++ b/lib/huddlz/accounts/account_report/actions/report_organizer.ex @@ -0,0 +1,37 @@ +defmodule Huddlz.Accounts.AccountReport.Actions.ReportOrganizer do + @moduledoc """ + Reports the organizer of a huddl through the ordinary `:report` action, + so the same rules decide who may report whom. The reporter names only + the huddl and learns nothing about the account: the action returns no + report. + """ + + use Ash.Resource.Actions.Implementation + + alias Huddlz.Accounts + alias Huddlz.Accounts.HuddlOrganizer + alias Huddlz.Communities.Huddl + + @impl true + def run(input, _opts, %{actor: actor}) do + huddl_id = input.arguments.huddl_id + + with {:ok, organizer_id} <- HuddlOrganizer.fetch(huddl_id, actor), + {:ok, _report} <- + Accounts.report_account( + %{ + reported_user_id: organizer_id, + reason: Map.get(input.arguments, :reason), + details: Map.get(input.arguments, :details), + source_type: :huddl, + source_id: huddl_id + }, + actor: actor + ) do + :ok + else + :error -> {:error, Ash.Error.Query.NotFound.exception(resource: Huddl)} + {:error, error} -> {:error, error} + end + end +end diff --git a/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex b/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex index 6a1de0ef7..3fe1fb4af 100644 --- a/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex +++ b/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex @@ -9,7 +9,7 @@ defmodule Huddlz.Accounts.AccountReport.Checks.ReporterCanSeeAccount do use Ash.Policy.SimpleCheck - alias Huddlz.Communities.{GroupMember, Huddl, HuddlAttendee} + alias Huddlz.Communities.{Group, GroupMember, Huddl, HuddlAttendee} require Ash.Query @@ -31,7 +31,8 @@ defmodule Huddlz.Accounts.AccountReport.Checks.ReporterCanSeeAccount do shares_group?(actor_id, reported_id) or shares_huddl?(actor_id, reported_id) or organizes_attended_huddl?(actor_id, reported_id) or - organizes_public_huddl?(reported_id) + organizes_public_huddl?(reported_id) or + owns_public_group?(reported_id) end defp shares_group?(actor_id, reported_id) do @@ -61,4 +62,11 @@ defmodule Huddlz.Accounts.AccountReport.Checks.ReporterCanSeeAccount do |> Ash.Query.filter(creator_id == ^reported_id) |> Ash.exists?() end + + defp owns_public_group?(reported_id) do + Group + |> Ash.Query.for_read(:read, %{}, actor: nil) + |> Ash.Query.filter(owner_id == ^reported_id) + |> Ash.exists?() + end end diff --git a/lib/huddlz/accounts/group_owner.ex b/lib/huddlz/accounts/group_owner.ex new file mode 100644 index 000000000..aaf6bfae0 --- /dev/null +++ b/lib/huddlz/accounts/group_owner.ex @@ -0,0 +1,26 @@ +defmodule Huddlz.Accounts.GroupOwner do + @moduledoc """ + Who owns a group the actor can see. Apps that never learn a person's + identity, like the iOS app, report and block "the owner of this group", + and this lookup turns that into the account behind it without putting + the account in any response. + """ + + alias Huddlz.Communities.Group + + require Ash.Query + + @doc "The group owner's id, or `:error` when the actor cannot see the group." + def fetch(group_id, actor) when is_binary(group_id) do + Group + |> Ash.Query.for_read(:read, %{}, actor: actor) + |> Ash.Query.filter(id == ^group_id) + |> Ash.read_one() + |> case do + {:ok, %Group{owner_id: owner_id}} -> {:ok, owner_id} + _ -> :error + end + end + + def fetch(_group_id, _actor), do: :error +end diff --git a/lib/huddlz/accounts/huddl_organizer.ex b/lib/huddlz/accounts/huddl_organizer.ex new file mode 100644 index 000000000..8577e8fe2 --- /dev/null +++ b/lib/huddlz/accounts/huddl_organizer.ex @@ -0,0 +1,26 @@ +defmodule Huddlz.Accounts.HuddlOrganizer do + @moduledoc """ + Who organized a huddl the actor can see. Apps that never learn a + person's identity, like the iOS app, report and block "the organizer of + this huddl", and this lookup turns that into the account behind it + without putting the account in any response. + """ + + alias Huddlz.Communities.Huddl + + require Ash.Query + + @doc "The organizer's id, or `:error` when the actor cannot see the huddl." + def fetch(huddl_id, actor) when is_binary(huddl_id) do + Huddl + |> Ash.Query.for_read(:read, %{}, actor: actor) + |> Ash.Query.filter(id == ^huddl_id) + |> Ash.read_one() + |> case do + {:ok, %Huddl{creator_id: creator_id}} -> {:ok, creator_id} + _ -> :error + end + end + + def fetch(_huddl_id, _actor), do: :error +end diff --git a/lib/huddlz/accounts/user_block.ex b/lib/huddlz/accounts/user_block.ex new file mode 100644 index 000000000..7eb8d54be --- /dev/null +++ b/lib/huddlz/accounts/user_block.ex @@ -0,0 +1,159 @@ +defmodule Huddlz.Accounts.UserBlock do + @moduledoc """ + A person's choice to stop seeing huddlz someone else organizes. Today a + block is made from a huddl the person can see, and it blocks that + huddl's organizer: their huddlz leave the person's discovery and group + lists on every app. Huddlz the person already RSVPed to stay on their + calendar, and an open link still works. + + Blocking is private. The blocked person is not told and can still see + everything they could before. Only the person who blocked reads their + blocks, by the blocked person's display name, and can remove them. + """ + + use Ash.Resource, + otp_app: :huddlz, + domain: Huddlz.Accounts, + data_layer: AshPostgres.DataLayer, + authorizers: [Ash.Policy.Authorizer], + extensions: [AshJsonApi.Resource] + + alias Huddlz.Accounts.User + + json_api do + type "user_block" + + default_fields [:id, :blocked_user_name, :inserted_at] + + routes do + base "/blocks" + + index :mine + post :block_organizer, route: "/organizer" + post :block_group_owner, route: "/group" + delete :unblock + end + end + + postgres do + table "user_blocks" + repo Huddlz.Repo + + references do + reference :blocker, on_delete: :delete + reference :blocked_user, on_delete: :delete + end + + custom_indexes do + index [:blocked_user_id] + end + end + + actions do + defaults [:read] + + read :mine do + description "The people the actor has blocked, most recent first" + filter expr(blocker_id == ^actor(:id)) + prepare build(sort: [inserted_at: :desc], load: [:blocked_user_name]) + end + + create :block_organizer do + description """ + Block the organizer of a huddl the actor can see. Blocking someone + already blocked changes nothing. + """ + + accept [] + + argument :huddl_id, :uuid do + description "The huddl whose organizer to block" + allow_nil? false + end + + change Huddlz.Accounts.UserBlock.Changes.BlockHuddlOrganizer + change relate_actor(:blocker, allow_nil?: true) + + upsert? true + upsert_identity :one_per_person + upsert_fields [:blocker_id] + end + + create :block_group_owner do + description """ + Block the owner of a group the actor can see. Blocking someone + already blocked changes nothing. + """ + + accept [] + + argument :group_id, :uuid do + description "The group whose owner to block" + allow_nil? false + end + + change Huddlz.Accounts.UserBlock.Changes.BlockGroupOwner + change relate_actor(:blocker, allow_nil?: true) + + upsert? true + upsert_identity :one_per_person + upsert_fields [:blocker_id] + end + + destroy :unblock do + description "Remove a block; the person's huddlz show up again" + primary? true + end + end + + policies do + policy action([:block_organizer, :block_group_owner]) do + description "Anyone signed in may block an organizer or group owner they can see" + authorize_if actor_present() + end + + policy action_type([:read, :destroy]) do + description "People see and remove only their own blocks" + authorize_if expr(blocker_id == ^actor(:id)) + end + end + + attributes do + uuid_primary_key :id + + create_timestamp :inserted_at do + public? true + end + end + + relationships do + belongs_to :blocker, User do + description "Who chose to block" + allow_nil? false + end + + belongs_to :blocked_user, User do + description "The person whose huddlz are hidden; never part of the API shape" + allow_nil? false + end + end + + calculations do + calculate :blocked_user_name, + :string, + expr( + if is_nil(blocked_user.suspended_at) do + blocked_user.display_name + else + "Suspended account" + end + ) do + public? true + description "The blocked person's display name, or a neutral label once suspended" + end + end + + identities do + identity :one_per_person, [:blocker_id, :blocked_user_id] + end +end diff --git a/lib/huddlz/accounts/user_block/changes/block_group_owner.ex b/lib/huddlz/accounts/user_block/changes/block_group_owner.ex new file mode 100644 index 000000000..9318a3d94 --- /dev/null +++ b/lib/huddlz/accounts/user_block/changes/block_group_owner.ex @@ -0,0 +1,30 @@ +defmodule Huddlz.Accounts.UserBlock.Changes.BlockGroupOwner do + @moduledoc """ + Blocks whoever owns the named group, which the actor must be able to see. + Nobody blocks themselves. + """ + + use Ash.Resource.Change + + alias Huddlz.Accounts.GroupOwner + + @impl true + def change(changeset, _opts, context) do + actor_id = context.actor && context.actor.id + group_id = Ash.Changeset.get_argument(changeset, :group_id) + + case GroupOwner.fetch(group_id, context.actor) do + {:ok, ^actor_id} -> + Ash.Changeset.add_error(changeset, field: :group_id, message: "You own this group.") + + {:ok, owner_id} -> + Ash.Changeset.force_change_attribute(changeset, :blocked_user_id, owner_id) + + :error -> + Ash.Changeset.add_error(changeset, + field: :group_id, + message: "This group is not available." + ) + end + end +end diff --git a/lib/huddlz/accounts/user_block/changes/block_huddl_organizer.ex b/lib/huddlz/accounts/user_block/changes/block_huddl_organizer.ex new file mode 100644 index 000000000..601b41709 --- /dev/null +++ b/lib/huddlz/accounts/user_block/changes/block_huddl_organizer.ex @@ -0,0 +1,30 @@ +defmodule Huddlz.Accounts.UserBlock.Changes.BlockHuddlOrganizer do + @moduledoc """ + Blocks whoever organized the named huddl, which the actor must be able + to see. Nobody blocks themselves. + """ + + use Ash.Resource.Change + + alias Huddlz.Accounts.HuddlOrganizer + + @impl true + def change(changeset, _opts, context) do + actor_id = context.actor && context.actor.id + huddl_id = Ash.Changeset.get_argument(changeset, :huddl_id) + + case HuddlOrganizer.fetch(huddl_id, context.actor) do + {:ok, ^actor_id} -> + Ash.Changeset.add_error(changeset, field: :huddl_id, message: "You organize this huddl.") + + {:ok, organizer_id} -> + Ash.Changeset.force_change_attribute(changeset, :blocked_user_id, organizer_id) + + :error -> + Ash.Changeset.add_error(changeset, + field: :huddl_id, + message: "This huddl is not available." + ) + end + end +end diff --git a/lib/huddlz/communities/group.ex b/lib/huddlz/communities/group.ex index aa3932bb6..fe74c66cd 100644 --- a/lib/huddlz/communities/group.ex +++ b/lib/huddlz/communities/group.ex @@ -547,6 +547,12 @@ defmodule Huddlz.Communities.Group do end calculations do + calculate :owned_by_me, :boolean do + public? true + description "Whether the current caller owns this group" + calculation expr(not is_nil(^actor(:id)) and owner_id == ^actor(:id)) + end + calculate :search_relevance, :float do argument :query, :string, allow_nil?: false diff --git a/lib/huddlz/communities/huddl.ex b/lib/huddlz/communities/huddl.ex index f7554c5ba..a7b53b351 100644 --- a/lib/huddlz/communities/huddl.ex +++ b/lib/huddlz/communities/huddl.ex @@ -59,6 +59,7 @@ defmodule Huddlz.Communities.Huddl do :thumbnail_url, :max_attendees, :attendance_state, + :organized_by_me, :lifecycle_state, :published_at, :cancelled_at, @@ -492,6 +493,7 @@ defmodule Huddlz.Communities.Huddl do read :upcoming do filter expr(lifecycle_state == :published and ends_at > now()) prepare Huddlz.Communities.Huddl.Preparations.FilterByVisibility + prepare Huddlz.Communities.Huddl.Preparations.HideBlockedOrganizers prepare build(sort: [starts_at: :asc]) end @@ -563,6 +565,7 @@ defmodule Huddlz.Communities.Huddl do prepare Huddlz.Communities.Huddl.Preparations.FilterByVisibility prepare Huddlz.Communities.Huddl.Preparations.ApplySearchFilters + prepare Huddlz.Communities.Huddl.Preparations.HideBlockedOrganizers end read :by_group do @@ -582,6 +585,7 @@ defmodule Huddlz.Communities.Huddl do default_limit: 10 prepare Huddlz.Communities.Huddl.Preparations.FilterByVisibility + prepare Huddlz.Communities.Huddl.Preparations.HideBlockedOrganizers prepare build(sort: [starts_at: :asc]) end @@ -1207,6 +1211,12 @@ defmodule Huddlz.Communities.Huddl do has_many :huddl_cover_images, Huddlz.Communities.HuddlCoverImage do destination_attribute :huddl_id end + + has_many :organizer_blocks, Huddlz.Accounts.UserBlock do + description "Blocks people have placed on this huddl's organizer" + source_attribute :creator_id + destination_attribute :blocked_user_id + end end calculations do @@ -1228,6 +1238,12 @@ defmodule Huddlz.Communities.Huddl do ) end + calculate :organized_by_me, :boolean do + public? true + description "Whether the current caller organized this huddl" + calculation expr(not is_nil(^actor(:id)) and creator_id == ^actor(:id)) + end + calculate :status, :atom do calculation expr( cond do diff --git a/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex b/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex new file mode 100644 index 000000000..ed41c4619 --- /dev/null +++ b/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex @@ -0,0 +1,19 @@ +defmodule Huddlz.Communities.Huddl.Preparations.HideBlockedOrganizers do + @moduledoc """ + Leaves out huddlz organized by people the actor has blocked. Discovery + and group lists use it; a personal view such as the huddlz someone is + going to, or a huddl opened by its link, does not. + """ + use Ash.Resource.Preparation + require Ash.Query + + def prepare(query, _opts, %{actor: %{id: actor_id}}) do + if is_nil(Ash.Query.get_argument(query, :relationship)) do + Ash.Query.filter(query, not exists(organizer_blocks, blocker_id == ^actor_id)) + else + query + end + end + + def prepare(query, _opts, _context), do: query +end diff --git a/priv/repo/migrations/20261125033612_add_user_blocks.exs b/priv/repo/migrations/20261125033612_add_user_blocks.exs new file mode 100644 index 000000000..08877ddba --- /dev/null +++ b/priv/repo/migrations/20261125033612_add_user_blocks.exs @@ -0,0 +1,59 @@ +defmodule Huddlz.Repo.Migrations.AddUserBlocks do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + create table(:user_blocks, primary_key: false) do + add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true + + add :inserted_at, :utc_datetime_usec, + null: false, + default: fragment("(now() AT TIME ZONE 'utc')") + + add :blocker_id, + references(:users, + column: :id, + name: "user_blocks_blocker_id_fkey", + type: :uuid, + prefix: "public", + on_delete: :delete_all + ), + null: false + + add :blocked_user_id, + references(:users, + column: :id, + name: "user_blocks_blocked_user_id_fkey", + type: :uuid, + prefix: "public", + on_delete: :delete_all + ), + null: false + end + + create unique_index(:user_blocks, [:blocker_id, :blocked_user_id], + name: "user_blocks_one_per_person_index" + ) + + create index(:user_blocks, [:blocked_user_id]) + end + + def down do + drop_if_exists index(:user_blocks, [:blocked_user_id]) + + drop constraint(:user_blocks, "user_blocks_blocked_user_id_fkey") + + drop constraint(:user_blocks, "user_blocks_blocker_id_fkey") + + drop_if_exists unique_index(:user_blocks, [:blocker_id, :blocked_user_id], + name: "user_blocks_one_per_person_index" + ) + + drop table(:user_blocks) + end +end diff --git a/priv/resource_snapshots/repo/user_blocks/20261125033613.json b/priv/resource_snapshots/repo/user_blocks/20261125033613.json new file mode 100644 index 000000000..1d52bb704 --- /dev/null +++ b/priv/resource_snapshots/repo/user_blocks/20261125033613.json @@ -0,0 +1,154 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "precision": null, + "primary_key?": true, + "references": null, + "scale": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "precision": null, + "primary_key?": false, + "references": null, + "scale": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "precision": null, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "index_where": null, + "match_tenant?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "user_blocks_blocker_id_fkey", + "on_delete": "delete", + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "users" + }, + "scale": null, + "size": null, + "source": "blocker_id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "precision": null, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "index_where": null, + "match_tenant?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "user_blocks_blocked_user_id_fkey", + "on_delete": "delete", + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "users" + }, + "scale": null, + "size": null, + "source": "blocked_user_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "create_table_options": null, + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [ + "blocked_user_id" + ], + "fields": [ + { + "type": "atom", + "value": "blocked_user_id" + } + ], + "include": null, + "include_base_filter?": true, + "message": null, + "name": null, + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": null, + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "2A735D842B289686C18B908680EFC77C8EC0EAE11BD5C8E32A4B0862F3E23837", + "identities": [ + { + "all_tenants?": false, + "base_filter": null, + "index_name": "user_blocks_one_per_person_index", + "keys": [ + { + "type": "atom", + "value": "blocker_id" + }, + { + "type": "atom", + "value": "blocked_user_id" + } + ], + "name": "one_per_person", + "nils_distinct?": true, + "where": null + } + ], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.Huddlz.Repo", + "schema": null, + "table": "user_blocks", + "temporal": null +} \ No newline at end of file diff --git a/test/features/huddl_organizer_moderation.feature b/test/features/huddl_organizer_moderation.feature new file mode 100644 index 000000000..5ae73d4ee --- /dev/null +++ b/test/features/huddl_organizer_moderation.feature @@ -0,0 +1,107 @@ +@async @database @conn @huddl_organizer_moderation +Feature: Report or block a huddl's organizer from the huddl + As a person browsing huddlz in an app that never shows who organized them + I want to report or block the organizer of a huddl I can see + So that I can raise a concern and stop seeing their huddlz + + Background: + Given the following users exist: + | email | role | display_name | + | owner612@example.com | user | Owner Olive | + | spam612@example.com | user | Crypto Kings Promo | + | member612@example.com | user | Member Maya | + And a public group "Moderation Brooklyn Coffee" exists with owner "owner612@example.com" + And "spam612@example.com" is an organizer of "Moderation Brooklyn Coffee" + And the huddl "Free Coin Giveaway" exists in group "Moderation Brooklyn Coffee" hosted by "spam612@example.com" + And the huddl "Saturday Pour Over" exists in group "Moderation Brooklyn Coffee" hosted by "owner612@example.com" + + Scenario: A member reports a huddl's organizer without learning who they are + Given I am signed in as "member612@example.com" + When I report the organizer of "Free Coin Giveaway" for "spam" saying "Coin listings" through JSON:API + Then the organizer report is accepted without naming the organizer + And "member612@example.com" has an open report about "spam612@example.com" for "spam" saying "Coin listings" + And the report about "spam612@example.com" came from the huddl "Free Coin Giveaway" + + Scenario: Reporting an organizer follows the rules for reporting an account + Given I am signed in as "member612@example.com" + When I report the organizer of "Free Coin Giveaway" for "" saying "" through JSON:API + Then JSON:API asks for an organizer report reason + Given I am signed in as "spam612@example.com" + When I report the organizer of "Free Coin Giveaway" for "spam" saying "" through JSON:API + Then the organizer report is refused + Given "member612@example.com" has not confirmed their address + And I am signed in as "member612@example.com" + When I report the organizer of "Free Coin Giveaway" for "spam" saying "" through JSON:API + Then the organizer report is refused + And there are no reports about "spam612@example.com" + + Scenario: Visitors cannot report or block an organizer + When I report the organizer of "Free Coin Giveaway" for "spam" saying "" through JSON:API + Then the organizer report is refused + When I block the organizer of "Free Coin Giveaway" through JSON:API + Then the block is refused + And there are no reports about "spam612@example.com" + + Scenario: Blocking an organizer hides their huddlz from discovery and the group + Given I am signed in as "member612@example.com" + When I block the organizer of "Free Coin Giveaway" through JSON:API + Then the block is accepted + And discovery through JSON:API shows "Saturday Pour Over" + But discovery through JSON:API does not show "Free Coin Giveaway" + And the group's upcoming huddlz through JSON:API do not show "Free Coin Giveaway" + And I can still open "Free Coin Giveaway" through JSON:API + + Scenario: Blocking again keeps a single block + Given I am signed in as "member612@example.com" + When I block the organizer of "Free Coin Giveaway" through JSON:API + And I block the organizer of "Free Coin Giveaway" through JSON:API + Then the block is accepted + And my blocked people through JSON:API are "Crypto Kings Promo" + + Scenario: Unblocking brings an organizer's huddlz back + Given I am signed in as "member612@example.com" + And I block the organizer of "Free Coin Giveaway" through JSON:API + When I unblock "Crypto Kings Promo" through JSON:API + Then my blocked people through JSON:API are "" + And discovery through JSON:API shows "Free Coin Giveaway" + + Scenario: A block is private to the person who made it + Given "member612@example.com" has blocked the organizer of "Free Coin Giveaway" + And I am signed in as "spam612@example.com" + Then my blocked people through JSON:API are "" + And discovery through JSON:API shows "Free Coin Giveaway" + When I try to remove the block "member612@example.com" made through JSON:API + Then "member612@example.com" still blocks "spam612@example.com" + + Scenario: Nobody blocks themselves + Given I am signed in as "spam612@example.com" + When I block the organizer of "Free Coin Giveaway" through JSON:API + Then the block is turned down with "You organize this huddl." + + Scenario: A huddl tells its organizer that they organized it + Given I am signed in as "spam612@example.com" + Then JSON:API says I organized "Free Coin Giveaway" + And JSON:API says I did not organize "Saturday Pour Over" + Given I am signed in as "member612@example.com" + Then JSON:API says I did not organize "Free Coin Giveaway" + + Scenario: A member reports and blocks the owner of a public group with no huddlz + Given a public group "Quiet Spam Club" exists with owner "spam612@example.com" + And I am signed in as "member612@example.com" + When I report the group "Quiet Spam Club" for "spam" saying "Promotional description" through JSON:API + Then the group report is accepted without naming the owner + And "member612@example.com" has an open report about "spam612@example.com" for "spam" saying "Promotional description" + And the report about "spam612@example.com" came from the group "Quiet Spam Club" + When I block the owner of group "Quiet Spam Club" through JSON:API + Then the block is accepted + And my blocked people through JSON:API are "Crypto Kings Promo" + And discovery through JSON:API does not show "Free Coin Giveaway" + + Scenario: A group owner cannot block themselves and sees they own the group + Given a public group "Quiet Spam Club" exists with owner "spam612@example.com" + And I am signed in as "spam612@example.com" + When I block the owner of group "Quiet Spam Club" through JSON:API + Then the block is turned down with "You own this group." + And JSON:API says I own the group "Quiet Spam Club" + Given I am signed in as "member612@example.com" + Then JSON:API says I do not own the group "Quiet Spam Club" diff --git a/test/features/step_definitions/account_reports_steps.exs b/test/features/step_definitions/account_reports_steps.exs index f3524d3d4..aeddec9e4 100644 --- a/test/features/step_definitions/account_reports_steps.exs +++ b/test/features/step_definitions/account_reports_steps.exs @@ -189,7 +189,11 @@ defmodule AccountReportsSteps do method in ["get", "post", "patch", "put", "delete"], do: {path, method} - assert [{"/api/json/account_reports", "post"}] = report_routes + assert Enum.sort(report_routes) == [ + {"/api/json/account_reports", "post"}, + {"/api/json/account_reports/organizer", "post"} + ] + context end diff --git a/test/features/step_definitions/huddl_organizer_moderation_steps.exs b/test/features/step_definitions/huddl_organizer_moderation_steps.exs new file mode 100644 index 000000000..341049e46 --- /dev/null +++ b/test/features/step_definitions/huddl_organizer_moderation_steps.exs @@ -0,0 +1,311 @@ +defmodule HuddlOrganizerModerationSteps do + use Cucumber.StepDefinition + + import ExUnit.Assertions + import HuddlzWeb.ApiCase, only: [authenticated_conn: 2] + import Phoenix.ConnTest, only: [build_conn: 0, dispatch: 5, json_response: 2] + + require Ash.Query + + alias Huddlz.Accounts + alias Huddlz.Accounts.{AccountReport, User, UserBlock} + alias Huddlz.Communities.{Group, Huddl} + + # ── reporting ─────────────────────────────────────────────────────── + + step "I report the organizer of {string} for {string} saying {string} through JSON:API", + %{args: [title, reason, details]} = context do + attributes = + %{"huddl_id" => find_huddl(title).id, "reason" => reason, "details" => details} + |> Map.reject(fn {_key, value} -> value == "" end) + + # Generic actions take their inputs directly under "data". + response = + api_conn(context) + |> Plug.Conn.put_req_header("content-type", "application/vnd.api+json") + |> dispatch(HuddlzWeb.Endpoint, :post, "/api/json/account_reports/organizer", %{ + "data" => attributes + }) + + Map.put(context, :organizer_report_response, response) + end + + step "the organizer report is accepted without naming the organizer", context do + response = context.organizer_report_response + assert response.status in 200..299, response.resp_body + + organizer = find_user("spam612@example.com") + refute response.resp_body =~ organizer.id + refute response.resp_body =~ to_string(organizer.email) + refute response.resp_body =~ organizer.display_name + + context + end + + step "the organizer report is refused", context do + assert %{"errors" => [_ | _]} = json_response(context.organizer_report_response, 403) + context + end + + step "JSON:API asks for an organizer report reason", context do + assert %{"errors" => errors} = json_response(context.organizer_report_response, 400) + assert Enum.any?(errors, &(&1["detail"] =~ "Say what's wrong")) + context + end + + step "the report about {string} came from the huddl {string}", + %{args: [email, title]} = context do + huddl_id = find_huddl(title).id + + assert [%AccountReport{source_type: :huddl, source_id: ^huddl_id}] = + AccountReport + |> Ash.Query.filter(reported_user_id == ^find_user(email).id) + |> Ash.read!(authorize?: false) + + context + end + + step "I report the group {string} for {string} saying {string} through JSON:API", + %{args: [name, reason, details]} = context do + attributes = + %{"group_id" => find_group(name).id, "reason" => reason, "details" => details} + |> Map.reject(fn {_key, value} -> value == "" end) + + response = + api_conn(context) + |> Plug.Conn.put_req_header("content-type", "application/vnd.api+json") + |> dispatch(HuddlzWeb.Endpoint, :post, "/api/json/account_reports/group", %{ + "data" => attributes + }) + + Map.put(context, :group_report_response, response) + end + + step "the group report is accepted without naming the owner", context do + response = context.group_report_response + assert response.status in 200..299, response.resp_body + + owner = find_user("spam612@example.com") + refute response.resp_body =~ owner.id + refute response.resp_body =~ to_string(owner.email) + refute response.resp_body =~ owner.display_name + + context + end + + step "the report about {string} came from the group {string}", + %{args: [email, name]} = context do + group_id = find_group(name).id + + assert [%AccountReport{source_type: :group, source_id: ^group_id}] = + AccountReport + |> Ash.Query.filter(reported_user_id == ^find_user(email).id) + |> Ash.read!(authorize?: false) + + context + end + + step "I block the owner of group {string} through JSON:API", %{args: [name]} = context do + response = + post(context, "/api/json/blocks/group", "user_block", %{ + "group_id" => find_group(name).id + }) + + Map.put(context, :block_response, response) + end + + # ── blocking ──────────────────────────────────────────────────────── + + step "{string} has blocked the organizer of {string}", %{args: [email, title]} = context do + Accounts.block_huddl_organizer!(find_huddl(title).id, actor: find_user(email)) + context + end + + step "I block the organizer of {string} through JSON:API", %{args: [title]} = context do + response = + post(context, "/api/json/blocks/organizer", "user_block", %{ + "huddl_id" => find_huddl(title).id + }) + + Map.put(context, :block_response, response) + end + + step "the block is accepted", context do + assert %{"data" => %{"type" => "user_block", "attributes" => attributes}} = + json_response(context.block_response, 201) + + refute Map.has_key?(attributes, "blocked_user_id") + refute Map.has_key?(attributes, "blocker_id") + refute context.block_response.resp_body =~ find_user("spam612@example.com").id + context + end + + step "the block is refused", context do + assert %{"errors" => [_ | _]} = json_response(context.block_response, 403) + context + end + + step "the block is turned down with {string}", %{args: [message]} = context do + assert %{"errors" => errors} = json_response(context.block_response, 400) + assert Enum.any?(errors, &(&1["detail"] =~ message)), inspect(errors) + context + end + + step "my blocked people through JSON:API are {string}", %{args: [names]} = context do + expected = if names == "", do: [], else: String.split(names, ", ") + assert Enum.map(blocks(context), & &1["attributes"]["blocked_user_name"]) == expected + context + end + + step "I unblock {string} through JSON:API", %{args: [name]} = context do + block = Enum.find(blocks(context), &(&1["attributes"]["blocked_user_name"] == name)) + + response = + api_conn(context) + |> dispatch(HuddlzWeb.Endpoint, :delete, "/api/json/blocks/#{block["id"]}", %{}) + + assert response.status in 200..299, response.resp_body + context + end + + step "I try to remove the block {string} made through JSON:API", + %{args: [email]} = context do + [block] = blocks_by(email) + + response = + api_conn(context) + |> dispatch(HuddlzWeb.Endpoint, :delete, "/api/json/blocks/#{block.id}", %{}) + + assert response.status in 400..499 + context + end + + step "{string} still blocks {string}", %{args: [email, blocked]} = context do + blocked_id = find_user(blocked).id + assert [%UserBlock{blocked_user_id: ^blocked_id}] = blocks_by(email) + context + end + + # ── what the person sees ──────────────────────────────────────────── + + step "discovery through JSON:API shows {string}", %{args: [title]} = context do + assert title in titles(context, "/api/json/huddlz", %{}) + context + end + + step "discovery through JSON:API does not show {string}", %{args: [title]} = context do + refute title in titles(context, "/api/json/huddlz", %{}) + context + end + + step "the group's upcoming huddlz through JSON:API do not show {string}", + %{args: [title]} = context do + huddl = find_huddl(title) + titles = titles(context, "/api/json/huddlz/by_group", %{"group_id" => huddl.group_id}) + refute title in titles + assert titles != [], "the group should still list its other huddlz" + context + end + + step "I can still open {string} through JSON:API", %{args: [title]} = context do + huddl = find_huddl(title) + + assert %{"data" => %{"id" => id}} = + api_conn(context) + |> dispatch(HuddlzWeb.Endpoint, :get, "/api/json/huddlz/#{huddl.id}", %{}) + |> json_response(200) + + assert id == huddl.id + context + end + + step "JSON:API says I organized {string}", %{args: [title]} = context do + assert organized_by_me(context, title) == true + context + end + + step "JSON:API says I did not organize {string}", %{args: [title]} = context do + assert organized_by_me(context, title) == false + context + end + + step "JSON:API says I own the group {string}", %{args: [name]} = context do + assert owned_by_me(context, name) == true + context + end + + step "JSON:API says I do not own the group {string}", %{args: [name]} = context do + assert owned_by_me(context, name) == false + context + end + + # ── helpers ───────────────────────────────────────────────────────── + + defp organized_by_me(context, title) do + api_conn(context) + |> dispatch(HuddlzWeb.Endpoint, :get, "/api/json/huddlz/#{find_huddl(title).id}", %{}) + |> json_response(200) + |> get_in(["data", "attributes", "organized_by_me"]) + end + + defp owned_by_me(context, name) do + api_conn(context) + |> dispatch( + HuddlzWeb.Endpoint, + :get, + "/api/json/groups/#{find_group(name).id}?fields[group]=owned_by_me", + %{} + ) + |> json_response(200) + |> get_in(["data", "attributes", "owned_by_me"]) + end + + defp titles(context, path, params) do + api_conn(context) + |> dispatch(HuddlzWeb.Endpoint, :get, path, params) + |> json_response(200) + |> Map.fetch!("data") + |> Enum.map(& &1["attributes"]["title"]) + end + + defp blocks(context) do + api_conn(context) + |> dispatch(HuddlzWeb.Endpoint, :get, "/api/json/blocks", %{}) + |> json_response(200) + |> Map.fetch!("data") + end + + defp blocks_by(email) do + UserBlock + |> Ash.Query.filter(blocker_id == ^find_user(email).id) + |> Ash.read!(authorize?: false) + end + + defp post(context, path, type, attributes) do + api_conn(context) + |> Plug.Conn.put_req_header("content-type", "application/vnd.api+json") + |> dispatch(HuddlzWeb.Endpoint, :post, path, %{ + "data" => %{"type" => type, "attributes" => attributes} + }) + end + + defp api_conn(%{current_user: %User{} = user}), do: authenticated_conn(build_conn(), user) + defp api_conn(_context), do: build_conn() + + defp find_user(email) do + User |> Ash.Query.filter(email == ^email) |> Ash.read_one!(authorize?: false) + end + + defp find_huddl(title) do + Huddl + |> Ash.Query.for_read(:read_for_group_lifecycle) + |> Ash.Query.filter(title == ^title) + |> Ash.read_one!(authorize?: false) + end + + defp find_group(name) do + Group + |> Ash.Query.filter(name == ^name) + |> Ash.read_one!(authorize?: false) + end +end From be6dd50d138109114a570a807a7459cf9b72b612 Mon Sep 17 00:00:00 2001 From: Micah Woods Date: Tue, 24 Nov 2026 21:45:54 -0600 Subject: [PATCH 2/3] Filter blocked organizers in member search, update OpenAPI route check, and fix credo --- .../accounts/account_report/actions/report_group.ex | 3 ++- .../account_report/actions/report_organizer.ex | 3 ++- .../account_report/checks/reporter_can_see_account.ex | 6 +++--- lib/huddlz/accounts/user_block.ex | 10 +++++----- .../huddl/preparations/hide_blocked_organizers.ex | 2 +- test/features/huddl_organizer_moderation.feature | 4 +++- .../step_definitions/account_reports_steps.exs | 1 + .../huddl_organizer_moderation_steps.exs | 5 +++++ 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/huddlz/accounts/account_report/actions/report_group.ex b/lib/huddlz/accounts/account_report/actions/report_group.ex index 9cf684d5e..67c72924b 100644 --- a/lib/huddlz/accounts/account_report/actions/report_group.ex +++ b/lib/huddlz/accounts/account_report/actions/report_group.ex @@ -8,6 +8,7 @@ defmodule Huddlz.Accounts.AccountReport.Actions.ReportGroup do use Ash.Resource.Actions.Implementation + alias Ash.Error.Query.NotFound alias Huddlz.Accounts alias Huddlz.Accounts.GroupOwner alias Huddlz.Communities.Group @@ -30,7 +31,7 @@ defmodule Huddlz.Accounts.AccountReport.Actions.ReportGroup do ) do :ok else - :error -> {:error, Ash.Error.Query.NotFound.exception(resource: Group)} + :error -> {:error, NotFound.exception(resource: Group)} {:error, error} -> {:error, error} end end diff --git a/lib/huddlz/accounts/account_report/actions/report_organizer.ex b/lib/huddlz/accounts/account_report/actions/report_organizer.ex index 04e50de9e..db19f54d4 100644 --- a/lib/huddlz/accounts/account_report/actions/report_organizer.ex +++ b/lib/huddlz/accounts/account_report/actions/report_organizer.ex @@ -8,6 +8,7 @@ defmodule Huddlz.Accounts.AccountReport.Actions.ReportOrganizer do use Ash.Resource.Actions.Implementation + alias Ash.Error.Query.NotFound alias Huddlz.Accounts alias Huddlz.Accounts.HuddlOrganizer alias Huddlz.Communities.Huddl @@ -30,7 +31,7 @@ defmodule Huddlz.Accounts.AccountReport.Actions.ReportOrganizer do ) do :ok else - :error -> {:error, Ash.Error.Query.NotFound.exception(resource: Huddl)} + :error -> {:error, NotFound.exception(resource: Huddl)} {:error, error} -> {:error, error} end end diff --git a/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex b/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex index 3fe1fb4af..bc820a774 100644 --- a/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex +++ b/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex @@ -2,9 +2,9 @@ defmodule Huddlz.Accounts.AccountReport.Checks.ReporterCanSeeAccount do @moduledoc """ Reporting grants no new visibility: the reporter must already meet the account on an ordinary member surface. That is a group they both belong - to, or a huddl they both go to, or a huddl the reporter goes to that - the account organizes, or a public huddl whose organizer they can see. - Nobody reports themselves. + to, a huddl they both go to, a huddl the reporter goes to that the + account organizes, a public huddl whose organizer they can see, or a + public group the account owns. Nobody reports themselves. """ use Ash.Policy.SimpleCheck diff --git a/lib/huddlz/accounts/user_block.ex b/lib/huddlz/accounts/user_block.ex index 7eb8d54be..b44daaac1 100644 --- a/lib/huddlz/accounts/user_block.ex +++ b/lib/huddlz/accounts/user_block.ex @@ -1,10 +1,10 @@ defmodule Huddlz.Accounts.UserBlock do @moduledoc """ - A person's choice to stop seeing huddlz someone else organizes. Today a - block is made from a huddl the person can see, and it blocks that - huddl's organizer: their huddlz leave the person's discovery and group - lists on every app. Huddlz the person already RSVPed to stay on their - calendar, and an open link still works. + A person's choice to stop seeing huddlz someone else organizes. A block can + be made from a huddl or group the person can see, targeting that huddl's + organizer or group's owner: their huddlz leave the person's discovery and + group lists on every app. Huddlz the person already RSVPed to stay on + their calendar, and an open link still works. Blocking is private. The blocked person is not told and can still see everything they could before. Only the person who blocked reads their diff --git a/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex b/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex index ed41c4619..5d1a360ad 100644 --- a/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex +++ b/lib/huddlz/communities/huddl/preparations/hide_blocked_organizers.ex @@ -8,7 +8,7 @@ defmodule Huddlz.Communities.Huddl.Preparations.HideBlockedOrganizers do require Ash.Query def prepare(query, _opts, %{actor: %{id: actor_id}}) do - if is_nil(Ash.Query.get_argument(query, :relationship)) do + if Ash.Query.get_argument(query, :relationship) in [nil, :member] do Ash.Query.filter(query, not exists(organizer_blocks, blocker_id == ^actor_id)) else query diff --git a/test/features/huddl_organizer_moderation.feature b/test/features/huddl_organizer_moderation.feature index 5ae73d4ee..a67b3025d 100644 --- a/test/features/huddl_organizer_moderation.feature +++ b/test/features/huddl_organizer_moderation.feature @@ -43,11 +43,13 @@ Feature: Report or block a huddl's organizer from the huddl And there are no reports about "spam612@example.com" Scenario: Blocking an organizer hides their huddlz from discovery and the group - Given I am signed in as "member612@example.com" + Given "member612@example.com" is a member of "Moderation Brooklyn Coffee" + And I am signed in as "member612@example.com" When I block the organizer of "Free Coin Giveaway" through JSON:API Then the block is accepted And discovery through JSON:API shows "Saturday Pour Over" But discovery through JSON:API does not show "Free Coin Giveaway" + And member discovery through JSON:API does not show "Free Coin Giveaway" And the group's upcoming huddlz through JSON:API do not show "Free Coin Giveaway" And I can still open "Free Coin Giveaway" through JSON:API diff --git a/test/features/step_definitions/account_reports_steps.exs b/test/features/step_definitions/account_reports_steps.exs index aeddec9e4..e7ed43513 100644 --- a/test/features/step_definitions/account_reports_steps.exs +++ b/test/features/step_definitions/account_reports_steps.exs @@ -191,6 +191,7 @@ defmodule AccountReportsSteps do assert Enum.sort(report_routes) == [ {"/api/json/account_reports", "post"}, + {"/api/json/account_reports/group", "post"}, {"/api/json/account_reports/organizer", "post"} ] diff --git a/test/features/step_definitions/huddl_organizer_moderation_steps.exs b/test/features/step_definitions/huddl_organizer_moderation_steps.exs index 341049e46..e67f35383 100644 --- a/test/features/step_definitions/huddl_organizer_moderation_steps.exs +++ b/test/features/step_definitions/huddl_organizer_moderation_steps.exs @@ -198,6 +198,11 @@ defmodule HuddlOrganizerModerationSteps do context end + step "member discovery through JSON:API does not show {string}", %{args: [title]} = context do + refute title in titles(context, "/api/json/huddlz", %{"relationship" => "member"}) + context + end + step "the group's upcoming huddlz through JSON:API do not show {string}", %{args: [title]} = context do huddl = find_huddl(title) From 4881715a16ad0068fa0c8f07a2f493297e616c1e Mon Sep 17 00:00:00 2001 From: Micah Woods Date: Tue, 24 Nov 2026 21:54:02 -0600 Subject: [PATCH 3/3] Scope public-group report visibility to group reports and fix moderation test requests --- .../checks/reporter_can_see_account.ex | 21 ++++++++++++------- .../huddl_organizer_moderation_steps.exs | 14 ++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex b/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex index bc820a774..c8a9905b9 100644 --- a/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex +++ b/lib/huddlz/accounts/account_report/checks/reporter_can_see_account.ex @@ -21,18 +21,18 @@ defmodule Huddlz.Accounts.AccountReport.Checks.ReporterCanSeeAccount do case Ash.Changeset.get_attribute(changeset, :reported_user_id) do nil -> false ^actor_id -> false - reported_id -> visible?(actor_id, reported_id) + reported_id -> visible?(actor_id, reported_id, changeset) end end def match?(_actor, _context, _opts), do: false - defp visible?(actor_id, reported_id) do + defp visible?(actor_id, reported_id, changeset) do shares_group?(actor_id, reported_id) or shares_huddl?(actor_id, reported_id) or organizes_attended_huddl?(actor_id, reported_id) or organizes_public_huddl?(reported_id) or - owns_public_group?(reported_id) + owns_reported_public_group?(reported_id, changeset) end defp shares_group?(actor_id, reported_id) do @@ -63,10 +63,15 @@ defmodule Huddlz.Accounts.AccountReport.Checks.ReporterCanSeeAccount do |> Ash.exists?() end - defp owns_public_group?(reported_id) do - Group - |> Ash.Query.for_read(:read, %{}, actor: nil) - |> Ash.Query.filter(owner_id == ^reported_id) - |> Ash.exists?() + defp owns_reported_public_group?(reported_id, changeset) do + with :group <- Ash.Changeset.get_attribute(changeset, :source_type), + group_id when is_binary(group_id) <- Ash.Changeset.get_attribute(changeset, :source_id) do + Group + |> Ash.Query.for_read(:read, %{}, actor: nil) + |> Ash.Query.filter(id == ^group_id and owner_id == ^reported_id) + |> Ash.exists?() + else + _ -> false + end end end diff --git a/test/features/step_definitions/huddl_organizer_moderation_steps.exs b/test/features/step_definitions/huddl_organizer_moderation_steps.exs index e67f35383..c03ff01bc 100644 --- a/test/features/step_definitions/huddl_organizer_moderation_steps.exs +++ b/test/features/step_definitions/huddl_organizer_moderation_steps.exs @@ -162,7 +162,7 @@ defmodule HuddlOrganizerModerationSteps do response = api_conn(context) - |> dispatch(HuddlzWeb.Endpoint, :delete, "/api/json/blocks/#{block["id"]}", %{}) + |> dispatch(HuddlzWeb.Endpoint, :delete, "/api/json/blocks/#{block["id"]}", nil) assert response.status in 200..299, response.resp_body context @@ -174,7 +174,7 @@ defmodule HuddlOrganizerModerationSteps do response = api_conn(context) - |> dispatch(HuddlzWeb.Endpoint, :delete, "/api/json/blocks/#{block.id}", %{}) + |> dispatch(HuddlzWeb.Endpoint, :delete, "/api/json/blocks/#{block.id}", nil) assert response.status in 400..499 context @@ -189,17 +189,21 @@ defmodule HuddlOrganizerModerationSteps do # ── what the person sees ──────────────────────────────────────────── step "discovery through JSON:API shows {string}", %{args: [title]} = context do - assert title in titles(context, "/api/json/huddlz", %{}) + assert title in titles(context, "/api/json/huddlz", %{"date_filter" => "upcoming"}) context end step "discovery through JSON:API does not show {string}", %{args: [title]} = context do - refute title in titles(context, "/api/json/huddlz", %{}) + refute title in titles(context, "/api/json/huddlz", %{"date_filter" => "upcoming"}) context end step "member discovery through JSON:API does not show {string}", %{args: [title]} = context do - refute title in titles(context, "/api/json/huddlz", %{"relationship" => "member"}) + refute title in titles(context, "/api/json/huddlz", %{ + "date_filter" => "upcoming", + "relationship" => "member" + }) + context end