From 7ff701c998f16430a9812f0ece88080d9f00587d Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Thu, 24 Aug 2023 10:15:42 +0200
Subject: [PATCH] refactor

---
 app/controllers/api/osuny/server/websites_controller.rb | 7 ++++---
 app/models/communication/website/with_theme.rb          | 7 +++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/app/controllers/api/osuny/server/websites_controller.rb b/app/controllers/api/osuny/server/websites_controller.rb
index bc5c1f1f8..2cd27c0e2 100644
--- a/app/controllers/api/osuny/server/websites_controller.rb
+++ b/app/controllers/api/osuny/server/websites_controller.rb
@@ -5,9 +5,10 @@ class Api::Osuny::Server::WebsitesController < Api::ApplicationController
   end
 
   def theme_released
-    render_forbidden unless params[:secret_key].present? && params[:secret_key] == ENV['OSUNY_API_AUTOUPDATE_THEME_KEY']
-    Communication::Website.with_automatic_update.find_each do |website|
-      website.update_theme_version
+    if params[:secret_key].present? && params[:secret_key] == ENV['OSUNY_API_AUTOUPDATE_THEME_KEY']
+      Communication::Website.autoupdate_websites
+    else
+      render_forbidden 
     end
   end
 end
diff --git a/app/models/communication/website/with_theme.rb b/app/models/communication/website/with_theme.rb
index 022d669bf..b2d1e9f7a 100644
--- a/app/models/communication/website/with_theme.rb
+++ b/app/models/communication/website/with_theme.rb
@@ -4,8 +4,15 @@ module Communication::Website::WithTheme
   included do
     scope :with_automatic_update, -> { where(autoupdate_theme: true) }
     scope :with_manual_update, -> { where(autoupdate_theme: false) }
+
+    def self.autoupdate_websites
+      Communication::Website.with_automatic_update.find_each do |website|
+        website.update_theme_version
+      end
+    end
   end
 
+
   def get_current_theme_version!
     self.update_column :theme_version, current_theme_version
   end
-- 
GitLab