Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiments: Prevent user enabling to the same experiment multiple times #22763

Merged
merged 2 commits into from May 30, 2018

Conversation

caleybrock
Copy link
Contributor

@caleybrock caleybrock commented May 30, 2018

It seemed like I couldn't disable my experiment on production, but in reality I had enabled it multiple times (creating multiples rows in the experiments table), so even if I disabled one, there were still more.

This PR prevents that.

@caleybrock
Copy link
Contributor Author

cc others using this experiment: @davidsbailey @epeach @Erin007 @madelynkasula

if Experiment.enabled?(experiment_name: experiment_name, user: current_user)
redirect_to '/', flash: {alert: "Already enabled in experiment '#{params[:experiment_name]}'."}
return
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be resilient to any existing bad data, you could also use .where(...).destroy_all instead of .find_by(...).destroy below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion - will follow up.

@caleybrock caleybrock merged commit 5ce7cd6 into staging May 30, 2018
@caleybrock caleybrock deleted the prevent-multiple-enables branch May 30, 2018 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants