Skip to content

Commit

Permalink
Merge pull request #12 from fetlife/adding-error-on-rollout-change
Browse files Browse the repository at this point in the history
Adding error when rollout has been changed during session
  • Loading branch information
fl-slava authored Nov 15, 2022
2 parents da2eb37 + 59d509e commit 622228d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rollout/ui/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Rollout
module UI
VERSION = "0.5.0"
VERSION = "0.5.1"
end
end
3 changes: 3 additions & 0 deletions lib/rollout/ui/views/features/show.slim
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
a.text-sm.text-blue-600(href=index_path class='hover:text-blue-700 hover:underline')
' ← back to overview

- if params[:error]
pre.text-red-500= params[:error]
h2.font-semibold.text-xl.text-gray-500.pt-12
= @feature.name

.w-8.h-1.bg-gray-300.my-10
main.p-6.bg-gray-100.max-w-lg.w-full.text-sm.rounded-sm
form#updateFormSubmit action=feature_path(@feature.name) method='POST'
input type='hidden' name='last_updated_at' value=(@feature.data['updated_at'])
.mb-5
label.block.text-gray-500.mb-2(for='description') Description
input.appearance-none.border.rounded-sm.w-full.py-2.px-4.text-gray-600.leading-relaxed.bg-white(
Expand Down
7 changes: 6 additions & 1 deletion lib/rollout/ui/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class Web < Sinatra::Base
post '/features/:feature_name' do
rollout = config.get(:instance)
actor = config.get(:actor, scope: self)

feature_data = rollout.get(params[:feature_name]).data
if feature_data['updated_at'] && params[:last_updated_at] != feature_data['updated_at']
redirect "#{feature_path(params[:feature_name])}?error=Rollout version outdated. Review changes below and try again."
end
with_rollout_context(rollout, actor: actor) do
rollout.with_feature(params[:feature_name]) do |feature|
feature.percentage = params[:percentage].to_f.clamp(0.0, 100.0)
Expand All @@ -58,6 +61,7 @@ class Web < Sinatra::Base
feature.users = params[:users].split(',').map(&:strip).uniq.sort
end
feature.data.update(description: params[:description])
feature.data.update(updated_at: Time.now.to_i)
end
end

Expand All @@ -71,6 +75,7 @@ class Web < Sinatra::Base
with_rollout_context(rollout, actor: actor) do
rollout.with_feature(params[:feature_name]) do |feature|
feature.percentage = params[:percentage].to_f.clamp(0.0, 100.0)
feature.data.update(updated_at: Time.now.to_i)
end
end

Expand Down

0 comments on commit 622228d

Please sign in to comment.