From fd9e19ce07b51f5d2c129b476282292e92b86f0d Mon Sep 17 00:00:00 2001
From: Aileen Nowak <AileenCGN@gmail.com>
Date: Tue, 9 Aug 2022 12:54:37 +0100
Subject: [PATCH] Fixed limit service not allowing explore integration

no issue

- Don't run limit checks for the Ghost Explore integration
---
 ghost/core/core/server/services/auth/api-key/admin.js   | 6 +++++-
 ghost/core/core/server/services/auth/api-key/content.js | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ghost/core/core/server/services/auth/api-key/admin.js b/ghost/core/core/server/services/auth/api-key/admin.js
index 6ddd976642..16a6ffa3bf 100644
--- a/ghost/core/core/server/services/auth/api-key/admin.js
+++ b/ghost/core/core/server/services/auth/api-key/admin.js
@@ -127,7 +127,11 @@ const authenticateWithToken = async (req, res, next, {token, JWT_OPTIONS}) => {
 
         // CASE: blocking all non-internal: "custom" and "builtin" integration requests when the limit is reached
         if (limitService.isLimited('customIntegrations')
-            && (apiKey.relations.integration && !['internal'].includes(apiKey.relations.integration.get('type')))) {
+            && (apiKey.relations.integration
+                && !['internal'].includes(apiKey.relations.integration.get('type'))
+                && !['ghost-explore'].includes(apiKey.relations.integration.get('slug'))
+            )
+        ) {
             // NOTE: using "checkWouldGoOverLimit" instead of "checkIsOverLimit" here because flag limits don't have
             //       a concept of measuring if the limit has been surpassed
             await limitService.errorIfWouldGoOverLimit('customIntegrations');
diff --git a/ghost/core/core/server/services/auth/api-key/content.js b/ghost/core/core/server/services/auth/api-key/content.js
index 6dd51bee2b..c6a3a6f6eb 100644
--- a/ghost/core/core/server/services/auth/api-key/content.js
+++ b/ghost/core/core/server/services/auth/api-key/content.js
@@ -43,7 +43,11 @@ const authenticateContentApiKey = async function authenticateContentApiKey(req,
 
         // CASE: blocking all non-internal: "custom" and "builtin" integration requests when the limit is reached
         if (limitService.isLimited('customIntegrations')
-            && (apiKey.relations.integration && !['internal'].includes(apiKey.relations.integration.get('type')))) {
+            && (apiKey.relations.integration
+                && !['internal'].includes(apiKey.relations.integration.get('type'))
+                && !['ghost-explore'].includes(apiKey.relations.integration.get('slug'))
+            )
+        ) {
             // NOTE: using "checkWouldGoOverLimit" instead of "checkIsOverLimit" here because flag limits don't have
             //       a concept of measuring if the limit has been surpassed
             await limitService.errorIfWouldGoOverLimit('customIntegrations');