2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-08-20 10:26:56 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
package bundb
|
2021-08-20 10:26:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-23 14:53:48 +00:00
|
|
|
"errors"
|
2021-08-20 10:26:56 +00:00
|
|
|
"net/url"
|
2024-10-23 14:53:48 +00:00
|
|
|
"slices"
|
2021-08-20 10:26:56 +00:00
|
|
|
|
2024-10-26 12:04:40 +00:00
|
|
|
"github.com/miekg/dns"
|
2022-05-23 09:46:50 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
2021-08-20 10:26:56 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2024-10-23 14:53:48 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
2023-09-21 10:12:04 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
2021-08-20 10:26:56 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2024-10-23 14:53:48 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
2022-12-08 17:35:14 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/state"
|
2023-05-07 17:53:21 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
2022-10-08 11:50:48 +00:00
|
|
|
"github.com/uptrace/bun"
|
2021-08-20 10:26:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type domainDB struct {
|
2024-02-07 14:43:27 +00:00
|
|
|
db *bun.DB
|
2022-12-08 17:35:14 +00:00
|
|
|
state *state.State
|
2021-08-20 10:26:56 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 10:12:04 +00:00
|
|
|
func (d *domainDB) CreateDomainAllow(ctx context.Context, allow *gtsmodel.DomainAllow) error {
|
|
|
|
// Normalize the domain as punycode
|
|
|
|
var err error
|
|
|
|
allow.Domain, err = util.Punify(allow.Domain)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to store domain allow in DB
|
|
|
|
if _, err := d.db.NewInsert().
|
|
|
|
Model(allow).
|
|
|
|
Exec(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the domain allow cache (for later reload)
|
2024-07-24 08:41:43 +00:00
|
|
|
d.state.Caches.DB.DomainAllow.Clear()
|
2023-09-21 10:12:04 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainAllow(ctx context.Context, domain string) (*gtsmodel.DomainAllow, error) {
|
|
|
|
// Normalize the domain as punycode
|
|
|
|
domain, err := util.Punify(domain)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for easy case, domain referencing *us*
|
|
|
|
if domain == "" || domain == config.GetAccountDomain() ||
|
|
|
|
domain == config.GetHost() {
|
|
|
|
return nil, db.ErrNoEntries
|
|
|
|
}
|
|
|
|
|
|
|
|
var allow gtsmodel.DomainAllow
|
|
|
|
|
|
|
|
// Look for allow matching domain in DB
|
|
|
|
q := d.db.
|
|
|
|
NewSelect().
|
|
|
|
Model(&allow).
|
|
|
|
Where("? = ?", bun.Ident("domain_allow.domain"), domain)
|
|
|
|
if err := q.Scan(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &allow, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainAllows(ctx context.Context) ([]*gtsmodel.DomainAllow, error) {
|
|
|
|
allows := []*gtsmodel.DomainAllow{}
|
|
|
|
|
|
|
|
if err := d.db.
|
|
|
|
NewSelect().
|
|
|
|
Model(&allows).
|
|
|
|
Scan(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return allows, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainAllowByID(ctx context.Context, id string) (*gtsmodel.DomainAllow, error) {
|
|
|
|
var allow gtsmodel.DomainAllow
|
|
|
|
|
|
|
|
q := d.db.
|
|
|
|
NewSelect().
|
|
|
|
Model(&allow).
|
|
|
|
Where("? = ?", bun.Ident("domain_allow.id"), id)
|
|
|
|
if err := q.Scan(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &allow, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) DeleteDomainAllow(ctx context.Context, domain string) error {
|
|
|
|
// Normalize the domain as punycode
|
|
|
|
domain, err := util.Punify(domain)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to delete domain allow
|
|
|
|
if _, err := d.db.NewDelete().
|
|
|
|
Model((*gtsmodel.DomainAllow)(nil)).
|
|
|
|
Where("? = ?", bun.Ident("domain_allow.domain"), domain).
|
|
|
|
Exec(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the domain allow cache (for later reload)
|
2024-07-24 08:41:43 +00:00
|
|
|
d.state.Caches.DB.DomainAllow.Clear()
|
2023-09-21 10:12:04 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) error {
|
2022-12-14 09:55:36 +00:00
|
|
|
// Normalize the domain as punycode
|
2023-05-07 17:53:21 +00:00
|
|
|
var err error
|
|
|
|
block.Domain, err = util.Punify(block.Domain)
|
2022-10-01 15:48:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-09-02 10:17:46 +00:00
|
|
|
|
2023-07-07 09:34:12 +00:00
|
|
|
// Attempt to store domain block in DB
|
2023-07-25 08:34:05 +00:00
|
|
|
if _, err := d.db.NewInsert().
|
2022-12-14 09:55:36 +00:00
|
|
|
Model(block).
|
|
|
|
Exec(ctx); err != nil {
|
2023-08-17 16:26:21 +00:00
|
|
|
return err
|
2022-12-14 09:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the domain block cache (for later reload)
|
2024-07-24 08:41:43 +00:00
|
|
|
d.state.Caches.DB.DomainBlock.Clear()
|
2022-12-14 09:55:36 +00:00
|
|
|
|
|
|
|
return nil
|
2022-09-02 10:17:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) GetDomainBlock(ctx context.Context, domain string) (*gtsmodel.DomainBlock, error) {
|
2022-12-14 09:55:36 +00:00
|
|
|
// Normalize the domain as punycode
|
2023-05-07 17:53:21 +00:00
|
|
|
domain, err := util.Punify(domain)
|
2022-10-01 15:48:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-09-02 10:17:46 +00:00
|
|
|
|
2022-12-14 09:55:36 +00:00
|
|
|
// Check for easy case, domain referencing *us*
|
|
|
|
if domain == "" || domain == config.GetAccountDomain() ||
|
|
|
|
domain == config.GetHost() {
|
|
|
|
return nil, db.ErrNoEntries
|
|
|
|
}
|
2022-09-02 10:17:46 +00:00
|
|
|
|
2022-12-14 09:55:36 +00:00
|
|
|
var block gtsmodel.DomainBlock
|
2022-09-02 10:17:46 +00:00
|
|
|
|
2022-12-14 09:55:36 +00:00
|
|
|
// Look for block matching domain in DB
|
2023-07-25 08:34:05 +00:00
|
|
|
q := d.db.
|
2022-12-14 09:55:36 +00:00
|
|
|
NewSelect().
|
|
|
|
Model(&block).
|
|
|
|
Where("? = ?", bun.Ident("domain_block.domain"), domain)
|
|
|
|
if err := q.Scan(ctx); err != nil {
|
2023-08-17 16:26:21 +00:00
|
|
|
return nil, err
|
2022-12-14 09:55:36 +00:00
|
|
|
}
|
2022-09-02 10:17:46 +00:00
|
|
|
|
2022-12-14 09:55:36 +00:00
|
|
|
return &block, nil
|
2021-08-20 10:26:56 +00:00
|
|
|
}
|
|
|
|
|
2023-07-07 09:34:12 +00:00
|
|
|
func (d *domainDB) GetDomainBlocks(ctx context.Context) ([]*gtsmodel.DomainBlock, error) {
|
|
|
|
blocks := []*gtsmodel.DomainBlock{}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
if err := d.db.
|
2023-07-07 09:34:12 +00:00
|
|
|
NewSelect().
|
|
|
|
Model(&blocks).
|
|
|
|
Scan(ctx); err != nil {
|
2023-08-17 16:26:21 +00:00
|
|
|
return nil, err
|
2023-07-07 09:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return blocks, nil
|
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) GetDomainBlockByID(ctx context.Context, id string) (*gtsmodel.DomainBlock, error) {
|
2023-07-07 09:34:12 +00:00
|
|
|
var block gtsmodel.DomainBlock
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
q := d.db.
|
2023-07-07 09:34:12 +00:00
|
|
|
NewSelect().
|
|
|
|
Model(&block).
|
|
|
|
Where("? = ?", bun.Ident("domain_block.id"), id)
|
|
|
|
if err := q.Scan(ctx); err != nil {
|
2023-08-17 16:26:21 +00:00
|
|
|
return nil, err
|
2023-07-07 09:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &block, nil
|
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) DeleteDomainBlock(ctx context.Context, domain string) error {
|
2023-05-07 17:53:21 +00:00
|
|
|
// Normalize the domain as punycode
|
|
|
|
domain, err := util.Punify(domain)
|
2022-10-01 15:48:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-20 10:26:56 +00:00
|
|
|
|
2022-09-02 10:17:46 +00:00
|
|
|
// Attempt to delete domain block
|
2023-07-25 08:34:05 +00:00
|
|
|
if _, err := d.db.NewDelete().
|
2022-09-02 10:17:46 +00:00
|
|
|
Model((*gtsmodel.DomainBlock)(nil)).
|
2022-10-08 11:50:48 +00:00
|
|
|
Where("? = ?", bun.Ident("domain_block.domain"), domain).
|
2022-10-01 15:48:38 +00:00
|
|
|
Exec(ctx); err != nil {
|
2023-08-17 16:26:21 +00:00
|
|
|
return err
|
2022-09-02 10:17:46 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 09:55:36 +00:00
|
|
|
// Clear the domain block cache (for later reload)
|
2024-07-24 08:41:43 +00:00
|
|
|
d.state.Caches.DB.DomainBlock.Clear()
|
2022-09-02 10:17:46 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) IsDomainBlocked(ctx context.Context, domain string) (bool, error) {
|
2022-12-14 09:55:36 +00:00
|
|
|
// Normalize the domain as punycode
|
2023-05-07 17:53:21 +00:00
|
|
|
domain, err := util.Punify(domain)
|
2022-12-14 09:55:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2022-09-02 10:17:46 +00:00
|
|
|
}
|
2022-12-14 09:55:36 +00:00
|
|
|
|
2023-09-21 10:12:04 +00:00
|
|
|
// Domain referencing *us* cannot be blocked.
|
2022-12-14 09:55:36 +00:00
|
|
|
if domain == "" || domain == config.GetAccountDomain() ||
|
|
|
|
domain == config.GetHost() {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2023-09-21 10:12:04 +00:00
|
|
|
// Check the cache for an explicit domain allow (hydrating the cache with callback if necessary).
|
2024-07-24 08:41:43 +00:00
|
|
|
explicitAllow, err := d.state.Caches.DB.DomainAllow.Matches(domain, func() ([]string, error) {
|
2023-09-21 10:12:04 +00:00
|
|
|
var domains []string
|
|
|
|
|
|
|
|
// Scan list of all explicitly allowed domains from DB
|
|
|
|
q := d.db.NewSelect().
|
|
|
|
Table("domain_allows").
|
|
|
|
Column("domain")
|
|
|
|
if err := q.Scan(ctx, &domains); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return domains, nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
2022-12-14 09:55:36 +00:00
|
|
|
// Check the cache for a domain block (hydrating the cache with callback if necessary)
|
2024-07-24 08:41:43 +00:00
|
|
|
explicitBlock, err := d.state.Caches.DB.DomainBlock.Matches(domain, func() ([]string, error) {
|
2022-12-14 09:55:36 +00:00
|
|
|
var domains []string
|
|
|
|
|
|
|
|
// Scan list of all blocked domains from DB
|
2023-07-25 08:34:05 +00:00
|
|
|
q := d.db.NewSelect().
|
2022-12-14 09:55:36 +00:00
|
|
|
Table("domain_blocks").
|
|
|
|
Column("domain")
|
|
|
|
if err := q.Scan(ctx, &domains); err != nil {
|
2023-08-17 16:26:21 +00:00
|
|
|
return nil, err
|
2022-12-14 09:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return domains, nil
|
|
|
|
})
|
2023-09-21 10:12:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate if blocked
|
|
|
|
// based on federation mode.
|
|
|
|
switch mode := config.GetInstanceFederationMode(); mode {
|
|
|
|
|
|
|
|
case config.InstanceFederationModeBlocklist:
|
|
|
|
// Blocklist/default mode: explicit allow
|
|
|
|
// takes precedence over explicit block.
|
|
|
|
//
|
|
|
|
// Domains that have neither block
|
|
|
|
// or allow entries are allowed.
|
|
|
|
return !(explicitAllow || !explicitBlock), nil
|
|
|
|
|
|
|
|
case config.InstanceFederationModeAllowlist:
|
|
|
|
// Allowlist mode: explicit block takes
|
|
|
|
// precedence over explicit allow.
|
|
|
|
//
|
|
|
|
// Domains that have neither block
|
|
|
|
// or allow entries are blocked.
|
|
|
|
return (explicitBlock || !explicitAllow), nil
|
|
|
|
|
|
|
|
default:
|
|
|
|
// This should never happen but account
|
|
|
|
// for it anyway to make the code tidier.
|
|
|
|
return false, gtserror.Newf("unrecognized federation mode: %s", mode)
|
|
|
|
}
|
2022-09-02 10:17:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) AreDomainsBlocked(ctx context.Context, domains []string) (bool, error) {
|
2022-09-02 10:17:46 +00:00
|
|
|
for _, domain := range domains {
|
|
|
|
if blocked, err := d.IsDomainBlocked(ctx, domain); err != nil {
|
2021-08-20 10:26:56 +00:00
|
|
|
return false, err
|
|
|
|
} else if blocked {
|
|
|
|
return blocked, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) IsURIBlocked(ctx context.Context, uri *url.URL) (bool, error) {
|
2022-09-02 10:17:46 +00:00
|
|
|
return d.IsDomainBlocked(ctx, uri.Hostname())
|
2021-08-20 10:26:56 +00:00
|
|
|
}
|
|
|
|
|
2023-07-25 08:34:05 +00:00
|
|
|
func (d *domainDB) AreURIsBlocked(ctx context.Context, uris []*url.URL) (bool, error) {
|
2021-08-20 10:26:56 +00:00
|
|
|
for _, uri := range uris {
|
2022-09-02 10:17:46 +00:00
|
|
|
if blocked, err := d.IsDomainBlocked(ctx, uri.Hostname()); err != nil {
|
|
|
|
return false, err
|
|
|
|
} else if blocked {
|
|
|
|
return blocked, nil
|
|
|
|
}
|
2021-08-20 10:26:56 +00:00
|
|
|
}
|
2022-09-02 10:17:46 +00:00
|
|
|
return false, nil
|
2021-08-20 10:26:56 +00:00
|
|
|
}
|
2024-10-23 14:53:48 +00:00
|
|
|
|
|
|
|
func (d *domainDB) getDomainPermissionDraft(
|
|
|
|
ctx context.Context,
|
|
|
|
lookup string,
|
|
|
|
dbQuery func(*gtsmodel.DomainPermissionDraft) error,
|
|
|
|
keyParts ...any,
|
|
|
|
) (*gtsmodel.DomainPermissionDraft, error) {
|
|
|
|
// Fetch perm draft from database cache with loader callback.
|
|
|
|
permDraft, err := d.state.Caches.DB.DomainPermissionDraft.LoadOne(
|
|
|
|
lookup,
|
|
|
|
// Only called if not cached.
|
|
|
|
func() (*gtsmodel.DomainPermissionDraft, error) {
|
|
|
|
var permDraft gtsmodel.DomainPermissionDraft
|
|
|
|
if err := dbQuery(&permDraft); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &permDraft, nil
|
|
|
|
},
|
|
|
|
keyParts...,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if gtscontext.Barebones(ctx) {
|
|
|
|
// No need to fully populate.
|
|
|
|
return permDraft, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if permDraft.CreatedByAccount == nil {
|
|
|
|
// Not set, fetch from database.
|
|
|
|
permDraft.CreatedByAccount, err = d.state.DB.GetAccountByID(
|
|
|
|
gtscontext.SetBarebones(ctx),
|
|
|
|
permDraft.CreatedByAccountID,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, gtserror.Newf("error populating created by account: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return permDraft, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainPermissionDraftByID(
|
|
|
|
ctx context.Context,
|
|
|
|
id string,
|
|
|
|
) (*gtsmodel.DomainPermissionDraft, error) {
|
|
|
|
return d.getDomainPermissionDraft(
|
|
|
|
ctx,
|
|
|
|
"ID",
|
|
|
|
func(permDraft *gtsmodel.DomainPermissionDraft) error {
|
|
|
|
return d.db.
|
|
|
|
NewSelect().
|
|
|
|
Model(permDraft).
|
|
|
|
Where("? = ?", bun.Ident("domain_permission_draft.id"), id).
|
|
|
|
Scan(ctx)
|
|
|
|
},
|
|
|
|
id,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainPermissionDrafts(
|
|
|
|
ctx context.Context,
|
|
|
|
permType *gtsmodel.DomainPermissionType,
|
|
|
|
permSubID string,
|
|
|
|
domain string,
|
|
|
|
page *paging.Page,
|
|
|
|
) (
|
|
|
|
[]*gtsmodel.DomainPermissionDraft,
|
|
|
|
error,
|
|
|
|
) {
|
|
|
|
var (
|
|
|
|
// Get paging params.
|
|
|
|
minID = page.GetMin()
|
|
|
|
maxID = page.GetMax()
|
|
|
|
limit = page.GetLimit()
|
|
|
|
order = page.GetOrder()
|
|
|
|
|
|
|
|
// Make educated guess for slice size
|
|
|
|
permDraftIDs = make([]string, 0, limit)
|
|
|
|
)
|
|
|
|
|
|
|
|
q := d.db.
|
|
|
|
NewSelect().
|
|
|
|
TableExpr(
|
|
|
|
"? AS ?",
|
|
|
|
bun.Ident("domain_permission_drafts"),
|
|
|
|
bun.Ident("domain_permission_draft"),
|
|
|
|
).
|
|
|
|
// Select only IDs from table
|
|
|
|
Column("domain_permission_draft.id")
|
|
|
|
|
|
|
|
// Return only items with id
|
|
|
|
// lower than provided maxID.
|
|
|
|
if maxID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? < ?",
|
|
|
|
bun.Ident("domain_permission_draft.id"),
|
|
|
|
maxID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with id
|
|
|
|
// greater than provided minID.
|
|
|
|
if minID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? > ?",
|
|
|
|
bun.Ident("domain_permission_draft.id"),
|
|
|
|
minID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with
|
|
|
|
// given subscription ID.
|
|
|
|
if permType != nil {
|
|
|
|
q = q.Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_draft.permission_type"),
|
|
|
|
*permType,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with
|
|
|
|
// given subscription ID.
|
|
|
|
if permSubID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_draft.subscription_id"),
|
|
|
|
permSubID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items
|
|
|
|
// with given domain.
|
|
|
|
if domain != "" {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Normalize domain as punycode.
|
|
|
|
domain, err = util.Punify(domain)
|
|
|
|
if err != nil {
|
|
|
|
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
q = q.Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_draft.domain"),
|
|
|
|
domain,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if limit > 0 {
|
|
|
|
// Limit amount of
|
|
|
|
// items returned.
|
|
|
|
q = q.Limit(limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
if order == paging.OrderAscending {
|
|
|
|
// Page up.
|
|
|
|
q = q.OrderExpr(
|
|
|
|
"? ASC",
|
|
|
|
bun.Ident("domain_permission_draft.id"),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
// Page down.
|
|
|
|
q = q.OrderExpr(
|
|
|
|
"? DESC",
|
|
|
|
bun.Ident("domain_permission_draft.id"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.Scan(ctx, &permDraftIDs); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Catch case of no items early
|
|
|
|
if len(permDraftIDs) == 0 {
|
|
|
|
return nil, db.ErrNoEntries
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're paging up, we still want items
|
|
|
|
// to be sorted by ID desc, so reverse slice.
|
|
|
|
if order == paging.OrderAscending {
|
|
|
|
slices.Reverse(permDraftIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate return slice (will be at most len permDraftIDs)
|
|
|
|
permDrafts := make([]*gtsmodel.DomainPermissionDraft, 0, len(permDraftIDs))
|
|
|
|
for _, id := range permDraftIDs {
|
|
|
|
permDraft, err := d.GetDomainPermissionDraftByID(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf(ctx, "error getting domain permission draft %q: %v", id, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append to return slice
|
|
|
|
permDrafts = append(permDrafts, permDraft)
|
|
|
|
}
|
|
|
|
|
|
|
|
return permDrafts, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) PutDomainPermissionDraft(
|
|
|
|
ctx context.Context,
|
|
|
|
permDraft *gtsmodel.DomainPermissionDraft,
|
|
|
|
) error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Normalize the domain as punycode
|
|
|
|
permDraft.Domain, err = util.Punify(permDraft.Domain)
|
|
|
|
if err != nil {
|
|
|
|
return gtserror.Newf("error punifying domain %s: %w", permDraft.Domain, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return d.state.Caches.DB.DomainPermissionDraft.Store(
|
|
|
|
permDraft,
|
|
|
|
func() error {
|
|
|
|
_, err := d.db.
|
|
|
|
NewInsert().
|
|
|
|
Model(permDraft).
|
|
|
|
Exec(ctx)
|
|
|
|
return err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) DeleteDomainPermissionDraft(
|
|
|
|
ctx context.Context,
|
|
|
|
id string,
|
|
|
|
) error {
|
|
|
|
// Delete the permDraft from DB.
|
|
|
|
q := d.db.NewDelete().
|
|
|
|
TableExpr(
|
|
|
|
"? AS ?",
|
|
|
|
bun.Ident("domain_permission_drafts"),
|
|
|
|
bun.Ident("domain_permission_draft"),
|
|
|
|
).
|
|
|
|
Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_draft.id"),
|
|
|
|
id,
|
|
|
|
)
|
|
|
|
|
|
|
|
_, err := q.Exec(ctx)
|
|
|
|
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalidate any cached model by ID.
|
|
|
|
d.state.Caches.DB.DomainPermissionDraft.Invalidate("ID", id)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) getDomainPermissionSubscription(
|
|
|
|
ctx context.Context,
|
|
|
|
lookup string,
|
|
|
|
dbQuery func(*gtsmodel.DomainPermissionSubscription) error,
|
|
|
|
keyParts ...any,
|
|
|
|
) (*gtsmodel.DomainPermissionSubscription, error) {
|
|
|
|
// Fetch perm subscription from database cache with loader callback.
|
2024-10-26 12:04:40 +00:00
|
|
|
permSub, err := d.state.Caches.DB.DomainPermissionSubscription.LoadOne(
|
2024-10-23 14:53:48 +00:00
|
|
|
lookup,
|
|
|
|
// Only called if not cached.
|
|
|
|
func() (*gtsmodel.DomainPermissionSubscription, error) {
|
2024-10-26 12:04:40 +00:00
|
|
|
var permSub gtsmodel.DomainPermissionSubscription
|
|
|
|
if err := dbQuery(&permSub); err != nil {
|
2024-10-23 14:53:48 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-26 12:04:40 +00:00
|
|
|
return &permSub, nil
|
2024-10-23 14:53:48 +00:00
|
|
|
},
|
|
|
|
keyParts...,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if gtscontext.Barebones(ctx) {
|
|
|
|
// No need to fully populate.
|
2024-10-26 12:04:40 +00:00
|
|
|
return permSub, nil
|
2024-10-23 14:53:48 +00:00
|
|
|
}
|
|
|
|
|
2024-10-26 12:04:40 +00:00
|
|
|
if permSub.CreatedByAccount == nil {
|
2024-10-23 14:53:48 +00:00
|
|
|
// Not set, fetch from database.
|
2024-10-26 12:04:40 +00:00
|
|
|
permSub.CreatedByAccount, err = d.state.DB.GetAccountByID(
|
2024-10-23 14:53:48 +00:00
|
|
|
gtscontext.SetBarebones(ctx),
|
2024-10-26 12:04:40 +00:00
|
|
|
permSub.CreatedByAccountID,
|
2024-10-23 14:53:48 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, gtserror.Newf("error populating created by account: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-26 12:04:40 +00:00
|
|
|
return permSub, nil
|
2024-10-23 14:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainPermissionSubscriptionByID(
|
|
|
|
ctx context.Context,
|
|
|
|
id string,
|
|
|
|
) (*gtsmodel.DomainPermissionSubscription, error) {
|
|
|
|
return d.getDomainPermissionSubscription(
|
|
|
|
ctx,
|
|
|
|
"ID",
|
2024-10-26 12:04:40 +00:00
|
|
|
func(permSub *gtsmodel.DomainPermissionSubscription) error {
|
2024-10-23 14:53:48 +00:00
|
|
|
return d.db.
|
|
|
|
NewSelect().
|
2024-10-26 12:04:40 +00:00
|
|
|
Model(permSub).
|
2024-10-23 14:53:48 +00:00
|
|
|
Where("? = ?", bun.Ident("domain_permission_subscription.id"), id).
|
|
|
|
Scan(ctx)
|
|
|
|
},
|
|
|
|
id,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainPermissionSubscriptions(
|
|
|
|
ctx context.Context,
|
|
|
|
permType *gtsmodel.DomainPermissionType,
|
|
|
|
page *paging.Page,
|
|
|
|
) (
|
|
|
|
[]*gtsmodel.DomainPermissionSubscription,
|
|
|
|
error,
|
|
|
|
) {
|
|
|
|
var (
|
|
|
|
// Get paging params.
|
|
|
|
minID = page.GetMin()
|
|
|
|
maxID = page.GetMax()
|
|
|
|
limit = page.GetLimit()
|
|
|
|
order = page.GetOrder()
|
|
|
|
|
|
|
|
// Make educated guess for slice size
|
|
|
|
permSubIDs = make([]string, 0, limit)
|
|
|
|
)
|
|
|
|
|
|
|
|
q := d.db.
|
|
|
|
NewSelect().
|
|
|
|
TableExpr(
|
|
|
|
"? AS ?",
|
|
|
|
bun.Ident("domain_permission_subscriptions"),
|
|
|
|
bun.Ident("domain_permission_subscription"),
|
|
|
|
).
|
|
|
|
// Select only IDs from table
|
|
|
|
Column("domain_permission_subscription.id")
|
|
|
|
|
|
|
|
// Return only items with id
|
|
|
|
// lower than provided maxID.
|
|
|
|
if maxID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? < ?",
|
|
|
|
bun.Ident("domain_permission_subscription.id"),
|
|
|
|
maxID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with id
|
|
|
|
// greater than provided minID.
|
|
|
|
if minID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? > ?",
|
|
|
|
bun.Ident("domain_permission_subscription.id"),
|
|
|
|
minID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with
|
|
|
|
// given subscription ID.
|
|
|
|
if permType != nil {
|
|
|
|
q = q.Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_subscription.permission_type"),
|
|
|
|
*permType,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if limit > 0 {
|
|
|
|
// Limit amount of
|
|
|
|
// items returned.
|
|
|
|
q = q.Limit(limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
if order == paging.OrderAscending {
|
|
|
|
// Page up.
|
|
|
|
q = q.OrderExpr(
|
|
|
|
"? ASC",
|
|
|
|
bun.Ident("domain_permission_subscription.id"),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
// Page down.
|
|
|
|
q = q.OrderExpr(
|
|
|
|
"? DESC",
|
|
|
|
bun.Ident("domain_permission_subscription.id"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.Scan(ctx, &permSubIDs); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Catch case of no items early
|
|
|
|
if len(permSubIDs) == 0 {
|
|
|
|
return nil, db.ErrNoEntries
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're paging up, we still want items
|
|
|
|
// to be sorted by ID desc, so reverse slice.
|
|
|
|
if order == paging.OrderAscending {
|
|
|
|
slices.Reverse(permSubIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate return slice (will be at most len permSubIDs).
|
|
|
|
permSubs := make([]*gtsmodel.DomainPermissionSubscription, 0, len(permSubIDs))
|
|
|
|
for _, id := range permSubIDs {
|
2024-10-26 12:04:40 +00:00
|
|
|
permSub, err := d.GetDomainPermissionSubscriptionByID(ctx, id)
|
2024-10-23 14:53:48 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf(ctx, "error getting domain permission subscription %q: %v", id, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append to return slice
|
2024-10-26 12:04:40 +00:00
|
|
|
permSubs = append(permSubs, permSub)
|
2024-10-23 14:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return permSubs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) PutDomainPermissionSubscription(
|
|
|
|
ctx context.Context,
|
|
|
|
permSubscription *gtsmodel.DomainPermissionSubscription,
|
|
|
|
) error {
|
|
|
|
return d.state.Caches.DB.DomainPermissionSubscription.Store(
|
|
|
|
permSubscription,
|
|
|
|
func() error {
|
|
|
|
_, err := d.db.
|
|
|
|
NewInsert().
|
|
|
|
Model(permSubscription).
|
|
|
|
Exec(ctx)
|
|
|
|
return err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) DeleteDomainPermissionSubscription(
|
|
|
|
ctx context.Context,
|
|
|
|
id string,
|
|
|
|
) error {
|
|
|
|
// Delete the permSub from DB.
|
|
|
|
q := d.db.NewDelete().
|
|
|
|
TableExpr(
|
|
|
|
"? AS ?",
|
|
|
|
bun.Ident("domain_permission_subscriptions"),
|
|
|
|
bun.Ident("domain_permission_subscription"),
|
|
|
|
).
|
|
|
|
Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_subscription.id"),
|
|
|
|
id,
|
|
|
|
)
|
|
|
|
|
|
|
|
_, err := q.Exec(ctx)
|
|
|
|
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalidate any cached model by ID.
|
|
|
|
d.state.Caches.DB.DomainPermissionSubscription.Invalidate("ID", id)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2024-10-26 12:04:40 +00:00
|
|
|
|
|
|
|
func (d *domainDB) PutDomainPermissionIgnore(
|
|
|
|
ctx context.Context,
|
|
|
|
ignore *gtsmodel.DomainPermissionIgnore,
|
|
|
|
) error {
|
|
|
|
// Normalize the domain as punycode
|
|
|
|
var err error
|
|
|
|
ignore.Domain, err = util.Punify(ignore.Domain)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to store domain perm ignore in DB
|
|
|
|
if _, err := d.db.NewInsert().
|
|
|
|
Model(ignore).
|
|
|
|
Exec(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the domain perm ignore cache (for later reload)
|
|
|
|
d.state.Caches.DB.DomainPermissionIgnore.Clear()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) IsDomainPermissionIgnored(ctx context.Context, domain string) (bool, error) {
|
|
|
|
// Normalize the domain as punycode
|
|
|
|
domain, err := util.Punify(domain)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if our host and given domain are equal
|
|
|
|
// or part of the same second-level domain; we
|
|
|
|
// always ignore such perms as creating blocks
|
|
|
|
// or allows in such cases may break things.
|
|
|
|
if dns.CompareDomainName(domain, config.GetHost()) >= 2 {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Func to scan list of all
|
|
|
|
// ignored domain perms from DB.
|
|
|
|
loadF := func() ([]string, error) {
|
|
|
|
var domains []string
|
|
|
|
|
|
|
|
if err := d.db.
|
|
|
|
NewSelect().
|
|
|
|
Table("domain_ignores").
|
|
|
|
Column("domain").
|
|
|
|
Scan(ctx, &domains); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return domains, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the cache for a domain perm ignore,
|
|
|
|
// hydrating the cache with loadF if necessary.
|
|
|
|
return d.state.Caches.DB.DomainPermissionIgnore.Matches(domain, loadF)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainPermissionIgnoreByID(
|
|
|
|
ctx context.Context,
|
|
|
|
id string,
|
|
|
|
) (*gtsmodel.DomainPermissionIgnore, error) {
|
|
|
|
ignore := new(gtsmodel.DomainPermissionIgnore)
|
|
|
|
|
|
|
|
q := d.db.
|
|
|
|
NewSelect().
|
|
|
|
Model(ignore).
|
|
|
|
Where("? = ?", bun.Ident("domain_permission_ignore.id"), id)
|
|
|
|
if err := q.Scan(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if gtscontext.Barebones(ctx) {
|
|
|
|
// No need to fully populate.
|
|
|
|
return ignore, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if ignore.CreatedByAccount == nil {
|
|
|
|
// Not set, fetch from database.
|
|
|
|
var err error
|
|
|
|
ignore.CreatedByAccount, err = d.state.DB.GetAccountByID(
|
|
|
|
gtscontext.SetBarebones(ctx),
|
|
|
|
ignore.CreatedByAccountID,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, gtserror.Newf("error populating created by account: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ignore, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) GetDomainPermissionIgnores(
|
|
|
|
ctx context.Context,
|
|
|
|
permType *gtsmodel.DomainPermissionType,
|
|
|
|
page *paging.Page,
|
|
|
|
) (
|
|
|
|
[]*gtsmodel.DomainPermissionIgnore,
|
|
|
|
error,
|
|
|
|
) {
|
|
|
|
var (
|
|
|
|
// Get paging params.
|
|
|
|
minID = page.GetMin()
|
|
|
|
maxID = page.GetMax()
|
|
|
|
limit = page.GetLimit()
|
|
|
|
order = page.GetOrder()
|
|
|
|
|
|
|
|
// Make educated guess for slice size
|
|
|
|
ignoreIDs = make([]string, 0, limit)
|
|
|
|
)
|
|
|
|
|
|
|
|
q := d.db.
|
|
|
|
NewSelect().
|
|
|
|
TableExpr(
|
|
|
|
"? AS ?",
|
|
|
|
bun.Ident("domain_permission_ignores"),
|
|
|
|
bun.Ident("domain_permission_ignore"),
|
|
|
|
).
|
|
|
|
// Select only IDs from table
|
|
|
|
Column("domain_permission_ignore.id")
|
|
|
|
|
|
|
|
// Return only items with id
|
|
|
|
// lower than provided maxID.
|
|
|
|
if maxID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? < ?",
|
|
|
|
bun.Ident("domain_permission_ignore.id"),
|
|
|
|
maxID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with id
|
|
|
|
// greater than provided minID.
|
|
|
|
if minID != "" {
|
|
|
|
q = q.Where(
|
|
|
|
"? > ?",
|
|
|
|
bun.Ident("domain_permission_ignore.id"),
|
|
|
|
minID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return only items with
|
|
|
|
// given subscription ID.
|
|
|
|
if permType != nil {
|
|
|
|
q = q.Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_ignore.permission_type"),
|
|
|
|
*permType,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if limit > 0 {
|
|
|
|
// Limit amount of
|
|
|
|
// items returned.
|
|
|
|
q = q.Limit(limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
if order == paging.OrderAscending {
|
|
|
|
// Page up.
|
|
|
|
q = q.OrderExpr(
|
|
|
|
"? ASC",
|
|
|
|
bun.Ident("domain_permission_ignore.id"),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
// Page down.
|
|
|
|
q = q.OrderExpr(
|
|
|
|
"? DESC",
|
|
|
|
bun.Ident("domain_permission_ignore.id"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.Scan(ctx, &ignoreIDs); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Catch case of no items early
|
|
|
|
if len(ignoreIDs) == 0 {
|
|
|
|
return nil, db.ErrNoEntries
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're paging up, we still want items
|
|
|
|
// to be sorted by ID desc, so reverse slice.
|
|
|
|
if order == paging.OrderAscending {
|
|
|
|
slices.Reverse(ignoreIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate return slice (will be at most len permSubIDs).
|
|
|
|
ignores := make([]*gtsmodel.DomainPermissionIgnore, 0, len(ignoreIDs))
|
|
|
|
for _, id := range ignoreIDs {
|
|
|
|
ignore, err := d.GetDomainPermissionIgnoreByID(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf(ctx, "error getting domain permission ignore %q: %v", id, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append to return slice
|
|
|
|
ignores = append(ignores, ignore)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ignores, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *domainDB) DeleteDomainPermissionIgnore(
|
|
|
|
ctx context.Context,
|
|
|
|
id string,
|
|
|
|
) error {
|
|
|
|
// Delete the permSub from DB.
|
|
|
|
q := d.db.NewDelete().
|
|
|
|
TableExpr(
|
|
|
|
"? AS ?",
|
|
|
|
bun.Ident("domain_permission_ignores"),
|
|
|
|
bun.Ident("domain_permission_ignore"),
|
|
|
|
).
|
|
|
|
Where(
|
|
|
|
"? = ?",
|
|
|
|
bun.Ident("domain_permission_ignore.id"),
|
|
|
|
id,
|
|
|
|
)
|
|
|
|
|
|
|
|
_, err := q.Exec(ctx)
|
|
|
|
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the domain perm ignore cache (for later reload)
|
|
|
|
d.state.Caches.DB.DomainPermissionIgnore.Clear()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|