коммит произвёл
GitHub
родитель
98d72e51fe
Коммит
0118db9d23
@@ -88,3 +88,17 @@ func NewErrNotFound(resource, id string) *ErrNotFound {
|
||||
func (e *ErrNotFound) Error() string {
|
||||
return "resource: " + e.resource + " id: " + e.Id
|
||||
}
|
||||
|
||||
// ErrOutOfBounds indicates that the requested total numbers of rows
|
||||
// was greater than the allowed limit.
|
||||
type ErrOutOfBounds struct {
|
||||
value int
|
||||
}
|
||||
|
||||
func (e *ErrOutOfBounds) Error() string {
|
||||
return fmt.Sprintf("invalid limit parameter: %d", e.value)
|
||||
}
|
||||
|
||||
func NewErrOutOfBounds(value int) *ErrOutOfBounds {
|
||||
return &ErrOutOfBounds{value: value}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ type OpenTracingLayerWebhookStore struct {
|
||||
Root *OpenTracingLayer
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerAuditStore) Get(user_id string, offset int, limit int) (model.Audits, *model.AppError) {
|
||||
func (s *OpenTracingLayerAuditStore) Get(user_id string, offset int, limit int) (model.Audits, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "AuditStore.Get")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -347,7 +347,7 @@ func (s *OpenTracingLayerAuditStore) Get(user_id string, offset int, limit int)
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerAuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (s *OpenTracingLayerAuditStore) PermanentDeleteByUser(userId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "AuditStore.PermanentDeleteByUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -365,7 +365,7 @@ func (s *OpenTracingLayerAuditStore) PermanentDeleteByUser(userId string) *model
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerAuditStore) Save(audit *model.Audit) *model.AppError {
|
||||
func (s *OpenTracingLayerAuditStore) Save(audit *model.Audit) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "AuditStore.Save")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
@@ -36,19 +35,19 @@ func (s SqlAuditStore) createIndexesIfNotExists() {
|
||||
s.CreateIndexIfNotExists("idx_audits_user_id", "Audits", "UserId")
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) Save(audit *model.Audit) *model.AppError {
|
||||
func (s SqlAuditStore) Save(audit *model.Audit) error {
|
||||
audit.Id = model.NewId()
|
||||
audit.CreateAt = model.GetMillis()
|
||||
|
||||
if err := s.GetMaster().Insert(audit); err != nil {
|
||||
return model.NewAppError("SqlAuditStore.Save", "store.sql_audit.save.saving.app_error", nil, "user_id="+audit.UserId+" action="+audit.Action, http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to save Audit with userId=%s and action=%s", audit.UserId, audit.Action)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) Get(user_id string, offset int, limit int) (model.Audits, *model.AppError) {
|
||||
func (s SqlAuditStore) Get(userId string, offset int, limit int) (model.Audits, error) {
|
||||
if limit > 1000 {
|
||||
return nil, model.NewAppError("SqlAuditStore.Get", "store.sql_audit.get.limit.app_error", nil, "user_id="+user_id, http.StatusBadRequest)
|
||||
return nil, store.NewErrOutOfBounds(limit)
|
||||
}
|
||||
|
||||
query := s.getQueryBuilder().
|
||||
@@ -58,26 +57,26 @@ func (s SqlAuditStore) Get(user_id string, offset int, limit int) (model.Audits,
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset))
|
||||
|
||||
if len(user_id) != 0 {
|
||||
query = query.Where(sq.Eq{"UserId": user_id})
|
||||
if len(userId) != 0 {
|
||||
query = query.Where(sq.Eq{"UserId": userId})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlAuditStore.Get", "store.sql_audit.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrap(err, "audits_tosql")
|
||||
}
|
||||
|
||||
var audits model.Audits
|
||||
if _, err := s.GetReplica().Select(&audits, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlAuditStore.Get", "store.sql_audit.get.finding.app_error", nil, "user_id="+user_id, http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "failed to get Audit list for userId=%s", userId)
|
||||
}
|
||||
return audits, nil
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (s SqlAuditStore) PermanentDeleteByUser(userId string) error {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Audits WHERE UserId = :userId",
|
||||
map[string]interface{}{"userId": userId}); err != nil {
|
||||
return model.NewAppError("SqlAuditStore.Delete", "store.sql_audit.permanent_delete_by_user.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to delete Audit with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -374,9 +374,9 @@ type SessionStore interface {
|
||||
}
|
||||
|
||||
type AuditStore interface {
|
||||
Save(audit *model.Audit) *model.AppError
|
||||
Get(user_id string, offset int, limit int) (model.Audits, *model.AppError)
|
||||
PermanentDeleteByUser(userId string) *model.AppError
|
||||
Save(audit *model.Audit) error
|
||||
Get(user_id string, offset int, limit int) (model.Audits, error)
|
||||
PermanentDeleteByUser(userId string) error
|
||||
}
|
||||
|
||||
type ClusterDiscoveryStore interface {
|
||||
|
||||
@@ -15,7 +15,7 @@ type AuditStore struct {
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: user_id, offset, limit
|
||||
func (_m *AuditStore) Get(user_id string, offset int, limit int) (model.Audits, *model.AppError) {
|
||||
func (_m *AuditStore) Get(user_id string, offset int, limit int) (model.Audits, error) {
|
||||
ret := _m.Called(user_id, offset, limit)
|
||||
|
||||
var r0 model.Audits
|
||||
@@ -27,45 +27,39 @@ func (_m *AuditStore) Get(user_id string, offset int, limit int) (model.Audits,
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
|
||||
r1 = rf(user_id, offset, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByUser provides a mock function with given fields: userId
|
||||
func (_m *AuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (_m *AuditStore) PermanentDeleteByUser(userId string) error {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Save provides a mock function with given fields: audit
|
||||
func (_m *AuditStore) Save(audit *model.Audit) *model.AppError {
|
||||
func (_m *AuditStore) Save(audit *model.Audit) error {
|
||||
ret := _m.Called(audit)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(*model.Audit) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(*model.Audit) error); ok {
|
||||
r0 = rf(audit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
|
||||
@@ -329,7 +329,7 @@ type TimerLayerWebhookStore struct {
|
||||
Root *TimerLayer
|
||||
}
|
||||
|
||||
func (s *TimerLayerAuditStore) Get(user_id string, offset int, limit int) (model.Audits, *model.AppError) {
|
||||
func (s *TimerLayerAuditStore) Get(user_id string, offset int, limit int) (model.Audits, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.AuditStore.Get(user_id, offset, limit)
|
||||
@@ -345,7 +345,7 @@ func (s *TimerLayerAuditStore) Get(user_id string, offset int, limit int) (model
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerAuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
func (s *TimerLayerAuditStore) PermanentDeleteByUser(userId string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.AuditStore.PermanentDeleteByUser(userId)
|
||||
@@ -361,7 +361,7 @@ func (s *TimerLayerAuditStore) PermanentDeleteByUser(userId string) *model.AppEr
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerAuditStore) Save(audit *model.Audit) *model.AppError {
|
||||
func (s *TimerLayerAuditStore) Save(audit *model.Audit) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.AuditStore.Save(audit)
|
||||
|
||||
Ссылка в новой задаче
Block a user