diff --git a/dashboard/intents.go b/dashboard/intents.go index acd8ca2..8dc45b3 100644 --- a/dashboard/intents.go +++ b/dashboard/intents.go @@ -81,11 +81,19 @@ func GetIntents(w http.ResponseWriter, r *http.Request) { // CreateIntent is the route to create a new intent func CreateIntent(w http.ResponseWriter, r *http.Request) { + allowedHeaders := "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization,Olivia-Token" + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") + w.Header().Set("Access-Control-Allow-Headers", allowedHeaders) + w.Header().Set("Access-Control-Expose-Headers", "Authorization") + + data := mux.Vars(r) + // Checks if the token present in the headers is the right one token := r.Header.Get("Olivia-Token") if !ChecksToken(token) { json.NewEncoder(w).Encode(Error{ - Message: "You don't have the permission to do this.", + Message: util.GetMessage(data["locale"], "no permission"), }) return } @@ -96,12 +104,20 @@ func CreateIntent(w http.ResponseWriter, r *http.Request) { if intent.Responses == nil || intent.Patterns == nil { json.NewEncoder(w).Encode(Error{ - Message: "Patterns and responses can't be null", + Message: util.GetMessage(data["locale"], "patterns same"), }) return } - data := mux.Vars(r) + // Returns an error if the tags are the same + for _, _intent := range analysis.GetIntents(data["locale"]) { + if _intent.Tag == intent.Tag { + json.NewEncoder(w).Encode(Error{ + Message: util.GetMessage(data["locale"], "tags same"), + }) + return + } + } // Adds the intent AddIntent(data["locale"], intent) diff --git a/res/locales/ca/messages.json b/res/locales/ca/messages.json index 4ba232f..d727fc6 100644 --- a/res/locales/ca/messages.json +++ b/res/locales/ca/messages.json @@ -14,6 +14,18 @@ "No teniu permís per fer-ho." ] }, + { + "tag": "patterns same", + "messages": [ + "Els patrons i/o les respostes no poden estar buits." + ] + }, + { + "tag": "tags same", + "messages": [ + "Ja existeix un intent amb aquesta etiqueta." + ] + }, { "tag": "spotify tokens", "messages": [ diff --git a/res/locales/en/messages.json b/res/locales/en/messages.json index 7676781..4f5e3d3 100644 --- a/res/locales/en/messages.json +++ b/res/locales/en/messages.json @@ -14,6 +14,18 @@ "You don't have the permission to do this." ] }, + { + "tag": "patterns same", + "messages": [ + "The patterns and/or responses can't be empty." + ] + }, + { + "tag": "tags same", + "messages": [ + "An intent already exists with this tag." + ] + }, { "tag": "spotify tokens", "messages": [ diff --git a/res/locales/es/messages.json b/res/locales/es/messages.json index 3e0e15c..d5c4dd5 100644 --- a/res/locales/es/messages.json +++ b/res/locales/es/messages.json @@ -14,6 +14,18 @@ "No tienes permiso para hacer esto.." ] }, + { + "tag": "patterns same", + "messages": [ + "Los patrones y/o respuestas no pueden estar vacíos." + ] + }, + { + "tag": "tags same", + "messages": [ + "Ya existe un intent con esta etiqueta." + ] + }, { "tag": "spotify tokens", "messages": [ diff --git a/res/locales/fr/messages.json b/res/locales/fr/messages.json index 9d55ad1..fd94b7f 100644 --- a/res/locales/fr/messages.json +++ b/res/locales/fr/messages.json @@ -14,6 +14,18 @@ "Vous n'avez pas la permission pour faire ceci." ] }, + { + "tag": "patterns same", + "messages": [ + "Les modèles et/ou les réponses ne peuvent pas être vides." + ] + }, + { + "tag": "tags same", + "messages": [ + "Un intent existe déjà avec cette étiquette" + ] + }, { "tag": "spotify tokens", "messages": [