-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers_ex.go
293 lines (217 loc) · 8.91 KB
/
handlers_ex.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package main
import (
"jutra/router"
sm "jutra/session"
"net/http"
"sort"
"strconv"
)
type BranchesFilter struct {
LabelTemplate string
}
func (f *BranchesFilter) HasSomethingToFilter() bool {
return f.LabelTemplate != ""
}
func extractBranchesFilter(r *http.Request) *BranchesFilter {
filter := new(BranchesFilter)
lblTemplate := r.URL.Query().Get("label")
if lblTemplate != "" {
filter.LabelTemplate = lblTemplate
}
return filter
}
func serveMainPage(context *router.HttpContext) {
projects := DAO.GetAllProjects()
var ro MainPageRO
ro.Projects = projects
RenderInCommonTemplateEx(context, ro, "main_page.tmpl")
}
func serveProject(context *router.HttpContext) {
projectIdStr := context.PathParams["projectId"]
var projectId int64
if projectIdStr == "" {
// Get ID of default project
projectId = DAO.GetProjectIdByProjectName("")
} else {
projectId = ParseInt64(projectIdStr, "Invalid project ID")
}
filter := extractBranchesFilter(context.Req)
branches := DAO.GetAllBranchesInfo(projectId, filter)
sort.Sort(sort.Reverse(SortableSlice(branches)))
sort.Reverse(SortableSlice(branches))
RenderInCommonTemplateEx(context, branches, "list_branches.tmpl")
}
func serveFilterBranches(context *router.HttpContext) {
RenderInCommonTemplateEx(context, nil, "filter_branches.tmpl")
}
func serveLaunchesInBranchEx(context *router.HttpContext) {
branchIdStr := context.Req.URL.Query().Get("branchId")
branchId := ParseInt64(branchIdStr, "Wrong branch ID")
launches := DAO.GetAllLaunchesInBranch(branchId)
RenderInCommonTemplateEx(context, launches, "view_branch.tmpl")
}
func serverLaunchEx(context *router.HttpContext) {
launchIdParam := context.Req.URL.Query().Get("launch_id")
launchId := ParseInt64(launchIdParam, "Invalid test run ID")
testCases := DAO.GetAllTestsForLaunch(launchId)
launchInfo := DAO.GetLaunchInfo(launchId)
var dto ViewLaunchDTO
dto.LaunchId = launchId
dto.BranchId = launchInfo.BranchId
dto.Label = launchInfo.Label
dto.Tests = testCases
dto.FailedTestsNum = TestsWithStatusNum(dto.Tests, TEST_CASE_STATUS_FAILED)
dto.PassedTestsNum = TestsWithStatusNum(dto.Tests, TEST_CASE_STATUS_PASSED)
dto.SkippedTestsNum = TestsWithStatusNum(dto.Tests, TEST_CASE_STATUS_SKIPPED)
RenderInCommonTemplateEx(context, dto, "view_launch.tmpl")
}
func servePackageEx(context *router.HttpContext) {
launchIdParam := context.Req.URL.Query().Get("launch_id")
launchId := ParseInt64(launchIdParam, "Invalid test run ID")
packageParam := context.Req.URL.Query().Get("package")
if packageParam == "" {
http.Error(context.Resp, "package should be specified", http.StatusInternalServerError)
return
}
testCases := DAO.GetAllTestsForPackage(int64(launchId), packageParam)
var dto ViewPackageDTO
dto.LaunchId = launchId
dto.Package = packageParam
dto.Tests = testCases
RenderInCommonTemplateEx(context, dto, "view_package.tmpl")
}
func serverLaunchPackagesEx(context *router.HttpContext) {
launchIdParam := context.Req.URL.Query().Get("launch_id")
launchId := ParseInt64(launchIdParam, "Invalid test run ID")
packages := DAO.GetPackagesForLaunch(int64(launchId))
var dto PackagesDTO
dto.LaunchId = launchId
dto.Packages = packages
RenderInCommonTemplateEx(context, dto, "view_packages.tmpl")
}
func serverTestCaseEx(context *router.HttpContext) {
testCaseIdParam := context.Req.URL.Query().Get("test_id")
testCaseId := ParseInt64(testCaseIdParam, "Invalid test ID")
testCase := DAO.GetTestCaseDetails(int64(testCaseId))
RenderInCommonTemplateEx(context, testCase, "view_test_case.tmpl")
}
func serverTestDymanicsEx(context *router.HttpContext) {
testCaseIdParam := context.Req.URL.Query().Get("test_id")
testCaseId := ParseInt64(testCaseIdParam, "Invalid test ID")
tests := DAO.GetTestDynamics(testCaseId)
RenderInCommonTemplateEx(context, tests, "test_dynamics.tmpl")
}
func serveDiffLaunchesEx(context *router.HttpContext) {
launchId1Param := context.Req.URL.Query().Get("launch_id1")
launchId1 := ParseInt64(launchId1Param, "Invalid left test run ID")
launchId2Param := context.Req.URL.Query().Get("launch_id2")
launchId2 := ParseInt64(launchId2Param, "Invalid right test run ID")
var dto LaunchesDiffDTO
dto.LaunchId1 = launchId1
dto.LaunchId2 = launchId2
dto.AddedTests = DAO.GetAddedTestsInDiff(int64(launchId1), int64(launchId2))
dto.RemovedTests = DAO.GetAddedTestsInDiff(int64(launchId2), int64(launchId1))
dto.PassedToFailedTests = DAO.GetTestsFromStatus1ToStatus2(int64(launchId1), int64(launchId2), TEST_CASE_STATUS_PASSED, TEST_CASE_STATUS_FAILED)
dto.PassedToSkippedTests = DAO.GetTestsFromStatus1ToStatus2(int64(launchId1), int64(launchId2), TEST_CASE_STATUS_PASSED, TEST_CASE_STATUS_SKIPPED)
dto.FailedToPassedTests = DAO.GetTestsFromStatus1ToStatus2(int64(launchId1), int64(launchId2), TEST_CASE_STATUS_FAILED, TEST_CASE_STATUS_PASSED)
dto.FailedToSkippedTests = DAO.GetTestsFromStatus1ToStatus2(int64(launchId1), int64(launchId2), TEST_CASE_STATUS_FAILED, TEST_CASE_STATUS_SKIPPED)
dto.SkippedToFailedTests = DAO.GetTestsFromStatus1ToStatus2(int64(launchId1), int64(launchId2), TEST_CASE_STATUS_SKIPPED, TEST_CASE_STATUS_FAILED)
dto.SkippedToPassedTests = DAO.GetTestsFromStatus1ToStatus2(int64(launchId1), int64(launchId2), TEST_CASE_STATUS_SKIPPED, TEST_CASE_STATUS_PASSED)
RenderInCommonTemplateEx(context, dto, "view_launches_diff.tmpl")
}
func serveDeleteLaunchEx(context *router.HttpContext) {
session := context.Session
if !session.IsLoggedIn() {
errDto := HttpErrDTO{Code: 403, Message: "No permissions"}
RenderInCommonTemplateEx(context, errDto, "error.tmpl")
return
}
launchIdParam := context.Req.URL.Query().Get("launch_id")
launchId := ParseInt64(launchIdParam, "Invalid test run ID")
launchInfo := DAO.GetLaunchInfo(int64(launchId))
if launchInfo == nil {
http.Error(context.Resp, "Unable to find launch "+launchIdParam, http.StatusBadRequest)
return
}
err := DAO.DeleteLaunch(int64(launchId))
if err != nil {
daoErr := HttpErrDTO{Code: http.StatusInternalServerError, Message: err.Error()}
RenderInCommonTemplateEx(context, daoErr, "error.tmpl")
return
}
// TODO : Find why orphans tests occure after launche is deleted
DAO.DeleteOrphans()
http.Redirect(context.Resp, context.Req, "/branch?branchId="+strconv.FormatInt(launchInfo.BranchId, 10), http.StatusMovedPermanently)
}
func serveDeleteThisAndPreviousLaunch(context *router.HttpContext) {
session := context.Session
if !session.IsLoggedIn() {
errDto := HttpErrDTO{Code: 403, Message: "No permissions"}
RenderInCommonTemplateEx(context, errDto, "error.tmpl")
return
}
launchIdParam := context.Req.URL.Query().Get("launch_id")
launchId := ParseInt64(launchIdParam, "Invalid launch id")
launchInfo := DAO.GetLaunchInfo(launchId)
if launchInfo == nil {
http.Error(context.Resp, "Can't find run", http.StatusBadRequest)
return
}
DAO.DeleteGivenLaunchWithAllPrevious(launchId)
// TODO : Find why orphans tests occure after launche is deleted
DAO.DeleteOrphans()
http.Redirect(context.Resp, context.Req, "/branch?branchId="+strconv.FormatInt(launchInfo.BranchId, 10), http.StatusMovedPermanently)
//http.Redirect(context.Resp, context.Req, "/", http.StatusMovedPermanently)
}
func serveDeleteBranch(context *router.HttpContext) {
session := context.Session
if !session.IsLoggedIn() {
errDto := HttpErrDTO{Code: 403, Message: "No permissions"}
RenderInCommonTemplateEx(context, errDto, "error.tmpl")
return
}
branchIdStr := context.PathParams["branchId"]
branchId := ParseInt64(branchIdStr, "Invalid branch ID")
projectId, err := DAO.GetParentProjectForBranch(branchId)
if err != nil {
http.Error(context.Resp, "Can't find project for given branch ID", http.StatusBadRequest)
return
}
DAO.DeleteAllLaunchesInBranch(branchId)
// TODO : Find why orphans tests occure after launche is deleted
DAO.DeleteOrphans()
http.Redirect(context.Resp, context.Req, "/project/"+strconv.FormatInt(projectId, 10), http.StatusMovedPermanently)
}
func handleLoginEx(context *router.HttpContext) {
session := context.Session
if session.IsLoggedIn() {
http.Redirect(context.Resp, context.Req, "/", http.StatusFound)
return
}
if context.Req.Method != "POST" {
RenderInCommonTemplateEx(context, nil, "login.tmpl")
return
}
login := context.Req.FormValue("login")
password := context.Req.FormValue("password")
userInfo := DAO.FindUser(login, password)
errMsg := ""
if login == "" {
} else if userInfo == nil {
errMsg = "Can't find user with login " + login
} else if userInfo.Password != password {
errMsg = "Wrong password"
}
if login == "" || errMsg != "" {
RenderInCommonTemplateEx(context, errMsg, "login.tmpl")
return
}
sm.InitSession(context.Resp, userInfo)
context.Resp.Header().Set("Cache-Control", "no-cache")
context.Resp.Header().Set("Pragma", "no-cache")
http.Redirect(context.Resp, context.Req, "/", http.StatusFound)
}
func handleLogoutEx(context *router.HttpContext) {
sm.ClearSession(context.Req, context.Resp)
http.Redirect(context.Resp, context.Req, "/login", http.StatusFound)
}