fanforce-plugin-factory 0.36.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,9 +8,7 @@ module Sinatra::FanforceHelpers
|
|
8
8
|
def ff
|
9
9
|
return @ff if @ff.present?
|
10
10
|
@ff = Fanforce::API.new(params)
|
11
|
-
|
12
|
-
|
13
|
-
@ff.auth Sinatra::FanforceHelpers.find_api_key(ff.params[:organization_id])
|
11
|
+
@ff.auth(Sinatra::FanforceHelpers.find_api_key(ff.params[:organization_id]))
|
14
12
|
@ff
|
15
13
|
end
|
16
14
|
|
@@ -11,11 +11,14 @@ class FanforcePlugin::Sinatra
|
|
11
11
|
# INSTALL ######################################################################
|
12
12
|
def route_install(params)
|
13
13
|
raise "This is not a valid plugin install request: #{env['HTTP_HOST']}" if !ff.valid_install_request?(params)
|
14
|
-
api_key = $Redis.get("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{
|
14
|
+
api_key = $Redis.get("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{params[:organization_id]}")
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
if api_key.present? and api_key != params[:api_key]
|
17
|
+
is_valid_key = Fanforce::API.new.get("/api_auths/is_valid_key/#{params[:api_key]}", organization_id: params[:organization_id], plugin_id: params[:plugin_id])[:result]
|
18
|
+
raise 'A different API key already exists for this addon. Please uninstall first.' if !is_valid_key
|
19
|
+
end
|
20
|
+
$Redis.set("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{params[:organization_id]}", params[:api_key])
|
21
|
+
ff.auth(params[:api_key])
|
19
22
|
|
20
23
|
json status: 'finished-processing'
|
21
24
|
end
|
@@ -24,10 +27,10 @@ class FanforcePlugin::Sinatra
|
|
24
27
|
# UNINSTALL ####################################################################
|
25
28
|
def route_uninstall(params)
|
26
29
|
raise 'This is not a valid plugin uninstall request.' if !ff.valid_uninstall_request?(params)
|
27
|
-
api_key = $Redis.get("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{
|
30
|
+
api_key = $Redis.get("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{params[:organization_id]}")
|
28
31
|
|
29
|
-
raise 'API keys must match before an addon can be uninstalled.' if api_key.present? and
|
30
|
-
$Redis.del("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{
|
32
|
+
raise 'API keys must match before an addon can be uninstalled.' if api_key.present? and params[:api_key] != api_key
|
33
|
+
$Redis.del("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{params[:organization_id]}")
|
31
34
|
json status: 'finished-processing'
|
32
35
|
end
|
33
36
|
any '/uninstall' do route_uninstall(params) end
|