annotot 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acb7f756f361431eb365f9c7fe77febc9a5cc306
4
- data.tar.gz: 69bf28e6148de3a0bfb2cb90c446df5662d18052
3
+ metadata.gz: ac87d8c015fd3899dbc19d4c0fa12a86903c0344
4
+ data.tar.gz: e2afe1764a6066501ce6188da467347a1616bb91
5
5
  SHA512:
6
- metadata.gz: b49b9693b0354745d0ff550281c7980ce53a45d7c530a5f5a86998a28a4e48796c97311412275b432d11f788d350217d3729b22db5df9b209cd4e4d98c61546d
7
- data.tar.gz: f7d3ed313d39d68a90bdea0231872de99ea5535701240ea2528676e12b61874839d675515384a12db1e6756739449bb1f1313388bd1614712c5e1c2d972de572
6
+ metadata.gz: 1768923be84227b0a0e3ddf14f030700bc087912522ea8a5228ad4ac3839061a8e5521c8ce75ae62b931ffdfc4d7f21ff6519fff567a47314702823c509926fa
7
+ data.tar.gz: adee2f5434e7df3ca0f4aa68ce7cdb0850909aa6fa0b4256dd572d3e661ddcc0ce25cad88357712cafad374196383be7e05806d992750a6bd81529c3a250953f
@@ -31,7 +31,7 @@
31
31
  search: function(options, successCallback, errorCallback) {
32
32
  var _this = this;
33
33
  _this.annotationsList = [];
34
- options.format = 'json'
34
+ options.format = 'json';
35
35
 
36
36
  jQuery.ajax({
37
37
  url: _this.endpoint,
@@ -89,8 +89,8 @@
89
89
  update: function(oaAnnotation, successCallback, errorCallback) {
90
90
  var _this = this;
91
91
  var annotation = _this.getAnnotationInEndpoint(oaAnnotation);
92
-
93
- var annotationID = annotation.annotation['uuid'];
92
+
93
+ var annotationID = annotation.annotation.uuid;
94
94
 
95
95
  jQuery.ajax({
96
96
  url: _this.endpoint + '/' + encodeURIComponent(annotationID),
@@ -158,13 +158,15 @@
158
158
  // Converts OA Annotation to endpoint format
159
159
  getAnnotationInEndpoint: function(oaAnnotation) {
160
160
  // Generate a new uuid if one is not present
161
- if (oaAnnotation['@id'] == null) {
161
+ // condition needs to be set to check for "falsy" values
162
+ // !oaAnnotation['@id'] should match null and undefined
163
+ if (!oaAnnotation['@id']) {
162
164
  oaAnnotation["@id"] = Mirador.genUUID();
163
165
  }
164
-
166
+
165
167
  canvas = oaAnnotation.on[0].full;
166
168
  var newAnno = jQuery.extend({}, oaAnnotation);
167
- delete newAnno.endpoint
169
+ delete newAnno.endpoint;
168
170
  return {
169
171
  annotation: {
170
172
  uuid: oaAnnotation["@id"],
@@ -50,7 +50,9 @@ module Annotot
50
50
  private
51
51
 
52
52
  def set_annotation
53
- @annotation = Annotation.find_by(id: CGI.unescape(params[:id])) || Annotation.find_by(uuid: CGI.unescape(params[:id]))
53
+ @annotation = Annotot::Annotation.retrieve_by_id_or_uuid(
54
+ CGI.unescape(params[:id])
55
+ )
54
56
  raise ActiveRecord::RecordNotFound unless @annotation.present?
55
57
  end
56
58
 
@@ -1,5 +1,5 @@
1
1
  module Annotot
2
2
  class ApplicationController < ActionController::Base
3
- protect_from_forgery
3
+ protect_from_forgery with: :exception, unless: -> { request.format.json? }
4
4
  end
5
5
  end
@@ -4,5 +4,17 @@ module Annotot
4
4
  validates :canvas, presence: true
5
5
 
6
6
  serialize :data, JSON
7
+
8
+ ##
9
+ # Used to differentiate between a numeric id and a uuid. Rails will trim a
10
+ # uuid with leading numbers eg '123a'.to_i => 123
11
+ # @param [String] identifier
12
+ def self.retrieve_by_id_or_uuid(identifier)
13
+ if identifier =~ /\A\d+\z/
14
+ find_by(id: identifier)
15
+ else
16
+ find_by(uuid: identifier)
17
+ end
18
+ end
7
19
  end
8
20
  end
@@ -1,3 +1,3 @@
1
1
  module Annotot
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Reed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-29 00:00:00.000000000 Z
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails