fix(permission): change permission checking

read permissions from settings.json instead
This commit is contained in:
pakintada@gmail.com 2024-03-18 14:11:24 +07:00
parent 8744ddcb8c
commit cd0f67bb44
6 changed files with 128 additions and 60 deletions

View file

@ -95,3 +95,78 @@ func ScanRecipeFiles(countries []CountryName) map[string][]RecipePath {
}
return recipeFiles
}
func LoadCountrySettings() []CountryName {
res := make([]CountryName, 0)
// read file country.settings.json
content, err := os.Open("country.settings.json")
if err != nil {
fmt.Errorf("country.settings.json not found")
}
// read content to json
var countrySettings []map[string]interface{}
err = json.NewDecoder(content).Decode(&countrySettings)
if err != nil {
fmt.Errorf("error in country.settings")
return nil
}
for _, v := range countrySettings {
if ignore, ok := v["ignore"].(bool); ok {
if ignore {
continue
}
}
res = append(res, CountryName{
CountryID: v["short"].(string),
CountryName: v["name"].(string),
})
}
return res
}
// integrate with permissions
type CountryNamePerms struct {
CountryID string
CountryName string
CountryPermission int
}
func LoadCountrySettingsWithPermissions() []CountryNamePerms {
res := make([]CountryNamePerms, 0)
// read file country.settings.json
content, err := os.Open("country.settings.json")
if err != nil {
fmt.Errorf("country.settings.json not found")
}
// read content to json
var countrySettings []map[string]interface{}
err = json.NewDecoder(content).Decode(&countrySettings)
if err != nil {
fmt.Errorf("error in country.settings")
return nil
}
for _, v := range countrySettings {
if ignore, ok := v["ignore"].(bool); ok {
if ignore {
continue
}
}
res = append(res, CountryNamePerms{
CountryID: v["short"].(string),
CountryName: v["name"].(string),
CountryPermission: int(v["permissions"].(float64)),
})
}
return res
}