Skip to content

Commit

Permalink
Merge pull request #133 from c4dt/37
Browse files Browse the repository at this point in the history
Add URL for each candidate
  • Loading branch information
PascalinDe authored Mar 1, 2024
2 parents ae9e179 + 26e0700 commit af1c47a
Show file tree
Hide file tree
Showing 29 changed files with 545 additions and 352 deletions.
18 changes: 12 additions & 6 deletions contracts/evoting/types/ballots.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (b *Ballot) Unmarshal(marshalledBallot string, form Form) error {
ID: ID(questionID),
MaxN: q.GetMaxN(),
MinN: q.GetMinN(),
Choices: make([]string, q.GetChoicesLength()),
Choices: make([]Choice, q.GetChoicesLength()),
}

results, err := selectQ.unmarshalAnswers(selections)
Expand All @@ -108,7 +108,7 @@ func (b *Ballot) Unmarshal(marshalledBallot string, form Form) error {
ID: ID(questionID),
MaxN: q.GetMaxN(),
MinN: q.GetMinN(),
Choices: make([]string, q.GetChoicesLength()),
Choices: make([]Choice, q.GetChoicesLength()),
}

results, err := rankQ.unmarshalAnswers(ranks)
Expand All @@ -127,7 +127,7 @@ func (b *Ballot) Unmarshal(marshalledBallot string, form Form) error {
MaxN: q.GetMaxN(),
MinN: q.GetMinN(),
MaxLength: 0, // TODO: Should the length check be also done at decryption?
Choices: make([]string, q.GetChoicesLength()),
Choices: make([]Choice, q.GetChoicesLength()),
}

results, err := textQ.unmarshalAnswers(texts)
Expand Down Expand Up @@ -267,6 +267,12 @@ type Hint struct {
De string
}

// Choice contains a choice and an optional URL
type Choice struct {
Choice string
URL string
}

// Subject is a wrapper around multiple questions that can be of type "select",
// "rank", or "text".
type Subject struct {
Expand Down Expand Up @@ -431,7 +437,7 @@ type Select struct {
Title Title
MaxN uint
MinN uint
Choices []string
Choices []Choice
Hint Hint
}

Expand Down Expand Up @@ -497,7 +503,7 @@ type Rank struct {
Title Title
MaxN uint
MinN uint
Choices []string
Choices []Choice
Hint Hint
}

Expand Down Expand Up @@ -572,7 +578,7 @@ type Text struct {
MinN uint
MaxLength uint
Regex string
Choices []string
Choices []Choice
Hint Hint
}

Expand Down
28 changes: 14 additions & 14 deletions contracts/evoting/types/ballots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ func TestBallot_Unmarshal(t *testing.T) {
Title: Title{En: "", Fr: "", De: ""},
MaxN: 2,
MinN: 2,
Choices: make([]string, 3),
Choices: make([]Choice, 3),
}, {
ID: decodedQuestionID(2),
Title: Title{En: "", Fr: "", De: ""},
MaxN: 3,
MinN: 3,
Choices: make([]string, 5),
Choices: make([]Choice, 5),
}},

Ranks: []Rank{{
ID: decodedQuestionID(3),
Title: Title{En: "", Fr: "", De: ""},
MaxN: 4,
MinN: 0,
Choices: make([]string, 4),
Choices: make([]Choice, 4),
}},

Texts: []Text{{
Expand All @@ -83,7 +83,7 @@ func TestBallot_Unmarshal(t *testing.T) {
MinN: 2,
MaxLength: 10,
Regex: "",
Choices: make([]string, 2),
Choices: make([]Choice, 2),
}},
},
}}
Expand Down Expand Up @@ -318,21 +318,21 @@ func TestSubject_MaxEncodedSize(t *testing.T) {
Title: Title{En: "", Fr: "", De: ""},
MaxN: 3,
MinN: 0,
Choices: make([]string, 3),
Choices: make([]Choice, 3),
}, {
ID: encodedQuestionID(2),
Title: Title{En: "", Fr: "", De: ""},
MaxN: 5,
MinN: 0,
Choices: make([]string, 5),
Choices: make([]Choice, 5),
}},

Ranks: []Rank{{
ID: encodedQuestionID(3),
Title: Title{En: "", Fr: "", De: ""},
MaxN: 4,
MinN: 0,
Choices: make([]string, 4),
Choices: make([]Choice, 4),
}},

Texts: []Text{{
Expand All @@ -342,15 +342,15 @@ func TestSubject_MaxEncodedSize(t *testing.T) {
MinN: 0,
MaxLength: 10,
Regex: "",
Choices: make([]string, 2),
Choices: make([]Choice, 2),
}, {
ID: encodedQuestionID(5),
Title: Title{En: "", Fr: "", De: ""},
MaxN: 1,
MinN: 0,
MaxLength: 10,
Regex: "",
Choices: make([]string, 3),
Choices: make([]Choice, 3),
}},
}

Expand Down Expand Up @@ -403,15 +403,15 @@ func TestSubject_IsValid(t *testing.T) {
Title: Title{En: "", Fr: "", De: ""},
MaxN: 0,
MinN: 0,
Choices: make([]string, 0),
Choices: make([]Choice, 0),
}}

mainSubject.Ranks = []Rank{{
ID: encodedQuestionID(1),
Title: Title{En: "", Fr: "", De: ""},
MaxN: 0,
MinN: 0,
Choices: make([]string, 0),
Choices: make([]Choice, 0),
}}

configuration.Scaffold = []Subject{*mainSubject}
Expand All @@ -426,7 +426,7 @@ func TestSubject_IsValid(t *testing.T) {
Title: Title{En: "", Fr: "", De: ""},
MaxN: 0,
MinN: 2,
Choices: make([]string, 0),
Choices: make([]Choice, 0),
}

configuration.Scaffold = []Subject{*mainSubject}
Expand All @@ -442,7 +442,7 @@ func TestSubject_IsValid(t *testing.T) {
Title: Title{En: "", Fr: "", De: ""},
MaxN: 1,
MinN: 0,
Choices: make([]string, 0),
Choices: make([]Choice, 0),
}

configuration.Scaffold = []Subject{*mainSubject}
Expand All @@ -460,7 +460,7 @@ func TestSubject_IsValid(t *testing.T) {
MinN: 4,
MaxLength: 0,
Regex: "",
Choices: make([]string, 0),
Choices: make([]Choice, 0),
}}

