flipper-ui 1.4.2 → 1.5.0.rc1

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/flipper/ui/action.rb +46 -35
  3. data/lib/flipper/ui/actions/actors_gate.rb +17 -3
  4. data/lib/flipper/ui/actions/cloud_migrate.rb +1 -0
  5. data/lib/flipper/ui/actions/features.rb +5 -1
  6. data/lib/flipper/ui/actions/groups_gate.rb +6 -1
  7. data/lib/flipper/ui/actions/import.rb +20 -2
  8. data/lib/flipper/ui/actions/percentage_of_actors_gate.rb +2 -0
  9. data/lib/flipper/ui/actions/percentage_of_time_gate.rb +2 -0
  10. data/lib/flipper/ui/configuration.rb +6 -1
  11. data/lib/flipper/ui/decorators/feature.rb +6 -12
  12. data/lib/flipper/ui/error.rb +2 -2
  13. data/lib/flipper/ui/middleware.rb +10 -0
  14. data/lib/flipper/ui/public/images/logo.png +0 -0
  15. data/lib/flipper/ui/util.rb +5 -4
  16. data/lib/flipper/ui/views/feature.erb +8 -0
  17. data/lib/flipper/ui/views/layout.erb +8 -4
  18. data/lib/flipper/ui/views/settings.erb +21 -18
  19. data/lib/flipper/ui.rb +4 -1
  20. data/lib/flipper/version.rb +1 -1
  21. metadata +5 -32
  22. data/examples/ui/authorization.ru +0 -48
  23. data/examples/ui/basic.ru +0 -71
  24. data/examples/ui/prefixed.ru +0 -21
  25. data/examples/ui/read_only.ru +0 -43
  26. data/flipper-ui.gemspec +0 -29
  27. data/lib/flipper/ui/decorators/gate.rb +0 -37
  28. data/lib/flipper/ui/public/js/jquery-3.6.0.slim.js +0 -8782
  29. data/spec/flipper/ui/action_spec.rb +0 -76
  30. data/spec/flipper/ui/actions/actors_gate_spec.rb +0 -201
  31. data/spec/flipper/ui/actions/add_feature_spec.rb +0 -57
  32. data/spec/flipper/ui/actions/boolean_gate_spec.rb +0 -139
  33. data/spec/flipper/ui/actions/cloud_migrate_spec.rb +0 -54
  34. data/spec/flipper/ui/actions/export_spec.rb +0 -51
  35. data/spec/flipper/ui/actions/feature_spec.rb +0 -254
  36. data/spec/flipper/ui/actions/features_spec.rb +0 -233
  37. data/spec/flipper/ui/actions/file_spec.rb +0 -21
  38. data/spec/flipper/ui/actions/groups_gate_spec.rb +0 -144
  39. data/spec/flipper/ui/actions/home_spec.rb +0 -14
  40. data/spec/flipper/ui/actions/import_spec.rb +0 -63
  41. data/spec/flipper/ui/actions/percentage_of_actors_gate_spec.rb +0 -65
  42. data/spec/flipper/ui/actions/percentage_of_time_gate_spec.rb +0 -65
  43. data/spec/flipper/ui/actions/settings_spec.rb +0 -35
  44. data/spec/flipper/ui/configuration_spec.rb +0 -229
  45. data/spec/flipper/ui/decorators/feature_spec.rb +0 -59
  46. data/spec/flipper/ui/decorators/gate_spec.rb +0 -45
  47. data/spec/flipper/ui/util_spec.rb +0 -17
  48. data/spec/flipper/ui_spec.rb +0 -197
@@ -1,76 +0,0 @@
1
- RSpec.describe Flipper::UI::Action do
2
- describe 'request methods' do
3
- let(:action_subclass) do
4
- Class.new(described_class) do
5
- def noooope
6
- raise 'should never run this'
7
- end
8
-
9
- def get
10
- [200, {}, 'get']
11
- end
12
-
13
- def post
14
- [200, {}, 'post']
15
- end
16
-
17
- def put
18
- [200, {}, 'put']
19
- end
20
-
21
- def delete
22
- [200, {}, 'delete']
23
- end
24
- end
25
- end
26
-
27
- it "won't run method that isn't whitelisted" do
28
- fake_request = Struct.new(:request_method, :env, :session).new('NOOOOPE', {}, {})
29
- action = action_subclass.new(flipper, fake_request)
30
- expect do
31
- action.run
32
- end.to raise_error(Flipper::UI::RequestMethodNotSupported)
33
- end
34
-
35
- it 'will run get' do
36
- fake_request = Struct.new(:request_method, :env, :session).new('GET', {}, {})
37
- action = action_subclass.new(flipper, fake_request)
38
- expect(action.run).to eq([200, {}, 'get'])
39
- end
40
-
41
- it 'will run post' do
42
- fake_request = Struct.new(:request_method, :env, :session).new('POST', {}, {})
43
- action = action_subclass.new(flipper, fake_request)
44
- expect(action.run).to eq([200, {}, 'post'])
45
- end
46
-
47
- it 'will run put' do
48
- fake_request = Struct.new(:request_method, :env, :session).new('PUT', {}, {})
49
- action = action_subclass.new(flipper, fake_request)
50
- expect(action.run).to eq([200, {}, 'put'])
51
- end
52
- end
53
-
54
- describe 'FeatureNameFromRoute' do
55
- let(:action_subclass) do
56
- Class.new(described_class) do |parent|
57
- include parent::FeatureNameFromRoute
58
-
59
- route %r{\A/features/(?<feature_name>.*)\Z}
60
-
61
- def get
62
- [200, { feature_name: feature_name }, 'get']
63
- end
64
- end
65
- end
66
-
67
- it 'decodes feature_name' do
68
- requested_feature_name = Rack::Utils.escape("team:side_pane")
69
- fake_request = Struct
70
- .new(:request_method, :env, :session, :path_info)
71
- .new('GET', {}, {}, "/features/#{requested_feature_name}")
72
- action = action_subclass.new(flipper, fake_request)
73
- expect(action.run).to eq([200, { feature_name: "team:side_pane" }, 'get'])
74
- end
75
- end
76
- end
@@ -1,201 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::ActorsGate do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
- let(:session) do
10
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
11
- end
12
-
13
- describe 'GET /features/:feature/actors' do
14
- before do
15
- get 'features/search/actors'
16
- end
17
-
18
- it 'responds with success' do
19
- expect(last_response.status).to be(200)
20
- end
21
-
22
- it 'renders add new actor form' do
23
- form = '<form action="/features/search/actors" method="post" class="row">'
24
- expect(last_response.body).to include(form)
25
- end
26
- end
27
-
28
- describe 'GET /features/:feature/actors with slash in feature name' do
29
- before do
30
- get 'features/a/b/actors'
31
- end
32
-
33
- it 'responds with success' do
34
- expect(last_response.status).to be(200)
35
- end
36
-
37
- it 'renders add new actor form' do
38
- form = '<form action="/features/a%2Fb/actors" method="post" class="row">'
39
- expect(last_response.body).to include(form)
40
- end
41
- end
42
-
43
- describe 'POST /features/:feature/actors' do
44
- context 'enabling an actor' do
45
- let(:value) { 'User;6' }
46
- let(:multi_value) { 'User;5, User;7, User;9, User;12' }
47
-
48
- before do
49
- post 'features/search/actors',
50
- { 'value' => value, 'operation' => 'enable', 'authenticity_token' => token },
51
- 'rack.session' => session
52
- end
53
-
54
- it 'adds item to members' do
55
- expect(flipper[:search].actors_value).to include(value)
56
- end
57
-
58
- it 'adds item to multiple members' do
59
- post 'features/search/actors',
60
- { 'value' => multi_value, 'operation' => 'enable', 'authenticity_token' => token },
61
- 'rack.session' => session
62
-
63
- expect(flipper[:search].actors_value).to include('User;5')
64
- expect(flipper[:search].actors_value).to include('User;7')
65
- expect(flipper[:search].actors_value).to include('User;9')
66
- expect(flipper[:search].actors_value).to include('User;12')
67
- end
68
-
69
- it 'redirects back to feature' do
70
- expect(last_response.status).to be(302)
71
- expect(last_response.headers['location']).to eq('/features/search')
72
- end
73
-
74
- context "when feature name contains space" do
75
- before do
76
- post 'features/sp+ace/actors',
77
- { 'value' => value, 'operation' => 'enable', 'authenticity_token' => token },
78
- 'rack.session' => session
79
- end
80
-
81
- it 'adds item to members' do
82
- expect(flipper["sp ace"].actors_value).to include('User;6')
83
- end
84
-
85
- it "redirects back to feature" do
86
- expect(last_response.status).to be(302)
87
- expect(last_response.headers['location']).to eq('/features/sp+ace')
88
- end
89
- end
90
-
91
- context 'value contains whitespace' do
92
- let(:value) { ' User;6 ' }
93
- let(:multi_value) { ' User;5 , User;7 , User;9 , User;12 ' }
94
-
95
- it 'adds item without whitespace' do
96
- expect(flipper[:search].actors_value).to include('User;6')
97
- end
98
-
99
- it 'adds item to multi members without whitespace' do
100
- post 'features/search/actors',
101
- { 'value' => multi_value, 'operation' => 'enable', 'authenticity_token' => token },
102
- 'rack.session' => session
103
-
104
- expect(flipper[:search].actors_value).to include('User;5')
105
- expect(flipper[:search].actors_value).to include('User;7')
106
- expect(flipper[:search].actors_value).to include('User;9')
107
- expect(flipper[:search].actors_value).to include('User;12')
108
- end
109
- end
110
-
111
- context 'for an invalid actor value' do
112
- context 'empty value' do
113
- let(:value) { '' }
114
-
115
- it 'redirects back to feature' do
116
- expect(last_response.status).to be(302)
117
- expect(last_response.headers['location']).to eq('/features/search/actors?error=%22%22+is+not+a+valid+actor+value.')
118
- end
119
- end
120
-
121
- context 'nil value' do
122
- let(:value) { nil }
123
-
124
- it 'redirects back to feature' do
125
- expect(last_response.status).to be(302)
126
- expect(last_response.headers['location']).to eq('/features/search/actors?error=%22%22+is+not+a+valid+actor+value.')
127
- end
128
- end
129
- end
130
- end
131
-
132
- context "when a readonly adapter is configured" do
133
- let(:value) { 'User;6' }
134
-
135
- before do
136
- allow(flipper).to receive(:read_only?) { true }
137
- end
138
-
139
- it "does not allow an actor to be added" do
140
- post 'features/search/actors',
141
- { 'value' => value, 'operation' => 'enable', 'authenticity_token' => token },
142
- 'rack.session' => session
143
-
144
- expect(flipper[:search].actors_value).not_to include('User;6')
145
- expect(last_response.body).to include("The UI is currently in read only mode.")
146
- end
147
- end
148
-
149
- context 'disabling an actor' do
150
- let(:value) { 'User;6' }
151
- let(:multi_value) { 'User;5, User;7, User;9, User;12' }
152
-
153
- before do
154
- flipper[:search].enable_actor Flipper::Actor.new(value)
155
- post 'features/search/actors',
156
- { 'value' => value, 'operation' => 'disable', 'authenticity_token' => token },
157
- 'rack.session' => session
158
- end
159
-
160
- it 'removes item from members' do
161
- expect(flipper[:search].actors_value).not_to include(value)
162
- end
163
-
164
- it 'removes item from multi members' do
165
- multi_value.split(',').map(&:strip).each do |value|
166
- flipper[:search].enable_actor Flipper::Actor.new(value)
167
- end
168
-
169
- post 'features/search/actors',
170
- { 'value' => multi_value, 'operation' => 'disable', 'authenticity_token' => token },
171
- 'rack.session' => session
172
-
173
- expect(flipper[:search].actors_value).not_to eq(Set.new(multi_value.split(',').map(&:strip)))
174
- end
175
-
176
- it 'redirects back to feature' do
177
- expect(last_response.status).to be(302)
178
- expect(last_response.headers['location']).to eq('/features/search')
179
- end
180
-
181
- context 'value contains whitespace' do
182
- let(:value) { ' User;6 ' }
183
- let(:multi_value) { ' User;5 , User;7 , User;9 , User;12 ' }
184
-
185
- it 'removes item without whitespace' do
186
- expect(flipper[:search].actors_value).not_to include('User;6')
187
- end
188
-
189
- it 'removes item without whitespace' do
190
- multi_value.split(',').map(&:strip).each do |value|
191
- flipper[:search].enable_actor Flipper::Actor.new(value)
192
- end
193
- post 'features/search/actors',
194
- { 'value' => multi_value, 'operation' => 'disable', 'authenticity_token' => token },
195
- 'rack.session' => session
196
- expect(flipper[:search].actors_value).not_to eq(Set.new(multi_value.split(',').map(&:strip)))
197
- end
198
- end
199
- end
200
- end
201
- end
@@ -1,57 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::AddFeature do
2
- describe 'GET /features/new with feature_creation_enabled set to true' do
3
- before do
4
- @original_feature_creation_enabled = Flipper::UI.configuration.feature_creation_enabled
5
- Flipper::UI.configuration.feature_creation_enabled = true
6
- get '/features/new'
7
- end
8
-
9
- after do
10
- Flipper::UI.configuration.feature_creation_enabled = @original_feature_creation_enabled
11
- end
12
-
13
- it 'responds with success' do
14
- expect(last_response.status).to be(200)
15
- end
16
-
17
- it 'renders template' do
18
- form = '<form action="/features" method="post" class="row g-3 mb-2">'
19
- expect(last_response.body).to include(form)
20
- end
21
- end
22
-
23
- describe 'GET /features/new with feature_creation_enabled set to false' do
24
- before do
25
- @original_feature_creation_enabled = Flipper::UI.configuration.feature_creation_enabled
26
- Flipper::UI.configuration.feature_creation_enabled = false
27
- get '/features/new'
28
- end
29
-
30
- after do
31
- Flipper::UI.configuration.feature_creation_enabled = @original_feature_creation_enabled
32
- end
33
-
34
- it 'returns 403' do
35
- expect(last_response.status).to be(403)
36
- end
37
-
38
- it 'renders feature creation disabled template' do
39
- expect(last_response.body).to include('Feature creation is disabled.')
40
- end
41
- end
42
-
43
- describe 'GET /features/new when an adpter is set to readonly' do
44
- before do
45
- allow(flipper).to receive(:read_only?) { true }
46
- get '/features/new'
47
- end
48
-
49
- it 'returns 403' do
50
- expect(last_response.status).to be(403)
51
- end
52
-
53
- it 'shows that the UI is currently read-only mode' do
54
- expect(last_response.body).to include('The UI is currently in read only mode.')
55
- end
56
- end
57
- end
@@ -1,139 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::BooleanGate do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
- let(:session) do
10
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
11
- end
12
-
13
- describe 'POST /features/:feature/boolean' do
14
- context 'with enable' do
15
- before do
16
- flipper.disable :search
17
- post 'features/search/boolean',
18
- { 'action' => 'Enable', 'authenticity_token' => token },
19
- 'rack.session' => session
20
- end
21
-
22
- it 'enables the feature' do
23
- expect(flipper.enabled?(:search)).to be(true)
24
- end
25
-
26
- it 'redirects back to feature' do
27
- expect(last_response.status).to be(302)
28
- expect(last_response.headers['location']).to eq('/features/search')
29
- end
30
- end
31
-
32
- context "with space in feature name" do
33
- before do
34
- flipper.disable :search
35
- post 'features/sp%20ace/boolean',
36
- { 'action' => 'Enable', 'authenticity_token' => token },
37
- 'rack.session' => session
38
- end
39
-
40
- it 'updates feature' do
41
- expect(flipper.enabled?("sp ace")).to be(true)
42
- end
43
-
44
- it 'redirects back to feature' do
45
- expect(last_response.status).to be(302)
46
- expect(last_response.headers['location']).to eq('/features/sp+ace')
47
- end
48
- end
49
-
50
- context 'with disable' do
51
- before do
52
- flipper.enable :search
53
- post 'features/search/boolean',
54
- { 'action' => 'Disable', 'authenticity_token' => token },
55
- 'rack.session' => session
56
- end
57
-
58
- it 'disables the feature' do
59
- expect(flipper.enabled?(:search)).to be(false)
60
- end
61
-
62
- it 'redirects back to feature' do
63
- expect(last_response.status).to be(302)
64
- expect(last_response.headers['location']).to eq('/features/search')
65
- end
66
- end
67
-
68
- context 'when disable_fully_enable is false' do
69
- before { Flipper::UI.configuration.disable_fully_enable = false }
70
- after { Flipper::UI.configuration.disable_fully_enable = nil }
71
-
72
- it 'allows enabling the feature' do
73
- flipper.disable :search
74
- post 'features/search/boolean',
75
- { 'action' => 'Enable', 'authenticity_token' => token },
76
- 'rack.session' => session
77
- expect(flipper.enabled?(:search)).to be(true)
78
- end
79
- end
80
-
81
- context 'when disable_fully_enable is true' do
82
- before { Flipper::UI.configuration.disable_fully_enable = true }
83
- after { Flipper::UI.configuration.disable_fully_enable = nil }
84
-
85
- context 'with enable' do
86
- before do
87
- flipper.disable :search
88
- post 'features/search/boolean',
89
- { 'action' => 'Enable', 'authenticity_token' => token },
90
- 'rack.session' => session
91
- end
92
-
93
- it 'does not enable the feature' do
94
- expect(flipper.enabled?(:search)).to be(false)
95
- end
96
-
97
- it 'returns 403 status' do
98
- expect(last_response.status).to be(403)
99
- end
100
-
101
- it 'renders the default disabled message' do
102
- expect(last_response.body).to include('Fully enabling features via the UI is disabled.')
103
- end
104
- end
105
-
106
- context 'with disable' do
107
- before do
108
- flipper.enable :search
109
- post 'features/search/boolean',
110
- { 'action' => 'Disable', 'authenticity_token' => token },
111
- 'rack.session' => session
112
- end
113
-
114
- it 'still allows disabling the feature' do
115
- expect(flipper.enabled?(:search)).to be(false)
116
- end
117
-
118
- it 'redirects back to feature' do
119
- expect(last_response.status).to be(302)
120
- expect(last_response.headers['location']).to eq('/features/search')
121
- end
122
- end
123
- end
124
-
125
- context 'when disable_fully_enable is a custom message' do
126
- before { Flipper::UI.configuration.disable_fully_enable = "Use deploy pipeline instead." }
127
- after { Flipper::UI.configuration.disable_fully_enable = nil }
128
-
129
- it 'renders the custom message on 403' do
130
- flipper.disable :search
131
- post 'features/search/boolean',
132
- { 'action' => 'Enable', 'authenticity_token' => token },
133
- 'rack.session' => session
134
- expect(last_response.status).to be(403)
135
- expect(last_response.body).to include('Use deploy pipeline instead.')
136
- end
137
- end
138
- end
139
- end
@@ -1,54 +0,0 @@
1
- require 'flipper/cloud/migrate'
2
-
3
- RSpec.describe Flipper::UI::Actions::CloudMigrate do
4
- let(:token) do
5
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
6
- Rack::Protection::AuthenticityToken.random_token
7
- else
8
- 'a'
9
- end
10
- end
11
-
12
- let(:session) do
13
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
14
- end
15
-
16
- describe "POST /settings/cloud" do
17
- context "when migration succeeds" do
18
- before do
19
- flipper.enable :search
20
- allow(Flipper::Cloud).to receive(:migrate).and_return(
21
- Flipper::Cloud::MigrateResult.new(code: 200, url: "https://www.flippercloud.io/cloud/setup/abc123")
22
- )
23
-
24
- post '/settings/cloud',
25
- {'authenticity_token' => token},
26
- 'rack.session' => session
27
- end
28
-
29
- it 'redirects to the cloud URL' do
30
- expect(last_response.status).to be(302)
31
- expect(last_response.headers['location']).to eq('https://www.flippercloud.io/cloud/setup/abc123')
32
- end
33
- end
34
-
35
- context "when migration fails" do
36
- before do
37
- flipper.enable :search
38
- allow(Flipper::Cloud).to receive(:migrate).and_return(
39
- Flipper::Cloud::MigrateResult.new(code: 500, url: nil)
40
- )
41
-
42
- post '/settings/cloud',
43
- {'authenticity_token' => token},
44
- 'rack.session' => session
45
- end
46
-
47
- it 'redirects back to settings with error' do
48
- expect(last_response.status).to be(302)
49
- expect(last_response.headers['location']).to include('/settings')
50
- expect(last_response.headers['location']).to include('error=')
51
- end
52
- end
53
- end
54
- end
@@ -1,51 +0,0 @@
1
- RSpec.describe Flipper::UI::Actions::Features do
2
- let(:token) do
3
- if Rack::Protection::AuthenticityToken.respond_to?(:random_token)
4
- Rack::Protection::AuthenticityToken.random_token
5
- else
6
- 'a'
7
- end
8
- end
9
-
10
- let(:session) do
11
- { :csrf => token, 'csrf' => token, '_csrf_token' => token }
12
- end
13
-
14
- describe "POST /settings/export" do
15
- before do
16
- flipper.enable_percentage_of_actors :search, 10
17
- flipper.enable_percentage_of_time :search, 15
18
- flipper.enable_actor :search, Flipper::Actor.new('User;1')
19
- flipper.enable_actor :search, Flipper::Actor.new('User;100')
20
- flipper.enable_group :search, :admins
21
- flipper.enable_group :search, :employees
22
- flipper.enable :plausible
23
- flipper.disable :google_analytics
24
- flipper.enable :analytics, Flipper.property(:plan).eq("basic")
25
-
26
- post '/settings/export',
27
- {'authenticity_token' => token},
28
- 'rack.session' => session
29
- end
30
-
31
- it 'responds with success' do
32
- expect(last_response.status).to be(200)
33
- end
34
-
35
- it 'sets content disposition' do
36
- expect(last_response.headers['content-disposition']).to match(/Attachment;filename=flipper_memory_[0-9]*\.json/)
37
- end
38
-
39
- it 'renders json' do
40
- data = JSON.parse(last_response.body)
41
- expect(last_response.headers['content-type']).to eq('application/json')
42
- expect(data['version']).to eq(1)
43
- expect(data['features']).to eq({
44
- "analytics" => {"boolean"=>nil, "expression"=>{"Equal"=>[{"Property"=>["plan"]}, "basic"]}, "groups"=>[], "actors"=>[], "percentage_of_actors"=>nil, "percentage_of_time"=>nil},
45
- "search"=> {"boolean"=>nil, "expression"=>nil, "groups"=>["admins", "employees"], "actors"=>["User;1", "User;100"], "percentage_of_actors"=>"10", "percentage_of_time"=>"15"},
46
- "plausible"=> {"boolean"=>"true", "expression"=>nil, "groups"=>[], "actors"=>[], "percentage_of_actors"=>nil, "percentage_of_time"=>nil},
47
- "google_analytics"=> {"boolean"=>nil, "expression"=>nil, "groups"=>[], "actors"=>[], "percentage_of_actors"=>nil, "percentage_of_time"=>nil},
48
- })
49
- end
50
- end
51
- end