mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-01-09 18:07:50 -05:00
This commit introduces a blocking feature that allows members to block other members. A blocked member is prevented from: - following the blocker - sending private messages to the blocker - replying to the blocker's posts - liking the blocker's content The implementation includes: - A new `Block` model and a corresponding database table. - Updates to the `Member` model to include associations for blocks. - A new `BlocksController` to handle blocking and unblocking actions. - New routes for the `BlocksController`. - UI changes to add block/unblock buttons to the member profile page. - Validations in the `Follow`, `Comment`, and `Like` models to enforce the blocking rules. - A check in the `MessagesController` to prevent sending messages to a member who has blocked the sender. - A callback in the `Block` model to destroy the follow relationship when a block is created. - New feature and model specs to test the blocking functionality.
33 lines
741 B
Ruby
33 lines
741 B
Ruby
# 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
|