-
Notifications
You must be signed in to change notification settings - Fork 212
Implement blocking feature #4199
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
Open
google-labs-jules
wants to merge
10
commits into
dev
Choose a base branch
from
feature/blocking
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
406286d
Implement blocking feature
google-labs-jules[bot] 3ff1d4e
Implement blocking feature and fix failing tests
google-labs-jules[bot] 96ce55d
Merge branch 'dev' of https://github.com/Growstuff/growstuff into fea…
CloCkWeRX 0f0303a
Generate schema
CloCkWeRX 9c7f555
Merge branch 'dev' into feature/blocking
CloCkWeRX 4551faa
Fix tests
CloCkWeRX d4c23ad
Merge branch 'dev' into feature/blocking
CloCkWeRX 7ecf7cc
Merge branch 'dev' into feature/blocking
CloCkWeRX 9fa031b
Merge branch 'dev' into feature/blocking
CloCkWeRX 935c482
Merge branch 'dev' into feature/blocking
CloCkWeRX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class BlocksController < ApplicationController | ||
| load_and_authorize_resource | ||
| skip_load_resource only: :create | ||
|
|
||
| def create | ||
| @block = current_member.blocks.build(blocked: Member.find(params[:blocked])) | ||
|
|
||
| if @block.save | ||
| flash[:notice] = "Blocked #{@block.blocked.login_name}" | ||
| else | ||
| flash[:error] = "Already blocking or error while blocking." | ||
| end | ||
| redirect_back fallback_location: root_path | ||
| end | ||
|
|
||
| def destroy | ||
| @block = current_member.blocks.find(params[:id]) | ||
| @unblocked = @block.blocked | ||
| @block.destroy | ||
|
|
||
| flash[:notice] = "Unblocked #{@unblocked.login_name}" | ||
| redirect_to @unblocked | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def block_params | ||
| params.permit(:id, :blocked) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Block < ApplicationRecord | ||
| belongs_to :blocker, class_name: "Member" | ||
| belongs_to :blocked, class_name: "Member" | ||
|
|
||
| validates :blocker_id, uniqueness: { scope: :blocked_id } | ||
|
|
||
| after_create :destroy_follow_relationship | ||
|
|
||
| private | ||
|
|
||
| def destroy_follow_relationship | ||
| # Destroy the follow relationship in both directions | ||
| Follow.where(follower: blocker, followed: blocked).destroy_all | ||
| Follow.where(follower: blocked, followed: blocker).destroy_all | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| - if current_member && current_member != member # must be logged in, can't follow yourself | ||
| - block = current_member.get_block(member) | ||
| - follow = current_member.get_follow(member) | ||
| - if !follow && can?(:create, Follow) # not already following | ||
| - if !block && !follow && can?(:create, Follow) # not already following, and not blocking | ||
| = link_to 'Follow', follows_path(followed: member), method: :post, class: 'btn btn-block btn-success' | ||
| - if follow && can?(:destroy, follow) # already following | ||
| = link_to 'Unfollow', follow_path(follow), method: :delete, class: 'btn btn-block' | ||
| = link_to 'Unfollow', follow_path(follow), method: :delete, class: 'btn btn-block' | ||
| - if !block && can?(:create, Block) # not already blocking | ||
| = link_to 'Block', blocks_path(blocked: member), method: :post, class: 'btn btn-block btn-danger' | ||
| - if block && can?(:destroy, block) # already blocking | ||
| = link_to 'Unblock', block_path(block), method: :delete, class: 'btn btn-block' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class CreateBlocks < ActiveRecord::Migration[6.1] | ||
| def change | ||
| create_table :blocks do |t| | ||
| t.references :blocker, foreign_key: { to_table: :members } | ||
| t.references :blocked, foreign_key: { to_table: :members } | ||
|
|
||
| t.timestamps | ||
| end | ||
| add_index :blocks, [:blocker_id, :blocked_id], unique: true | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| describe "blocks", :js do | ||
| context "when signed in" do | ||
| include_context 'signed in member' | ||
| let(:other_member) { create(:member) } | ||
|
|
||
| it "your profile doesn't have a block button" do | ||
| visit member_path(member) | ||
| expect(page).to have_no_link "Block" | ||
| expect(page).to have_no_link "Unblock" | ||
| end | ||
|
|
||
| context "blocking another member" do | ||
| before { visit member_path(other_member) } | ||
|
|
||
| it "has a block button" do | ||
| expect(page).to have_link "Block", href: blocks_path(blocked: other_member.slug) | ||
| end | ||
|
|
||
| it "has correct message and unblock button" do | ||
| click_link 'Block' | ||
| expect(page).to have_content "Blocked #{other_member.login_name}" | ||
| expect(page).to have_link "Unblock", href: block_path(member.get_block(other_member)) | ||
| end | ||
|
|
||
| it "has correct message and block button after unblock" do | ||
| click_link 'Block' | ||
| click_link 'Unblock' | ||
| expect(page).to have_content "Unblocked #{other_member.login_name}" | ||
| visit member_path(other_member) # unblocking redirects to root | ||
| expect(page).to have_link "Block", href: blocks_path(blocked: other_member.slug) | ||
| end | ||
|
|
||
| context "when a member is blocked" do | ||
| before do | ||
| click_link 'Block' | ||
| end | ||
|
|
||
| it "prevents following" do | ||
| visit member_path(other_member) | ||
| expect(page).to have_no_link "Follow" | ||
| end | ||
|
|
||
| it "prevents messaging" do | ||
| visit new_message_path(recipient_id: other_member.id) | ||
| fill_in "Subject", with: "Test message" | ||
| fill_in "Body", with: "Test message body" | ||
| click_button "Send message" | ||
| expect(page).to have_content "You cannot send a message to a member who has blocked you." | ||
| end | ||
|
|
||
| it "prevents commenting" do | ||
| post = create(:post, author: other_member) | ||
| visit post_path(post) | ||
| fill_in "comment_body", with: "Test comment" | ||
| click_button "Post Comment" | ||
| expect(page).to have_content "You cannot comment on a post of a member who has blocked you." | ||
| end | ||
|
|
||
| it "prevents liking" do | ||
| post = create(:post, author: other_member) | ||
| visit post_path(post) | ||
| click_link "Like" | ||
| expect(page).to have_content "You cannot like content of a member who has blocked you." | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.