mirror of
http://ghproxy.cn/https://github.com/multunus/onemdm-server
synced 2025-12-06 10:14:59 +00:00
Add GCM push for pushing OneMDM app to devices
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
class App < ActiveRecord::Base
|
||||
|
||||
has_many :batch_installations, dependent: :destroy
|
||||
|
||||
validates :name, :package_name, presence: true
|
||||
|
||||
def apk_url
|
||||
return DEFAULT_APP_URL if self.package_name.eql?(DEFAULT_APP_PACKAGE_NAME)
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
class BatchInstallation < ActiveRecord::Base
|
||||
belongs_to :app
|
||||
|
||||
has_many :installations, dependent: :destroy
|
||||
end
|
||||
|
||||
@@ -10,6 +10,7 @@ class Device < ActiveRecord::Base
|
||||
after_create :update_last_heartbeats_time
|
||||
|
||||
has_many :heartbeats, dependent: :destroy
|
||||
has_many :installations, dependent: :destroy
|
||||
|
||||
scope :active, -> {where("last_heartbeat_recd_time > '#{Time.now.utc - ACTIVE_TIMEFRAME}'")}
|
||||
scope :missing, -> {where("last_heartbeat_recd_time < '#{Time.now.utc - ACTIVE_TIMEFRAME}'AND last_heartbeat_recd_time > '#{Time.now.utc - MISSING_TIMEFRAME}'")}
|
||||
|
||||
@@ -1,9 +1,28 @@
|
||||
class Installation < ActiveRecord::Base
|
||||
enum status: [:pushed, :downloaded, :cancelled, :installed]
|
||||
|
||||
|
||||
delegate :app, to: :batch_installation
|
||||
|
||||
belongs_to :device
|
||||
belongs_to :batch_installation
|
||||
|
||||
after_create :push_apps
|
||||
|
||||
def as_json(options={})
|
||||
{
|
||||
:id => self.id,
|
||||
:name => self.app.name,
|
||||
:package_name => self.app.package_name,
|
||||
:apk_url => self.app.apk_url
|
||||
}
|
||||
end
|
||||
|
||||
def push_apps
|
||||
if self.pushed?
|
||||
gcm = GCM.new(GCM_KEY)
|
||||
registration_ids = [self.device.gcm_token]
|
||||
options = { data: {message: self.to_json }}
|
||||
response = gcm.send(registration_ids, options)
|
||||
logger.debug "response #{response}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user