From 5579991d6644c10f7aae014f1c9ddf3127138c90 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 27 Dec 2024 10:07:05 +0300 Subject: [PATCH 1/6] guard profile update after being set --- internal/handlers/ussd/menuhandler.go | 47 ++++++++++++++------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 986f8f0..901f9b3 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -69,15 +69,15 @@ func (fm *FlagManager) GetFlag(label string) (uint32, error) { } type Handlers struct { - pe *persist.Persister - st *state.State - ca cache.Memory - userdataStore common.DataStore - adminstore *utils.AdminStore - flagManager *asm.FlagParser - accountService remote.AccountServiceInterface - prefixDb storage.PrefixDb - profile *models.Profile + pe *persist.Persister + st *state.State + ca cache.Memory + userdataStore common.DataStore + adminstore *utils.AdminStore + flagManager *asm.FlagParser + accountService remote.AccountServiceInterface + prefixDb storage.PrefixDb + profile *models.Profile ReplaceSeparatorFunc func(string) string } @@ -94,12 +94,12 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *util prefixDb := storage.NewSubPrefixDb(userdataStore, prefix) h := &Handlers{ - userdataStore: userDb, - flagManager: appFlags, - adminstore: adminstore, - accountService: accountService, - prefixDb: prefixDb, - profile: &models.Profile{Max: 6}, + userdataStore: userDb, + flagManager: appFlags, + adminstore: adminstore, + accountService: accountService, + prefixDb: prefixDb, + profile: &models.Profile{Max: 6}, ReplaceSeparatorFunc: replaceSeparatorFunc, } return h, nil @@ -1986,15 +1986,16 @@ func (h *Handlers) insertProfileItems(ctx context.Context, sessionId string, res for index, profileItem := range h.profile.ProfileItems { // Ensure the profileItem is not "0"(is set) if profileItem != "0" { - err = store.WriteEntry(ctx, sessionId, profileDataKeys[index], []byte(profileItem)) - if err != nil { - logg.ErrorCtxf(ctx, "failed to write profile entry with", "key", profileDataKeys[index], "value", profileItem, "error", err) - return err - } - - // Get the flag for the current index flag, _ := h.flagManager.GetFlag(profileFlagNames[index]) - res.FlagSet = append(res.FlagSet, flag) + isProfileItemSet := h.st.MatchFlag(flag, true) + if !isProfileItemSet { + err = store.WriteEntry(ctx, sessionId, profileDataKeys[index], []byte(profileItem)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write profile entry with", "key", profileDataKeys[index], "value", profileItem, "error", err) + return err + } + res.FlagSet = append(res.FlagSet, flag) + } } } return nil From 11eb61ba3524d6f3ee25e2e962a274986c1e58ce Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 27 Dec 2024 16:11:09 +0300 Subject: [PATCH 2/6] repeat same node on invalid selection --- services/registration/select_gender.vis | 1 + 1 file changed, 1 insertion(+) diff --git a/services/registration/select_gender.vis b/services/registration/select_gender.vis index c1a00f5..e41da10 100644 --- a/services/registration/select_gender.vis +++ b/services/registration/select_gender.vis @@ -11,3 +11,4 @@ INCMP _ 0 INCMP set_male 1 INCMP set_female 2 INCMP set_unspecified 3 +INCMP . * From 46edf2b819a250043d2c7fa99deafd6c34bcbd3c Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 27 Dec 2024 16:13:36 +0300 Subject: [PATCH 3/6] remove redundant catch on pin entry --- services/registration/edit_offerings.vis | 1 - 1 file changed, 1 deletion(-) diff --git a/services/registration/edit_offerings.vis b/services/registration/edit_offerings.vis index ddbc9e0..9c1e747 100644 --- a/services/registration/edit_offerings.vis +++ b/services/registration/edit_offerings.vis @@ -10,5 +10,4 @@ CATCH _ flag_back_set 1 RELOAD save_offerings INCMP _ 0 CATCH pin_entry flag_offerings_set 1 -CATCH pin_entry flag_offerings_set 0 INCMP update_profile_items * From 58a60f2c81efa3c5971748ab81dd31519da5adce Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Sat, 28 Dec 2024 08:47:51 +0300 Subject: [PATCH 4/6] update expected age in test --- menutraversal_test/group_test.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index 8f43ff5..5ffe615 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -430,7 +430,7 @@ }, { "input": "1234", - "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 84\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" + "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" }, { "input": "0", From 0a332ec5012ba3b03027bbb72af5f470a560b83f Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Dec 2024 08:05:36 +0300 Subject: [PATCH 5/6] chore: ensure swahili language translation. --- internal/handlers/ussd/menuhandler.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 7a188c6..6b6407b 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1367,6 +1367,7 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input [] func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result var profileInfo []byte + var defaultValue string var err error flag_firstname_set, _ := h.flagManager.GetFlag("flag_firstname_set") @@ -1383,7 +1384,18 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input if !ok { return res, fmt.Errorf("missing session") } - // Extract the field name from the state machine position. + language, ok := ctx.Value("Language").(lang.Language) + if !ok { + return res, fmt.Errorf("value for 'Language' is not of type lang.Language") + } + code := language.Code + if code == "swa" { + defaultValue = "Haipo" + } else { + defaultValue = "Not Provided" + } + + sm, _ := h.st.Where() parts := strings.SplitN(sm, "_", 2) filename := parts[1] @@ -1400,7 +1412,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME) if err != nil { if db.IsNotFound(err) { - res.Content = "Not provided" + res.Content = defaultValue break } logg.ErrorCtxf(ctx, "Failed to read first name entry with", "key", "error", common.DATA_FIRST_NAME, err) @@ -1412,7 +1424,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME) if err != nil { if db.IsNotFound(err) { - res.Content = "Not provided" + res.Content = defaultValue break } logg.ErrorCtxf(ctx, "Failed to read family name entry with", "key", "error", common.DATA_FAMILY_NAME, err) @@ -1425,7 +1437,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER) if err != nil { if db.IsNotFound(err) { - res.Content = "Not provided" + res.Content = defaultValue break } logg.ErrorCtxf(ctx, "Failed to read gender entry with", "key", "error", common.DATA_GENDER, err) @@ -1437,7 +1449,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB) if err != nil { if db.IsNotFound(err) { - res.Content = "Not provided" + res.Content = defaultValue break } logg.ErrorCtxf(ctx, "Failed to read year of birth(yob) entry with", "key", "error", common.DATA_YOB, err) @@ -1449,7 +1461,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION) if err != nil { if db.IsNotFound(err) { - res.Content = "Not provided" + res.Content = defaultValue break } logg.ErrorCtxf(ctx, "Failed to read location entry with", "key", "error", common.DATA_LOCATION, err) @@ -1461,7 +1473,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS) if err != nil { if db.IsNotFound(err) { - res.Content = "Not provided" + res.Content = defaultValue break } logg.ErrorCtxf(ctx, "Failed to read offerings entry with", "key", "error", common.DATA_OFFERINGS, err) From db7c9bf56d4f7c173b30947d6c6ec2b511a39acc Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Dec 2024 08:07:39 +0300 Subject: [PATCH 6/6] chore: add colon to enhance formatting. --- services/registration/edit_first_name_swa | 2 +- services/registration/edit_location_swa | 2 +- services/registration/edit_yob_swa | 2 +- services/registration/select_gender_swa | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/registration/edit_first_name_swa b/services/registration/edit_first_name_swa index 3fdd986..5776bf0 100644 --- a/services/registration/edit_first_name_swa +++ b/services/registration/edit_first_name_swa @@ -1,2 +1,2 @@ -Jina la kwanza la sasa {{.get_current_profile_info}} +Jina la kwanza la sasa: {{.get_current_profile_info}} Weka majina yako ya kwanza: \ No newline at end of file diff --git a/services/registration/edit_location_swa b/services/registration/edit_location_swa index 0a3476e..179c421 100644 --- a/services/registration/edit_location_swa +++ b/services/registration/edit_location_swa @@ -1,2 +1,2 @@ -Eneo la sasa {{.get_current_profile_info}} +Eneo la sasa: {{.get_current_profile_info}} Weka eneo: \ No newline at end of file diff --git a/services/registration/edit_yob_swa b/services/registration/edit_yob_swa index e0b5708..f923c86 100644 --- a/services/registration/edit_yob_swa +++ b/services/registration/edit_yob_swa @@ -1,2 +1,2 @@ -Mwaka wa sasa wa kuzaliwa {{.get_current_profile_info}} +Mwaka wa sasa wa kuzaliwa: {{.get_current_profile_info}} Weka mwaka wa kuzaliwa \ No newline at end of file diff --git a/services/registration/select_gender_swa b/services/registration/select_gender_swa index b077a0b..39d99d5 100644 --- a/services/registration/select_gender_swa +++ b/services/registration/select_gender_swa @@ -1,2 +1,2 @@ -Jinsia ya sasa {{.get_current_profile_info}} +Jinsia ya sasa: {{.get_current_profile_info}} Chagua jinsia \ No newline at end of file