diff --git a/src/agreements_api.go b/src/agreements_api.go index 6c71c18..dda974e 100644 --- a/src/agreements_api.go +++ b/src/agreements_api.go @@ -220,14 +220,14 @@ func (e mainEnv) agreementWithdraw(w http.ResponseWriter, r *http.Request, ps ht } if authResult == "login" && selfService == false { - rtoken, err := e.db.saveUserRequest("agreement-withdraw", userTOKEN, "", brief, nil) + rtoken, rstatus, err := e.db.saveUserRequest("agreement-withdraw", userTOKEN, "", brief, nil) if err != nil { returnError(w, r, "internal error", 405, err, event) return } w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) - fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken) + fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken) return } switch mode { diff --git a/src/requests_db.go b/src/requests_db.go index 887e68d..f6e2365 100644 --- a/src/requests_db.go +++ b/src/requests_db.go @@ -24,7 +24,7 @@ type requestEvent struct { Reason string `json:"reason"` } -func (dbobj dbcon) saveUserRequest(action string, token string, app string, brief string, change []byte) (string, error) { +func (dbobj dbcon) saveUserRequest(action string, token string, app string, brief string, change []byte) (string, string, error) { now := int32(time.Now().Unix()) bdoc := bson.M{} bdoc["token"] = token @@ -39,7 +39,7 @@ func (dbobj dbcon) saveUserRequest(action string, token string, app string, brie record, err := dbobj.store.LookupRecord(storage.TblName.Requests, bdoc) if record != nil { fmt.Printf("This record already exists.\n") - return record["rtoken"].(string), nil + return record["rtoken"].(string), "request-exists", nil } rtoken, _ := uuid.GenerateUUID() bdoc["when"] = now @@ -48,12 +48,12 @@ func (dbobj dbcon) saveUserRequest(action string, token string, app string, brie if change != nil { encodedStr, err := dbobj.userEncrypt(token, change) if err != nil { - return "", err + return "", "", err } bdoc["change"] = encodedStr } _, err = dbobj.store.CreateRecord(storage.TblName.Requests, &bdoc) - return rtoken, err + return rtoken, "request-created", err } func (dbobj dbcon) getRequests(status string, offset int32, limit int32) ([]byte, int64, error) { diff --git a/src/userapps_api.go b/src/userapps_api.go index 79294d0..d600124 100644 --- a/src/userapps_api.go +++ b/src/userapps_api.go @@ -117,14 +117,14 @@ func (e mainEnv) userappChange(w http.ResponseWriter, r *http.Request, ps httpro } } } - rtoken, err := e.db.saveUserRequest("change-app-data", userTOKEN, appName, "", jsonData) + rtoken, rstatus, err := e.db.saveUserRequest("change-app-data", userTOKEN, appName, "", jsonData) if err != nil { returnError(w, r, "internal error", 405, err, event) return } w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) - fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken) + fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken) } func (e mainEnv) userappList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { diff --git a/src/users_api.go b/src/users_api.go index 252c8f1..4bd39a8 100644 --- a/src/users_api.go +++ b/src/users_api.go @@ -201,14 +201,14 @@ func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httproute if authResult == "login" { event.Title = "user change-profile request" if e.conf.SelfService.UserRecordChange == false || adminRecordChanged == true { - rtoken, err := e.db.saveUserRequest("change-profile", userTOKEN, "", "", parsedData.jsonData) + rtoken, rstatus, err := e.db.saveUserRequest("change-profile", userTOKEN, "", "", parsedData.jsonData) if err != nil { returnError(w, r, "internal error", 405, err, event) return } w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) - fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken) + fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken) return } } @@ -265,14 +265,14 @@ func (e mainEnv) userDelete(w http.ResponseWriter, r *http.Request, ps httproute if authResult == "login" { event.Title = "user forget-me request" if e.conf.SelfService.ForgetMe == false { - rtoken, err := e.db.saveUserRequest("forget-me", userTOKEN, "", "", nil) + rtoken, rstatus, err := e.db.saveUserRequest("forget-me", userTOKEN, "", "", nil) if err != nil { returnError(w, r, "internal error", 405, err, event) return } w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) - fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken) + fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken) return } } diff --git a/ui/site/user-apps.html b/ui/site/user-apps.html index 0718552..c52167e 100644 --- a/ui/site/user-apps.html +++ b/ui/site/user-apps.html @@ -108,6 +108,8 @@ if (conf["custom_css_link"]) { var data = JSON.parse(xhr0.responseText); if (data.status == "ok" && data.result && data.result == "request-created") { showAlert("Admin request created to approve your app data changes."); + } else if (data.status == "ok" && data.result && data.result == "request-exists") { + showAlert("Similar request already exists for Admin approval."); } } else if (xhr0.status > 400 && xhr0.status < 500) { document.location = "/"; diff --git a/ui/site/user-consent-management.html b/ui/site/user-consent-management.html index 139a81a..7f4704e 100644 --- a/ui/site/user-consent-management.html +++ b/ui/site/user-consent-management.html @@ -125,6 +125,8 @@ if (conf["custom_css_link"]) { var data = JSON.parse(xhr.responseText); if (data.status == "ok" && data.result && data.result == "request-created") { showAlert("Admin request created to withdraw your consent."); + } else if (data.status == "ok" && data.result && data.result == "request-exists") { + showAlert("Similar request already exists for Admin approval."); } else { document.location.reload(); } diff --git a/ui/site/user-profile.html b/ui/site/user-profile.html index f003c06..c3dec26 100644 --- a/ui/site/user-profile.html +++ b/ui/site/user-profile.html @@ -120,7 +120,6 @@ if (conf["custom_css_link"]) { forgetMeDo(); confirmModal.modal('hide'); }); - confirmModal.modal('show'); } function forgetMeDo(brief) { @@ -133,6 +132,8 @@ if (conf["custom_css_link"]) { var data = JSON.parse(xhr.responseText); if (data.status == "ok" && data.result && data.result == "request-created") { showAlert("Admin request created to cancel your account."); + } else if (data.status == "ok" && data.result && data.result == "request-exists") { + showAlert("Similar request already exists for Admin approval."); } else { bunker_logout(); } @@ -157,6 +158,8 @@ if (conf["custom_css_link"]) { var data = JSON.parse(xhr0.responseText); if (data.status == "ok" && data.result && data.result == "request-created") { showAlert("Admin request created to approve changes in your profile."); + } else if (data.status == "ok" && data.result && data.result == "request-exists") { + showAlert("Similar request already exists for Admin approval."); } } else if (xhr0.status === 403) { document.location = "/";