check boosted account ID when performing usermute checks (#3708)

This commit is contained in:
kim 2025-01-30 15:05:15 +00:00 committed by GitHub
parent b3ecfe1e0a
commit 527587155a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 2 deletions

View file

@ -943,8 +943,9 @@ func (c *Converter) statusToAPIFilterResults(
// Both mutes and filters can expire. // Both mutes and filters can expire.
now := time.Now() now := time.Now()
// If the requesting account mutes the account that created this status, hide the status. // If requesting account mutes the author (taking boosts into account), hide it.
if mutes.Matches(s.AccountID, filterContext, now) { if (s.BoostOfAccountID != "" && mutes.Matches(s.AccountID, filterContext, now)) ||
mutes.Matches(s.AccountID, filterContext, now) {
return nil, statusfilter.ErrHideStatus return nil, statusfilter.ErrHideStatus
} }

View file

@ -1161,6 +1161,7 @@ func (suite *InternalToFrontendTestSuite) TestHashtagAnywhereFilteredBoostToFron
func (suite *InternalToFrontendTestSuite) TestMutedStatusToFrontend() { func (suite *InternalToFrontendTestSuite) TestMutedStatusToFrontend() {
testStatus := suite.testStatuses["admin_account_status_1"] testStatus := suite.testStatuses["admin_account_status_1"]
requestingAccount := suite.testAccounts["local_account_1"] requestingAccount := suite.testAccounts["local_account_1"]
mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{ mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
{ {
AccountID: requestingAccount.ID, AccountID: requestingAccount.ID,
@ -1168,6 +1169,7 @@ func (suite *InternalToFrontendTestSuite) TestMutedStatusToFrontend() {
Notifications: util.Ptr(false), Notifications: util.Ptr(false),
}, },
}) })
_, err := suite.typeconverter.StatusToAPIStatus( _, err := suite.typeconverter.StatusToAPIStatus(
context.Background(), context.Background(),
testStatus, testStatus,
@ -1186,6 +1188,7 @@ func (suite *InternalToFrontendTestSuite) TestMutedReplyStatusToFrontend() {
testStatus.InReplyToID = suite.testStatuses["local_account_2_status_1"].ID testStatus.InReplyToID = suite.testStatuses["local_account_2_status_1"].ID
testStatus.InReplyToAccountID = mutedAccount.ID testStatus.InReplyToAccountID = mutedAccount.ID
requestingAccount := suite.testAccounts["local_account_1"] requestingAccount := suite.testAccounts["local_account_1"]
mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{ mutes := usermute.NewCompiledUserMuteList([]*gtsmodel.UserMute{
{ {
AccountID: requestingAccount.ID, AccountID: requestingAccount.ID,
@ -1193,11 +1196,46 @@ func (suite *InternalToFrontendTestSuite) TestMutedReplyStatusToFrontend() {
Notifications: util.Ptr(false), Notifications: util.Ptr(false),
}, },
}) })
// Populate status so the converter has the account objects it needs for muting. // Populate status so the converter has the account objects it needs for muting.
err := suite.db.PopulateStatus(context.Background(), testStatus) err := suite.db.PopulateStatus(context.Background(), testStatus)
if err != nil { if err != nil {
suite.FailNow(err.Error()) 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. // Convert the status to API format, which should fail.
_, err = suite.typeconverter.StatusToAPIStatus( _, err = suite.typeconverter.StatusToAPIStatus(
context.Background(), context.Background(),