0619587ada7ce99ebb36ecb3bb871e4c88ce7f8f
[cacert-boardvoting.git] / actions.go
1 package main
2
3 import (
4 "fmt"
5 "github.com/Masterminds/sprig"
6 "os"
7 "text/template"
8 )
9
10 func CreateMotion(decision *Decision, voter *Voter) (err error) {
11 decision.ProponentId = voter.Id
12 err = decision.Save()
13 if err != nil {
14 logger.Println("Error saving motion:", err)
15 return
16 }
17
18 type mailContext struct {
19 Decision
20 Name string
21 Sender string
22 Recipient string
23 VoteURL string
24 UnvotedURL string
25 }
26 voteURL := fmt.Sprintf("%s/vote", config.BaseURL)
27 unvotedURL := fmt.Sprintf("%s/motions/?unvoted=1", config.BaseURL)
28 context := mailContext{
29 *decision, voter.Name, config.NoticeSenderAddress,
30 config.BoardMailAddress, voteURL,
31 unvotedURL}
32
33 t, err := template.New("create_motion_mail.txt").Funcs(
34 sprig.GenericFuncMap()).ParseFiles("templates/create_motion_mail.txt")
35 if err != nil {
36 logger.Fatal(err)
37 }
38 t.Execute(os.Stdout, context)
39
40 // TODO: implement mail sending
41 return
42 }
43
44 func WithdrawMotion(decision *Decision, voter *Voter) (err error) {
45 // load template, fill name, tag, title, content
46 type mailContext struct {
47 *Decision
48 Name string
49 Sender string
50 Recipient string
51 }
52 context := mailContext{decision, voter.Name, config.NoticeSenderAddress, config.BoardMailAddress}
53
54 // fill withdraw_mail.txt
55 t, err := template.New("withdraw_mail.txt").Funcs(
56 sprig.GenericFuncMap()).ParseFiles("templates/withdraw_mail.txt")
57 if err != nil {
58 logger.Fatal(err)
59 }
60 // TODO: send mail
61 t.Execute(os.Stdout, context)
62
63 // TODO: implement call decision.Close()
64 return
65 }