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

Fix muting users with duration via the REST api #15516

Merged
merged 1 commit into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def block
end

def mute
MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications), duration: (params[:duration] || 0))
MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications), duration: (params[:duration]&.to_i || 0))
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end

Expand Down
28 changes: 28 additions & 0 deletions spec/controllers/api/v1/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,34 @@
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
end

describe 'POST #mute with nonzero duration set' do
let(:scopes) { 'write:mutes' }
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }

before do
user.account.follow!(other_account)
post :mute, params: { id: other_account.id, duration: 300 }
end

it 'returns http success' do
expect(response).to have_http_status(200)
end

it 'does not remove the following relation between user and target user' do
expect(user.account.following?(other_account)).to be true
end

it 'creates a muting relation' do
expect(user.account.muting?(other_account)).to be true
end

it 'mutes notifications' do
expect(user.account.muting_notifications?(other_account)).to be true
end

it_behaves_like 'forbidden for wrong scope', 'read:accounts'
end

describe 'POST #unmute' do
let(:scopes) { 'write:mutes' }
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
Expand Down