phrasing 4.3.1 → 4.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51a7fa5981d49230fb228307dbec0daa90401e3ce8ac7d341c2d29de997fe208
4
- data.tar.gz: b02168d944d05b30cad1bc8c5dde71720a62e93a883a560150c706bcf95e67fb
3
+ metadata.gz: 83301b282dedbe937faf28eaf197cf9356c6beafff92f44d1f04847ab2a09ab7
4
+ data.tar.gz: b95a0281ff86a4f96b6915c946752b671dbdf6c469a1f1ec430835757a9bcda7
5
5
  SHA512:
6
- metadata.gz: 3286529d7e7c899685d1e267e5352fac9f019458b3200b8a68c26bcd1652b0c09a7d27f91cdcd73b3efdef0affba940ca7110fce55688f6cb2b2bbdfa233462b
7
- data.tar.gz: e5583b1e3e3c6578e7d8bb082e1b6ec1f726dc7bff75b3d9bf1a0d3c06601fce49ed115eefa57693139599603467b19f5f1d421ac1215cd22ff3dcc2d57f5cbc
6
+ metadata.gz: d0ee9d2fdd94f71c7e6c48e2e50103f0687232a1e7a93b46b893b78a63a673aa4a1548ec6e81e010cd317970c3efbcc0053d429a172c4d88b19b328a2c262204
7
+ data.tar.gz: 593e4c12e28556d1afa7a11cf5a5c7db2ea7550a716879c53bdcf539da5039650f8cacb2d52072617a8fb293844ad71a1f530d765a2b9f45fe4ecfe3b4a3bc4c
@@ -1,5 +1,9 @@
1
1
  # Phrasing Change Log
2
2
 
3
+ ## 4.3.2 (Oct 30th, 2020)
4
+
5
+ - Send `edit_mode_enabled` as parameter and reject phrasing update if not `true` - fixes issue [#90](https://github.com/infinum/phrasing/issues/90)
6
+
3
7
  ## 4.3.1 (Sep 3rd, 2019)
4
8
 
5
9
  - Bump nokogiri version from 1.8.3 to 1.10.4 due to [security vulnerability](https://github.com/sparklemotion/nokogiri/issues/1915)
@@ -119,7 +119,7 @@ var phrasing_setup = function(){
119
119
  $.ajax({
120
120
  type: "PUT",
121
121
  url: url,
122
- data: { new_value: content },
122
+ data: { new_value: content, edit_mode_enabled: Phrasing.isEditModeEnabled() },
123
123
  success: function(e){
124
124
  userTriggeredPhrasingDOMChange = false;
125
125
  if(content === "Empty"){
@@ -135,6 +135,7 @@ var phrasing_setup = function(){
135
135
  }
136
136
  },
137
137
  error: function(e){
138
+ console.log("Phrasing:", e.responseText);
138
139
  statusBubbleWidget.error();
139
140
  }
140
141
  });
@@ -1,3 +1,5 @@
1
+ require 'phrasing/string'
2
+
1
3
  class PhrasingPhrasesController < Phrasing.parent_controller.constantize
2
4
 
3
5
  layout 'phrasing'
@@ -66,6 +68,7 @@ class PhrasingPhrasesController < Phrasing.parent_controller.constantize
66
68
  klass, attribute = params[:klass], params[:attribute]
67
69
 
68
70
  return render status: 403, text: 'Phrase not whitelisted' unless Phrasing.whitelisted?(klass, attribute)
71
+ return render status: 403, text: 'Edit mode is disabled' unless edit_mode?
69
72
 
70
73
  record = klass.classify.constantize.find(params[:id])
71
74
 
@@ -88,4 +91,7 @@ class PhrasingPhrasesController < Phrasing.parent_controller.constantize
88
91
  PhrasingPhrase.fuzzy_search(params[:search], params[:locale])
89
92
  end
90
93
 
94
+ def edit_mode?
95
+ Phrasing::String.new(params[:edit_mode_enabled]).to_bool
96
+ end
91
97
  end
@@ -1,5 +1,6 @@
1
1
  require 'phrasing'
2
2
  require 'phrasing/serializer'
3
+ require 'phrasing/string'
3
4
  require 'phrasing/rails/engine'
4
5
  require 'jquery-rails'
5
6
  require 'haml'
@@ -0,0 +1,33 @@
1
+ module Phrasing
2
+ class String
3
+ attr_reader :value
4
+
5
+ def initialize(value)
6
+ @value = value
7
+ end
8
+
9
+ def to_bool
10
+ if major_version >= 5
11
+ ActiveModel::Type::Boolean.new.cast(value)
12
+ elsif major_version == 4 && minor_version >= 2
13
+ ActiveRecord::Type::Boolean.new.type_cast_from_database(value)
14
+ else
15
+ ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def major_version
22
+ rails_version.first.to_i
23
+ end
24
+
25
+ def minor_version
26
+ rails_version.second.to_i
27
+ end
28
+
29
+ def rails_version
30
+ @rails_version ||= ::Rails.version.split('.')
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Phrasing
2
- VERSION = '4.3.1'.freeze
2
+ VERSION = '4.3.2'.freeze
3
3
  end
@@ -6,29 +6,61 @@ describe PhrasingPhrasesController do
6
6
  get :index
7
7
  expect(response).to render_template(:index)
8
8
  end
9
+ end
9
10
 
11
+ describe 'PUT #update' do
10
12
  let(:phrase) { FactoryBot.create(:phrasing_phrase, value: 'old_value') }
11
13
 
12
- it 'updates phrase' do
13
- expect do
14
- xhr(:put, :update, klass: 'PhrasingPhrase',
15
- attribute: 'value',
16
- id: phrase.id,
17
- new_value: 'new_value')
18
- end.to change { phrase.reload.value }.from('old_value').to('new_value')
14
+ context 'when edit model is enabled' do
15
+ it 'updates phrase' do
16
+ expect do
17
+ xhr(
18
+ :put,
19
+ :update,
20
+ klass: 'PhrasingPhrase',
21
+ attribute: 'value',
22
+ id: phrase.id,
23
+ new_value: 'new_value',
24
+ edit_model_enabled: 'true'
25
+ )
26
+ end.to change { phrase.reload.value }.from('old_value').to('new_value')
27
+
28
+ expect(response.code).to eq('200')
29
+ end
30
+
31
+ it "doesn't update locale" do
32
+ expect do
33
+ xhr(
34
+ :put,
35
+ :update,
36
+ klass: 'PhrasingPhrase',
37
+ attribute: 'locale',
38
+ id: phrase.id,
39
+ new_value: 'de',
40
+ edit_model_enabled: 'true'
41
+ )
42
+ end.to_not(change { phrase.reload.locale })
19
43
 
20
- expect(response.code).to eq('200')
44
+ expect(response.code).to eq('403')
45
+ end
21
46
  end
22
47
 
23
- it 'updates phrase' do
24
- expect do
25
- xhr(:put, :update, klass: 'PhrasingPhrase',
26
- attribute: 'locale',
27
- id: phrase.id,
28
- new_value: 'de')
29
- end.to_not change { phrase.reload.locale }
48
+ context 'when edit mode is disabled' do
49
+ it "doesn't update phrase" do
50
+ expect do
51
+ xhr(
52
+ :put,
53
+ :update,
54
+ klass: 'PhrasingPhrase',
55
+ attribute: 'value',
56
+ id: phrase.id,
57
+ new_value: 'new_value',
58
+ edit_model_enabled: 'false'
59
+ )
60
+ end.not_to(change { phrase.reload.value })
30
61
 
31
- expect(response.code).to eq('403')
62
+ expect(response.code).to eq('403')
63
+ end
32
64
  end
33
65
  end
34
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrasing
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.1
4
+ version: 4.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomislav Car
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-03 00:00:00.000000000 Z
12
+ date: 2020-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -132,6 +132,7 @@ files:
132
132
  - lib/phrasing.rb
133
133
  - lib/phrasing/rails/engine.rb
134
134
  - lib/phrasing/serializer.rb
135
+ - lib/phrasing/string.rb
135
136
  - lib/phrasing/version.rb
136
137
  - phrasing.gemspec
137
138
  - spec/controllers/phrasing_phrases_controller.rb