summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application.rb18
-rw-r--r--lazar.rb4
2 files changed, 21 insertions, 1 deletions
diff --git a/application.rb b/application.rb
index eb7db12..b522baf 100644
--- a/application.rb
+++ b/application.rb
@@ -8,7 +8,16 @@ class ModelStore
property :id, Serial
property :uri, String, :length => 255
property :yaml, Text, :length => 2**32-1
+ property :token_id, String, :length => 255
property :created_at, DateTime
+
+ after :save, :check_policy
+
+ private
+ def check_policy
+ OpenTox::Authorization.check_policy(uri, token_id)
+ end
+
end
class PredictionCache
@@ -47,8 +56,17 @@ end
delete '/:id/?' do
begin
+ uri = ModelStore.get(params[:id]).uri
ModelStore.get(params[:id]).destroy!
"Model #{params[:id]} deleted."
+ if params[:token_id] and !Model.get(params[:id]) and uri
+ begin
+ aa = OpenTox::Authorization.delete_policy_from_uri(uri, params[:token_id])
+ LOGGER.debug "Policy deleted for Model URI: #{uri} with token_id: #{params[:token_id]} with result: #{aa}"
+ rescue
+ LOGGER.warn "Policy delete error for Model URI: #{uri}"
+ end
+ end
rescue
halt 404, "Model #{params[:id]} does not exist."
end
diff --git a/lazar.rb b/lazar.rb
index e543802..13c3caa 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -45,6 +45,8 @@ end
post '/?' do # create model
halt 400, "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/)
model = ModelStore.create
+ model.token_id = params[:token_id] if params[:token_id]
+ model.token_id = request.env["HTTP_TOKEN_ID"] if !model.token_id and request.env["HTTP_TOKEN_ID"]
model.uri = url_for("/#{model.id}", :full)
lazar = YAML.load request.env["rack.input"].read
lazar.uri = model.uri
@@ -66,6 +68,7 @@ post '/:id/?' do
halt 404, "No compound_uri or dataset_uri parameter." unless compound_uri = params[:compound_uri] or dataset_uri = params[:dataset_uri]
response['Content-Type'] = 'text/uri-list'
+
if compound_uri
cache = PredictionCache.first(:model_uri => @lazar.uri, :compound_uri => compound_uri)
return cache.dataset_uri if cache and uri_available?(cache.dataset_uri)
@@ -77,7 +80,6 @@ post '/:id/?' do
LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} "
halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed."
end
-
elsif dataset_uri
task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do
@lazar.predict_dataset(dataset_uri).uri