sn-revisions 0.1.9 → 0.2.4

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
- SHA1:
3
- metadata.gz: 0390856e64f4c09a2a0cfd392291462ff57e6f53
4
- data.tar.gz: dba7dd937b46200b3eaa5ece18c0bc1e01caf270
2
+ SHA256:
3
+ metadata.gz: 6ef6dde5ce7bff0360fb048f422bca949d38397153bbeb56156c31f2999e2be7
4
+ data.tar.gz: 1f1e88f5a87f06e160b12112604b507e27c5306120f6b06f6a481207d5f04afd
5
5
  SHA512:
6
- metadata.gz: 80313e953ce4f4c4f9eebdfedbae92abc0842beaa21d2bfac9addcc330221df36ece60b02693bcf6f55218a41bebd25641aeadce08f28bbb9886524f8e1805b6
7
- data.tar.gz: d03e874be2b56c6dc8d2dc0aedf2dd998302c07e77043f5a5441372f97e9808aee0928db2a41b69c235d4601ba47eae631d099b8eb58a522611e532d6fa85cf4
6
+ metadata.gz: f9ea13efaca49cf5dfcdbc8f122c0b53302dc94f6e5bd69d19de3f4d30840d08cf7bb7047019584073001c894462bb37eb419eb6e6f7d5e2873fbeea61737496
7
+ data.tar.gz: b07790d2b0f691dd4bf16d5d10430786a38305a2c6a0ce158cb04f9034294f1465fa9fac36755c2425309cb102592ef6f947087fbfed9020cdc9e917b172a30f
@@ -2,19 +2,21 @@ require_dependency "revisions/application_controller"
2
2
 
3
3
  module Revisions
4
4
  class ItemsController < ApplicationController
5
-
6
5
  def save
7
6
  items = params[:items]
7
+ auth_params = params[:auth_params]
8
+
8
9
  items.each do |item_hash|
9
10
  item = current_user.items.find_or_create_by(:item_uuid => item_hash["uuid"])
10
11
  item.prune_history
11
- item.add_revision(item_hash["content"], item_hash["enc_item_key"], item_hash["auth_hash"])
12
+ item.add_revision(item_hash["content"], item_hash["enc_item_key"], item_hash["auth_hash"], auth_params)
12
13
  if item.content_type == nil
13
14
  item.content_type = item_hash["content_type"]
14
15
  item.save
15
16
  end
16
17
  end
17
- end
18
18
 
19
+ head :no_content
20
+ end
19
21
  end
20
22
  end
@@ -10,7 +10,19 @@ module Revisions
10
10
  return
11
11
  end
12
12
 
13
- render :json => {:item => revision.as_json.merge({:uuid => revision.item.item_uuid, :content_type => revision.item.content_type})}
13
+ if revision.auth_params
14
+ # Handles issue where auth params were not previously properly serialized before being inserted
15
+ begin
16
+ auth_params = JSON.parse(revision.auth_params)
17
+ rescue
18
+ auth_params = JSON.parse(revision.auth_params.gsub('=>', ':'))
19
+ end
20
+ end
21
+
22
+ render :json => {
23
+ :item => revision.as_json.merge({:uuid => revision.item.item_uuid, :content_type => revision.item.content_type}),
24
+ :auth_params => auth_params
25
+ }
14
26
  end
15
27
 
16
28
  end
@@ -3,21 +3,25 @@ module Revisions
3
3
 
4
4
  has_many :revisions, -> { order 'created_at desc' }
5
5
 
6
- def add_revision(content, item_key, auth_hash)
6
+ def add_revision(content, item_key, auth_hash, auth_params)
7
7
  revision = self.revisions.new
8
8
  revision.content = content
9
9
  revision.enc_item_key = item_key
10
10
  revision.auth_hash = auth_hash
11
+ revision.auth_params = auth_params.to_json
11
12
  # revision.num = self.revisions.length > 0 && self.revisions.first.num ? (self.revisions.first.num + 1) : 0
12
13
  revision.save
13
14
  end
14
15
 
16
+ def prune_all_history
17
+ prune_history(400)
18
+ end
15
19
 
16
- def prune_history
20
+ # prunes recent history
21
+ def prune_history(days = 30)
17
22
  # revisions past 30 days are limited to min_revs revision per day
18
23
  # any revision within 30 days is capped to 30-days_from_today revisions per day
19
24
  # so if there are 50 revisions from 5 days ago, 50 - (30-5) = 25 revisions are allowed
20
- days = 30
21
25
  max_revs = 8
22
26
  min_revs = 4
23
27
  days.times do |days_from_today|
@@ -0,0 +1,5 @@
1
+ class AddAuthParamsToRevisions < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :revisions_revisions, :auth_params, :text
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Revisions
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sn-revisions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Standard Notes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-26 00:00:00.000000000 Z
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -68,6 +68,7 @@ files:
68
68
  - db/migrate/20170211000426_create_revisions_revisions.rb
69
69
  - db/migrate/20170211001350_create_revisions_users.rb
70
70
  - db/migrate/20170713154559_change_item_key_to_text.rb
71
+ - db/migrate/20180526182951_add_auth_params_to_revisions.rb
71
72
  - lib/revisions.rb
72
73
  - lib/revisions/engine.rb
73
74
  - lib/revisions/version.rb
@@ -91,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.12
95
+ rubygems_version: 3.0.3
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: The Note History extension for Standard Notes allows you to track changes