forked from saurabh/orbit4-5
72 lines
2.3 KiB
Ruby
72 lines
2.3 KiB
Ruby
#This module will initialize the registration process for a ModuleApp
|
|
module OrbitApp
|
|
module RegisterModule
|
|
def registration(name,type ={:type=> "ModuleApp"} ,&block)
|
|
if type[:type].eql?("ModuleApp")
|
|
Module::Registration.new(name,&block)
|
|
elsif type[:type] == "PersonalPlugin"
|
|
Plugin::Registration.new(name,&block)
|
|
elsif type[:type] == "OrbitWidget"
|
|
Widget::Registration.new(name,&block)
|
|
end
|
|
end
|
|
|
|
def cleanup_modules
|
|
module_apps = ModuleApp.all
|
|
module_apps.each do |ma|
|
|
reg = OrbitApp::Module::Registration.find_by_key(ma.key) rescue nil
|
|
if reg.nil?
|
|
ma.destroy
|
|
end
|
|
end
|
|
end
|
|
|
|
def check_module_permissions
|
|
store_token = Site.first.store_token rescue nil
|
|
module_apps = ModuleApp.all
|
|
exceptions = OrbitStore::MODULE_EXCEPTIONS
|
|
if !store_token.nil?
|
|
ids = []
|
|
module_index = {}
|
|
module_apps.each do |ma|
|
|
ids << ma.key
|
|
module_index[ma.key] = ma
|
|
end
|
|
params_to_send = {'store_token' => store_token, "apps" => ids}
|
|
uri = URI.parse(OrbitStore::URL)
|
|
http = Net::HTTP.new(uri.host,uri.port)
|
|
request = Net::HTTP::Post.new("/store/check_module_permissions")
|
|
request.body = params_to_send.to_query
|
|
response = http.request(request) rescue nil
|
|
if !response.nil?
|
|
data = JSON.parse(response.body)
|
|
if response.code == "200"
|
|
if data["success"]
|
|
permissions = data["permissions"]
|
|
permissions.each do |permission|
|
|
ma = module_index[permission["app"]]
|
|
ma.store_permission_granted = (exceptions.include?(ma.key) ? true : permission["granted"])
|
|
ma.save
|
|
end
|
|
else
|
|
module_apps.each do |ma|
|
|
ma.store_permission_granted = (exceptions.include?(ma.key) ? true : false)
|
|
ma.save
|
|
end
|
|
end
|
|
end
|
|
else
|
|
module_apps.each do |ma|
|
|
ma.store_permission_granted = (exceptions.include?(ma.key) ? true : false)
|
|
ma.save
|
|
end
|
|
end
|
|
else
|
|
module_apps.each do |ma|
|
|
ma.store_permission_granted = (exceptions.include?(ma.key) ? true : false)
|
|
ma.save
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |