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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique nicknames #2360

Merged
merged 38 commits into from Dec 20, 2017

Conversation

Projects
None yet
3 participants
@deivid-rodriguez
Copy link
Contributor

commented Dec 12, 2017

馃帺 What? Why?

This PR adds a unique nickname column to the users table. This column will be displayed together with the public display information in a "twitter-like" way.

馃搶 Related Issues

馃搵 Subtasks

  • Add nickname column to DB and fill it with current "name" data.
  • Add nickname to new account form and validate it.
  • Display the new nickname together with the "display name" everywhere where the display name is currently displayed.

馃摲 Screenshots (optional)

Proposal List

proposallist

Proposal Page

proposalpage

Commens

comments

Conversations

conversations

馃懟 GIF

plant_love

@ghost ghost added the in-progress label Dec 12, 2017

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch from a89aa21 to cd92384 Dec 12, 2017

@codecov

This comment has been minimized.

Copy link

commented Dec 13, 2017

Codecov Report

Merging #2360 into master will increase coverage by 0.82%.
The diff coverage is 99.52%.

@@            Coverage Diff             @@
##           master    #2360      +/-   ##
==========================================
+ Coverage   97.81%   98.64%   +0.82%     
==========================================
  Files        1266     1279      +13     
  Lines       29334    29576     +242     
==========================================
+ Hits        28694    29175     +481     
+ Misses        640      401     -239

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch 8 times, most recently from d70427a to 03d2d3f Dec 13, 2017

name: Run main folder yarn lint
command: yarn lint
name: Run main folder yarn lint & tests
command: yarn test:ci

This comment has been minimized.

Copy link
@mrcasals

mrcasals Dec 14, 2017

Contributor

Damn it, sorry :(

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

No problem! :)

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch from 03d2d3f to c45b13b Dec 14, 2017

@josepjaume

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2017

Is this still WIP or should I review it?

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2017

Just a bit of tweaks left. I'll ping you in a bit!

  • Codeclimate.
  • Rebase.
  • Fix developer omniauth strategy.
@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2017

@josepjaume You can start reviewing it though, there won't be substantial changes.

