From 185d67a7f8249df9653f0d2565bf6fcfed5e2e28 Mon Sep 17 00:00:00 2001 From: Rogerio Pontual <44991200+jyeshe@users.noreply.github.com> Date: Mon, 19 Aug 2024 10:38:25 +0100 Subject: [PATCH] Pass user_id param on check usage limits (#2388) --- CHANGELOG.md | 3 +++ lib/lightning/extensions/usage_limiting.ex | 3 ++- lib/lightning_web/live/live_helpers.ex | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d5d7cae5..5eb08249af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to ### Added +- Pass the user_id param on check usage limits. + [#2387](https://github.com/OpenFn/lightning/issues/2387) + ### Changed ### Fixed diff --git a/lib/lightning/extensions/usage_limiting.ex b/lib/lightning/extensions/usage_limiting.ex index c5711f9ebe..f0d9e0da52 100644 --- a/lib/lightning/extensions/usage_limiting.ex +++ b/lib/lightning/extensions/usage_limiting.ex @@ -28,7 +28,8 @@ defmodule Lightning.Extensions.UsageLimiting do @moduledoc false @type t :: %Context{ - project_id: Ecto.UUID.t() + project_id: Ecto.UUID.t(), + user_id: Ecto.UUID.t() } defstruct [:project_id, :user_id] diff --git a/lib/lightning_web/live/live_helpers.ex b/lib/lightning_web/live/live_helpers.ex index 26166a9577..55263bebdd 100644 --- a/lib/lightning_web/live/live_helpers.ex +++ b/lib/lightning_web/live/live_helpers.ex @@ -172,9 +172,10 @@ defmodule LightningWeb.LiveHelpers do %{socket | assigns: check_limits(assigns, project_id)} end - def check_limits(assigns, project_id) do + def check_limits(%{current_user: user} = assigns, project_id) do case UsageLimiter.check_limits(%Context{ - project_id: project_id + project_id: project_id, + user_id: user.id }) do :ok -> assigns