From 957584b69c7853b711f6389caf29fd8261bd0ac2 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Thu, 13 Jun 2024 17:03:38 -0400 Subject: [PATCH] Clean up sync logic (#871) --- app/controllers/accounts_controller.rb | 17 +++-------------- app/controllers/application_controller.rb | 12 ------------ config/locales/views/accounts/en.yml | 1 - test/controllers/accounts_controller_test.rb | 5 +++++ 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 94e9bbe3..a0576b3a 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -63,22 +63,11 @@ class AccountsController < ApplicationController end def sync - if @account.can_sync? + unless @account.syncing? @account.sync_later - respond_to do |format| - format.html { redirect_to account_path(@account), notice: t(".success") } - format.turbo_stream do - render turbo_stream: turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "success", content: { body: t(".success") } }) - end - end - else - respond_to do |format| - format.html { redirect_to account_path(@account), notice: t(".cannot_sync") } - format.turbo_stream do - render turbo_stream: turbo_stream.append("notification-tray", partial: "shared/notification", locals: { type: "error", content: { body: t(".cannot_sync") } }) - end - end end + + redirect_to account_path(@account), notice: t(".success") end private diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d37580ac..500432af 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,20 +2,8 @@ class ApplicationController < ActionController::Base include Authentication, Invitable, SelfHostable include Pagy::Backend - before_action :sync_accounts - default_form_builder ApplicationFormBuilder # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. allow_browser versions: :modern - - private - - def sync_accounts - return if Current.user.blank? - - if Current.user.last_login_at.nil? || Current.user.last_login_at.before?(Date.current.beginning_of_day) - Current.family.sync_accounts - end - end end diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml index 7b4d04e5..eaf049f1 100644 --- a/config/locales/views/accounts/en.yml +++ b/config/locales/views/accounts/en.yml @@ -71,7 +71,6 @@ en: summary: new: New account sync: - cannot_sync: Account cannot be synced at the moment success: Account sync started update: success: Account updated diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb index 8e3af537..a2ceb6ba 100644 --- a/test/controllers/accounts_controller_test.rb +++ b/test/controllers/accounts_controller_test.rb @@ -25,6 +25,11 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest assert_response :ok end + test "can sync an account" do + post sync_account_path(@account) + assert_redirected_to account_url(@account) + end + test "should update account" do patch account_url(@account), params: { account: {