From d2de063e73b42ef416412ef08e5baa48380e8bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Rodrigues?= Date: Mon, 8 Apr 2024 16:35:29 +0100 Subject: [PATCH] fix: CI --- lib/atomic/activities.ex | 6 ++++-- lib/atomic/organizations.ex | 6 ++++-- lib/atomic/rate_limiter.ex | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) 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(