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

Followable #1727

Merged
merged 23 commits into from
Jul 11, 2017
Merged

Followable #1727

merged 23 commits into from
Jul 11, 2017

Conversation

taitus
Copy link
Member

@taitus taitus commented Jul 5, 2017

Where

What

Allow logged users to follow/unfollow proposals or budgets investments
Show in the user profile their interests according to the proposals or budgets investments they are following.
User can mark his interests as public.
Show current followers at proposal and budget investment pages.
Followers of a proposal or budget investment will receive related notifications.

How

Create polymorphic association on model concern “Followable” and adding to Proposal and Budget investments.
Adding check “public_interest” to user account.
Adding interests to user profile.
Adding new tab to proposals and budget investment for display Followers and notifications
Create new reusable partials to display followable buttons, followable followers

Screenshots

1. Follow button - Mobile
captura de pantalla 2017-07-11 a las 10 37 43

2. Follow button - Tablet
captura de pantalla 2017-07-11 a las 10 37 29

3. Follow button - Desktop
captura de pantalla 2017-07-11 a las 10 37 15

4. Public interest check on user account
captura de pantalla 2017-07-05 a las 17 49 25

5. Interest list on user profile
captura de pantalla 2017-07-05 a las 17 50 18

Test

Adding Followable shared feature specs, and apply to Proposals and Budget Investment
Increased the user spec feature to display public interest
Increased the notification and proposal notification spec feature to check notification sending to new followers

Deployment

Run migrations

Warnings

None

@@ -95,9 +95,8 @@
create_table "budget_ballots", force: :cascade do |t|
t.integer "user_id"
t.integer "budget_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "ballot_lines_count", default: 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is 👍 , I messed up somehow on a PR and didn't realize it. I added this on a feature branch that is still on PR stage https://github.com/consul/consul/pull/1712/files#diff-ddcb0cf5e4dfc6ac0c06b85bac771760 My apologies >_< 🙇

@@ -25,8 +25,8 @@ def account_params
if @account.organization?
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name])
else
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter, :official_position_badge)
params.require(:account).permit(:username, :public_activity, :public_interest, :email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter, :official_position_badge)
Copy link
Member

Choose a reason for hiding this comment

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

@bertocq maybe public_interest should be public_interests?

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 Yes it sounds more descriptive, right? Feature is "User can mark his interests as public." so plural makes sense.

@@ -0,0 +1,31 @@
class Follow < ActiveRecord::Base
belongs_to :user
#TODO Rock&RoR: Check touch usage on cache system
Copy link
Member

Choose a reason for hiding this comment

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

@taitus We have to do the check, fix if necessary and remove the comment.

@@ -0,0 +1,31 @@
class Follow < ActiveRecord::Base
belongs_to :user
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a cool improvement here (even if there is no actual use on the code right now) would have been to use a counter_cache

Something like belongs_to :user, counter_cache: :following_count

Without forgetting the migration:

    add_column :users, :following_count, :integer, default: 0
    add_index :users, :following_count

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't worry about adding this, seems like there is no actual usage not even reason to. On the mockups there is nowhere to use it (only individual Followable counts) so when that time comes we'll add it if @decabeza thinks it makes sense to put a global following count 👍 .

Copy link
Member

Choose a reason for hiding this comment

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

Because of that we do not have implemented it. Yes, maybe is a YAGNI thing for now.

class Follow < ActiveRecord::Base
belongs_to :user
#TODO Rock&RoR: Check touch usage on cache system
belongs_to :followable, polymorphic: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think here the counter_cache usage I suggested for the belongs_to :user would actually be used, so its more like a performance improvement for any @investment.follows.count or @proposal.follows.count around. What do you think about naming it "followers_count" twitter-style? 😄

!! by_user_and_followable(user, followable).try(:first)
end

def self.interests_by(user)
Copy link
Collaborator

@bertocq bertocq Jul 6, 2017

Choose a reason for hiding this comment

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

What do you think about using a symbol proc and { |item| .. } syntax to make function body smaller? It would be something like user.follows.map { |follow| follow.followable.tags.map(&:name) }.flatten.compact.uniq (the entire function body)

Copy link
Collaborator

Choose a reason for hiding this comment

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

As we commented, this method could make more sense in the User model, to be used as user.interests

<div class="callout primary text-center">
<%= t('follows.no_followers') %>
</div>
<% end %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding here an else and including inside it the following .each loop could maybe be safer?

@@ -170,6 +171,10 @@ def notifications
proposal_notifications
end

def users_to_notify
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe increasing proposal model spec to check this new method, just reusing existing spec for voters could be a nice test improvement https://github.com/rockandror/consul/blob/followable/spec/models/proposal_spec.rb#L382-L425

@@ -166,8 +166,8 @@
end

trait :flagged do
after :create do |debate|
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch! 👍

@@ -0,0 +1,182 @@
shared_examples "followable" do |followable_class_name, followable_path, followable_path_arguments|
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really like the usage of shared_examples 👏 😊

@@ -5,6 +5,7 @@
require 'knapsack'
Dir["./spec/models/concerns/*.rb"].each { |f| require f }
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
Dir["./spec/shared/**/*.rb"].sort.each { |f| require f }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we have 4 shared_examples for concerns, but they are across 3 different subfolder 🙈 . I'll correct this afterwards don't worry :). IMHO /spec/models/concerns/ should be the path for a concern shared_example

@Senen Senen force-pushed the followable branch 2 times, most recently from c21cb0a to f5e8789 Compare July 7, 2017 12:40
…sts. Add specification to check the discard of duplicate interests.
Copy link
Collaborator

@bertocq bertocq left a comment

Choose a reason for hiding this comment

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

👏 !!

@bertocq bertocq merged commit 9c4eb4c into consuldemocracy:master Jul 11, 2017
javierm pushed a commit to javierm/consul that referenced this pull request Dec 7, 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

4 participants