Skip to content

Conversation

ElliottAYoung
Copy link
Contributor

@ElliottAYoung ElliottAYoung commented Apr 17, 2017

Purpose:

Sets up and configures the Flipper feature flagging gem for Cortex to allow for controlled releases of content / in-site A/B testing.

As a product owner, I want to be able to have the dev team build features behind a flag so that we can control the release and change management of new features to Cortex users. The UI is locked down so only admins are able to access it.

JIRA:

https://cb-content-enablement.atlassian.net/browse/COR-749

Steps to Take On Prod

  • Log into Cortex
  • Go to /flipper

Changes:

  • Changes to setup

    • Adds Flipper Gems (3 total)
  • Architectural changes

    • ^
  • Migrations

    • Runs a base migration, generated by Flipper
  • Library changes

    • Installs 3 flipper gems
  • Side effects

    • N/A

Screenshots

  • Before
    N/A

  • After
    N/A

QA Links:

http://web.cortex-7.development.c66.me

How to Verify These Changes

  • Specific pages to visit

    • /flipper
  • Steps to take
    Because of the admin restriction there are three different paths to verifying this story
    ** Admin Route - Log in as an Admin and go to /flipper. You should succeed.
    ** Anonymous Route - Don't Log in, then go to /flipper. You should fail.
    ** Regular User Route - Log in and go to /flipper. You should fail.

  • Responsive considerations

    • N/A

Relevant PRs/Dependencies:

N/A

Additional Information

Based on the Employer implementation.


Flipper.register(:internal) { |request| request.internal? }
Flipper.register(:authenticated) { |request| request.session[:current_user].present? && request.session[:current_user][:authenticated] }
Flipper.register(:hiring_dot) { |request| request.host == 'admin.cbcortex.com' }
Copy link
Member

Choose a reason for hiding this comment

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

What's the hiring_dot group used for? Is this misnamed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is misnamed, my bad

# Needed until there is a better fix for Paperclip. https://github.com/thoughtbot/paperclip/issues/1924#issuecomment-123927367
Paperclip.options[:content_type_mappings] = {:csv => 'text/plain'}

config.middleware.use Flipper::Middleware::Memoizer, lambda {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than using a lambda, we can throw this line and our group definitions in the flipper.rb initializer. This'll also cut down on the noise in application.rb (and we should eventually do the same for our CORS middleware init). For example, flipper.rb might look like:

module Cortex
  def self.flipper
    @flipper ||= Flipper.new(Flipper::Adapters::ActiveRecord.new)
  end
end

Cortex::Application.config.middleware.use Flipper::Middleware::Memoizer, Cortex.flipper

Flipper.register(:internal) { |request| request.internal? }
Flipper.register(:authenticated) { |request| request.session[:current_user].present? && request.session[:current_user][:authenticated] }
Flipper.register(:hiring_dot) { |request| request.host == 'admin.cbcortex.com' }
Flipper.register(:dev) { |request| request.host == 'dev.admin.cbcortex.com' || request.host == 'localhost' }
Flipper.register(:staging) { |request| request.host == 'stg.admin.cbcortex.com' }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we tried this on Employer and the reason I ultimately moved this chunk of code into application.rb is that the Memorizer can't properly lazy load Flipper if it's in the initializer / we encountered some issues with the Memorizer and the Webpack building

Copy link
Member

Choose a reason for hiding this comment

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

I tested it out before I made the comment, so I believe it /should/ work - I didn't test Webpack, however.

@toastercup
Copy link
Member

Would you also mind looking into why your migrations generate schema.rb noise? Are you dropping the entire DB at any point? IIRC, that can cause issues if you're running db:migrate after a db:drop instead of db:schema:load, but my memory here is hazy. Before merging this PR, I'd like to regenerate schema.rb

@ElliottAYoung
Copy link
Contributor Author

@toastercup I noticed that too, I think the random noise comes from rolled back changes in my local schema.rb that has collected over time...I will remove the noise

@ElliottAYoung
Copy link
Contributor Author

@toastercup Applied changes and cleaned Schema

@ElliottAYoung ElliottAYoung merged commit d14d30d into develop Apr 21, 2017
@ElliottAYoung ElliottAYoung deleted the topic/COR-749-Set-up-Flipper branch April 21, 2017 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants