fix activation/deactivation of crm, add rename handling crm
This commit is contained in:
parent
b75c725b3e
commit
6c545c2477
1
go.mod
1
go.mod
@ -31,6 +31,7 @@ require (
|
|||||||
github.com/jinzhu/now v0.0.0-20180511015916-ed742868f2ae // indirect
|
github.com/jinzhu/now v0.0.0-20180511015916-ed742868f2ae // indirect
|
||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||||
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b // indirect
|
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b // indirect
|
||||||
|
github.com/jstemmer/go-junit-report v0.0.0-20180614143834-385fac0ced9a // indirect
|
||||||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
github.com/lib/pq v1.0.0 // indirect
|
github.com/lib/pq v1.0.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -64,6 +64,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
|
|||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||||
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b h1:X61dhFTE1Au92SvyF8HyAwdjWqiSdfBgFR7wTxC0+uU=
|
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b h1:X61dhFTE1Au92SvyF8HyAwdjWqiSdfBgFR7wTxC0+uU=
|
||||||
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
|
github.com/jstemmer/go-junit-report v0.0.0-20180614143834-385fac0ced9a h1:2qq552JOlVHGYvqPc9ynBnGPDHeA7p0/QRn2NkrO8vk=
|
||||||
|
github.com/jstemmer/go-junit-report v0.0.0-20180614143834-385fac0ced9a/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||||
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
|
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
|
||||||
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
|
@ -29,6 +29,10 @@ func (c *Connection) createConnection() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) saveConnection() error {
|
func (c *Connection) saveConnection() error {
|
||||||
|
return orm.DB.Save(c).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Connection) saveConnectionByClientID() error {
|
||||||
return orm.DB.Model(c).Where("client_id = ?", c.ClientID).Update(c).Error
|
return orm.DB.Model(c).Where("client_id = ?", c.ClientID).Update(c).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -159,7 +160,7 @@ func saveHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.saveConnection()
|
err = conn.saveConnectionByClientID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
return
|
return
|
||||||
@ -220,14 +221,13 @@ func createHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func activityHandler(c *gin.Context) {
|
func activityHandler(c *gin.Context) {
|
||||||
var rec v5.ActivityCallback
|
var (
|
||||||
|
activity v5.Activity
|
||||||
|
systemUrl = c.PostForm("systemUrl")
|
||||||
|
clientId = c.PostForm("clientId")
|
||||||
|
)
|
||||||
|
|
||||||
if err := c.ShouldBindJSON(&rec); err != nil {
|
conn := getConnection(clientId)
|
||||||
c.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
conn := getConnection(rec.ClientId)
|
|
||||||
if conn.ID == 0 {
|
if conn.ID == 0 {
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest,
|
c.AbortWithStatusJSON(http.StatusBadRequest,
|
||||||
gin.H{
|
gin.H{
|
||||||
@ -238,9 +238,24 @@ func activityHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.Active = rec.Activity.Active && !rec.Activity.Freeze
|
err := json.Unmarshal([]byte(c.PostForm("activity")), &activity)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest,
|
||||||
|
gin.H{
|
||||||
|
"success": false,
|
||||||
|
"error": "Wrong data",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := conn.setConnectionActivity(); err != nil {
|
conn.Active = activity.Active && !activity.Freeze
|
||||||
|
|
||||||
|
if systemUrl != "" {
|
||||||
|
conn.APIURL = systemUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := conn.saveConnection(); err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -187,14 +187,17 @@ func TestRouting_saveHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouting_activityHandler(t *testing.T) {
|
func TestRouting_activityHandler(t *testing.T) {
|
||||||
req, err := http.NewRequest("POST", "/actions/activity",
|
data := url.Values{}
|
||||||
strings.NewReader(
|
data.Set("clientId", "123123")
|
||||||
`{"clientId": "123123","activity": {"active": true}}`,
|
data.Set("activity", `{"active": true, "freeze": false}`)
|
||||||
))
|
|
||||||
|
req, err := http.NewRequest("POST", "/actions/activity", strings.NewReader(data.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
router.ServeHTTP(rr, req)
|
router.ServeHTTP(rr, req)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user