mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Clean up sync logic (#871)
This commit is contained in:
parent
d0a15b8a98
commit
957584b69c
4 changed files with 8 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue