-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listen to Argyle Webhooks to check when paystubs are fully sync'd #13
Changes from all commits
bc31594
d659cef
0a8bebb
07df633
6907c0c
85aa7bf
c385e08
9a767cf
0a464d9
971d83b
bed0b03
571e674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ARGYLE_API_TOKEN= | ||
ARGYLE_SANDBOX= | ||
ARGYLE_WEBHOOK_SECRET= | ||
NGROK_URL= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
/* Entry point for your PostCSS build */ | ||
@forward "uswds-settings.scss"; | ||
@forward "uswds-components.scss"; | ||
|
||
.argyle-loading { | ||
position: relative; | ||
} | ||
|
||
.argyle-loading::after { | ||
background-color: rgba(0, 0, 0, 0.128); | ||
content: ""; | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
z-index: 9999; | ||
} | ||
Comment on lines
+5
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks pretty crappy. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
module ApplicationCable | ||
class Connection < ActionCable::Connection::Base | ||
def session | ||
@request.session | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ArgylePaystubsChannel < ApplicationCable::Channel | ||
def subscribed | ||
cbv_flow = CbvFlow.find(connection.session[:cbv_flow_id]) | ||
stream_for cbv_flow | ||
allthesignals marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Webhooks::Argyle::EventsController < ApplicationController | ||
skip_before_action :verify_authenticity_token | ||
allthesignals marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def create | ||
signature = OpenSSL::HMAC.hexdigest('SHA512', ENV['ARGYLE_WEBHOOK_SECRET'], request.raw_post) | ||
|
||
unless request.headers["X-Argyle-Signature"] == signature | ||
return render json: { error: 'Invalid signature' }, status: :unauthorized | ||
end | ||
|
||
if params['event'] == 'paystubs.fully_synced' || params['event'] == 'paystubs.partially_synced' | ||
@cbv_flow = CbvFlow.find_by_argyle_user_id(params['data']['user']) | ||
|
||
if @cbv_flow | ||
@cbv_flow.update(payroll_data_available_from: params['data']['available_from']) | ||
ArgylePaystubsChannel.broadcast_to(@cbv_flow, params) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Webhooks::Argyle::EventsHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import * as ActionCable from '@rails/actioncable' | ||
|
||
import metaContent from "../utilities/meta"; | ||
import { loadArgyle, initializeArgyle } from "../utilities/argyle" | ||
|
@@ -8,23 +9,45 @@ function toOptionHTML({ value }) { | |
} | ||
|
||
export default class extends Controller { | ||
static targets = ["options", "continue", "userAccountId"]; | ||
static targets = ["options", "continue", "userAccountId", "fullySynced", "form"]; | ||
static classes = ["loading"] | ||
|
||
selection = null; | ||
|
||
argyle = null; | ||
|
||
argyleUserToken = null; | ||
|
||
cable = ActionCable.createConsumer(); | ||
|
||
// TODO: information stored on the CbvFlow model can infer whether the paystubs are sync'd | ||
// by checking the value of payroll_data_available_from. We should make that the initial value. | ||
fullySynced = false; | ||
|
||
connect() { | ||
// check for this value when connected | ||
this.argyleUserToken = metaContent('argyle_user_token'); | ||
this.cable.subscriptions.create({ channel: 'ArgylePaystubsChannel' }, { | ||
connected: () => { | ||
console.log("Connected to the channel:", this); | ||
}, | ||
disconnected: () => { | ||
console.log("Disconnected"); | ||
}, | ||
received: (data) => { | ||
console.log("Received some data:", data); | ||
if (data.event === 'paystubs.fully_synced' || data.event === 'paystubs.partially_synced') { | ||
this.fullySynced = true; | ||
|
||
this.formTarget.submit(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the event from Argyle is "fully_synced," submit the form and proceed to the next step! |
||
} | ||
} | ||
}); | ||
} | ||
|
||
onSignInSuccess(event) { | ||
this.userAccountIdTarget.value = event.accountId; | ||
|
||
this.element.submit(); | ||
this.element.classList.add(this.loadingClass); | ||
} | ||
|
||
onAccountError(event) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddPayrollColumnToCbvFlows < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :cbv_flows, :payroll_data_available_from, :date | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ArgylePaystubsChannel, type: :channel do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the Webhooks::Argyle::EventsHelper. For example: | ||
# | ||
# describe Webhooks::Argyle::EventsHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe Webhooks::Argyle::EventsHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "Webhooks::Argyle::Events", type: :request do | ||
describe "GET /index" do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder where this churn is coming from. How many times will this end up getting added to the Gemfile, lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tdooner hmmm Yeah I"m not sure. I think when George did the Docker stuff it changed.