summaryrefslogtreecommitdiff
blob: cfc699f245f76344a934420e925e3a7d2c22ea2e (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
// Used to show the landing page of the application

package drafts

import (
	"glsamaker/pkg/app/handler/authentication"
	"glsamaker/pkg/app/handler/authentication/utils"
	"glsamaker/pkg/database/connection"
	"glsamaker/pkg/logger"
	"glsamaker/pkg/models"
	"net/http"
)

// Show renders a template to show the landing page of the application
func Show(w http.ResponseWriter, r *http.Request) {

	user := utils.GetAuthenticatedUser(r)

	if !user.Permissions.Glsa.View {
		authentication.AccessDenied(w, r)
		return
	}

	var drafts []*models.Glsa
	err := user.CanAccess(connection.DB.Model(&drafts).
		Where("type = ?", "draft").
		Relation("Bugs").
		Relation("Creator").
		Relation("Comments")).
		Select()

	if err != nil {
		logger.Info.Println("Error during draft selection")
		logger.Info.Println(err)
		http.NotFound(w, r)
		return
	}

	for _, draft := range drafts {
		draft.ComputeStatus(user)
	}

	renderDraftsTemplate(w, user, drafts)
}