From 0ca47d56e6bc4a9536ecd6d23df0e59855d36450 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Fri, 25 Sep 2020 16:08:39 -0700 Subject: [PATCH] fix iso code validation --- cmd/server/assets/admin/realms/new.html | 5 +++-- pkg/database/realm.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/server/assets/admin/realms/new.html b/cmd/server/assets/admin/realms/new.html index 3827d2934..fecfd4a5d 100644 --- a/cmd/server/assets/admin/realms/new.html +++ b/cmd/server/assets/admin/realms/new.html @@ -43,8 +43,9 @@

New realm

{{template "errorable" $realm.ErrorsFor "regionCode"}} Used in creating deep link SMS for multi-helath authority apps. Region should - be ISO 3166-1 country codes and ISO 3166-2 subdivision codes where applicable. - For example, Washington State would be US-WA. + be ISO 3166-1 country codes and (optionally) ISO 3166-2 subdivision codes where applicable. + For example, Washington State would be US-WA, and Canada would be CA. The region code should be scoped to the authority of the public health + system represented by this verification system. diff --git a/pkg/database/realm.go b/pkg/database/realm.go index 8a0ad67ea..418d68b66 100644 --- a/pkg/database/realm.go +++ b/pkg/database/realm.go @@ -254,8 +254,10 @@ func (r *Realm) BeforeSave(tx *gorm.DB) error { r.AddError("regionCode", "cannot be blank when using EN Express") } else { parts := strings.Split(r.RegionCode, "-") - if len(parts) != 2 { - r.AddError("regionCode", "must be formated like 'region-subregion', 2 characters dash 2 or 3 characters") + if lp := len(parts); lp != 2 { + if lp == 1 && len(parts[0]) != 2 { + r.AddError("regionCode", "must be formated like 'region' (2 characters) or 'region-subregion' (2 characters dash 2 or 3 characters)") + } } else { if len(parts[0]) != 2 { r.AddError("regionCode", "first part must be exactly 2 characters in length")