mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-22 18:57:30 -06:00
[bugfix] Fix set obfuscate = null error in adoptPerm
This commit is contained in:
parent
8d5c298419
commit
ebe0e50544
2 changed files with 28 additions and 4 deletions
|
|
@ -19,10 +19,12 @@ package subscriptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"cmp"
|
||||||
"context"
|
"context"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -869,10 +871,13 @@ func (s *Subscriptions) adoptPerm(
|
||||||
perm.SetCreatedByAccount(permSub.CreatedByAccount)
|
perm.SetCreatedByAccount(permSub.CreatedByAccount)
|
||||||
|
|
||||||
// Set new metadata on the perm.
|
// Set new metadata on the perm.
|
||||||
perm.SetObfuscate(obfuscate)
|
|
||||||
perm.SetPrivateComment(privateComment)
|
perm.SetPrivateComment(privateComment)
|
||||||
perm.SetPublicComment(publicComment)
|
perm.SetPublicComment(publicComment)
|
||||||
|
|
||||||
|
// Avoid trying to blat nil into the db directly by
|
||||||
|
// defaulting to false if not set on wanted perm.
|
||||||
|
perm.SetObfuscate(cmp.Or(obfuscate, util.Ptr(false)))
|
||||||
|
|
||||||
// Update the perm in the db.
|
// Update the perm in the db.
|
||||||
var err error
|
var err error
|
||||||
switch p := perm.(type) {
|
switch p := perm.(type) {
|
||||||
|
|
|
||||||
|
|
@ -827,19 +827,27 @@ func (suite *SubscriptionsTestSuite) TestDomainAllowsAndBlocks() {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a subscription for a CSV list of goodies.
|
// Create a subscription for a CSV list of goodies.
|
||||||
|
// This one adopts orphans.
|
||||||
testAllowSubscription = >smodel.DomainPermissionSubscription{
|
testAllowSubscription = >smodel.DomainPermissionSubscription{
|
||||||
ID: "01JGE681TQSBPAV59GZXPKE62H",
|
ID: "01JGE681TQSBPAV59GZXPKE62H",
|
||||||
Priority: 255,
|
Priority: 255,
|
||||||
Title: "goodies!",
|
Title: "goodies!",
|
||||||
PermissionType: gtsmodel.DomainPermissionAllow,
|
PermissionType: gtsmodel.DomainPermissionAllow,
|
||||||
AsDraft: util.Ptr(false),
|
AsDraft: util.Ptr(false),
|
||||||
AdoptOrphans: util.Ptr(false),
|
AdoptOrphans: util.Ptr(true),
|
||||||
CreatedByAccountID: testAccount.ID,
|
CreatedByAccountID: testAccount.ID,
|
||||||
CreatedByAccount: testAccount,
|
CreatedByAccount: testAccount,
|
||||||
URI: "https://lists.example.org/goodies",
|
URI: "https://lists.example.org/goodies",
|
||||||
ContentType: gtsmodel.DomainPermSubContentTypePlain,
|
ContentType: gtsmodel.DomainPermSubContentTypePlain,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingAllow = >smodel.DomainAllow{
|
||||||
|
ID: "01JHX2V5WN250TKB6FQ1M3QE1H",
|
||||||
|
Domain: "people.we.like.com",
|
||||||
|
CreatedByAccount: testAccount,
|
||||||
|
CreatedByAccountID: testAccount.ID,
|
||||||
|
}
|
||||||
|
|
||||||
testBlockSubscription = >smodel.DomainPermissionSubscription{
|
testBlockSubscription = >smodel.DomainPermissionSubscription{
|
||||||
ID: "01JPMVY19TKZND838Z7Y6S4EG8",
|
ID: "01JPMVY19TKZND838Z7Y6S4EG8",
|
||||||
Priority: 255,
|
Priority: 255,
|
||||||
|
|
@ -852,7 +860,6 @@ func (suite *SubscriptionsTestSuite) TestDomainAllowsAndBlocks() {
|
||||||
URI: "https://lists.example.org/baddies.csv",
|
URI: "https://lists.example.org/baddies.csv",
|
||||||
ContentType: gtsmodel.DomainPermSubContentTypeCSV,
|
ContentType: gtsmodel.DomainPermSubContentTypeCSV,
|
||||||
}
|
}
|
||||||
|
|
||||||
)
|
)
|
||||||
defer testrig.TearDownTestStructs(testStructs)
|
defer testrig.TearDownTestStructs(testStructs)
|
||||||
|
|
||||||
|
|
@ -868,9 +875,14 @@ func (suite *SubscriptionsTestSuite) TestDomainAllowsAndBlocks() {
|
||||||
suite.FailNow(err.Error())
|
suite.FailNow(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store existing allow.
|
||||||
|
if err := testStructs.State.DB.CreateDomainAllow(ctx, existingAllow); err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// Put the instance in allowlist mode.
|
// Put the instance in allowlist mode.
|
||||||
config.SetInstanceFederationMode("allowlist")
|
config.SetInstanceFederationMode("allowlist")
|
||||||
|
|
||||||
// Fetch + process subscribed perms in order.
|
// Fetch + process subscribed perms in order.
|
||||||
var order [2]gtsmodel.DomainPermissionType
|
var order [2]gtsmodel.DomainPermissionType
|
||||||
if config.GetInstanceFederationMode() == config.InstanceFederationModeBlocklist {
|
if config.GetInstanceFederationMode() == config.InstanceFederationModeBlocklist {
|
||||||
|
|
@ -929,6 +941,13 @@ func (suite *SubscriptionsTestSuite) TestDomainAllowsAndBlocks() {
|
||||||
|
|
||||||
suite.Equal(testBlockSubscription.ID, perm.GetSubscriptionID())
|
suite.Equal(testBlockSubscription.ID, perm.GetSubscriptionID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
existingAllow, err = testStructs.State.DB.GetDomainAllow(ctx, "people.we.like.com")
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
suite.Equal(existingAllow.SubscriptionID, testAllowSubscription.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubscriptionTestSuite(t *testing.T) {
|
func TestSubscriptionTestSuite(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue