From 183eaa5b298235acb8f25ba8f18b98e31471d965 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 21 Sep 2023 12:12:04 +0200 Subject: [feature] Implement explicit domain allows + allowlist federation mode (#2200) * love like winter! wohoah, wohoah * domain allow side effects * tests! logging! unallow! * document federation modes * linty linterson * test * further adventures in documentation * finish up domain block documentation (i think) * change wording a wee little bit * docs, example * consolidate shared domainPermission code * call mode once * fetch federation mode within domain blocked func * read domain perm import in streaming manner * don't use pointer to slice for domain perms * don't bother copying blocks + allows before deleting * admonish! * change wording just a scooch * update docs --- internal/typeutils/internaltofrontend.go | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'internal/typeutils/internaltofrontend.go') diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 050997bda..11838e2bd 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1041,32 +1041,39 @@ func (c *converter) NotificationToAPINotification(ctx context.Context, n *gtsmod }, nil } -func (c *converter) DomainBlockToAPIDomainBlock(ctx context.Context, b *gtsmodel.DomainBlock, export bool) (*apimodel.DomainBlock, error) { +func (c *converter) DomainPermToAPIDomainPerm( + ctx context.Context, + d gtsmodel.DomainPermission, + export bool, +) (*apimodel.DomainPermission, error) { // Domain may be in Punycode, // de-punify it just in case. - d, err := util.DePunify(b.Domain) + domain, err := util.DePunify(d.GetDomain()) if err != nil { - return nil, fmt.Errorf("DomainBlockToAPIDomainBlock: error de-punifying domain %s: %w", b.Domain, err) + return nil, gtserror.Newf("error de-punifying domain %s: %w", d.GetDomain(), err) } - domainBlock := &apimodel.DomainBlock{ + domainPerm := &apimodel.DomainPermission{ Domain: apimodel.Domain{ - Domain: d, - PublicComment: b.PublicComment, + Domain: domain, + PublicComment: d.GetPublicComment(), }, } - // if we're exporting a domain block, return it with minimal information attached - if !export { - domainBlock.ID = b.ID - domainBlock.Obfuscate = *b.Obfuscate - domainBlock.PrivateComment = b.PrivateComment - domainBlock.SubscriptionID = b.SubscriptionID - domainBlock.CreatedBy = b.CreatedByAccountID - domainBlock.CreatedAt = util.FormatISO8601(b.CreatedAt) + // If we're exporting, provide + // only bare minimum detail. + if export { + return domainPerm, nil } - return domainBlock, nil + domainPerm.ID = d.GetID() + domainPerm.Obfuscate = *d.GetObfuscate() + domainPerm.PrivateComment = d.GetPrivateComment() + domainPerm.SubscriptionID = d.GetSubscriptionID() + domainPerm.CreatedBy = d.GetCreatedByAccountID() + domainPerm.CreatedAt = util.FormatISO8601(d.GetCreatedAt()) + + return domainPerm, nil } func (c *converter) ReportToAPIReport(ctx context.Context, r *gtsmodel.Report) (*apimodel.Report, error) { -- cgit v1.2.3