mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
use base context to handle the cases where the user IP address is unavailable
This commit is contained in:
@@ -383,7 +383,7 @@ func (c *DataTableTransactionDataImporter) ParseImportedData(ctx core.Context, u
|
|||||||
Comment: description,
|
Comment: description,
|
||||||
GeoLongitude: geoLongitude,
|
GeoLongitude: geoLongitude,
|
||||||
GeoLatitude: geoLatitude,
|
GeoLatitude: geoLatitude,
|
||||||
CreatedIp: "127.0.0.1",
|
CreatedIp: ctx.ClientIP(),
|
||||||
},
|
},
|
||||||
TagIds: tagIds,
|
TagIds: tagIds,
|
||||||
OriginalCategoryName: subCategoryName,
|
OriginalCategoryName: subCategoryName,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import "context"
|
|||||||
// Context is the base context of ezBookkeeping
|
// Context is the base context of ezBookkeeping
|
||||||
type Context interface {
|
type Context interface {
|
||||||
context.Context
|
context.Context
|
||||||
|
ClientIP() string
|
||||||
GetContextId() string
|
GetContextId() string
|
||||||
GetClientLocale() string
|
GetClientLocale() string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ type CliContext struct {
|
|||||||
command *cli.Command
|
command *cli.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientIP returns the client IP address, for CLI context, it always returns the loopback address
|
||||||
|
func (c *CliContext) ClientIP() string {
|
||||||
|
return "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
// GetContextId returns the current context id
|
// GetContextId returns the current context id
|
||||||
func (c *CliContext) GetContextId() string {
|
func (c *CliContext) GetContextId() string {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ type CronContext struct {
|
|||||||
cronJobInterval time.Duration
|
cronJobInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientIP returns the client IP address, for cron job context, it always returns the loopback address
|
||||||
|
func (c *CronContext) ClientIP() string {
|
||||||
|
return "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
// GetContextId returns the current context id
|
// GetContextId returns the current context id
|
||||||
func (c *CronContext) GetContextId() string {
|
func (c *CronContext) GetContextId() string {
|
||||||
return c.contextId
|
return c.contextId
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ type NullContext struct {
|
|||||||
context.Context
|
context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientIP returns the client IP address, for null context, it always returns the loopback address
|
||||||
|
func (c *NullContext) ClientIP() string {
|
||||||
|
return "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
// GetContextId returns the current context id
|
// GetContextId returns the current context id
|
||||||
func (c *NullContext) GetContextId() string {
|
func (c *NullContext) GetContextId() string {
|
||||||
return nullContextId
|
return nullContextId
|
||||||
|
|||||||
@@ -778,7 +778,7 @@ func (s *TransactionService) CreateScheduledTransactions(c core.Context, current
|
|||||||
Amount: template.Amount,
|
Amount: template.Amount,
|
||||||
HideAmount: template.HideAmount,
|
HideAmount: template.HideAmount,
|
||||||
Comment: template.Comment,
|
Comment: template.Comment,
|
||||||
CreatedIp: "127.0.0.1",
|
CreatedIp: c.ClientIP(),
|
||||||
ScheduledCreated: true,
|
ScheduledCreated: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user