mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-23 22:33:31 -06:00
[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
This commit is contained in:
parent
d6add4ef93
commit
183eaa5b29
52 changed files with 2877 additions and 730 deletions
|
|
@ -91,8 +91,8 @@ type TypeConverter interface {
|
|||
RelationshipToAPIRelationship(ctx context.Context, r *gtsmodel.Relationship) (*apimodel.Relationship, error)
|
||||
// NotificationToAPINotification converts a gts notification into a api notification
|
||||
NotificationToAPINotification(ctx context.Context, n *gtsmodel.Notification) (*apimodel.Notification, error)
|
||||
// DomainBlockToAPIDomainBlock converts a gts model domin block into a api domain block, for serving at /api/v1/admin/domain_blocks
|
||||
DomainBlockToAPIDomainBlock(ctx context.Context, b *gtsmodel.DomainBlock, export bool) (*apimodel.DomainBlock, error)
|
||||
// DomainPermToAPIDomainPerm converts a gts model domin block or allow into an api domain permission.
|
||||
DomainPermToAPIDomainPerm(ctx context.Context, d gtsmodel.DomainPermission, export bool) (*apimodel.DomainPermission, error)
|
||||
// ReportToAPIReport converts a gts model report into an api model report, for serving at /api/v1/reports
|
||||
ReportToAPIReport(ctx context.Context, r *gtsmodel.Report) (*apimodel.Report, error)
|
||||
// ReportToAdminAPIReport converts a gts model report into an admin view report, for serving at /api/v1/admin/reports
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue