Skip to content
Snippets Groups Projects
Commit e901381e authored by Kali Kaneko's avatar Kali Kaneko
Browse files

add urgency

parent 82364eb7
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ The structure of the `motd.json` file is like follows:
"end": "Dec 31 2021 23:59:00",
"type": "daily",
"platform": "all",
"urgency": "normal",
"text": [
{ "lang": "en",
"str": "This is a <a href='https://leap.se'>test!</a>"},
......@@ -33,7 +34,8 @@ Valid values are:
* Begin, End are date strings, like "Jan 1 2021 00:00:00".
* Type: "once" for a one-shot message, "daily" for a message that is displayed daily during the specified duration.
* Platform: one of "windows", "linux", "osx" or "all".
* Platform: one of "windows", "osx", "snap", "linux", or "all".
* Urgency: either "normal" or "critical".
The text message can contain links.
......@@ -48,6 +50,7 @@ Message 1 ✓
-----------
Type: daily ✓
Platform: all ✓
Urgency: normal ✓
Languages: 2 ✓
```
......
......@@ -28,20 +28,24 @@ type Message struct {
End string `json:"end"`
Type string `json:"type"`
Platform string `json:"platform"`
Urgency string `json:"urgency"`
Text []LocalizedText `json:"text"`
}
func (m *Message) IsValid() bool {
valid := (m.IsValidBegin() && m.IsValidEnd() &&
m.IsValidType() && m.IsValidPlatform() && m.HasLocalizedText())
m.IsValidType() && m.IsValidPlatform() && m.IsValidUrgency() &&
m.HasLocalizedText())
return valid
}
func (m *Message) IsValidBegin() bool {
// FIXME check that begin is before 1y for instance
return true
}
func (m *Message) IsValidEnd() bool {
// FIXME check end is within next year/months
return true
}
......@@ -63,8 +67,17 @@ func (m *Message) IsValidPlatform() bool {
}
}
func (m *Message) IsValidUrgency() bool {
switch m.Urgency {
case "normal", "critical":
return true
default:
return false
}
}
func (m *Message) HasLocalizedText() bool {
return true
return len(m.Text) > 0
}
type LocalizedText struct {
......@@ -89,6 +102,7 @@ func main() {
fmt.Printf("Message %d %v\n-----------\n", i+1, mark(msg.IsValid()))
fmt.Printf("Type: %s %v\n", msg.Type, mark(msg.IsValidType()))
fmt.Printf("Platform: %s %v\n", msg.Platform, mark(msg.IsValidPlatform()))
fmt.Printf("Urgency: %s %v\n", msg.Urgency, mark(msg.IsValidUrgency()))
fmt.Printf("Languages: %d %v\n", len(msg.Text), mark(msg.HasLocalizedText()))
if !msg.IsValid() {
os.Exit(1)
......
......@@ -4,6 +4,7 @@
"end": "Dec 31 2021 23:59:00",
"type": "daily",
"platform": "all",
"urgency": "normal",
"text": [
{ "lang": "en",
"str": "This is a <a href='https://leap.se'>test!</a>"},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment