Skip to content
Open
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
189 changes: 104 additions & 85 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,155 +1,174 @@
PATH
remote: .
specs:
active-sync (0.1.1)
active-sync (0.2.0)
rails (>= 5.1.3)

GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.3.1)
actionpack (= 6.1.3.1)
activesupport (= 6.1.3.1)
actioncable (7.0.2.4)
actionpack (= 7.0.2.4)
activesupport (= 7.0.2.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.3.1)
actionpack (= 6.1.3.1)
activejob (= 6.1.3.1)
activerecord (= 6.1.3.1)
activestorage (= 6.1.3.1)
activesupport (= 6.1.3.1)
actionmailbox (7.0.2.4)
actionpack (= 7.0.2.4)
activejob (= 7.0.2.4)
activerecord (= 7.0.2.4)
activestorage (= 7.0.2.4)
activesupport (= 7.0.2.4)
mail (>= 2.7.1)
actionmailer (6.1.3.1)
actionpack (= 6.1.3.1)
actionview (= 6.1.3.1)
activejob (= 6.1.3.1)
activesupport (= 6.1.3.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.2.4)
actionpack (= 7.0.2.4)
actionview (= 7.0.2.4)
activejob (= 7.0.2.4)
activesupport (= 7.0.2.4)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (6.1.3.1)
actionview (= 6.1.3.1)
activesupport (= 6.1.3.1)
rack (~> 2.0, >= 2.0.9)
actionpack (7.0.2.4)
actionview (= 7.0.2.4)
activesupport (= 7.0.2.4)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.3.1)
actionpack (= 6.1.3.1)
activerecord (= 6.1.3.1)
activestorage (= 6.1.3.1)
activesupport (= 6.1.3.1)
actiontext (7.0.2.4)
actionpack (= 7.0.2.4)
activerecord (= 7.0.2.4)
activestorage (= 7.0.2.4)
activesupport (= 7.0.2.4)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (6.1.3.1)
activesupport (= 6.1.3.1)
actionview (7.0.2.4)
activesupport (= 7.0.2.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.3.1)
activesupport (= 6.1.3.1)
activejob (7.0.2.4)
activesupport (= 7.0.2.4)
globalid (>= 0.3.6)
activemodel (6.1.3.1)
activesupport (= 6.1.3.1)
activerecord (6.1.3.1)
activemodel (= 6.1.3.1)
activesupport (= 6.1.3.1)
activestorage (6.1.3.1)
actionpack (= 6.1.3.1)
activejob (= 6.1.3.1)
activerecord (= 6.1.3.1)
activesupport (= 6.1.3.1)
marcel (~> 1.0.0)
mini_mime (~> 1.0.2)
activesupport (6.1.3.1)
activemodel (7.0.2.4)
activesupport (= 7.0.2.4)
activerecord (7.0.2.4)
activemodel (= 7.0.2.4)
activesupport (= 7.0.2.4)
activestorage (7.0.2.4)
actionpack (= 7.0.2.4)
activejob (= 7.0.2.4)
activerecord (= 7.0.2.4)
activesupport (= 7.0.2.4)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.2.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
builder (3.2.4)
concurrent-ruby (1.1.8)
concurrent-ruby (1.1.10)
crass (1.0.6)
digest (3.1.0)
erubi (1.10.0)
foreman (0.87.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.10)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
loofah (2.9.1)
loofah (2.16.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.1)
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.0.3)
mini_portile2 (2.5.1)
minitest (5.14.4)
nio4r (2.5.7)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0)
net-imap (0.2.3)
digest
net-protocol
strscan
net-pop (0.1.1)
digest
net-protocol
timeout
net-protocol (0.1.3)
timeout
net-smtp (0.3.1)
digest
net-protocol
timeout
nio4r (2.5.8)
nokogiri (1.13.4)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
racc (1.5.2)
puma (5.5.2)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.3.1)
actioncable (= 6.1.3.1)
actionmailbox (= 6.1.3.1)
actionmailer (= 6.1.3.1)
actionpack (= 6.1.3.1)
actiontext (= 6.1.3.1)
actionview (= 6.1.3.1)
activejob (= 6.1.3.1)
activemodel (= 6.1.3.1)
activerecord (= 6.1.3.1)
activestorage (= 6.1.3.1)
activesupport (= 6.1.3.1)
rails (7.0.2.4)
actioncable (= 7.0.2.4)
actionmailbox (= 7.0.2.4)
actionmailer (= 7.0.2.4)
actionpack (= 7.0.2.4)
actiontext (= 7.0.2.4)
actionview (= 7.0.2.4)
activejob (= 7.0.2.4)
activemodel (= 7.0.2.4)
activerecord (= 7.0.2.4)
activestorage (= 7.0.2.4)
activesupport (= 7.0.2.4)
bundler (>= 1.15.0)
railties (= 6.1.3.1)
sprockets-rails (>= 2.0.0)
railties (= 7.0.2.4)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
railties (6.1.3.1)
actionpack (= 6.1.3.1)
activesupport (= 6.1.3.1)
railties (7.0.2.4)
actionpack (= 7.0.2.4)
activesupport (= 7.0.2.4)
method_source
rake (>= 0.8.7)
rake (>= 12.2)
thor (~> 1.0)
rake (13.0.3)
zeitwerk (~> 2.5)
rake (13.0.6)
semantic_range (3.0.0)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
thor (1.1.0)
strscan (3.0.1)
thor (1.2.1)
timeout (0.2.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
webpacker (5.3.0)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket-driver (0.7.3)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.4.2)
zeitwerk (2.5.4)

