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

Add Devise User #73

Closed
wants to merge 12 commits into from
Closed

Conversation

Katee
Copy link

@Katee Katee commented Mar 30, 2017

This creates a new model user which will be used to unify Admin, Artist and Voter. Users can register using devise at http://localhost:3000/users/sign_up (currently these pages are unstyled, that will happen in a future PR.)

I also added the letter_opener gem, in development emails will open up in the browser when they are "sent". To see this in action try running FactoryGirl.create(:user) in the rails console.

Gotchas:

  • New values have been added to config/secrets.yml which will require new values on the production servers
  • Devise stores confirmation_token, reset_password_token, etc directly in the database (passwords are salted/peppered and hashed). The previous tokens were created with BCrypt::Password.create(SecureRandom.urlsafe_base64)). I'm not sure if that behaviour is still required / what threat model pushed for that design choice.

Future PRs:

  • Styling
  • Use User model

Related issues:

@@ -1,5 +1,7 @@
common: &common
secret_key_base: 'f0b774b4d06f7ea3357dec260cd6231367009d35525b3c437b27e299d52599bebd4eb1cd83fc3f69ff0d46a0510e5e4ba3bffd26b503b7713100f6083fc4baba'
auth_secret_key: '89e115653bae4fafda3fc4c45b64aa07e20ad4d75ab4c1637e85e44b50e4a5cd24ea4dc065e047642d2ed17bebae7e856a292ab1f46ff7d04fc473df1a9ac577'
Copy link
Owner

Choose a reason for hiding this comment

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

are these secrets supposed to be stored in the repo? I thought the idea was that individual installations would have their own

Copy link
Author

Choose a reason for hiding this comment

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

Yes, secrets are required for running in test and development. If you read this file you'll notice that in the production section we use values from ENV exclusively. This means that production WILL NOT fall back to these values (I included a comment DO NOT use value in common as fallback to make this clear in the code).

If these secrets are not set in the ENV and rails is running in production then (at least for secret_key_base) rails will raise an error and refuse to run. (I think it will run if auth_secret_key is missing since devise will fallback to using the value for secret_key_base. I also think it will run if password_pepper is missing since that is optional.)

Copy link
Owner

Choose a reason for hiding this comment

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

oh I misread your comment as an instruction to the reader, telling them not to use the value as a fallback (I usually word things like: "This ensures that we don't fall back to common..."). OK I thought the idea was people had to make their own secrets for dev and test as well. I may litter some more comments around.

Copy link
Author

Choose a reason for hiding this comment

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

I usually don't require everyone to make their own secrets for test/dev. If they are binding to localhost it should never matter. If they aren't binding to localhost then someone who sees their dev/test server and knows about this repo could do various things depending on the secret in question (with secret_key_base they could fake sessions) but that seems really low risk.

When including values where there is no test/dev version (such as AWS credentials) usually I mock it out in test so that tests still run and provide instructions in the readme.

Copy link
Author

Choose a reason for hiding this comment

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

It is a command to the reader.

Often the pattern in secrets/config.yml is value: <%= ENV['NAME'] || 'default' %> but with these secrets using that pattern is unsafe as rails would happily work but would use a publicly known value for secret_key_base.

Copy link
Author

Choose a reason for hiding this comment

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

If you want to bikeshed on the comment I am not attached to any wording, feel free to contribute a change directly to this PR.

@ywwg
Copy link
Owner

ywwg commented Mar 30, 2017

We should have a conversation about The Future of FFAGC before you do too much major work, just so you have a sense of the roadmap I have in mind. There are assumptions that the current framework makes that I would like to upend at some point.

We will need the concept of user roles, which should be ORable (someone can be a voter and an admin, for instance). I assume that's something that can be added later?

@Katee
Copy link
Author

Katee commented Mar 30, 2017

That is my plan, please see #63.

I will either add a simple roles array to User so each user can be some subset of [:admin, :voter, :artist] or use a more intense solutions such as CanCanCan that more finely defines "abilities" for various users/roles.

@Katee
Copy link
Author

Katee commented Mar 30, 2017

I'm definitely interested in the future plans too. My current plan is to get this project in a better spot by adding reasonable validations, writing specs, and removing duplicate code.

@Katee
Copy link
Author

Katee commented Mar 30, 2017

This PR is probably easier to read commit by commit. Most of the lines come from the commit adding the devise views.

@ywwg
Copy link
Owner

ywwg commented Mar 31, 2017

I've been thinking about this PR and the general design plan to unify the user types, and unfortunately I think this addition of the new user type is the wrong place to start. If we do this first, then we have two user models at the same time and conflicting frontend choices, which means we need to maintain both versions (keep the deprecated one working while still improving the new one) until the new one is feature complete.

I think a better plan would be to start by writing a shim for the current three-table model so that various bits of the frontend can be rewritten so they can inquire about user permissions in a similar way to how the eventual backend model will work. So instead of "if admin_logged_in || voter_logged_in", there would be some sort of API like [totally pseudocode] "if user.permission_contains ['admin', 'voter']". The various calls can be replaced piecemeal and don't need to be done in one fell swoop. Once all the logic has been rewritten to use the shim API, then the backend model can be replaced with a simple swap -- replace the old model with the new and remove the shim.

Doing the migration that way will keep the codebase cleaner by avoiding having conflicting coexisting models, and will ensure that the master branch stays runnable and deployable.

Redoing the user model is a really heavy lift for this codebase because this transition will be hard to manage. But frankly it's low on my list of priorities compared with fixing some of the UX issues. I've tweaked some of the priority labels in the Issues list to give an idea of where I'd prefer to focus development effort right now.

@Katee Katee closed this Mar 31, 2017
@Katee Katee deleted the devise-user branch March 31, 2017 21:16
ywwg added a commit that referenced this pull request Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants