Skip to content

Commit

Permalink
moving stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst committed Sep 1, 2021
1 parent 684bd56 commit 4696e1a
Show file tree
Hide file tree
Showing 93 changed files with 878 additions and 1,750 deletions.
12 changes: 6 additions & 6 deletions internal/api/client/account/accountcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/validate"
)

// AccountCreatePOSTHandler swagger:operation POST /api/v1/accounts accountCreate
Expand Down Expand Up @@ -118,27 +118,27 @@ func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsC
return errors.New("registration is not open for this server")
}

if err := util.ValidateUsername(form.Username); err != nil {
if err := validate.Username(form.Username); err != nil {
return err
}

if err := util.ValidateEmail(form.Email); err != nil {
if err := validate.Email(form.Email); err != nil {
return err
}

if err := util.ValidateNewPassword(form.Password); err != nil {
if err := validate.NewPassword(form.Password); err != nil {
return err
}

if !form.Agreement {
return errors.New("agreement to terms and conditions not given")
}

if err := util.ValidateLanguage(form.Locale); err != nil {
if err := validate.Language(form.Locale); err != nil {
return err
}

if err := util.ValidateSignUpReason(form.Reason, c.ReasonRequired); err != nil {
if err := validate.SignUpReason(form.Reason, c.ReasonRequired); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/api/client/admin/emojicreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/validate"
)

// emojiCreateRequest swagger:operation POST /api/v1/admin/custom_emojis emojiCreate
Expand Down Expand Up @@ -132,5 +132,5 @@ func validateCreateEmoji(form *model.EmojiCreateRequest) error {
return fmt.Errorf("file size limit exceeded: limit is %d bytes but emoji was %d bytes", media.EmojiMaxBytes, form.Image.Size)
}

return util.ValidateEmojiShortcode(form.Shortcode)
return validate.EmojiShortcode(form.Shortcode)
}
1 change: 0 additions & 1 deletion internal/api/client/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (suite *AuthTestSuite) SetupSuite() {
ClientID: "a-known-client-id",
ClientSecret: "some-secret",
Scopes: "read",
VapidKey: uuid.NewString(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/api/client/auth/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oidc"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/validate"
)

// CallbackGETHandler parses a token from an external auth provider.
Expand Down Expand Up @@ -153,7 +153,7 @@ func (m *Module) parseUserFromClaims(ctx context.Context, claims *oidc.Claims, i
}

// check if we can just use claims.Name as-is
err = util.ValidateUsername(claims.Name)
err = validate.Username(claims.Name)
if err == nil {
// the name we have on the claims is already a valid username
username = claims.Name
Expand All @@ -166,7 +166,7 @@ func (m *Module) parseUserFromClaims(ctx context.Context, claims *oidc.Claims, i
// lowercase the whole thing
lower := strings.ToLower(underscored)
// see if this is valid....
if err := util.ValidateUsername(lower); err == nil {
if err := validate.Username(lower); err == nil {
// we managed to get a valid username
username = lower
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/api/client/status/statuscreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/validate"
)

// StatusCreatePOSTHandler swagger:operation POST /api/v1/statuses statusCreate
Expand Down Expand Up @@ -157,7 +157,7 @@ func validateCreateStatus(form *model.AdvancedStatusCreateForm, config *config.S

// validate post language
if form.Language != "" {
if err := util.ValidateLanguage(form.Language); err != nil {
if err := validate.Language(form.Language); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/api/client/streaming/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ func (m *Module) StreamGETHandler(c *gin.Context) {
}
defer conn.Close() // whatever happens, when we leave this function we want to close the websocket connection

// inform the processor that we have a new connection and want a stream for it
stream, errWithCode := m.processor.OpenStreamForAccount(c.Request.Context(), account, streamType)
// inform the processor that we have a new connection and want a s for it
s, errWithCode := m.processor.OpenStreamForAccount(c.Request.Context(), account, streamType)
if errWithCode != nil {
c.JSON(errWithCode.Code(), errWithCode.Safe())
return
}
defer close(stream.Hangup) // closing stream.Hangup indicates that we've finished with the connection (the client has gone), so we want to do this on exiting this handler
defer close(s.Hangup) // closing stream.Hangup indicates that we've finished with the connection (the client has gone), so we want to do this on exiting this handler

// spawn a new ticker for pinging the connection periodically
t := time.NewTicker(30 * time.Second)
Expand All @@ -161,7 +161,7 @@ func (m *Module) StreamGETHandler(c *gin.Context) {
sendLoop:
for {
select {
case m := <-stream.Messages:
case m := <-s.Messages:
// we've got a streaming message!!
l.Trace("received message from stream")
if err := conn.WriteJSON(m); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions internal/cliactions/admin/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/internal/validate"
"golang.org/x/crypto/bcrypt"
)

Expand All @@ -45,23 +45,23 @@ var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo
if !ok {
return errors.New("no username set")
}
if err := util.ValidateUsername(username); err != nil {
if err := validate.Username(username); err != nil {
return err
}

email, ok := c.AccountCLIFlags[config.EmailFlag]
if !ok {
return errors.New("no email set")
}
if err := util.ValidateEmail(email); err != nil {
if err := validate.Email(email); err != nil {
return err
}

password, ok := c.AccountCLIFlags[config.PasswordFlag]
if !ok {
return errors.New("no password set")
}
if err := util.ValidateNewPassword(password); err != nil {
if err := validate.NewPassword(password); err != nil {
return err
}

Expand All @@ -84,7 +84,7 @@ var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
if !ok {
return errors.New("no username set")
}
if err := util.ValidateUsername(username); err != nil {
if err := validate.Username(username); err != nil {
return err
}

Expand Down Expand Up @@ -119,7 +119,7 @@ var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
if !ok {
return errors.New("no username set")
}
if err := util.ValidateUsername(username); err != nil {
if err := validate.Username(username); err != nil {
return err
}

Expand Down Expand Up @@ -151,7 +151,7 @@ var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo
if !ok {
return errors.New("no username set")
}
if err := util.ValidateUsername(username); err != nil {
if err := validate.Username(username); err != nil {
return err
}

Expand Down Expand Up @@ -183,7 +183,7 @@ var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
if !ok {
return errors.New("no username set")
}
if err := util.ValidateUsername(username); err != nil {
if err := validate.Username(username); err != nil {
return err
}

Expand Down Expand Up @@ -221,15 +221,15 @@ var Password cliactions.GTSAction = func(ctx context.Context, c *config.Config,
if !ok {
return errors.New("no username set")
}
if err := util.ValidateUsername(username); err != nil {
if err := validate.Username(username); err != nil {
return err
}

password, ok := c.AccountCLIFlags[config.PasswordFlag]
if !ok {
return errors.New("no password set")
}
if err := util.ValidateNewPassword(password); err != nil {
if err := validate.NewPassword(password); err != nil {
return err
}

Expand Down
3 changes: 3 additions & 0 deletions internal/db/bundb/bundb.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func doMigration(ctx context.Context, db *bun.DB, log *logrus.Logger) error {

group, err := migrator.Migrate(ctx)
if err != nil {
if err.Error() == "migrate: there are no any migrations" {
return nil
}
return err
}

Expand Down
83 changes: 0 additions & 83 deletions internal/db/bundb/migrations/20210816411877_struct_validation.go

This file was deleted.

Loading

0 comments on commit 4696e1a

Please sign in to comment.