PLATFORMS
ruby

DEPENDENCIES
active-sync!
foreman
puma
sqlite3 (~> 1.4)
webpacker (>= 3.5.5)

Expand Down
1 change: 1 addition & 0 deletions active_sync.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "webpacker", ">= 3.5.5"
s.add_development_dependency "sqlite3", "~> 1.4"
s.add_development_dependency "foreman"
s.add_development_dependency "puma"
end
41 changes: 10 additions & 31 deletions app/channels/models_channel.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
# Rails currently doesn't allow namespacing channels in an engine
# module ActiveSync
class ModelsChannel < ActionCable::Channel::Base
# For providing DashData with data from rails models
# To change the data sent (like reducing how much is sent)
# implement broadcast_model in the respective modelc
# To change the data sent implement sync_record in the respective model

def subscribed
subscribe_models
transmit(subscription_model.where(params[:filter]).map(&:sync_record))
stream_from params[:model], coder: ActiveSupport::JSON do |message|
if (params[:filter].to_a - message.to_a).blank?
transmit([message])
end
end
end

def unsubscribed
# Any cleanup needed when channel is unsubscribed
end

private
def subscribe_models
if filter.nil?

stream_from "#{subscription_model.name}_All"
transmit( subscription_model.sync_all )

else

subscription_model.register_sync_subscription "#{subscription_model.name}_#{checksum}", filter
stream_from "#{subscription_model.name}_#{checksum}"

# TODO ensure that params are safe to pass to the model then register for syncing to.
transmit( subscription_model.sync_filtered( filter.to_h ) )

end
end

def subscription_model
model = params[:model].camelize.constantize
model.sync_model? ? model : raise "Model '#{params[:model]}' is not a registered sync model"
end

def model_association
ActiveSync::Sync.get_model_association( subscription_model, filter[:association_name] )
end

def checksum
# A checksum is generated and used in the stream name so all of the same filtered subscriptions should be on the same Stream
Digest::MD5.hexdigest( Marshal::dump( filter ) )
model = params[:model].singularize.camelize.constantize
raise "Model '#{params[:model]}' is not set up for syncing model" unless model.sync_model?
model
end
end
# end
2 changes: 1 addition & 1 deletion app/controllers/active_sync/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveSync
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
# protect_from_forgery with: :exception
end
end
16 changes: 11 additions & 5 deletions app/controllers/active_sync/models_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
module ActiveSync
class ModelsController < ApplicationController

def index
render json: model.sync_filtered(properties)
def update
#TODO some oversite on what can be edited for sync records
model.find(params[:id]).update(params.permit(model.sync_attributes))
head :no_content
end

def properties
params.permit(ActiveSync::Sync.model_descriptions[model.name][:attributes])
def create
#TODO some oversite on what can be created for sync records
render json: model.create(params.permit(model.sync_attributes)).id
end

private
def model
params[:model].singularize.camelize.safe_constantize || params[:model].camelize.safe_constantize
m = params[:model].singularize.camelize.safe_constantize || params[:model].camelize.safe_constantize
raise "Cannot edit #{params[:model]} as it is not a sync model" unless m.sync_model?
m
end
end
end
19 changes: 4 additions & 15 deletions app/jobs/broadcast_change_job.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
class BroadcastChangeJob < ApplicationJob
queue_as :default
queue_as :active_sync

def perform record
SyncSubscriptions.all.each do | subscription |
unless filter[:IsReference]

match = true
filter.each do | key, value |
unless self.send( key ) == value
match = false
break
end
end
include ActionCable::Channel::Broadcasting

ActionCable.server.broadcast( stream, ActiveSync::Sync.sync_record( self ) ) if match
end
end
def perform record
ActionCable.server.broadcast(record.class.name, record.sync_record)
end
end
Loading