diff options
author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2023-04-13 08:40:04 +0000 |
---|---|---|
committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2023-04-13 08:40:04 +0000 |
commit | 3867b52aefdab5c26bcd4f58155b1370ee40e4dd (patch) | |
tree | 8f1bc8a82185e9812dd16a43746257d515348206 /lib | |
parent | cf1ba77b9e6cfe173c21569cf4c9d0c858364270 (diff) | |
parent | 67d1897c6e9516ea76dff1456f15c9427813bda4 (diff) | |
download | pleroma-3867b52aefdab5c26bcd4f58155b1370ee40e4dd.tar.gz pleroma-3867b52aefdab5c26bcd4f58155b1370ee40e4dd.zip |
Merge branch 'tusooa/3027-dedupe-poll' into 'develop'
Dedupe poll options
Closes #3027
See merge request pleroma/pleroma!3860
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index ff0814329..a93c97e1e 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -145,6 +145,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do when is_list(options) do limits = Config.get([:instance, :poll_limits]) + options = options |> Enum.uniq() + with :ok <- validate_poll_expiration(expires_in, limits), :ok <- validate_poll_options_amount(options, limits), :ok <- validate_poll_options_length(options, limits) do @@ -180,10 +182,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do end defp validate_poll_options_amount(options, %{max_options: max_options}) do - if Enum.count(options) > max_options do - {:error, "Poll can't contain more than #{max_options} options"} - else - :ok + cond do + Enum.count(options) < 2 -> + {:error, "Poll must contain at least 2 options"} + + Enum.count(options) > max_options -> + {:error, "Poll can't contain more than #{max_options} options"} + + true -> + :ok end end |