summaryrefslogtreecommitdiff
path: root/application.rb
diff options
context:
space:
mode:
Diffstat (limited to 'application.rb')
-rw-r--r--application.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/application.rb b/application.rb
index 195dcaf..0f762eb 100644
--- a/application.rb
+++ b/application.rb
@@ -7,8 +7,17 @@ class Model
property :id, Serial
property :uri, String, :length => 255
property :owl, Text, :length => 2**32-1
- property :yaml, Text, :length => 2**32-1
+ 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 Prediction
@@ -46,8 +55,18 @@ end
delete '/:id/?' do
begin
- Model.get(params[:id]).destroy!
+ model = Model.get(params[:id])
+ uri = model.uri
+ model.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