func RecordsUpdateHandler(c echo.Context) error { session := session.NewSession(c) if !session.AuthFailed { endpoint := session.GetEndpoint() request := session.GetParam("request").(map[string]interface{}) bypass_plugin := false if session.User.SuperUser && request["content"].(map[string]interface{})["$bypass_plugin"] != nil { bypass_plugin = true delete(request["content"].(map[string]interface{}), "$bypass_plugin") } if !bypass_plugin && plugin.CheckPlugin("update", endpoint) { plugin.RunPlugin("update", endpoint, session) } else { id := bson.ObjectIdHex(session.GetParam("record_id").(string)) record := endpoint.FindWriteRecordById(id, session.User) if request != nil && request["content"] != nil { request_content := request["content"].(map[string]interface{}) request_permissions := request["permissions"].(map[string]interface{}) var trigger = false if request_content["$trigger"] != nil { trigger = request_content["$trigger"].(bool) delete(request_content, "$trigger") } else { trigger = !session.TriggerSession } if session.User.SuperUser != true { if request_content["protected"] != nil { request_content["protected"] = record.Content["protected"] } } record.Content = request_content record.Permissions.UpdatePermissions(request_permissions) record.UpdateReferenceMaps() record.StripReferenceData() record.SaveAndTrigger(endpoint.Name, trigger) session.SetRecordsAndCalculateCapabilitiesForUser(session.GetEndpoint().Name, []model.Record{record}, session.User) } session.SetRecordsAndCalculateCapabilitiesForUser(session.GetEndpoint().Name, []model.Record{record}, session.User) } } session.Write() return nil }
func RecordsQueryHandler(c echo.Context) error { session := session.NewSession(c) if !session.AuthFailed { endpoint := session.GetEndpoint() request := session.GetParam("request").(map[string]interface{}) bypass_plugin := false if session.User.SuperUser && request["where"].(map[string]interface{})["$bypass_plugin"] != nil { bypass_plugin = true delete(request["where"].(map[string]interface{}), "$bypass_plugin") } if !bypass_plugin && plugin.CheckPlugin("query", endpoint) { plugin.RunPlugin("query", endpoint, session) } else { records, count := endpoint.FindReadRecordsWhere(request["where"].(map[string]interface{}), session.User) session.SetRecordsAndCalculateCapabilitiesForUser(endpoint.Name, records, session.User) session.SetRecordCount(count) } } session.Write() return nil }
func RecordsCreateHandler(c echo.Context) error { session := session.NewSession(c) if !session.AuthFailed { endpoint := session.GetEndpoint() request := session.GetParam("request").(map[string]interface{}) bypass_plugin := false if session.User.SuperUser && request["content"].(map[string]interface{})["$bypass_plugin"] != nil { bypass_plugin = true delete(request["content"].(map[string]interface{}), "$bypass_plugin") } if !bypass_plugin && plugin.CheckPlugin("create", endpoint) { plugin.RunPlugin("create", endpoint, session) } else { if endpoint.CanCreate(session.User) { record := endpoint.NewRecord() if session.User.Id != bson.ObjectId("") { record.CreatedBy = session.User.Id } if request != nil && request["content"] != nil { var trigger = false if request["content"].(map[string]interface{})["$trigger"] != nil { trigger = request["content"].(map[string]interface{})["$trigger"].(bool) delete(request["content"].(map[string]interface{}), "$trigger") } else { trigger = !session.TriggerSession } if request["content"].(map[string]interface{})["$created_by"] != nil && session.User.SuperUser == true { record.CreatedBy = bson.ObjectIdHex(request["content"].(map[string]interface{})["$created_by"].(string)) delete(request["content"].(map[string]interface{}), "$created_by") } request_content := request["content"].(map[string]interface{}) request_permissions := request["permissions"].(map[string]interface{}) record.Content = request_content record.Permissions.UpdatePermissions(request_permissions) record.SaveAndTrigger("", false) record.UpdateReferenceMaps() record.SaveAndTriggerCreate(endpoint.Name, trigger) session.SetRecordsAndCalculateCapabilitiesForUser(session.GetEndpoint().Name, []model.Record{record}, session.User) } } } } session.Write() return nil }