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

[bugfix] check boosted account ID when performing usermute checks #3708

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
5 changes: 3 additions & 2 deletions internal/typeutils/internaltofrontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,9 @@ func (c *Converter) statusToAPIFilterResults(
// Both mutes and filters can expire.
now := time.Now()

// If the requesting account mutes the account that created this status, hide the status.
if mutes.Matches(s.AccountID, filterContext, now) {
// If requesting account mutes the author (taking boosts into account), hide it.
if (s.BoostOfAccountID != "" && mutes.Matches(s.AccountID, filterContext, now)) ||
mutes.Matches(s.AccountID, filterContext, now) {
return nil, statusfilter.ErrHideStatus
}

Expand Down
38 changes: 38 additions & 0 deletions internal/typeutils/internaltofrontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,13 +1161,15 @@ func (suite *InternalToFrontendTestSuite) TestHashtagAnywhereFilteredBoostToFron
func (suite *InternalToFrontendTestSuite) TestMutedStatusToFrontend() {
testStatus := suite.testStatuses["admin_account_status_1"]
requestingAccount := suite.testAccounts["local_account_1"]

mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
{
AccountID: requestingAccount.ID,
TargetAccountID: testStatus.AccountID,
Notifications: util.Ptr(false),
},
})

_, err := suite.typeconverter.StatusToAPIStatus(
context.Background(),
testStatus,
Expand All @@ -1186,18 +1188,54 @@ func (suite *InternalToFrontendTestSuite) TestMutedReplyStatusToFrontend() {
testStatus.InReplyToID = suite.testStatuses["local_account_2_status_1"].ID
testStatus.InReplyToAccountID = mutedAccount.ID
requestingAccount := suite.testAccounts["local_account_1"]

mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
{
AccountID: requestingAccount.ID,
TargetAccountID: mutedAccount.ID,
Notifications: util.Ptr(false),
},
})

// Populate status so the converter has the account objects it needs for muting.
err := suite.db.PopulateStatus(context.Background(), testStatus)
if err != nil {
suite.FailNow(err.Error())
}

// Convert the status to API format, which should fail.
_, err = suite.typeconverter.StatusToAPIStatus(
context.Background(),
testStatus,
requestingAccount,
statusfilter.FilterContextHome,
nil,
mutes,
)
suite.ErrorIs(err, statusfilter.ErrHideStatus)
}

func (suite *InternalToFrontendTestSuite) TestMutedBoostStatusToFrontend() {
mutedAccount := suite.testAccounts["local_account_2"]
testStatus := suite.testStatuses["admin_account_status_1"]
testStatus.BoostOfID = suite.testStatuses["local_account_2_status_1"].ID
testStatus.BoostOfAccountID = mutedAccount.ID
requestingAccount := suite.testAccounts["local_account_1"]

mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
{
AccountID: requestingAccount.ID,
TargetAccountID: mutedAccount.ID,
Notifications: util.Ptr(false),
},
})

// Populate status so the converter has the account objects it needs for muting.
err := suite.db.PopulateStatus(context.Background(), testStatus)
if err != nil {
suite.FailNow(err.Error())
}

// Convert the status to API format, which should fail.
_, err = suite.typeconverter.StatusToAPIStatus(
context.Background(),
Expand Down