Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

fix iso code validation #686

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/server/assets/admin/realms/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ <h1>New realm</h1>
{{template "errorable" $realm.ErrorsFor "regionCode"}}
<small class="form-text text-muted">
Used in creating deep link SMS for multi-helath authority apps. Region should
be <a href="https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes">ISO 3166-1 country codes and ISO 3166-2 subdivision codes</a> where applicable.
For example, Washington State would be <code>US-WA</code>.
be <a href="https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes">ISO 3166-1 country codes and (optionally) ISO 3166-2 subdivision codes</a> where applicable.
For example, Washington State would be <code>US-WA</code>, and Canada would be <code>CA</code>. The region code should be scoped to the authority of the public health
system represented by this verification system.
</small>
</div>

Expand Down
6 changes: 4 additions & 2 deletions pkg/database/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down