forked from fastenhealth/fasten-onprem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new system settings table. (fastenhealth#409)
* Adding new system settings table. Adding associated database migration. Added tests Fixing tests for user-settings. * updated migration, make sure default system settings are created. Added database commands to create and update system settings. Added generic response wrapper. * make sure we can get related versions (fasten sources, onprem and desktop) when starting the app.
- Loading branch information
Showing
22 changed files
with
560 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,5 @@ fasten-*.db-wal | |
fasten.db | ||
fasten.db-shm | ||
fasten.db-wal | ||
|
||
backend/resources/related_versions.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/pkg/database/migrations/20240208112210/system_setting_entry.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package _20240208112210 | ||
|
||
import "github.com/fastenhealth/fasten-onprem/backend/pkg/models" | ||
|
||
// SystemSettingEntry matches a setting row in the database | ||
type SystemSettingEntry struct { | ||
//GORM attributes, see: http://gorm.io/docs/conventions.html | ||
models.ModelBase | ||
|
||
SettingKeyName string `json:"setting_key_name" gorm:"not null;index:,unique,composite:system_setting_key_name"` | ||
SettingKeyDescription string `json:"setting_key_description"` | ||
SettingDataType string `json:"setting_data_type"` | ||
|
||
SettingValueNumeric int `json:"setting_value_numeric"` | ||
SettingValueString string `json:"setting_value_string"` | ||
SettingValueBool bool `json:"setting_value_bool"` | ||
SettingValueArray []string `json:"setting_value_array" gorm:"column:setting_value_array;type:text;serializer:json"` | ||
} | ||
|
||
func (s SystemSettingEntry) TableName() string { | ||
return "system_settings" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package models | ||
|
||
type InstallationRegistrationRequest struct { | ||
// AdministratorEmail specifies email address for the administrator of the installation | ||
AdministratorEmail string `json:"administrator_email,omitempty"` //opt-in | ||
|
||
SoftwareArchitecture string `json:"software_architecture,omitempty"` | ||
SoftwareOS string `json:"software_os,omitempty"` | ||
|
||
FastenDesktopVersion string `json:"fasten_desktop_version,omitempty"` | ||
FastenOnpremVersion string `json:"fasten_onprem_version,omitempty"` | ||
FastenSourcesVersion string `json:"fasten_sources_version,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package models | ||
|
||
import ( | ||
"github.com/fastenhealth/fasten-onprem/backend/pkg" | ||
"time" | ||
) | ||
|
||
type InstallationRegistrationResponse struct { | ||
// InstallationID specifies client identifier string. REQUIRED | ||
InstallationID string `json:"installation_id"` | ||
|
||
// InstallationSecret specifies client secret string. OPTIONAL | ||
InstallationSecret string `json:"installation_secret"` | ||
|
||
// InstallationIDIssuedAt specifies time at which the client identifier was issued. OPTIONAL | ||
InstallationIDIssuedAt time.Time `json:"installation_id_issued_at"` | ||
|
||
VerificationStatus pkg.InstallationVerificationStatus `json:"verification_status"` | ||
QuotaStatus pkg.InstallationQuotaStatus `json:"quota_status"` | ||
|
||
*InstallationRegistrationRequest `json:",inline"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package models | ||
|
||
// SystemSettingEntry matches a setting row in the database | ||
type SystemSettingEntry struct { | ||
//GORM attributes, see: http://gorm.io/docs/conventions.html | ||
ModelBase | ||
|
||
SettingKeyName string `json:"setting_key_name" gorm:"not null;index:,unique,composite:system_setting_key_name"` | ||
SettingKeyDescription string `json:"setting_key_description"` | ||
SettingDataType string `json:"setting_data_type"` | ||
|
||
SettingValueNumeric int `json:"setting_value_numeric"` | ||
SettingValueString string `json:"setting_value_string"` | ||
SettingValueBool bool `json:"setting_value_bool"` | ||
SettingValueArray []string `json:"setting_value_array" gorm:"column:setting_value_array;type:text;serializer:json"` | ||
} | ||
|
||
func (s SystemSettingEntry) TableName() string { | ||
return "system_settings" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package models | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
type SystemSettings struct { | ||
InstallationID string `json:"installation_id"` | ||
InstallationSecret string `json:"installation_secret"` | ||
} | ||
|
||
// see https://gist.github.com/lelandbatey/a5c957b537bed39d1d6fb202c3b8de06 | ||
func (s *SystemSettings) FromSystemSettingsEntry(entry *SystemSettingEntry) error { | ||
|
||
structType := reflect.ValueOf(s).Elem() | ||
|
||
for i := 0; i < structType.NumField(); i++ { | ||
typeField := structType.Type().Field(i) | ||
|
||
if jsonTagValue := typeField.Tag.Get("json"); jsonTagValue == entry.SettingKeyName { | ||
//fmt.Println("found field", field.Name) | ||
if entry.SettingDataType == "numeric" { | ||
structType.Field(i).SetInt(int64(entry.SettingValueNumeric)) | ||
} else if entry.SettingDataType == "string" { | ||
structType.Field(i).SetString(entry.SettingValueString) | ||
} else if entry.SettingDataType == "bool" { | ||
structType.Field(i).SetBool(entry.SettingValueBool) | ||
} else if entry.SettingDataType == "array" { | ||
structType.Field(i).Set(reflect.ValueOf(entry.SettingValueArray)) | ||
} | ||
break | ||
} | ||
} | ||
|
||
//if entry.SettingKeyName == "dashboard_locations" { | ||
// s.DashboardLocations = entry.SettingValueArray | ||
//} | ||
return nil | ||
} | ||
|
||
func (s *SystemSettings) ToSystemSettingsEntry(entries []SystemSettingEntry) ([]SystemSettingEntry, error) { | ||
|
||
structType := reflect.ValueOf(s).Elem() | ||
|
||
fieldNameNdxLookup := map[string]int{} | ||
|
||
for i := 0; i < structType.NumField(); i++ { | ||
typeField := structType.Type().Field(i) | ||
jsonTagValue := typeField.Tag.Get("json") | ||
fieldNameNdxLookup[jsonTagValue] = i | ||
} | ||
|
||
for ndx, entry := range entries { | ||
fieldId := fieldNameNdxLookup[entry.SettingKeyName] | ||
|
||
if entry.SettingDataType == "numeric" { | ||
entries[ndx].SettingValueNumeric = int(structType.Field(fieldId).Int()) | ||
} else if entry.SettingDataType == "string" { | ||
entries[ndx].SettingValueString = structType.Field(fieldId).String() | ||
} else if entry.SettingDataType == "bool" { | ||
entries[ndx].SettingValueBool = structType.Field(fieldId).Bool() | ||
} else if entry.SettingDataType == "array" { | ||
sliceVal := structType.Field(fieldId).Slice(0, structType.Field(fieldId).Len()) | ||
|
||
entries[ndx].SettingValueArray = sliceVal.Interface().([]string) | ||
} | ||
} | ||
|
||
return entries, nil | ||
} |
Oops, something went wrong.