-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
bio field now part of User; status moved off of DrupalUser #1497
Conversation
# copy bios into new fields for non-spam users | ||
DrupalUsers.where('status != 0').each do |u| | ||
user = u.user | ||
user.status = u.status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right here you could do something like user.token = SecureRandom.hex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren okay, I am setting up plots2 again and will do this hopefully by today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren I don't think SecureRandom.hex
will ensure uniqueness, though. What do you say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to regenerate the schema file. Doing this now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren great.
You can concatenate the UID to the beginning?
…On Jul 4, 2017 3:48 PM, "Ujjwal Sharma" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In db/migrate/20170704165711_add_user_bio_and_token.rb
<#1497 (comment)>:
> @@ -0,0 +1,23 @@
+class AddUserBioAndToken < ActiveRecord::Migration
+ def up
+ add_column :rusers, :bio, :text
+ add_column :rusers, :token, :string
+ add_column :rusers, :status, :integer, default: 0
+ remove_column :rusers, :location_privacy
+
+ # copy bios into new fields for non-spam users
+ DrupalUsers.where('status != 0').each do |u|
+ user = u.user
+ user.status = u.status
@jywarren <https://github.com/jywarren> I don't think SecureRandom.hex
will ensure uniqueness, though. What do you say?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1497 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ-SA2Kg-tK1gwGwWy4EOAOnt661Tks5sKpbsgaJpZM4ONkX1>
.
|
@jywarren
|
That's fine. We need to regenerate the schema too, and perhaps remove a few unused tables like searches, location tags |
Basically, these are our options: SecureRandom.uuid # => "8efb5d40-32d8-43c8-a92d-d5f048c8729c"
SecureRandom.hex # => "bad6650fc0142451e624bd89b6aa3acf"
SecureRandom.urlsafe_base64 # => "vp6xjBgi48Jgag6dqH8niw" The last one looks rather short, doesn't it? P.S: All of these have the exact same entropy. |
I trust your judgement on this!
…On Jul 4, 2017 4:00 PM, "Ujjwal Sharma" ***@***.***> wrote:
Basically, these are our options:
SecureRandom.uuid # => "8efb5d40-32d8-43c8-a92d-d5f048c8729c"SecureRandom.hex # => "bad6650fc0142451e624bd89b6aa3acf"SecureRandom.urlsafe_base64 # => "vp6xjBgi48Jgag6dqH8niw"
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1497 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ3UwAHUsDZmKZpIi7y6WlqJblKtTks5sKpnqgaJpZM4ONkX1>
.
|
@jywarren
|
I can remove the tables, that's not a big deal, or if you like you can
drop: `searches` and `location_tags`.
You should be able to open a PR against the feature branch I'm using, and I
can merge it into my feature branch :-) then the PRs combine!
…On Jul 4, 2017 4:12 PM, "Ujjwal Sharma" ***@***.***> wrote:
@jywarren <https://github.com/jywarren> SecureRandom.uuid looks a little
more verbose, but I will use it. Will make the required changes as soon as
the environment is setup locally. A few thing I would like to confirm
though:
1.
How do I add to this PR? Do I copy your branch, make changes and make
a PR for your fork's branch? When you push my changes, they will show up in
here, I guess.
2.
Apart from adding user.token = SecureRandom.uuid in
https://github.com/publiclab/plots2/pull/1497/files/
4014dfc#diff-
85d8a967f5e9f12cfb43f842e560d394
<https://github.com/publiclab/plots2/pull/1497/files/4014dfc777c83f9f97491676b9ffd0aadf2250c4#diff-85d8a967f5e9f12cfb43f842e560d394>,
what all other tasks do I need to perform? Which specific tables need to be
removed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1497 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ3HCSFWZWzpjHYay22Xz8XJCuFHGks5sKpyugaJpZM4ONkX1>
.
|
@jywarren Awesome. I will look more into safely dropping tables from the schema while |
You can drop tables in the migration itself and then copy your new
generated local schema over the schema example file.
@icarito was talking about caching some parts to save time. I also think we
could move some of our tests from integration into lower level unit tests
(and likewise actual code) as unit tests are more self contained and less
context dependent, and so run much faster. You could open an issue around
optimizing tests!
…On Jul 4, 2017 4:21 PM, "Ujjwal Sharma" ***@***.***> wrote:
@jywarren <https://github.com/jywarren> Awesome. I will look more into
safely dropping tables from the schema while bundle install executes. On
another note, are we using any dependencies we could avoid? The CI build
takes way too much time to finish.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1497 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ7MTrd2EO3Ul0ImhXEW-Oj_0LBtJks5sKp7VgaJpZM4ONkX1>
.
|
Definitely. One of the new contributors was also talking about Makefiles which reminded of the PR I once made for the same. I will consult @icarito and make one for real this time. |
@jywarren we figured out a workaround for |
I think you figured this out? Sorry i wasn't able to respond faster! |
@jywarren Yes, you already fixed it, I was using an older version :P I will submit a PR for this one in a moment, thanks for your patience. |
@jywarren Made a PR. Please look into it. Awaiting your approval before going ahead with the migration. |
|
@jywarren There's a pending migration. Do you want me to make a PR with the migration done and schema replaced? |
Sure, or I can do it in an hour. Just forgot a step.
…On Jul 6, 2017 3:22 PM, "Ujjwal Sharma" ***@***.***> wrote:
@jywarren <https://github.com/jywarren> There's a pending migration. Do
you want me to make a PR with the migration done and schema replaced?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1497 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ5FWdWVnrZ99hws6CcCXqoWErSw_ks5sLTP_gaJpZM4ONkX1>
.
|
@jywarren No problem. I'll do it right now, all I need to do is |
* Use SecureRandom.uuid for generating per-user tokens * Remove redundant drop_table calls * Run migration and copy database schema
Huh, did u notice there were changes to a few other tables in your schema? I think they're SQLite MySQL differences. Could you remove them? Thanks! |
@jywarren I will. Just a minute. |
* Use SecureRandom.uuid for generating per-user tokens * Remove redundant drop_table calls * Run migrations and update schema
@jywarren were they still there? (the sqlite differences) Strange. I made sure to manually remove them all. |
@jywarren Nope, here's my add_index "impressions", ["controller_name", "action_name", "ip_address"], :name => "controlleraction_ip_index"
add_index "impressions", ["controller_name", "action_name", "request_hash"], :name => "controlleraction_request_index"
add_index "impressions", ["controller_name", "action_name", "session_hash"], :name => "controlleraction_session_index"
add_index "impressions", ["impressionable_type", "impressionable_id", "ip_address"], :name => "poly_ip_index"
add_index "impressions", ["impressionable_type", "impressionable_id", "params"], :name => "poly_params_request_index", :unique => false, :length => { "params" => 255 }
add_index "impressions", ["impressionable_type", "impressionable_id", "request_hash"], :name => "poly_request_index"
add_index "impressions", ["impressionable_type", "impressionable_id", "session_hash"], :name => "poly_session_index"
add_index "impressions", ["impressionable_type", "message", "impressionable_id"], :name => "impressionable_type_message_index", :unique => false, :length => { "message" => 255 }
add_index "impressions", ["user_id"], :name => "index_impressions_on_user_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take care of these two.
db/schema.rb.example
Outdated
@@ -190,26 +190,12 @@ ActiveRecord::Schema.define(:version => 20170208174046) do | |||
add_index "impressions", ["controller_name", "action_name", "request_hash"], :name => "controlleraction_request_index" | |||
add_index "impressions", ["controller_name", "action_name", "session_hash"], :name => "controlleraction_session_index" | |||
add_index "impressions", ["impressionable_type", "impressionable_id", "ip_address"], :name => "poly_ip_index" | |||
add_index "impressions", ["impressionable_type", "impressionable_id", "params"], :name => "poly_params_request_index", :unique => false, :length => { "params" => 255 } | |||
add_index "impressions", ["impressionable_type", "impressionable_id", "params"], :name => "poly_params_request_index" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what went wrong, but this one was done in another commit, I think.
db/schema.rb.example
Outdated
add_index "impressions", ["impressionable_type", "impressionable_id", "request_hash"], :name => "poly_request_index" | ||
add_index "impressions", ["impressionable_type", "impressionable_id", "session_hash"], :name => "poly_session_index" | ||
add_index "impressions", ["impressionable_type", "message", "impressionable_id"], :name => "impressionable_type_message_index", :unique => false, :length => { "message" => 255 } | ||
add_index "impressions", ["impressionable_type", "message", "impressionable_id"], :name => "impressionable_type_message_index" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
Can you try reverting those lines? Thanks! |
@jywarren sure, I will. |
* Use SecureRandom.uuid for generating per-user tokens * Remove redundant drop_table calls * Fix database inconsistencies
Generated by 🚫 Danger |
aha! now this is my error. looking now. |
@jywarren But we did replace |
@jywarren the tests need to be changed to match the current schema. |
@@ -0,0 +1,26 @@ | |||
class AddUserBioAndToken < ActiveRecord::Migration | |||
def up | |||
add_column :rusers, :bio, :text, limit: 2147483647, default: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's odd; the error I'm seeing is:
Error: test_confirm_user_reset_key_not_visible_on_profile_to_non-admins(UsersControllerTest): ActionView::Template::Error: wrong argument type nil (expected String)
app/views/users/profile.html.erb:149:in `to_html'
that's on this line:
<p><small><%= raw auto_link(RDiscount.new(@profile_user.bio).to_html, :sanitize => false) %></small></p>
And @profile_user
is a User
as of this line: https://github.com/jywarren/plots2/blob/user-bio-and-token/app/controllers/users_controller.rb#L107
So, given this default, it should have a value of '', not nil
. What's the deal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm adding a unit test to ensure that a new User
record has a non-nil bio
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren I'll try to look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay. Yes, in the migration we set the default bio to ''
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's what's confusing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently default values are not universally supported??? whoa. I'll try setting it manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using rails console
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren Oh, the fixtures weren't updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh yeah. i should've done this all at once, locally, but i kept thinking it was a small fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren I'm glad we have this sorted. What next for this PR?
This is good to go! If you can now open a new PR with the comment_controller.rb work to enable posting a comment using only a token, and not just if you're logged in, that'd be great. |
@jywarren I would. I think I should go to bed now but I definitely will do so tomorrow morning. |
good night! Thanks for your hard work as always!
…On Fri, Jul 7, 2017 at 6:23 PM, Ujjwal Sharma ***@***.***> wrote:
@jywarren <https://github.com/jywarren> I would. I think I should go to
bed now but I definitely will do so tomorrow morning.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1497 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ2VgTqDRCoUdZoeJbBHb9GZQvUHVks5sLq_NgaJpZM4ONkX1>
.
|
This also establishes a 'token' field for API use and deprecates the
location_privacy
field of User.rake test:all
@ryzokuken - here I'm initializing a
token
field. You can autogen random tokens in this PR if you like; add to the migration file in each user. We only have to generate them for users of non-zero status.