configuration.Scaffold = []Subject{*mainSubject}
Expand Down
2 changes: 1 addition & 1 deletion integration/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func createFormNChunks(m txManager, title types.Title, admin string, numChunks i
MinN: 0,
MaxLength: uint(base64.StdEncoding.DecodedLen(textSize)),
Regex: "",
Choices: []string{"Your fav snack: "},
Choices: []types.Choice{{Choice: "Your fav snack: ", URL: ""}},
}},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/testing/fake/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var BasicConfiguration = types.Configuration{
Title: types.Title{En: "Select your favorite snacks", Fr: "", De: ""},
MaxN: 3,
MinN: 0,
Choices: []string{"snickers", "mars", "vodka", "babibel"},
Choices: []types.Choice{{Choice: "snickers", URL: ""}, {Choice: "mars", URL: ""}, {Choice: "vodka", URL: ""}, {Choice: "babibel", URL: ""}},
},
},
Ranks: []types.Rank{},
Expand All @@ -109,7 +109,7 @@ var BasicConfiguration = types.Configuration{
MinN: 1,
MaxLength: 3,
Regex: "",
Choices: []string{"write yes in your language"},
Choices: []types.Choice{{Choice: "write yes in your language", URL: ""}},
},
},
},
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/language/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"removetext": "Text entfernen",
"subject": "Betreff",
"choices": "Auswahlmöglichkeiten",
"url": "URL",
"answers": "Antworten",
"enterMaxLength": "Geben Sie die MaxLength",
"maxChoices": "Maximale Anzahl von Auswahlmöglichkeiten",
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"removetext": "Remove text",
"subject": "Subject",
"choices": "Choices",
"url": "URL",
"answers": "Answers",
"enterMaxLength": "Enter the MaxLength",
"maxChoices": "Max number of choices",
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/language/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"removetext": "Supprimer le texte",
"subject": "Sujet",
"choices": "Choix",
"url": "URL",
"answers": "Réponses",
"enterMaxLength": "Entrer la longueur max",
"maxChoices": "Max nombre de choix",
Expand Down
79 changes: 43 additions & 36 deletions web/frontend/src/mocks/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const mockForm1: any = {
MaxN: 2,
MinN: 1,
Choices: [
'{"en": "tomato", "fr": "tomate", "de": "Tomate"}',
'{"en": "salad", "fr": "salade", "de": "Salat"}',
'{"en": "onion", "fr": "oignon", "de": "Zwiebel"}',
{ Choice: '{"en": "tomato", "fr": "tomate", "de": "Tomate"}', URL: '' },
{ Choice: '{"en": "salad", "fr": "salade", "de": "Salat"}', URL: '' },
{ Choice: '{"en": "onion", "fr": "oignon", "de": "Zwiebel"}', URL: '' },
],
Hint: { En: '', Fr: '', De: '' },
},
Expand All @@ -69,9 +69,9 @@ const mockForm1: any = {
MaxN: 3,
MinN: 3,
Choices: [
'{"en": "BC", "fr": "BC", "de": "BC"}',
'{"en": "SV", "fr": "SV", "de": "SV"}',
'{"en": "Parmentier", "fr": "Parmentier", "de": "Parmentier"}',
{ Choice: '{"en": "BC", "fr": "BC", "de": "BC"}', URL: '' },
{ Choice: '{"en": "SV", "fr": "SV", "de": "SV"}', URL: '' },
{ Choice: '{"en": "Parmentier", "fr": "Parmentier", "de": "Parmentier"}', URL: '' },
],
Hint: { En: '', Fr: '', De: '' },
},
Expand All @@ -90,11 +90,11 @@ const mockForm1: any = {
MaxN: 1,
MinN: 1,
Choices: [
'{"en":"1" ,"fr": "1", "de": "1"}',
'{"en":"2", "fr": "2", "de": "2"}',
'{"en":"3", "fr": "3", "de": "3"}',
'{"en":"4", "fr": "4", "de": "4"}',
'{ "en": "5", "fr": "5", "de": "5" }',
{ Choice: '{"en":"1" ,"fr": "1", "de": "1"}', URL: '' },
{ Choice: '{"en":"2", "fr": "2", "de": "2"}', URL: '' },
{ Choice: '{"en":"3", "fr": "3", "de": "3"}', URL: '' },
{ Choice: '{"en":"4", "fr": "4", "de": "4"}', URL: '' },
{ Choice: '{ "en": "5", "fr": "5", "de": "5" }', URL: '' },
],
Hint: { En: '', Fr: '', De: '' },
},
Expand All @@ -108,9 +108,9 @@ const mockForm1: any = {
MaxN: 1,
MinN: 1,
Choices: [
'{"en" : "bad", "fr": "mauvais", "de": "schlecht"}',
'{"en" : "normal", "fr": "normal", "de": "durchschnittlich"}',
'{"en" : "good", "fr": "super", "de": "gut"}',
{ Choice: '{"en" : "bad", "fr": "mauvais", "de": "schlecht"}', URL: '' },
{ Choice: '{"en" : "normal", "fr": "normal", "de": "durchschnittlich"}', URL: '' },
{ Choice: '{"en" : "good", "fr": "super", "de": "gut"}', URL: '' },
],
Hint: {
En: 'Be honest. This is anonymous anyway',
Expand All @@ -132,8 +132,8 @@ const mockForm1: any = {
MinN: 1,
Regex: '',
Choices: [
'{"en":"TA1", "fr": "TA1", "de": "TA1"}',
'{"en":"TA2", "fr":"TA2","de": "TA2"}',
{ Choice: '{"en":"TA1", "fr": "TA1", "de": "TA1"}', URL: '' },
{ Choice: '{"en":"TA2", "fr":"TA2","de": "TA2"}', URL: '' },
],
Hint: { En: '', Fr: '', De: '' },
},
Expand Down Expand Up @@ -191,11 +191,11 @@ const mockForm2: any = {
MaxN: 1,
MinN: 1,
Choices: [
'{"en":"1" ,"fr": "1", "de": "1"}',
'{"en":"2", "fr": "2", "de": "2"}',
'{"en":"3", "fr": "3", "de": "3"}',
'{"en":"4", "fr": "4", "de": "4"}',
'{ "en": "5", "fr": "5", "de": "5" }',
{ Choice: '{"en":"1" ,"fr": "1", "de": "1"}', URL: '' },
{ Choice: '{"en":"2", "fr": "2", "de": "2"}', URL: '' },
{ Choice: '{"en":"3", "fr": "3", "de": "3"}', URL: '' },
{ Choice: '{"en":"4", "fr": "4", "de": "4"}', URL: '' },
{ Choice: '{ "en": "5", "fr": "5", "de": "5" }', URL: '' },
],
Hint: { En: '', Fr: '', De: '' },
},
Expand All @@ -212,8 +212,8 @@ const mockForm2: any = {
MaxN: 2,
MinN: 2,
Choices: [
'{"en":"TA1", "fr": "TA1", "de": "TA1"}',
'{"en":"TA2", "fr":"TA2","de": "TA2"}',
{ Choice: '{"en":"TA1", "fr": "TA1", "de": "TA1"}', URL: '' },
{ Choice: '{"en":"TA2", "fr":"TA2","de": "TA2"}', URL: '' },
],
Regex: '^[A-Z][a-z]+$',
Hint: { En: '', Fr: '', De: '' },
Expand All @@ -238,10 +238,10 @@ const mockForm2: any = {
MaxN: 3,
MinN: 0,
Choices: [
'{"en": "tomato", "fr": "tomate", "de": "Tomate"}',
'{"en": "salad", "fr": "salade", "de": "Salat"}',
'{"en": "onion", "fr": "oignon", "de": "Zwiebel"}',
'{"en": "falafel", "fr": "falafel", "de": "Falafel"}',
{ Choice: '{"en": "tomato", "fr": "tomate", "de": "Tomate"}', URL: '' },
{ Choice: '{"en": "salad", "fr": "salade", "de": "Salat"}', URL: '' },
{ Choice: '{"en": "onion", "fr": "oignon", "de": "Zwiebel"}', URL: '' },
{ Choice: '{"en": "falafel", "fr": "falafel", "de": "Falafel"}', URL: '' },
],
Hint: { En: '', Fr: '', De: '' },
},
Expand All @@ -258,10 +258,14 @@ const mockForm2: any = {
MaxN: 4,
MinN: 1,
Choices: [
'{"en": "Esplanade", "fr": "Esplanade", "de": "Esplanade"}',
'{"en": "Giacometti", "fr": "Giacometti", "de": "Giacometti"}',
'{"en": "Arcadie", "fr": "Arcadie", "de": "Arcadie"}',
'{"en": "Montreux Jazz Cafe", "fr": "Montreux Jazz Cafe", "de": "Montreux Jazz Cafe"}',
{ Choice: '{"en": "Esplanade", "fr": "Esplanade", "de": "Esplanade"}', URL: '' },
{ Choice: '{"en": "Giacometti", "fr": "Giacometti", "de": "Giacometti"}', URL: '' },
{ Choice: '{"en": "Arcadie", "fr": "Arcadie", "de": "Arcadie"}', URL: '' },
{
Choice:
'{"en": "Montreux Jazz Cafe", "fr": "Montreux Jazz Cafe", "de": "Montreux Jazz Cafe"}',
URL: '',
},
],
Hint: { En: '', Fr: '', De: '' },
},
Expand All @@ -270,7 +274,10 @@ const mockForm2: any = {
ID: (0xbeef).toString(),
MaxN: 2,
MinN: 1,
Choices: ['{"en": "IN", "fr": "IN", "de": "IN"}', '{"en": "SC", "fr": "SC", "de": "SC"}'],
Choices: [
{ Choice: '{"en": "IN", "fr": "IN", "de": "IN"}', URL: '' },
{ Choice: '{"en": "SC", "fr": "SC", "de": "SC"}', URL: '' },
],
Hint: {
En: 'The right answer is IN ;-)',
Fr: 'La bonne réponse est IN ;-)',
Expand Down Expand Up @@ -310,10 +317,10 @@ const mockForm3: any = {
MaxLength: 50,
Regex: '',
Choices: [
'{"en": "Firstname", "fr": "Prénom", "de": "Firstname"}',
'{"en": "Main 🍕", "fr" : "Principal 🍕", "de": "Main 🍕"}',
'{"en": "Drink 🧃", "fr": "Boisson 🧃", "de": "Drink 🧃"}',
'{"en":"Dessert 🍰", "fr": "Dessert 🍰", "de": "Nachtisch 🍰"}',
{ Choice: '{"en": "Firstname", "fr": "Prénom", "de": "Firstname"}', URL: '' },
{ Choice: '{"en": "Main 🍕", "fr" : "Principal 🍕", "de": "Main 🍕"}', URL: '' },
{ Choice: '{"en": "Drink 🧃", "fr": "Boisson 🧃", "de": "Drink 🧃"}', URL: '' },
{ Choice: '{"en":"Dessert 🍰", "fr": "Dessert 🍰", "de": "Nachtisch 🍰"}', URL: '' },
],
Hint: {
En: 'If you change opinion call me before 11:30 a.m.',
Expand Down
Loading

0 comments on commit af1c47a

Please sign in to comment.