fixed typos and some linter suggestions
This commit is contained in:
parent
80d65a198b
commit
aabe820e35
|
@ -16,6 +16,10 @@
|
||||||
|
|
||||||
- Added `TestMailer.SentMessages` field that holds all sent test app emails until cleanup.
|
- Added `TestMailer.SentMessages` field that holds all sent test app emails until cleanup.
|
||||||
|
|
||||||
|
- Optimized the cascade delete of records with multiple `relation`.
|
||||||
|
|
||||||
|
- Fixed the `admin` command error reporting.
|
||||||
|
|
||||||
- Minor Admin UI improvements (reduced the min table row height, added option to duplicate fields, added new TinyMCE codesample plugin languages, hide the collection sync settings when the `Settings.Meta.HideControls` is enabled, etc.)
|
- Minor Admin UI improvements (reduced the min table row height, added option to duplicate fields, added new TinyMCE codesample plugin languages, hide the collection sync settings when the `Settings.Meta.HideControls` is enabled, etc.)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ func InitApi(app core.App) (*echo.Echo, error) {
|
||||||
logRequest(app, c, apiErr)
|
logRequest(app, c, apiErr)
|
||||||
|
|
||||||
if c.Response().Committed {
|
if c.Response().Committed {
|
||||||
return // already commited
|
return // already committed
|
||||||
}
|
}
|
||||||
|
|
||||||
event := new(core.ApiErrorEvent)
|
event := new(core.ApiErrorEvent)
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (api *recordAuthApi) authMethods(c echo.Context) error {
|
||||||
|
|
||||||
provider, err := auth.NewProviderByName(name)
|
provider, err := auth.NewProviderByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.app.Logger().Debug("Missing or invalid provier name", slog.String("name", name))
|
api.app.Logger().Debug("Missing or invalid provider name", slog.String("name", name))
|
||||||
continue // skip provider
|
continue // skip provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ func RecordAuthResponse(
|
||||||
// EnrichRecord parses the request context and enrich the provided record:
|
// EnrichRecord parses the request context and enrich the provided record:
|
||||||
// - expands relations (if defaultExpands and/or ?expand query param is set)
|
// - expands relations (if defaultExpands and/or ?expand query param is set)
|
||||||
// - ensures that the emails of the auth record and its expanded auth relations
|
// - ensures that the emails of the auth record and its expanded auth relations
|
||||||
// are visibe only for the current logged admin, record owner or record with manage access
|
// are visible only for the current logged admin, record owner or record with manage access
|
||||||
func EnrichRecord(c echo.Context, dao *daos.Dao, record *models.Record, defaultExpands ...string) error {
|
func EnrichRecord(c echo.Context, dao *daos.Dao, record *models.Record, defaultExpands ...string) error {
|
||||||
return EnrichRecords(c, dao, []*models.Record{record}, defaultExpands...)
|
return EnrichRecords(c, dao, []*models.Record{record}, defaultExpands...)
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func EnrichRecord(c echo.Context, dao *daos.Dao, record *models.Record, defaultE
|
||||||
// EnrichRecords parses the request context and enriches the provided records:
|
// EnrichRecords parses the request context and enriches the provided records:
|
||||||
// - expands relations (if defaultExpands and/or ?expand query param is set)
|
// - expands relations (if defaultExpands and/or ?expand query param is set)
|
||||||
// - ensures that the emails of the auth records and their expanded auth relations
|
// - ensures that the emails of the auth records and their expanded auth relations
|
||||||
// are visibe only for the current logged admin, record owner or record with manage access
|
// are visible only for the current logged admin, record owner or record with manage access
|
||||||
func EnrichRecords(c echo.Context, dao *daos.Dao, records []*models.Record, defaultExpands ...string) error {
|
func EnrichRecords(c echo.Context, dao *daos.Dao, records []*models.Record, defaultExpands ...string) error {
|
||||||
requestInfo := RequestInfo(c)
|
requestInfo := RequestInfo(c)
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,10 @@ func adminDeleteCommand(app core.App) *cobra.Command {
|
||||||
return errors.New("Invalid or missing email address.")
|
return errors.New("Invalid or missing email address.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !app.Dao().HasTable((&models.Admin{}).TableName()) {
|
||||||
|
return errors.New("Migration are not initialized yet. Please run 'migrate up' and try again.")
|
||||||
|
}
|
||||||
|
|
||||||
admin, err := app.Dao().FindAdminByEmail(args[0])
|
admin, err := app.Dao().FindAdminByEmail(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Yellow("Admin %s is already deleted.", args[0])
|
color.Yellow("Admin %s is already deleted.", args[0])
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
|
||||||
CertificateDomains: args,
|
CertificateDomains: args,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != http.ErrServerClosed {
|
if !errors.Is(err, http.ErrServerClosed) {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
18
daos/base.go
18
daos/base.go
|
@ -18,7 +18,7 @@ func New(db dbx.Builder) *Dao {
|
||||||
return NewMultiDB(db, db)
|
return NewMultiDB(db, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Dao instance with the provided dedicated
|
// NewMultiDB creates a new Dao instance with the provided dedicated
|
||||||
// async and sync db builders.
|
// async and sync db builders.
|
||||||
func NewMultiDB(concurrentDB, nonconcurrentDB dbx.Builder) *Dao {
|
func NewMultiDB(concurrentDB, nonconcurrentDB dbx.Builder) *Dao {
|
||||||
return &Dao{
|
return &Dao{
|
||||||
|
@ -87,16 +87,16 @@ func (dao *Dao) Clone() *Dao {
|
||||||
// WithoutHooks returns a new Dao with the same configuration options
|
// WithoutHooks returns a new Dao with the same configuration options
|
||||||
// as the current one, but without create/update/delete hooks.
|
// as the current one, but without create/update/delete hooks.
|
||||||
func (dao *Dao) WithoutHooks() *Dao {
|
func (dao *Dao) WithoutHooks() *Dao {
|
||||||
new := dao.Clone()
|
clone := dao.Clone()
|
||||||
|
|
||||||
new.BeforeCreateFunc = nil
|
clone.BeforeCreateFunc = nil
|
||||||
new.AfterCreateFunc = nil
|
clone.AfterCreateFunc = nil
|
||||||
new.BeforeUpdateFunc = nil
|
clone.BeforeUpdateFunc = nil
|
||||||
new.AfterUpdateFunc = nil
|
clone.AfterUpdateFunc = nil
|
||||||
new.BeforeDeleteFunc = nil
|
clone.BeforeDeleteFunc = nil
|
||||||
new.AfterDeleteFunc = nil
|
clone.AfterDeleteFunc = nil
|
||||||
|
|
||||||
return new
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModelQuery creates a new preconfigured select query with preset
|
// ModelQuery creates a new preconfigured select query with preset
|
||||||
|
|
|
@ -162,8 +162,8 @@ func (dao *Dao) DeleteCollection(collection *models.Collection) error {
|
||||||
// SaveCollection persists the provided Collection model and updates
|
// SaveCollection persists the provided Collection model and updates
|
||||||
// its related records table schema.
|
// its related records table schema.
|
||||||
//
|
//
|
||||||
// If collecction.IsNew() is true, the method will perform a create, otherwise an update.
|
// If collection.IsNew() is true, the method will perform a create, otherwise an update.
|
||||||
// To explicitly mark a collection for update you can use collecction.MarkAsNotNew().
|
// To explicitly mark a collection for update you can use collection.MarkAsNotNew().
|
||||||
func (dao *Dao) SaveCollection(collection *models.Collection) error {
|
func (dao *Dao) SaveCollection(collection *models.Collection) error {
|
||||||
var oldCollection *models.Collection
|
var oldCollection *models.Collection
|
||||||
|
|
||||||
|
@ -263,11 +263,11 @@ func (dao *Dao) ImportCollections(
|
||||||
|
|
||||||
// extend existing schema
|
// extend existing schema
|
||||||
if !deleteMissing {
|
if !deleteMissing {
|
||||||
schema, _ := existing.Schema.Clone()
|
schemaClone, _ := existing.Schema.Clone()
|
||||||
for _, f := range imported.Schema.Fields() {
|
for _, f := range imported.Schema.Fields() {
|
||||||
schema.AddField(f) // add or replace
|
schemaClone.AddField(f) // add or replace
|
||||||
}
|
}
|
||||||
imported.Schema = *schema
|
imported.Schema = *schemaClone
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
imported.MarkAsNew()
|
imported.MarkAsNew()
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (form *RecordPasswordResetRequest) SetDao(dao *daos.Dao) {
|
||||||
|
|
||||||
// Validate makes the form validatable by implementing [validation.Validatable] interface.
|
// Validate makes the form validatable by implementing [validation.Validatable] interface.
|
||||||
//
|
//
|
||||||
// This method doesn't checks whether auth record with `form.Email` exists (this is done on Submit).
|
// This method doesn't check whether auth record with `form.Email` exists (this is done on Submit).
|
||||||
func (form *RecordPasswordResetRequest) Validate() error {
|
func (form *RecordPasswordResetRequest) Validate() error {
|
||||||
return validation.ValidateStruct(form,
|
return validation.ValidateStruct(form,
|
||||||
validation.Field(
|
validation.Field(
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/pocketbase/pocketbase/daos"
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Compare checks whether the provided model id exists.
|
// UniqueId checks whether the provided model id already exists.
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
|
|
|
@ -92,7 +92,7 @@ func SendRecordVerification(app core.App, authRecord *models.Record) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendUserChangeEmail sends a change email confirmation email to the specified user.
|
// SendRecordChangeEmail sends a change email confirmation email to the specified user.
|
||||||
func SendRecordChangeEmail(app core.App, record *models.Record, newEmail string) error {
|
func SendRecordChangeEmail(app core.App, record *models.Record, newEmail string) error {
|
||||||
token, tokenErr := tokens.NewRecordChangeEmailToken(app, record, newEmail)
|
token, tokenErr := tokens.NewRecordChangeEmailToken(app, record, newEmail)
|
||||||
if tokenErr != nil {
|
if tokenErr != nil {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,17 +16,17 @@ type TestMailer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset clears any previously test collected data.
|
// Reset clears any previously test collected data.
|
||||||
func (m *TestMailer) Reset() {
|
func (tm *TestMailer) Reset() {
|
||||||
m.TotalSend = 0
|
tm.TotalSend = 0
|
||||||
m.LastMessage = mailer.Message{}
|
tm.LastMessage = mailer.Message{}
|
||||||
m.SentMessages = nil
|
tm.SentMessages = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send implements `mailer.Mailer` interface.
|
// Send implements `mailer.Mailer` interface.
|
||||||
func (c *TestMailer) Send(m *mailer.Message) error {
|
func (tm *TestMailer) Send(m *mailer.Message) error {
|
||||||
c.TotalSend++
|
tm.TotalSend++
|
||||||
c.LastMessage = *m
|
tm.LastMessage = *m
|
||||||
c.SentMessages = append(c.SentMessages, c.LastMessage)
|
tm.SentMessages = append(tm.SentMessages, tm.LastMessage)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type AuthUser struct {
|
||||||
|
|
||||||
// Provider defines a common interface for an OAuth2 client.
|
// Provider defines a common interface for an OAuth2 client.
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
// Scopes returns the context associated with the provider (if any).
|
// Context returns the context associated with the provider (if any).
|
||||||
Context() context.Context
|
Context() context.Context
|
||||||
|
|
||||||
// SetContext assigns the specified context to the current provider.
|
// SetContext assigns the specified context to the current provider.
|
||||||
|
|
|
@ -26,7 +26,7 @@ type FileReader interface {
|
||||||
|
|
||||||
// File defines a single file [io.ReadSeekCloser] resource.
|
// File defines a single file [io.ReadSeekCloser] resource.
|
||||||
//
|
//
|
||||||
// The file could be from a local path, multipipart/formdata header, etc.
|
// The file could be from a local path, multipart/form-data header, etc.
|
||||||
type File struct {
|
type File struct {
|
||||||
Reader FileReader
|
Reader FileReader
|
||||||
Name string
|
Name string
|
||||||
|
|
|
@ -635,7 +635,7 @@ func multiMatchAfterBuildFunc(op fexpr.SignOp, multiMatchAliases ...string) func
|
||||||
// Add an optional "IS NULL" condition(s) to handle the empty rows result.
|
// Add an optional "IS NULL" condition(s) to handle the empty rows result.
|
||||||
//
|
//
|
||||||
// For example, let's assume that some "rel" field is [nonemptyRel1, nonemptyRel2, emptyRel3],
|
// For example, let's assume that some "rel" field is [nonemptyRel1, nonemptyRel2, emptyRel3],
|
||||||
// The filter "rel.total > 0" will ensures that the above will return true only if all relations
|
// The filter "rel.total > 0" ensures that the above will return true only if all relations
|
||||||
// are existing and match the condition.
|
// are existing and match the condition.
|
||||||
//
|
//
|
||||||
// The "=" operator is excluded because it will never equal directly with NULL anyway
|
// The "=" operator is excluded because it will never equal directly with NULL anyway
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (s *Provider) SkipTotal(skipTotal bool) *Provider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountCol allows changing the default column (id) that is used
|
// CountCol allows changing the default column (id) that is used
|
||||||
// to generated the COUNT SQL query statement.
|
// to generate the COUNT SQL query statement.
|
||||||
//
|
//
|
||||||
// This field is ignored if skipTotal is true.
|
// This field is ignored if skipTotal is true.
|
||||||
func (s *Provider) CountCol(name string) *Provider {
|
func (s *Provider) CountCol(name string) *Provider {
|
||||||
|
|
Loading…
Reference in New Issue