File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Import < UI::Action
88 route %r{\A /settings\/ import/?\Z }
99
1010 def post
11+ render_read_only if read_only?
1112 contents = params [ 'file' ] [ :tempfile ] . read
1213 export = Flipper ::Exporters ::Json ::Export . new ( contents : contents )
1314 flipper . import ( export )
Original file line number Diff line number Diff line change 3838 </ div >
3939</ div >
4040
41+ <% if write_allowed? %>
4142< div class ="card ">
4243 < div class ="card-header ">
4344 < h4 class ="m-0 "> Import</ h4 >
5152 </ form >
5253 </ div >
5354</ div >
55+ <% end %>
Original file line number Diff line number Diff line change 1111 { :csrf => token , 'csrf' => token , '_csrf_token' => token }
1212 end
1313
14+ let ( :path ) { FlipperRoot . join ( "spec" , "fixtures" , "flipper_pstore_1679087600.json" ) }
15+
1416 describe "POST /settings/import" do
1517 before do
1618 flipper . enable :plausible
1719 flipper . disable :google_analytics
18- path = FlipperRoot . join ( "spec" , "fixtures" , "flipper_pstore_1679087600.json" )
1920
2021 post '/settings/import' ,
2122 {
3738 expect ( last_response . status ) . to be ( 302 )
3839 expect ( last_response . headers [ 'location' ] ) . to eq ( '/features' )
3940 end
41+
42+ context "when in read only mode" do
43+ before do
44+ allow ( flipper ) . to receive ( :read_only? ) { true }
45+
46+ post '/settings/import' ,
47+ {
48+ 'authenticity_token' => token ,
49+ 'file' => Rack ::Test ::UploadedFile . new ( path , "application/json" ) ,
50+ } ,
51+ 'rack.session' => session
52+ end
53+
54+ it 'returns 403' do
55+ expect ( last_response . status ) . to be ( 403 )
56+ end
57+
58+ it 'renders read only template' do
59+ expect ( last_response . body ) . to include ( 'read only' )
60+ end
61+ end
4062 end
4163end
You can’t perform that action at this time.
0 commit comments