mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-16 10:43:01 -06:00
unblock domains properly
This commit is contained in:
parent
8285d09da5
commit
e8f1c33b48
15 changed files with 316 additions and 130 deletions
|
|
@ -86,6 +86,9 @@ type DB interface {
|
||||||
// UpdateOneByID updates interface i with database the given database id. It will update one field of key key and value value.
|
// UpdateOneByID updates interface i with database the given database id. It will update one field of key key and value value.
|
||||||
UpdateOneByID(id string, key string, value interface{}, i interface{}) error
|
UpdateOneByID(id string, key string, value interface{}, i interface{}) error
|
||||||
|
|
||||||
|
// UpdateWhere updates column key of interface i with the given value, where the given parameters apply.
|
||||||
|
UpdateWhere(where []Where, key string, value interface{}, i interface{}) error
|
||||||
|
|
||||||
// DeleteByID removes i with id id.
|
// DeleteByID removes i with id id.
|
||||||
// If i didn't exist anyway, then no error should be returned.
|
// If i didn't exist anyway, then no error should be returned.
|
||||||
DeleteByID(id string, i interface{}) error
|
DeleteByID(id string, i interface{}) error
|
||||||
|
|
|
||||||
57
internal/db/pg/delete.go
Normal file
57
internal/db/pg/delete.go
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ps *postgresService) DeleteByID(id string, i interface{}) error {
|
||||||
|
if _, err := ps.conn.Model(i).Where("id = ?", id).Delete(); err != nil {
|
||||||
|
// if there are no rows *anyway* then that's fine
|
||||||
|
// just return err if there's an actual error
|
||||||
|
if err != pg.ErrNoRows {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *postgresService) DeleteWhere(where []db.Where, i interface{}) error {
|
||||||
|
if len(where) == 0 {
|
||||||
|
return errors.New("no queries provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
q := ps.conn.Model(i)
|
||||||
|
for _, w := range where {
|
||||||
|
q = q.Where("? = ?", pg.Safe(w.Key), w.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := q.Delete(); err != nil {
|
||||||
|
// if there are no rows *anyway* then that's fine
|
||||||
|
// just return err if there's an actual error
|
||||||
|
if err != pg.ErrNoRows {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
75
internal/db/pg/get.go
Normal file
75
internal/db/pg/get.go
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ps *postgresService) GetByID(id string, i interface{}) error {
|
||||||
|
if err := ps.conn.Model(i).Where("id = ?", id).Select(); err != nil {
|
||||||
|
if err == pg.ErrNoRows {
|
||||||
|
return db.ErrNoEntries{}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *postgresService) GetWhere(where []db.Where, i interface{}) error {
|
||||||
|
if len(where) == 0 {
|
||||||
|
return errors.New("no queries provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
q := ps.conn.Model(i)
|
||||||
|
for _, w := range where {
|
||||||
|
|
||||||
|
if w.Value == nil {
|
||||||
|
q = q.Where("? IS NULL", pg.Ident(w.Key))
|
||||||
|
} else {
|
||||||
|
if w.CaseInsensitive {
|
||||||
|
q = q.Where("LOWER(?) = LOWER(?)", pg.Safe(w.Key), w.Value)
|
||||||
|
} else {
|
||||||
|
q = q.Where("? = ?", pg.Safe(w.Key), w.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := q.Select(); err != nil {
|
||||||
|
if err == pg.ErrNoRows {
|
||||||
|
return db.ErrNoEntries{}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *postgresService) GetAll(i interface{}) error {
|
||||||
|
if err := ps.conn.Model(i).Select(); err != nil {
|
||||||
|
if err == pg.ErrNoRows {
|
||||||
|
return db.ErrNoEntries{}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,21 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package pg
|
package pg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -197,119 +197,6 @@ func (ps *postgresService) CreateSchema(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *postgresService) GetByID(id string, i interface{}) error {
|
|
||||||
if err := ps.conn.Model(i).Where("id = ?", id).Select(); err != nil {
|
|
||||||
if err == pg.ErrNoRows {
|
|
||||||
return db.ErrNoEntries{}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) GetWhere(where []db.Where, i interface{}) error {
|
|
||||||
if len(where) == 0 {
|
|
||||||
return errors.New("no queries provided")
|
|
||||||
}
|
|
||||||
|
|
||||||
q := ps.conn.Model(i)
|
|
||||||
for _, w := range where {
|
|
||||||
|
|
||||||
if w.Value == nil {
|
|
||||||
q = q.Where("? IS NULL", pg.Ident(w.Key))
|
|
||||||
} else {
|
|
||||||
if w.CaseInsensitive {
|
|
||||||
q = q.Where("LOWER(?) = LOWER(?)", pg.Safe(w.Key), w.Value)
|
|
||||||
} else {
|
|
||||||
q = q.Where("? = ?", pg.Safe(w.Key), w.Value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := q.Select(); err != nil {
|
|
||||||
if err == pg.ErrNoRows {
|
|
||||||
return db.ErrNoEntries{}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) GetAll(i interface{}) error {
|
|
||||||
if err := ps.conn.Model(i).Select(); err != nil {
|
|
||||||
if err == pg.ErrNoRows {
|
|
||||||
return db.ErrNoEntries{}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) Put(i interface{}) error {
|
|
||||||
_, err := ps.conn.Model(i).Insert(i)
|
|
||||||
if err != nil && strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
|
|
||||||
return db.ErrAlreadyExists{}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) Upsert(i interface{}, conflictColumn string) error {
|
|
||||||
if _, err := ps.conn.Model(i).OnConflict(fmt.Sprintf("(%s) DO UPDATE", conflictColumn)).Insert(); err != nil {
|
|
||||||
if err == pg.ErrNoRows {
|
|
||||||
return db.ErrNoEntries{}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) UpdateByID(id string, i interface{}) error {
|
|
||||||
if _, err := ps.conn.Model(i).Where("id = ?", id).OnConflict("(id) DO UPDATE").Insert(); err != nil {
|
|
||||||
if err == pg.ErrNoRows {
|
|
||||||
return db.ErrNoEntries{}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) UpdateOneByID(id string, key string, value interface{}, i interface{}) error {
|
|
||||||
_, err := ps.conn.Model(i).Set("? = ?", pg.Safe(key), value).Where("id = ?", id).Update()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) DeleteByID(id string, i interface{}) error {
|
|
||||||
if _, err := ps.conn.Model(i).Where("id = ?", id).Delete(); err != nil {
|
|
||||||
// if there are no rows *anyway* then that's fine
|
|
||||||
// just return err if there's an actual error
|
|
||||||
if err != pg.ErrNoRows {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ps *postgresService) DeleteWhere(where []db.Where, i interface{}) error {
|
|
||||||
if len(where) == 0 {
|
|
||||||
return errors.New("no queries provided")
|
|
||||||
}
|
|
||||||
|
|
||||||
q := ps.conn.Model(i)
|
|
||||||
for _, w := range where {
|
|
||||||
q = q.Where("? = ?", pg.Safe(w.Key), w.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := q.Delete(); err != nil {
|
|
||||||
// if there are no rows *anyway* then that's fine
|
|
||||||
// just return err if there's an actual error
|
|
||||||
if err != pg.ErrNoRows {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
HANDY SHORTCUTS
|
HANDY SHORTCUTS
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
33
internal/db/pg/put.go
Normal file
33
internal/db/pg/put.go
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ps *postgresService) Put(i interface{}) error {
|
||||||
|
_, err := ps.conn.Model(i).Insert(i)
|
||||||
|
if err != nil && strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
|
||||||
|
return db.ErrAlreadyExists{}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,21 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package pg
|
package pg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
73
internal/db/pg/update.go
Normal file
73
internal/db/pg/update.go
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/go-pg/pg/v10"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ps *postgresService) Upsert(i interface{}, conflictColumn string) error {
|
||||||
|
if _, err := ps.conn.Model(i).OnConflict(fmt.Sprintf("(%s) DO UPDATE", conflictColumn)).Insert(); err != nil {
|
||||||
|
if err == pg.ErrNoRows {
|
||||||
|
return db.ErrNoEntries{}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *postgresService) UpdateByID(id string, i interface{}) error {
|
||||||
|
if _, err := ps.conn.Model(i).Where("id = ?", id).OnConflict("(id) DO UPDATE").Insert(); err != nil {
|
||||||
|
if err == pg.ErrNoRows {
|
||||||
|
return db.ErrNoEntries{}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *postgresService) UpdateOneByID(id string, key string, value interface{}, i interface{}) error {
|
||||||
|
_, err := ps.conn.Model(i).Set("? = ?", pg.Safe(key), value).Where("id = ?", id).Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *postgresService) UpdateWhere(where []db.Where, key string, value interface{}, i interface{}) error {
|
||||||
|
q := ps.conn.Model(i)
|
||||||
|
|
||||||
|
for _, w := range where {
|
||||||
|
if w.Value == nil {
|
||||||
|
q = q.Where("? IS NULL", pg.Ident(w.Key))
|
||||||
|
} else {
|
||||||
|
if w.CaseInsensitive {
|
||||||
|
q = q.Where("LOWER(?) = LOWER(?)", pg.Safe(w.Key), w.Value)
|
||||||
|
} else {
|
||||||
|
q = q.Where("? = ?", pg.Safe(w.Key), w.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
q = q.Set("? = ?", pg.Safe(key), value)
|
||||||
|
|
||||||
|
_, err := q.Update()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
@ -115,7 +115,7 @@ type Account struct {
|
||||||
CRYPTO FIELDS
|
CRYPTO FIELDS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Privatekey for validating activitypub requests, will obviously only be defined for local accounts
|
// Privatekey for validating activitypub requests, will only be defined for local accounts
|
||||||
PrivateKey *rsa.PrivateKey
|
PrivateKey *rsa.PrivateKey
|
||||||
// Publickey for encoding activitypub requests, will be defined for both local and remote accounts
|
// Publickey for encoding activitypub requests, will be defined for both local and remote accounts
|
||||||
PublicKey *rsa.PublicKey
|
PublicKey *rsa.PublicKey
|
||||||
|
|
@ -134,8 +134,8 @@ type Account struct {
|
||||||
SuspendedAt time.Time `pg:"type:timestamp"`
|
SuspendedAt time.Time `pg:"type:timestamp"`
|
||||||
// Should we hide this account's collections?
|
// Should we hide this account's collections?
|
||||||
HideCollections bool
|
HideCollections bool
|
||||||
// id of the user that suspended this account through an admin action
|
// id of the database entry that caused this account to become suspended -- can be an account ID or a domain block ID
|
||||||
SuspensionOrigin string
|
SuspensionOrigin string `pg:"type:CHAR(26)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field represents a key value field on an account, for things like pronouns, website, etc.
|
// Field represents a key value field on an account, for things like pronouns, website, etc.
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@ type Processor interface {
|
||||||
// Create processes the given form for creating a new account, returning an oauth token for that account if successful.
|
// Create processes the given form for creating a new account, returning an oauth token for that account if successful.
|
||||||
Create(applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, error)
|
Create(applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, error)
|
||||||
// Delete deletes an account, and all of that account's statuses, media, follows, notifications, etc etc etc.
|
// Delete deletes an account, and all of that account's statuses, media, follows, notifications, etc etc etc.
|
||||||
Delete(account *gtsmodel.Account, deletedBy string) error
|
// The origin passed here should be either the ID of the account doing the delete (can be itself), or the ID of a domain block.
|
||||||
|
Delete(account *gtsmodel.Account, origin string) error
|
||||||
// Get processes the given request for account information.
|
// Get processes the given request for account information.
|
||||||
Get(requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, error)
|
Get(requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, error)
|
||||||
// Update processes the update of an account with the given form
|
// Update processes the update of an account with the given form
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ import (
|
||||||
// 16. Delete account's user
|
// 16. Delete account's user
|
||||||
// 17. Delete account's timeline
|
// 17. Delete account's timeline
|
||||||
// 18. Delete account itself
|
// 18. Delete account itself
|
||||||
func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
func (p *processor) Delete(account *gtsmodel.Account, origin string) error {
|
||||||
l := p.log.WithFields(logrus.Fields{
|
l := p.log.WithFields(logrus.Fields{
|
||||||
"func": "Delete",
|
"func": "Delete",
|
||||||
"username": account.Username,
|
"username": account.Username,
|
||||||
|
|
@ -100,6 +100,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
|
|
||||||
// 4. Delete account's follow requests
|
// 4. Delete account's follow requests
|
||||||
|
// TODO: federate these if necessary
|
||||||
l.Debug("deleting account follow requests")
|
l.Debug("deleting account follow requests")
|
||||||
// first delete any follow requests that this account created
|
// first delete any follow requests that this account created
|
||||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.FollowRequest{}); err != nil {
|
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.FollowRequest{}); err != nil {
|
||||||
|
|
@ -112,6 +113,7 @@ func (p *processor) Delete(account *gtsmodel.Account, deletedBy string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Delete account's follows
|
// 5. Delete account's follows
|
||||||
|
// TODO: federate these if necessary
|
||||||
l.Debug("deleting account follows")
|
l.Debug("deleting account follows")
|
||||||
// first delete any follows that this account created
|
// first delete any follows that this account created
|
||||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.Follow{}); err != nil {
|
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.Follow{}); err != nil {
|
||||||
|
|
@ -217,6 +219,7 @@ selectStatusesLoop:
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12. Delete account's faves
|
// 12. Delete account's faves
|
||||||
|
// TODO: federate these if necessary
|
||||||
l.Debug("deleting account faves")
|
l.Debug("deleting account faves")
|
||||||
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.StatusFave{}); err != nil {
|
if err := p.db.DeleteWhere([]db.Where{{Key: "account_id", Value: account.ID}}, &[]*gtsmodel.StatusFave{}); err != nil {
|
||||||
l.Errorf("error deleting faves created by account: %s", err)
|
l.Errorf("error deleting faves created by account: %s", err)
|
||||||
|
|
@ -229,6 +232,7 @@ selectStatusesLoop:
|
||||||
}
|
}
|
||||||
|
|
||||||
// 14. Delete account's streams
|
// 14. Delete account's streams
|
||||||
|
// TODO
|
||||||
|
|
||||||
// 15. Delete account's tags
|
// 15. Delete account's tags
|
||||||
// TODO
|
// TODO
|
||||||
|
|
@ -240,6 +244,7 @@ selectStatusesLoop:
|
||||||
}
|
}
|
||||||
|
|
||||||
// 17. Delete account's timeline
|
// 17. Delete account's timeline
|
||||||
|
// TODO
|
||||||
|
|
||||||
// 18. Delete account itself
|
// 18. Delete account itself
|
||||||
// to prevent the account being created again, set all these fields and update it in the db
|
// to prevent the account being created again, set all these fields and update it in the db
|
||||||
|
|
@ -259,7 +264,7 @@ selectStatusesLoop:
|
||||||
account.UpdatedAt = time.Now()
|
account.UpdatedAt = time.Now()
|
||||||
|
|
||||||
account.SuspendedAt = time.Now()
|
account.SuspendedAt = time.Now()
|
||||||
account.SuspensionOrigin = deletedBy
|
account.SuspensionOrigin = origin
|
||||||
|
|
||||||
if err := p.db.UpdateByID(account.ID, account); err != nil {
|
if err := p.db.UpdateByID(account.ID, account); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func (p *processor) AdminDomainBlockCreate(authed *oauth.Auth, form *apimodel.Do
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) AdminDomainBlocksImport(authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) ([]*apimodel.DomainBlock, gtserror.WithCode) {
|
func (p *processor) AdminDomainBlocksImport(authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) ([]*apimodel.DomainBlock, gtserror.WithCode) {
|
||||||
return p.adminProcessor.DomainBlocksImport(authed.Account, form.Domains)
|
return p.adminProcessor.DomainBlocksImport(authed.Account, form.Domains)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) AdminDomainBlocksGet(authed *oauth.Auth, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode) {
|
func (p *processor) AdminDomainBlocksGet(authed *oauth.Auth, export bool) ([]*apimodel.DomainBlock, gtserror.WithCode) {
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ func (p *processor) DomainBlockCreate(account *gtsmodel.Account, domain string,
|
||||||
PrivateComment: privateComment,
|
PrivateComment: privateComment,
|
||||||
PublicComment: publicComment,
|
PublicComment: publicComment,
|
||||||
Obfuscate: obfuscate,
|
Obfuscate: obfuscate,
|
||||||
|
SubscriptionID: subscriptionID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// put the new block in the database
|
// put the new block in the database
|
||||||
|
|
@ -140,7 +141,7 @@ selectAccountsLoop:
|
||||||
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
p.fromClientAPI <- gtsmodel.FromClientAPI{
|
||||||
APObjectType: gtsmodel.ActivityStreamsPerson,
|
APObjectType: gtsmodel.ActivityStreamsPerson,
|
||||||
APActivityType: gtsmodel.ActivityStreamsDelete,
|
APActivityType: gtsmodel.ActivityStreamsDelete,
|
||||||
GTSModel: a,
|
GTSModel: block,
|
||||||
OriginAccount: account,
|
OriginAccount: account,
|
||||||
TargetAccount: a,
|
TargetAccount: a,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,5 +64,20 @@ func (p *processor) DomainBlockDelete(account *gtsmodel.Account, id string) (*ap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unsuspend all accounts whose suspension origin was this domain block
|
||||||
|
// 1. remove the 'suspended_at' entry from their accounts
|
||||||
|
if err := p.db.UpdateWhere([]db.Where{
|
||||||
|
{Key: "suspension_origin", Value: domainBlock.ID},
|
||||||
|
}, "suspended_at", nil, &[]*gtsmodel.Account{}); err != nil {
|
||||||
|
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error removing suspended_at from accounts: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. remove the 'suspension_origin' entry from their accounts
|
||||||
|
if err := p.db.UpdateWhere([]db.Where{
|
||||||
|
{Key: "suspension_origin", Value: domainBlock.ID},
|
||||||
|
}, "suspension_origin", nil, &[]*gtsmodel.Account{}); err != nil {
|
||||||
|
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error removing suspension_origin from accounts: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
return mastoDomainBlock, nil
|
return mastoDomainBlock, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,17 +193,17 @@ func (p *processor) processFromClientAPI(clientMsg gtsmodel.FromClientAPI) error
|
||||||
return p.federateStatusDelete(statusToDelete)
|
return p.federateStatusDelete(statusToDelete)
|
||||||
case gtsmodel.ActivityStreamsProfile, gtsmodel.ActivityStreamsPerson:
|
case gtsmodel.ActivityStreamsProfile, gtsmodel.ActivityStreamsPerson:
|
||||||
// DELETE ACCOUNT/PROFILE
|
// DELETE ACCOUNT/PROFILE
|
||||||
accountToDelete, ok := clientMsg.GTSModel.(*gtsmodel.Account)
|
|
||||||
if !ok {
|
|
||||||
return errors.New("account was not parseable as *gtsmodel.Account")
|
|
||||||
}
|
|
||||||
|
|
||||||
var deletedBy string
|
// the origin of the delete could be either a domain block, or an action by another (or this) account
|
||||||
if clientMsg.OriginAccount != nil {
|
var origin string
|
||||||
deletedBy = clientMsg.OriginAccount.ID
|
if domainBlock, ok := clientMsg.GTSModel.(*gtsmodel.DomainBlock); ok {
|
||||||
|
// origin is a domain block
|
||||||
|
origin = domainBlock.ID
|
||||||
|
} else {
|
||||||
|
// origin is whichever account caused this message
|
||||||
|
origin = clientMsg.OriginAccount.ID
|
||||||
}
|
}
|
||||||
|
return p.accountProcessor.Delete(clientMsg.TargetAccount, origin)
|
||||||
return p.accountProcessor.Delete(accountToDelete, deletedBy)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue