Skip to content
This repository has been archived by the owner. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ addons:
postgresql: "9.6"
services:
- postgresql
- redis-server
sudo: false
language: ruby
cache: bundler
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class ApplicationController < ActionController::Base

private

def development_enabled?
Util::DevelopmentHelper.development_enabled?
end

helper_method :development_enabled?

def raise_404(message: nil)
raise ActionController::RoutingError, (message || 'Not Found')
end
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/auth_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/auth_tokens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def destroy
end

def dev_login
raise_404 unless Rails.env.development?
raise_404 unless development_enabled?

warden.logout
authenticate!(:developer)
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/dev/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class BaseController < UIController
private

def ensure_development
raise_404 unless Rails.env.development?
return if development_enabled?

raise_404
end
end
end
end
24 changes: 24 additions & 0 deletions app/controllers/ledgers/test_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Ledgers
class TestController < DashboardBaseController
before_action :ensure_test_env
before_action :set_ledger, only: %i[show]

private

def ensure_test_env
return if Rails.env.test?

raise_404
end

def set_ledger
@ledger = current_organization
.ledgers(kind: LedgerSync.adaptors.test.root_key.to_s)
.object
.find(params[:id])
.decorate
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/ledgers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class LedgersController < DashboardBaseController
before_action :set_ledger, only: :show

Expand All @@ -10,4 +12,4 @@ def show
def set_ledger
@ledger = Ledger.find(params[:id]).decorate
end
end
end
5 changes: 4 additions & 1 deletion app/decorators/ledger_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ def name
end

def show_path
case kind
case kind.to_s
when Util::QuickBooksOnline::KEY
r.ledgers_quickbooks_online_path(self)
when LedgerSync.adaptors.test.root_key.to_s
raise NotImplementedError unless Rails.env.test?
r.ledgers_test_path(self)
else
raise NotImplementedError
end
Expand Down
9 changes: 0 additions & 9 deletions app/errors/routing_error.rb

This file was deleted.

4 changes: 3 additions & 1 deletion app/jobs/event_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def perform(data, event_object_type, event_object_id, organization_id, type)

class Emit < ApplicationJob
def perform(event_id)
event = Event.find(event_id)

Forms::Events::Emit.new(
event: Event.find(event_id)
event: event
).save.raise_if_error
end
end
Expand Down
2 changes: 0 additions & 2 deletions app/lib/acl.rb

This file was deleted.

17 changes: 15 additions & 2 deletions app/lib/forms/events/emit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ def emit
response = HTTP.headers(headers).post(url, body: serialized_event_json_string)
status = response.status

return failure(status.inspect) unless status.success?
return success(event) if status.success?

success(event)
notify_provider
failure(status.inspect)
end

def notify_provider
redis = Redis.new
key = 'webhooks/provider_last_notified_at'

provider_last_notified_at = redis.get(key)

return if provider_last_notified_at.present? && (Time.zone.now - Time.parse(provider_last_notified_at)) < 24.hours

redis.set(key, Time.zone.now.to_s)
DeveloperMailer.webhook_failure(event.id).deliver_later
end

def serialized_event_json_string
Expand Down
9 changes: 9 additions & 0 deletions app/lib/util/development_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Util
module DevelopmentHelper
def self.development_enabled?
Rails.env.development? || (Rails.env.test? && ENV['DEVELOPMENT'] == 'true')
end
end
end
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: Settings.mailer.from_email
layout 'mailer'
end
11 changes: 11 additions & 0 deletions app/mailers/developer_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class DeveloperMailer < ApplicationMailer
def webhook_failure(event_id)
@event = Event.find(event_id)
mail(
subject: "Webhook failure at #{Time.zone.now}",
to: Settings.application.developer_email
)
end
end
4 changes: 4 additions & 0 deletions app/views/developer_mailer/webhook_failure.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%h1 Webhook Failure

%p
Event ID: #{@event.id}
9 changes: 5 additions & 4 deletions app/views/layouts/_nav.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
%li.nav-item.mr-3
= link_to '#', class: 'nav-link' do
Log In
- if Rails.env.development?
%li.nav-item.mr-3
= link_to dev_login_path, class: 'btn btn-danger' do
Dev Log In
- if development_enabled?
%ul
%li.nav-item.mr-3
= link_to dev_login_path, class: 'btn btn-danger' do
Dev Log In
13 changes: 0 additions & 13 deletions app/views/layouts/mailer.html.erb

This file was deleted.

8 changes: 8 additions & 0 deletions app/views/layouts/mailer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
!!!
%html
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
:css
/* Email styles need to be inline */
%body
= yield
1 change: 0 additions & 1 deletion app/views/layouts/mailer.text.erb

This file was deleted.

2 changes: 2 additions & 0 deletions app/views/ledgers/test/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.container
%h1 Test Adaptor - You made it!
2 changes: 2 additions & 0 deletions config/initializers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
end

required(:application).schema do
required(:developer_email).filled(:str?)
required(:host_port).maybe(:int?)
required(:host_url).filled(:str?)
required(:login_url).maybe(:str?)
Expand All @@ -102,6 +103,7 @@
required(:mailer).filled do
schema do
required(:delivery_method).filled(:str?)
required(:from_email).filled(:str?)
optional(:smtp).filled do
schema do
required(:address).filled(:str?)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def result

Warden::Strategies.add(:developer) do
def valid?
raise 'Invalid strategy' unless Rails.env.development?
raise 'Invalid strategy' unless Util::DevelopmentHelper.development_enabled?

true
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
resources :ledgers, only: %i[index show]

namespace :ledgers do
resources :tests, path: :test, only: %i[show], controller: :test
resources :quickbooks_onlines, path: :quickbooks_online, only: %i[destroy new show update], controller: :quickbooks_online do
collection do
get :callback
Expand Down
4 changes: 3 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ api:
root_secret_key: # required: The API key your application will use to send data to the Ledger Sync App

application:
login_url: # required: the url where users will be redirect if authentication is required
developer_email: # required: email for developer notifications (e.g. webhook failure)
host_port: # optional
host_url: # required: where this app is hosted (e.g. `sync.example.com`)
login_url: # required: the url where users will be redirect if authentication is required
name: 'Ledger Sync' # required: usually your company name
theme: modern_treasury # optional: Name of theme in app/assets/stylesheets/themes
webhooks:
Expand All @@ -39,6 +40,7 @@ customization:
mailer:
delivery_method: # required: letter_opener (only in development), smtp, test (only in test)
disable_email_to_users: false # optional
from_email: # required: email address for replies
# smtp: # required if delivery_method=smtp
# address: # - required
# authentication: # - required
Expand Down
2 changes: 2 additions & 0 deletions config/settings/development.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
application:
developer_email: me@example.com
host_url: 'localhost'
host_port: 3000

Expand All @@ -7,3 +8,4 @@ dev:

mailer:
delivery_method: 'letter_opener'
from_email: 'no-reply-dev@example.com'
6 changes: 4 additions & 2 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ add_ons:
api:
root_secret_key: 'test_api_key'
application:
developer_email: test@example.com
host_url: 'lvh.me'
host_port: 3000
webhooks:
key: 'foobarbaz'
url: 'http://lvh.me'
url: 'http://127.0.0.1:3000'
mailer:
delivery_method: 'test'
delivery_method: 'test'
from_email: 'no-reply-test@example.com'
5 changes: 5 additions & 0 deletions spec/decorators/ledger_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

it do
ledger = create(:ledger, :test)
expect(ledger.decorate.show_path).to eq(r.ledgers_test_path(ledger))
end

it do
ledger = create(:ledger, kind: :asdf)
expect { ledger.decorate.show_path }.to raise_error(NotImplementedError)
end
end
Expand Down
30 changes: 30 additions & 0 deletions spec/features/dev/authentication_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'rails_helper'
require 'formify/spec_helpers'

describe 'dev/authentication', js: true, type: :feature do
def expect_authorized
expect_content('authorized')
end

def expect_unauthorized
expect_content('unauthorized')
end

it do
visit r.root_path
expect_no_content :invisible, 'Dev Log In'
visit r.auth_tokens_path
expect_unauthorized
end

it do
ClimateControl.modify(DEVELOPMENT: 'true') do
visit r.root_path
click_on 'Dev Log In'
visit r.auth_tokens_path
expect_authorized
end
end
end
15 changes: 15 additions & 0 deletions spec/features/dev/home_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'rails_helper'
require 'formify/spec_helpers'

describe 'dev/home', js: true, type: :feature do
it do
ClimateControl.modify(DEVELOPMENT: 'true') do
visit r.root_path
click_on 'Dev Log In'
visit r.dev_path
expect_content 'Create Sync'
end
end
end
22 changes: 22 additions & 0 deletions spec/features/dev/syncs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'sync_ledgers/create', js: true, type: :feature do
xit do
login
expect { visit r.new_dev_sync_path }.to raise_error(ActionController::RoutingError)
end

it do
ClimateControl.modify(DEVELOPMENT: 'true') do
login(FactoryBot.create(:user, :admin))
visit r.new_dev_sync_path
expect_content 'Create Sync'
expect do
click_on 'Send'
expect_content 'Operation'
end.to change(Sync, :count).from(0).to(1)
end
end
end
Loading