/, "IsLicensedUser=0")
+ action_url = action_url.gsub(/<.*?=.*?>/, "")
+
rest_url = Rails.application.routes.url_helpers.wopi_rest_endpoint_url(host: ENV["WOPI_ENDPOINT_URL"],id: id)
- edit_url = edit_url + "WOPISrc=#{rest_url}&access_token=#{user.get_wopi_token}&access_token_ttl=#{user.wopi_token_ttl.to_s}"
+ action_url = action_url + "WOPISrc=#{rest_url}"
+ if with_tokens
+ action_url = action_url + "&access_token=#{user.get_wopi_token}&access_token_ttl=#{(user.wopi_token_ttl*1000).to_s}"
+ else
+ action_url
+ end
else
return nil
end
end
+ #is_locked, lock_asset and refresh_lock rely on the asset being locked in the database to prevent race conditions
+ def is_locked
+ if lock.nil?
+ return false
+ else
+ return true
+ end
+ end
+
+ def lock_asset(lock_string)
+ self.lock = lock_string
+ self.lock_ttl = Time.now.to_i + LOCK_DURATION
+ delay(queue: :assets, run_at: LOCK_DURATION.seconds.from_now).unlock_expired
+ self.save!
+ end
+
+ def refresh_lock
+ self.lock_ttl = Time.now.to_i + LOCK_DURATION
+ delay(queue: :assets, run_at: LOCK_DURATION.seconds.from_now).unlock_expired
+ self.save!
+ end
+
+ def unlock
+ self.lock = nil
+ self.lock_ttl = nil
+ self.save!
+ end
+
+ def unlock_expired
+ self.with_lock do
+ if !self.lock_ttl.nil? and self.lock_ttl>= Time.now.to_i
+ self.lock = nil
+ self.lock_ttl = nil
+ self.save!
+ end
+ end
+ end
+
+ def update_contents(new_file)
+ new_file.class.class_eval { attr_accessor :original_filename }
+ new_file.original_filename = self.file_file_name
+ self.file = new_file
+ if self.version.nil?
+ self.version = 1
+ else
+ self.version = self.version + 1
+ end
+ self.save
+ end
+
+
protected
# Checks if attachments is an image (in post processing imagemagick will
diff --git a/app/models/user.rb b/app/models/user.rb
index f2953592c..b3d1dc20b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -270,6 +270,7 @@ class User < ActiveRecord::Base
unless token_valid
# if current token is not valid generate a new one with a one day TTL
self.wopi_token = Devise.friendly_token(20)
+ # WOPI uses millisecond TTLs
self.wopi_token_ttl = Time.now.to_i + 60*60*24
self.save
Rails.logger.warn("Generating new token #{self.wopi_token}")
diff --git a/app/models/wopi_app.rb b/app/models/wopi_app.rb
index 19f8d227f..3150a03df 100644
--- a/app/models/wopi_app.rb
+++ b/app/models/wopi_app.rb
@@ -1,7 +1,7 @@
class WopiApp < ActiveRecord::Base
belongs_to :wopi_discovery, :foreign_key => 'wopi_discovery_id', :class_name => 'WopiDiscovery'
- has_many :wopi_actions, class_name: 'WopiAction', foreign_key: 'wopi_app_id', :dependent => :delete_all
+ has_many :wopi_actions, class_name: 'WopiAction', foreign_key: 'wopi_app_id', :dependent => :destroy
validates :name, :icon, :wopi_discovery, presence: true
diff --git a/app/models/wopi_discovery.rb b/app/models/wopi_discovery.rb
index 9b72793a5..47f6f9d43 100644
--- a/app/models/wopi_discovery.rb
+++ b/app/models/wopi_discovery.rb
@@ -1,6 +1,6 @@
class WopiDiscovery < ActiveRecord::Base
- has_many :wopi_apps, class_name: 'WopiApp', foreign_key: 'wopi_discovery_id', :dependent => :delete_all
+ has_many :wopi_apps, class_name: 'WopiApp', foreign_key: 'wopi_discovery_id', :dependent => :destroy
validates :expires, :proof_key_mod, :proof_key_exp, :proof_key_old_mod, :proof_key_old_exp, presence: true
end
diff --git a/app/utilities/wopi_util.rb b/app/utilities/wopi_util.rb
index ad16dd00d..4ffe19950 100644
--- a/app/utilities/wopi_util.rb
+++ b/app/utilities/wopi_util.rb
@@ -58,7 +58,10 @@ module WopiUtil
end
rescue
Rails.logger.warn "Initialization failed"
- WopiDiscovery.first.destroy
+ discovery = WopiDiscovery.first
+ unless discovery.nil?
+ discovery.destroy
+ end
end
end
diff --git a/app/views/assets/edit.erb b/app/views/assets/edit.erb
new file mode 100644
index 000000000..41fa8eaf5
--- /dev/null
+++ b/app/views/assets/edit.erb
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/assets/view.erb b/app/views/assets/view.erb
new file mode 100644
index 000000000..41fa8eaf5
--- /dev/null
+++ b/app/views/assets/view.erb
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb
index b360b722b..95be5bcf5 100644
--- a/app/views/steps/_step.html.erb
+++ b/app/views/steps/_step.html.erb
@@ -72,6 +72,14 @@
<%= link_to download_asset_path(asset), data: {no_turbolink: true, id: true, status: "asset-present"} do %>
<%= image_tag preview_asset_path(asset) if asset.is_image? %>
<%= truncate(asset.file_file_name, length: 50) %>
+ <% if asset.can_perform_action("view") %>
+ <%= link_to "View", view_asset_url(id: asset) %>
+ <% end %>
+ <% if asset.can_perform_action("edit") %>
+ <%= link_to "Edit", edit_asset_url(id: asset) %>
+ <% end %>
+ <% else %>
+ <%= asset_loading_span(asset) %>
<% end %>
<% else %>
<%= asset_loading_span(asset) %>
diff --git a/config/application.rb b/config/application.rb
index 605efe45d..a95eb3598 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -30,7 +30,13 @@ module Scinote
"[#{datetime}] #{severity}: #{msg}\n"
end
+ config.action_dispatch.default_headers = {
+ 'X-WOPI-Lock' => "",
+ 'Random-header' => "with value",
+ 'Random-non-special-header' => "a"
+ }
+
# Paperclip spoof checking
- Paperclip.options[:content_type_mappings] = {:csv => "text/plain"}
+ Paperclip.options[:content_type_mappings] = {:csv => "text/plain", wopitest: ['text/plain', 'inode/x-empty'] }
end
end
diff --git a/config/routes.rb b/config/routes.rb
index bfa77a62e..47c65e092 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -267,11 +267,10 @@ Rails.application.routes.draw do
end
# Office integration
- get "wopi/files/:id/contents", to: "wopi#get_file_contents"
- post "wopi/files/:id/contents", to: "wopi#post_file_contents"
-
- get "wopi/files/:id", to: "wopi#get_file", as: 'wopi_rest_endpoint'
- post "wopi/files/:id", to: "wopi#post_file"
+ get "wopi/files/:id/contents", to: "wopi#get_file_contents_endpoint"
+ post "wopi/files/:id/contents", to: "wopi#post_file_contents_endpoint"
+ get "wopi/files/:id", to: "wopi#get_file_endpoint", as: 'wopi_rest_endpoint'
+ post "wopi/files/:id", to: "wopi#post_file_endpoint"
end
diff --git a/db/migrate/20160728145000_add_wopi.rb b/db/migrate/20160728145000_add_wopi.rb
index 471dc1872..01c7fc70b 100644
--- a/db/migrate/20160728145000_add_wopi.rb
+++ b/db/migrate/20160728145000_add_wopi.rb
@@ -6,7 +6,7 @@ class AddWopi< ActiveRecord::Migration
add_column :assets, :lock, :string, :limit => 1024
add_column :assets, :lock_ttl, :integer
- add_column :assets, :version, :integer
+ add_column :assets, :version, :integer, default: 1
create_table :wopi_discoveries do |t|
t.integer :expires, null: false
diff --git a/db/schema.rb b/db/schema.rb
index 64c4c79c4..3151280b9 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -58,7 +58,7 @@ ActiveRecord::Schema.define(version: 20160809074757) do
t.boolean "file_present", default: false, null: false
t.string "lock", limit: 1024
t.integer "lock_ttl"
- t.integer "version"
+ t.integer "version", default: 1
end
add_index "assets", ["created_at"], name: "index_assets_on_created_at", using: :btree