diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/conversation/participation.ex | 28 | ||||
-rw-r--r-- | lib/pleroma/moderation_log.ex | 11 | ||||
-rw-r--r-- | lib/pleroma/object/fetcher.ex | 5 | ||||
-rw-r--r-- | lib/pleroma/plugs/trailing_format_plug.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/admin_api/admin_api_controller.ex | 12 | ||||
-rw-r--r-- | lib/pleroma/web/endpoint.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 2 |
7 files changed, 55 insertions, 8 deletions
diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex index 176b82a20..aafe57280 100644 --- a/lib/pleroma/conversation/participation.ex +++ b/lib/pleroma/conversation/participation.ex @@ -122,9 +122,37 @@ defmodule Pleroma.Conversation.Participation do order_by: [desc: p.updated_at], preload: [conversation: [:users]] ) + |> restrict_recipients(user, params) |> Pleroma.Pagination.fetch_paginated(params) end + def restrict_recipients(query, user, %{"recipients" => user_ids}) do + user_ids = + [user.id | user_ids] + |> Enum.uniq() + |> Enum.reduce([], fn user_id, acc -> + case FlakeId.Ecto.CompatType.dump(user_id) do + {:ok, user_id} -> [user_id | acc] + _ -> acc + end + end) + + conversation_subquery = + __MODULE__ + |> group_by([p], p.conversation_id) + |> having( + [p], + count(p.user_id) == ^length(user_ids) and + fragment("array_agg(?) @> ?", p.user_id, ^user_ids) + ) + |> select([p], %{id: p.conversation_id}) + + query + |> join(:inner, [p], c in subquery(conversation_subquery), on: p.conversation_id == c.id) + end + + def restrict_recipients(query, _, _), do: query + def for_user_and_conversation(user, conversation) do from(p in __MODULE__, where: p.user_id == ^user.id, diff --git a/lib/pleroma/moderation_log.ex b/lib/pleroma/moderation_log.ex index 9dc4a94c9..ffa5dc25d 100644 --- a/lib/pleroma/moderation_log.ex +++ b/lib/pleroma/moderation_log.ex @@ -616,6 +616,17 @@ defmodule Pleroma.ModerationLog do "@#{actor_nickname} deleted status ##{subject_id}" end + @spec get_log_entry_message(ModerationLog) :: String.t() + def get_log_entry_message(%ModerationLog{ + data: %{ + "actor" => %{"nickname" => actor_nickname}, + "action" => "force_password_reset", + "subject" => subjects + } + }) do + "@#{actor_nickname} force password reset for users: #{users_to_nicknames_string(subjects)}" + end + defp nicknames_to_string(nicknames) do nicknames |> Enum.map(&"@#{&1}") diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index 441ae8b65..9a9a46550 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -38,7 +38,8 @@ defmodule Pleroma.Object.Fetcher do data <- maybe_reinject_internal_fields(data, struct), changeset <- Object.change(struct, %{data: data}), changeset <- touch_changeset(changeset), - {:ok, object} <- Repo.insert_or_update(changeset) do + {:ok, object} <- Repo.insert_or_update(changeset), + {:ok, object} <- Object.set_cache(object) do {:ok, object} else e -> @@ -53,7 +54,7 @@ defmodule Pleroma.Object.Fetcher do {:ok, object} <- reinject_object(object, data) do {:ok, object} else - {:local, true} -> object + {:local, true} -> {:ok, object} e -> {:error, e} end end diff --git a/lib/pleroma/plugs/trailing_format_plug.ex b/lib/pleroma/plugs/trailing_format_plug.ex index ce366b218..a4b8a406d 100644 --- a/lib/pleroma/plugs/trailing_format_plug.ex +++ b/lib/pleroma/plugs/trailing_format_plug.ex @@ -24,7 +24,8 @@ defmodule Pleroma.Plugs.TrailingFormatPlug do "/api/help", "/api/externalprofile", "/notice", - "/api/pleroma/emoji" + "/api/pleroma/emoji", + "/api/oauth_tokens" ] def init(opts) do diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 7d5ff7629..8c1318d1b 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -608,10 +608,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do end @doc "Force password reset for a given user" - def force_password_reset(conn, %{"nickname" => nickname}) do - (%User{local: true} = user) = User.get_cached_by_nickname(nickname) + def force_password_reset(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do + users = nicknames |> Enum.map(&User.get_cached_by_nickname/1) - User.force_password_reset_async(user) + Enum.map(users, &User.force_password_reset_async/1) + + ModerationLog.insert_log(%{ + actor: admin, + subject: users, + action: "force_password_reset" + }) json_response(conn, :no_content, "") end diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 2212e93f4..49735b5c2 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -12,7 +12,7 @@ defmodule Pleroma.Web.Endpoint do plug(Pleroma.Plugs.HTTPSecurityPlug) plug(Pleroma.Plugs.UploadedMedia) - @static_cache_control "public, no-cache" + @static_cache_control "public max-age=86400 must-revalidate" # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 7b9e9b1b7..7628077a2 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -171,7 +171,7 @@ defmodule Pleroma.Web.Router do post("/users/email_invite", AdminAPIController, :email_invite) get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset) - patch("/users/:nickname/force_password_reset", AdminAPIController, :force_password_reset) + patch("/users/force_password_reset", AdminAPIController, :force_password_reset) get("/users", AdminAPIController, :list_users) get("/users/:nickname", AdminAPIController, :user_show) |