summaryrefslogtreecommitdiff
blob: 61d77dd64621f2509ba0acbac0a84381a6feba13 (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 archive

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 glsas []*models.Glsa
	err := user.CanAccess(connection.DB.Model(&glsas).
		Where("type = ?", "glsa").
		Relation("Bugs").
		Relation("Creator").
		Relation("Comments")).
		Select()

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

	for _, glsa := range glsas {
		glsa.ComputeStatus(user)
	}

	renderArchiveTemplate(w, user, glsas)
}