diff --git a/lib/atomic/activities.ex b/lib/atomic/activities.ex index 7ef0894bb..3c6affa5b 100644 --- a/lib/atomic/activities.ex +++ b/lib/atomic/activities.ex @@ -195,7 +195,8 @@ defmodule Atomic.Activities do """ def create_activity_with_post(attrs \\ %{}, after_save \\ &{:ok, &1}) do - case RateLimiter.limit_activities(attrs["organization_id"]) do + case not is_nil(attrs["organization_id"]) and + RateLimiter.limit_activities(attrs["organization_id"]) do :ok -> Multi.new() |> Multi.insert(:post, fn _ -> @@ -224,7 +225,8 @@ defmodule Atomic.Activities do end def create_activity(attrs \\ %{}) do - case RateLimiter.limit_activities(attrs["organization_id"]) do + case not is_nil(attrs["organization_id"]) and + RateLimiter.limit_activities(attrs["organization_id"]) do :ok -> %Activity{} |> Activity.changeset(attrs) diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 487a200a5..4927130ab 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -732,7 +732,8 @@ defmodule Atomic.Organizations do """ def create_announcement_with_post(attrs \\ %{}) do - case RateLimiter.limit_announcements(attrs["organization_id"]) do + case not is_nil(attrs["organization_id"]) and + RateLimiter.limit_announcements(attrs["organization_id"]) do :ok -> Multi.new() |> Multi.insert(:post, fn _ -> @@ -761,7 +762,8 @@ defmodule Atomic.Organizations do end def create_announcement(attrs \\ %{}) do - case RateLimiter.limit_announcements(attrs["organization_id"]) do + case not is_nil(attrs["organization_id"]) and + RateLimiter.limit_announcements(attrs["organization_id"]) do :ok -> %Announcement{} |> Announcement.changeset(attrs) diff --git a/lib/atomic/rate_limiter.ex b/lib/atomic/rate_limiter.ex index 97105ffb5..2b8026993 100644 --- a/lib/atomic/rate_limiter.ex +++ b/lib/atomic/rate_limiter.ex @@ -3,8 +3,8 @@ defmodule Atomic.RateLimiter do Rate limiter module for Atomic. """ use Atomic.Context - alias Atomic.Organizations.Announcement alias Atomic.Activities.Activity + alias Atomic.Organizations.Announcement alias Atomic.Repo @activities_limit_per_day Application.compile_env!(:atomic, :activities_limit_per_day) @announcements_limit_per_day Application.compile_env!(:atomic, :announcements_limit_per_day) @@ -22,7 +22,7 @@ defmodule Atomic.RateLimiter do """ def limit_activities(organization_id) do current_time = DateTime.utc_now() - twenty_four_hours_ago = DateTime.add(current_time, -86400) + twenty_four_hours_ago = DateTime.add(current_time, -86_400) activity_count = Repo.all( @@ -52,7 +52,7 @@ defmodule Atomic.RateLimiter do """ def limit_announcements(organization_id) do current_time = DateTime.utc_now() - twenty_four_hours_ago = DateTime.add(current_time, -86400) + twenty_four_hours_ago = DateTime.add(current_time, -86_400) announcement_count = Repo.all(