|
|
@ -48,6 +48,7 @@ const (
|
|
|
|
subLevelNavMotionsAll subLevelNavItem = "all-motions"
|
|
|
|
subLevelNavMotionsAll subLevelNavItem = "all-motions"
|
|
|
|
subLevelNavMotionsUnvoted subLevelNavItem = "unvoted-motions"
|
|
|
|
subLevelNavMotionsUnvoted subLevelNavItem = "unvoted-motions"
|
|
|
|
subLevelNavUsers subLevelNavItem = "users"
|
|
|
|
subLevelNavUsers subLevelNavItem = "users"
|
|
|
|
|
|
|
|
subLevelNavVoters subLevelNavItem = "manage-voters"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (m *templateData) motionPaginationOptions(limit int, first, last *time.Time) error {
|
|
|
|
func (m *templateData) motionPaginationOptions(limit int, first, last *time.Time) error {
|
|
|
@ -75,12 +76,6 @@ func (m *templateData) motionPaginationOptions(limit int, first, last *time.Time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path != "/motions/" {
|
|
|
|
|
|
|
|
app.notFound(w)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
listOptions *models.MotionListOptions
|
|
|
|
listOptions *models.MotionListOptions
|
|
|
|
err error
|
|
|
|
err error
|
|
|
@ -97,16 +92,12 @@ func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
motions, err := app.motions.List(ctx, listOptions)
|
|
|
|
motions, err := app.motions.List(ctx, listOptions)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
first, last, err := app.motions.TimestampRange(ctx, listOptions)
|
|
|
|
first, last, err := app.motions.TimestampRange(ctx, listOptions)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
templateData := app.newTemplateData(r, "motions", "all-motions")
|
|
|
|
templateData := app.newTemplateData(r, "motions", "all-motions")
|
|
|
@ -119,9 +110,7 @@ func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
err = templateData.motionPaginationOptions(listOptions.Limit, first, last)
|
|
|
|
err = templateData.motionPaginationOptions(listOptions.Limit, first, last)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusOK, "motions.html", templateData)
|
|
|
|
app.render(w, http.StatusOK, "motions.html", templateData)
|
|
|
@ -207,17 +196,21 @@ func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
if !form.Valid() {
|
|
|
|
data := app.newTemplateData(r, topLevelNavMotions, subLevelNavMotionsAll)
|
|
|
|
data := app.newTemplateData(r, topLevelNavMotions, subLevelNavMotionsAll)
|
|
|
|
data.Form = form
|
|
|
|
data.Form = &form
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "create_motion.html", data)
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "create_motion.html", data)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form.Normalize()
|
|
|
|
|
|
|
|
|
|
|
|
user, err := app.GetUser(r)
|
|
|
|
user, err := app.GetUser(r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.clientError(w, http.StatusUnauthorized)
|
|
|
|
app.clientError(w, http.StatusUnauthorized)
|
|
|
@ -238,16 +231,12 @@ func (app *application) newMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
now.Add(dueDuration),
|
|
|
|
now.Add(dueDuration),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decision, err := app.motions.ByID(r.Context(), decisionID)
|
|
|
|
decision, err := app.motions.ByID(r.Context(), decisionID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.mailNotifier.Notify(&NewDecisionNotification{
|
|
|
|
app.mailNotifier.Notify(&NewDecisionNotification{
|
|
|
@ -300,11 +289,13 @@ func (app *application) editMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
if !form.Valid() {
|
|
|
|
data := app.newTemplateData(r, topLevelNavMotions, subLevelNavMotionsAll)
|
|
|
|
data := app.newTemplateData(r, topLevelNavMotions, subLevelNavMotionsAll)
|
|
|
|
data.Form = form
|
|
|
|
data.Form = &form
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "edit_motion.html", data)
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "edit_motion.html", data)
|
|
|
|
|
|
|
|
|
|
|
@ -334,16 +325,12 @@ func (app *application) editMotionSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decision, err := app.motions.ByID(r.Context(), motion.ID)
|
|
|
|
decision, err := app.motions.ByID(r.Context(), motion.ID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.mailNotifier.Notify(&UpdateDecisionNotification{
|
|
|
|
app.mailNotifier.Notify(&UpdateDecisionNotification{
|
|
|
@ -395,9 +382,7 @@ func (app *application) withdrawMotionSubmit(w http.ResponseWriter, r *http.Requ
|
|
|
|
err = app.motions.Withdraw(r.Context(), motion.ID)
|
|
|
|
err = app.motions.Withdraw(r.Context(), motion.ID)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.mailNotifier.Notify(&WithDrawMotionNotification{motion, user})
|
|
|
|
app.mailNotifier.Notify(&WithDrawMotionNotification{motion, user})
|
|
|
@ -459,9 +444,7 @@ func (app *application) voteSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
clientCert, err := getPEMClientCert(r)
|
|
|
|
clientCert, err := getPEMClientCert(r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := app.motions.UpdateVote(r.Context(), user.ID, motion.ID, func(v *models.Vote) {
|
|
|
|
if err := app.motions.UpdateVote(r.Context(), user.ID, motion.ID, func(v *models.Vote) {
|
|
|
@ -469,9 +452,7 @@ func (app *application) voteSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v.Voted = time.Now().UTC()
|
|
|
|
v.Voted = time.Now().UTC()
|
|
|
|
v.Notes = fmt.Sprintf("Direct Vote\n\n%s", clientCert)
|
|
|
|
v.Notes = fmt.Sprintf("Direct Vote\n\n%s", clientCert)
|
|
|
|
}); err != nil {
|
|
|
|
}); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.mailNotifier.Notify(&DirectVoteNotification{
|
|
|
|
app.mailNotifier.Notify(&DirectVoteNotification{
|
|
|
@ -499,9 +480,7 @@ func (app *application) proxyVoteForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
potentialVoters, err := app.users.Voters(r.Context())
|
|
|
|
potentialVoters, err := app.users.Voters(r.Context())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data.Form = &forms.ProxyVoteForm{
|
|
|
|
data.Form = &forms.ProxyVoteForm{
|
|
|
@ -526,7 +505,9 @@ func (app *application) proxyVoteSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
if !form.Valid() {
|
|
|
|
data := app.newTemplateData(r, topLevelNavMotions, subLevelNavMotionsAll)
|
|
|
|
data := app.newTemplateData(r, topLevelNavMotions, subLevelNavMotionsAll)
|
|
|
@ -534,13 +515,11 @@ func (app *application) proxyVoteSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
|
|
|
|
|
|
potentialVoters, err := app.users.Voters(r.Context())
|
|
|
|
potentialVoters, err := app.users.Voters(r.Context())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
form.Voters = potentialVoters
|
|
|
|
form.Voters = potentialVoters
|
|
|
|
data.Form = form
|
|
|
|
data.Form = &form
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "proxy_vote.html", data)
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "proxy_vote.html", data)
|
|
|
|
|
|
|
|
|
|
|
@ -558,9 +537,7 @@ func (app *application) proxyVoteSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
|
|
|
|
|
|
clientCert, err := getPEMClientCert(r)
|
|
|
|
clientCert, err := getPEMClientCert(r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
voter := app.getVoter(w, r, form.Voter.ID)
|
|
|
|
voter := app.getVoter(w, r, form.Voter.ID)
|
|
|
@ -573,9 +550,7 @@ func (app *application) proxyVoteSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
v.Voted = time.Now().UTC()
|
|
|
|
v.Voted = time.Now().UTC()
|
|
|
|
v.Notes = fmt.Sprintf("Proxy-Vote by %s\n\n%s\n\n%s", user.Name, form.Justification, clientCert)
|
|
|
|
v.Notes = fmt.Sprintf("Proxy-Vote by %s\n\n%s\n\n%s", user.Name, form.Justification, clientCert)
|
|
|
|
}); err != nil {
|
|
|
|
}); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.mailNotifier.Notify(&ProxyVoteNotification{
|
|
|
|
app.mailNotifier.Notify(&ProxyVoteNotification{
|
|
|
@ -604,9 +579,7 @@ func (app *application) userList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
app.users.CanDelete(),
|
|
|
|
app.users.CanDelete(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data.Users = users
|
|
|
|
data.Users = users
|
|
|
@ -622,16 +595,12 @@ func (app *application) editUserForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
roles, err := userToEdit.Roles()
|
|
|
|
roles, err := userToEdit.Roles()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
roleNames := make([]string, len(roles))
|
|
|
|
roleNames := make([]string, len(roles))
|
|
|
@ -673,9 +642,7 @@ func (app *application) editUserSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
form.AllRoles = models.AllRoles
|
|
|
|
form.AllRoles = models.AllRoles
|
|
|
|
|
|
|
|
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
@ -683,16 +650,12 @@ func (app *application) editUserSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !form.Valid() {
|
|
|
|
if !form.Valid() {
|
|
|
|
roles, err := userToEdit.Roles()
|
|
|
|
roles, err := userToEdit.Roles()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
roleNames := make([]string, len(roles))
|
|
|
|
roleNames := make([]string, len(roles))
|
|
|
@ -714,9 +677,7 @@ func (app *application) editUserSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
form.UpdateUser(userToEdit)
|
|
|
|
form.UpdateUser(userToEdit)
|
|
|
|
|
|
|
|
|
|
|
|
if err := app.users.EditUser(r.Context(), userToEdit, data.User, form.Roles, form.Reasoning); err != nil {
|
|
|
|
if err := app.users.EditUser(r.Context(), userToEdit, data.User, form.Roles, form.Reasoning); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
@ -738,9 +699,7 @@ func (app *application) userAddEmailForm(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
|
|
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
@ -771,16 +730,16 @@ func (app *application) userAddEmailSubmit(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
|
|
|
|
|
|
|
form.User = userToEdit
|
|
|
|
form.User = userToEdit
|
|
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
|
|
|
|
|
|
|
|
if form.Valid() {
|
|
|
|
if form.Valid() {
|
|
|
|
emailExists, err := app.users.EmailExists(r.Context(), form.EmailAddress)
|
|
|
|
emailExists, err := app.users.EmailExists(r.Context(), form.EmailAddress)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if emailExists {
|
|
|
|
if emailExists {
|
|
|
@ -793,9 +752,7 @@ func (app *application) userAddEmailSubmit(w http.ResponseWriter, r *http.Reques
|
|
|
|
if !form.Valid() {
|
|
|
|
if !form.Valid() {
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
emailAddresses, err := userToEdit.EmailAddresses()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
form.EmailAddresses = emailAddresses
|
|
|
|
form.EmailAddresses = emailAddresses
|
|
|
@ -810,9 +767,7 @@ func (app *application) userAddEmailSubmit(w http.ResponseWriter, r *http.Reques
|
|
|
|
form.Normalize()
|
|
|
|
form.Normalize()
|
|
|
|
|
|
|
|
|
|
|
|
if err := app.users.AddEmail(r.Context(), userToEdit, data.User, form.EmailAddress, form.Reasoning); err != nil {
|
|
|
|
if err := app.users.AddEmail(r.Context(), userToEdit, data.User, form.EmailAddress, form.Reasoning); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
@ -831,9 +786,7 @@ func (app *application) userAddEmailSubmit(w http.ResponseWriter, r *http.Reques
|
|
|
|
func (app *application) userDeleteEmailForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (app *application) userDeleteEmailForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
userToEdit, emailAddress, err := app.deleteEmailParams(w, r)
|
|
|
|
userToEdit, emailAddress, err := app.deleteEmailParams(w, r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if userToEdit == nil || emailAddress == "" {
|
|
|
|
if userToEdit == nil || emailAddress == "" {
|
|
|
@ -862,9 +815,7 @@ func (app *application) userDeleteEmailForm(w http.ResponseWriter, r *http.Reque
|
|
|
|
func (app *application) userDeleteEmailSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (app *application) userDeleteEmailSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
userToEdit, emailAddress, err := app.deleteEmailParams(w, r)
|
|
|
|
userToEdit, emailAddress, err := app.deleteEmailParams(w, r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if userToEdit == nil || emailAddress == "" {
|
|
|
|
if userToEdit == nil || emailAddress == "" {
|
|
|
@ -895,7 +846,9 @@ func (app *application) userDeleteEmailSubmit(w http.ResponseWriter, r *http.Req
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
if !form.Valid() {
|
|
|
|
form.EmailAddress = emailAddress
|
|
|
|
form.EmailAddress = emailAddress
|
|
|
@ -903,7 +856,7 @@ func (app *application) userDeleteEmailSubmit(w http.ResponseWriter, r *http.Req
|
|
|
|
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
|
|
|
|
|
|
|
|
data.Form = form
|
|
|
|
data.Form = &form
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "delete_email.html", data)
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "delete_email.html", data)
|
|
|
|
|
|
|
|
|
|
|
@ -913,9 +866,7 @@ func (app *application) userDeleteEmailSubmit(w http.ResponseWriter, r *http.Req
|
|
|
|
form.Normalize()
|
|
|
|
form.Normalize()
|
|
|
|
|
|
|
|
|
|
|
|
if err := app.users.DeleteEmail(r.Context(), userToEdit, admin, emailAddress, form.Reasoning); err != nil {
|
|
|
|
if err := app.users.DeleteEmail(r.Context(), userToEdit, admin, emailAddress, form.Reasoning); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
@ -931,14 +882,66 @@ func (app *application) userDeleteEmailSubmit(w http.ResponseWriter, r *http.Req
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/users/%d/", userToEdit.ID), http.StatusSeeOther)
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/users/%d/", userToEdit.ID), http.StatusSeeOther)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) newUserForm(_ http.ResponseWriter, _ *http.Request) {
|
|
|
|
func (app *application) newUserForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// TODO: implement newUserForm
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
panic("not implemented")
|
|
|
|
|
|
|
|
|
|
|
|
data.Form = &forms.NewUserForm{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusOK, "create_user.html", data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) newUserSubmit(_ http.ResponseWriter, _ *http.Request) {
|
|
|
|
func (app *application) newUserSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// TODO: implement newUserSubmit
|
|
|
|
admin, err := app.GetUser(r)
|
|
|
|
panic("not implemented")
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.clientError(w, http.StatusUnauthorized)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var form forms.NewUserForm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := app.decodePostForm(r, &form); err != nil {
|
|
|
|
|
|
|
|
app.clientError(w, http.StatusBadRequest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.Form = &form
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "create_user.html", data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form.Normalize()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createUserParams := &models.CreateUserParams{
|
|
|
|
|
|
|
|
Admin: admin,
|
|
|
|
|
|
|
|
Name: form.Name,
|
|
|
|
|
|
|
|
Reminder: form.EmailAddress,
|
|
|
|
|
|
|
|
Emails: []string{form.EmailAddress},
|
|
|
|
|
|
|
|
Reasoning: form.Reasoning,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userID, err := app.users.Create(r.Context(), createUserParams)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
|
|
|
|
|
Variant: flashSuccess,
|
|
|
|
|
|
|
|
Title: "User created",
|
|
|
|
|
|
|
|
Message: fmt.Sprintf("Created new user %s", form.Name),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/users/%d", userID), http.StatusSeeOther)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) deleteUserForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (app *application) deleteUserForm(w http.ResponseWriter, r *http.Request) {
|
|
|
@ -985,7 +988,9 @@ func (app *application) deleteUserSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
|
|
|
|
|
|
form.User = userToDelete
|
|
|
|
form.User = userToDelete
|
|
|
|
|
|
|
|
|
|
|
|
form.Validate()
|
|
|
|
if err := form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavUsers)
|
|
|
|
|
|
|
|
|
|
|
@ -1000,9 +1005,7 @@ func (app *application) deleteUserSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
form.Normalize()
|
|
|
|
form.Normalize()
|
|
|
|
|
|
|
|
|
|
|
|
if err = app.users.DeleteUser(r.Context(), userToDelete, data.User, form.Reasoning); err != nil {
|
|
|
|
if err = app.users.DeleteUser(r.Context(), userToDelete, data.User, form.Reasoning); err != nil {
|
|
|
|
app.serverError(w, err)
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
@ -1014,6 +1017,89 @@ func (app *application) deleteUserSubmit(w http.ResponseWriter, r *http.Request)
|
|
|
|
http.Redirect(w, r, "/users/", http.StatusSeeOther)
|
|
|
|
http.Redirect(w, r, "/users/", http.StatusSeeOther)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) chooseVotersForm(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavVoters)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allUsers, err := app.users.List(r.Context(), app.users.WithRoles())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
voterIDs := make([]int64, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, user := range allUsers {
|
|
|
|
|
|
|
|
isVoter, err := user.HasRole(models.RoleVoter)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isVoter {
|
|
|
|
|
|
|
|
voterIDs = append(voterIDs, user.ID)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.Form = &forms.ChooseVoterForm{
|
|
|
|
|
|
|
|
Users: allUsers,
|
|
|
|
|
|
|
|
VoterIDs: voterIDs,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusOK, "choose_voters.html", data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) chooseVotersSubmit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
admin, err := app.GetUser(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.clientError(w, http.StatusUnauthorized)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var form forms.ChooseVoterForm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = app.decodePostForm(r, &form); err != nil {
|
|
|
|
|
|
|
|
app.clientError(w, http.StatusBadRequest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = form.Validate(); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !form.Valid() {
|
|
|
|
|
|
|
|
data := app.newTemplateData(r, topLevelNavUsers, subLevelNavVoters)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allUsers, err := app.users.List(r.Context(), app.users.WithRoles())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form.Users = allUsers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.Form = &form
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusUnprocessableEntity, "choose_voters.html", data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form.Normalize()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = app.users.ChooseVoters(r.Context(), admin, form.VoterIDs, form.Reasoning); err != nil {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.addFlash(r, &FlashMessage{
|
|
|
|
|
|
|
|
Variant: flashSuccess,
|
|
|
|
|
|
|
|
Title: "Voters selected",
|
|
|
|
|
|
|
|
Message: "A new list of voters has been selected",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http.Redirect(w, r, "/users/", http.StatusSeeOther)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) healthCheck(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
func (app *application) healthCheck(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
ok = "OK"
|
|
|
|
ok = "OK"
|
|
|
|