diff --git a/action_create.go b/action_create.go index 99fc071..e7854d6 100644 --- a/action_create.go +++ b/action_create.go @@ -29,7 +29,6 @@ func (s Service) Create(payload CreatePayload) { // Get document doc := Audit{ ID: mongodb.NewObjectID(), - Source: s.Source, Target: payload.Target, TargetID: payload.TargetID, Action: payload.Action, diff --git a/action_query.go b/action_query.go index 9c13095..65569c9 100644 --- a/action_query.go +++ b/action_query.go @@ -26,7 +26,6 @@ func (s Service) All(query AllQuery) []Audit { // Find db cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{ - {"source", s.Source}, {"target", query.Target}, {"targetId", query.TargetID}, }, &options.FindOptions{ diff --git a/audit.go b/audit.go index cec6ae9..5c29906 100644 --- a/audit.go +++ b/audit.go @@ -15,8 +15,6 @@ type MongoDBConfig struct { // Config ... type Config struct { - // Source of server, e.g: selly - Source string // Targets: staff, article, ... Targets []string // MongoDB config, for save documents @@ -33,8 +31,8 @@ var s *Service // NewInstance ... func NewInstance(config Config) error { - if config.Source == "" || len(config.Targets) == 0 || config.MongoDB.Host == "" { - return errors.New("please provide all necessary information: source, targets, mongodb") + if len(config.Targets) == 0 || config.MongoDB.Host == "" { + return errors.New("please provide all necessary information: targets, mongodb") } // Connect MongoDB diff --git a/constant.go b/constant.go deleted file mode 100644 index 101f1eb..0000000 --- a/constant.go +++ /dev/null @@ -1,8 +0,0 @@ -package audit - -// List actions -const ( - ActionCreate = "create" - ActionUpdate = "update" - ActionUpdatePermissions = "update-permissions" -) diff --git a/db_index.go b/db_index.go index 4ff1dd0..a503f4c 100644 --- a/db_index.go +++ b/db_index.go @@ -6,9 +6,9 @@ import ( func (s Service) indexDB() { // Index key - commonIndex := mongodb.NewIndexKey("source", "target", "targetId") + commonIndex := mongodb.NewIndexKey("target", "targetId") - // Index all allowed sources + // Index all targets for _, target := range s.Targets { mongodb.CreateIndex(getColName(target), commonIndex) } diff --git a/db_model.go b/db_model.go index 5a17ecc..e0aaecf 100644 --- a/db_model.go +++ b/db_model.go @@ -9,7 +9,6 @@ import ( // Audit ... type Audit struct { ID primitive.ObjectID `bson:"_id" json:"id"` - Source string `bson:"source" json:"source"` Target string `bson:"target" json:"target"` TargetID string `bson:"targetId" json:"targetId"` Action string `bson:"action" json:"action"`