summaryrefslogtreecommitdiff
path: root/actions.go
blob: 0619587ada7ce99ebb36ecb3bb871e4c88ce7f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main

import (
	"fmt"
	"github.com/Masterminds/sprig"
	"os"
	"text/template"
)

func CreateMotion(decision *Decision, voter *Voter) (err error) {
	decision.ProponentId = voter.Id
	err = decision.Save()
	if err != nil {
		logger.Println("Error saving motion:", err)
		return
	}

	type mailContext struct {
		Decision
		Name       string
		Sender     string
		Recipient  string
		VoteURL    string
		UnvotedURL string
	}
	voteURL := fmt.Sprintf("%s/vote", config.BaseURL)
	unvotedURL := fmt.Sprintf("%s/motions/?unvoted=1", config.BaseURL)
	context := mailContext{
		*decision, voter.Name, config.NoticeSenderAddress,
		config.BoardMailAddress, voteURL,
		unvotedURL}

	t, err := template.New("create_motion_mail.txt").Funcs(
		sprig.GenericFuncMap()).ParseFiles("templates/create_motion_mail.txt")
	if err != nil {
		logger.Fatal(err)
	}
	t.Execute(os.Stdout, context)

	// TODO: implement mail sending
	return
}

func WithdrawMotion(decision *Decision, voter *Voter) (err error) {
	// load template, fill name, tag, title, content
	type mailContext struct {
		*Decision
		Name      string
		Sender    string
		Recipient string
	}
	context := mailContext{decision, voter.Name, config.NoticeSenderAddress, config.BoardMailAddress}

	// fill withdraw_mail.txt
	t, err := template.New("withdraw_mail.txt").Funcs(
		sprig.GenericFuncMap()).ParseFiles("templates/withdraw_mail.txt")
	if err != nil {
		logger.Fatal(err)
	}
	// TODO: send mail
	t.Execute(os.Stdout, context)

	// TODO: implement call decision.Close()
	return
}