commentsData.push({
id: random.uuid(),
type: "Decidim::Comments::Comment",
body: lorem.words(),
createdAt: date.past().toISOString(),
createdAt: creationDate.toISOString(),
formattedCreatedAt: creationDate.toLocaleTimeString(),

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

I'm adding this new parameter to unify the format of dates in messages & conversations. Previous dates were very verbose and I couldn't make it look decent with that amount of information. Also, I guess the same logic could be "repeated" in javascript but this was the easiest approach for me.

resolve lambda { |obj, _args, _ctx|
obj.friendly_created_at
}
end

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

This is the new parameter I mentioned in the previous comment.

This comment has been minimized.

Copy link
@josepjaume

josepjaume Dec 15, 2017

Contributor

it's GraphQL and denormalizing fields doesn't come at any cost, so great for me 馃憤

This comment has been minimized.

Copy link
@mrcasals

mrcasals Dec 15, 2017

Contributor

I think you can simplify this:

field :formattedCreatedAt, !types.String, "The creation date of the comment in relative format", property: : friendly_created_at
@@ -36,6 +36,8 @@ def create
on(:error) do |user|
if user.errors[:email]
set_flash_message :alert, :failure, kind: @form.provider.capitalize, reason: t("decidim.devise.omniauth_registrations.create.email_already_exists")
elsif user.errors[:nickname]
set_flash_message :alert, :failure, kind: @form.provider.capitalize, reason: t("decidim.devise.omniauth_registrations.create.nickname_already_exists")

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

This error logic is not very good (one single error per form, so two invalid submissions if both fields are incorrect), and I'm not sure it's correct at all. Some tests I made led to user.errors[:email] being empty and not nil when no errors were found so maybe this error is being displayed everytime if the form has any errors at all?

@@ -41,6 +44,10 @@ def email_unique_in_organization
errors.add :email, :taken if User.where(email: email, organization: current_organization).first.present?
end

def nickname_unique_in_organization
errors.add :nickname, :taken if User.where(nickname: nickname, organization: current_organization).first.present?
end

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

We have a lot of "duplicated validations" between the registration form and the User model. I just kept repeating them but maybe we can improve things in this regard in the future?

This comment has been minimized.

Copy link
@josepjaume

josepjaume Dec 19, 2017

Contributor

I think they have different purposes. models deal with data integrity and forms with data normalization & user input validation. I think it's natural that some validations (like presence) are duplicated, but others (length, format) are form-specific. Does this make sense?

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 19, 2017

Author Contributor

When I checked some validations felt off at the model level, but I didn't want to explore deeper. But yeah, you're right.

new:
complete_profile: Complete profile
nickname_help: Your unique identifier in decidim.

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

Once we add mentions and a public profile page, we can mention those things here. For now, I don't know what else to say to explain this field.


def migrate!
User.find_each do |user|
user.update!(nickname: User.nicknamize(user.name))

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 14, 2017

Author Contributor

I added this "migrator" class so I could properly unit test it, but in the end most of the logic went down to the model, so this could be removed and the tests moved around.

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 15, 2017

Author Contributor

I ended up removing it because I found a bug in nickname disambiguation and it was hard to test it against the migration. Now I'm testing the Nicknamizable mixin directly.

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2017

I added some self-review comments, and I'll be posting some screenshots in a bit.

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch from c45b13b to 4f17f08 Dec 14, 2017

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2017

Added a few screenshots!

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch from 4f17f08 to 7125dd8 Dec 14, 2017

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2017

I detected some bugs, working on them and adding tests.

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch from 7125dd8 to 29da631 Dec 14, 2017

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2017

Let me know what you think now. Specifically, if 8350dab is what you had in mind.

end
end

def clon(candidate, number)

This comment has been minimized.

Copy link
@mrcasals

This comment has been minimized.

Copy link
@deivid-rodriguez

deivid-rodriguez Dec 19, 2017

Author Contributor

I ended up changing the name of the method so it doesn't use none. Since clone is a core low level method, I don't want confusions!

@josepjaume

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2017

Hey! Thanks for the changes! 8350dab it actually half way of what I meant (but probably did a poor job explaining myself).

What I meant is: It looks like nicknamizable could come with ActiveRecord validations & other stuff, so why not put them in there instead of the models? Or is there any reason not to?

Anyway, if you think it'd be taking this too far, we could just merge it 馃憤

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2017

Aaaaah, I see. I can change that, yeah.

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2017

@josepjaume Unfortunately moving the validations doesn't work very well, since the mixin was included in both a form and a model, but the model has some conditionals on the validation. I moved the conditionals in 0788e33, but it looks plain wrong to me because now the mixin depends on some totally unrelated methods being defined.

Let me know how you want me to proceed.

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2017

I could maybe add allow_blank to the length validation?

deivid-rodriguez added some commits Dec 19, 2017

Some renaming for clarity
* Don't use clon or clone, since it conflicts with core methods and it's
a confusing words anyways.

* Rename local parameter, `candidate` doesn't make much sense here.
Fix unintented length limit set to 19
And add tests for length validation.
Don't use unique with `Faker::Lorem.character`
I guess for low values of length parameters, we run out of unique
values.

@deivid-rodriguez deivid-rodriguez force-pushed the feature/unique_nicknames branch from 4433d5b to 315167f Dec 19, 2017

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 19, 2017

Adding allow_blank worked fine. Ready again!

@deivid-rodriguez deivid-rodriguez referenced this pull request Dec 19, 2017

Merged

Public profile page #2391

2 of 2 tasks complete
@josepjaume

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2017

Merging this! Super nice job! 馃帀 After this, do you mind rebasing the profile page on top of master?

@josepjaume josepjaume merged commit 2e2931a into master Dec 20, 2017

19 checks passed

ci/circleci: accountability Your tests passed on CircleCI!
Details
ci/circleci: admin Your tests passed on CircleCI!
Details
ci/circleci: api Your tests passed on CircleCI!
Details
ci/circleci: assemblies Your tests passed on CircleCI!
Details
ci/circleci: budgets Your tests passed on CircleCI!
Details
ci/circleci: build_test_app Your tests passed on CircleCI!
Details
ci/circleci: comments Your tests passed on CircleCI!
Details
ci/circleci: core Your tests passed on CircleCI!
Details
ci/circleci: main Your tests passed on CircleCI!
Details
ci/circleci: meetings Your tests passed on CircleCI!
Details
ci/circleci: pages Your tests passed on CircleCI!
Details
ci/circleci: processes Your tests passed on CircleCI!
Details
ci/circleci: proposals Your tests passed on CircleCI!
Details
ci/circleci: surveys Your tests passed on CircleCI!
Details
ci/circleci: system Your tests passed on CircleCI!
Details
ci/circleci: verifications Your tests passed on CircleCI!
Details
codeclimate All good!
Details
codecov/patch 99.52% of diff hit (target 50%)
Details
codecov/project 98.64% (+0.82%) compared to 3b93867
Details

@ghost ghost removed the in-progress label Dec 20, 2017

@josepjaume josepjaume deleted the feature/unique_nicknames branch Dec 20, 2017

@deivid-rodriguez

This comment has been minimized.

Copy link
Contributor Author

commented Dec 20, 2017

Thanks @josepjaume, it's rebased!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.