-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_reviewable_request_show.go
65 lines (58 loc) · 1.67 KB
/
actions_reviewable_request_show.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
package horizon
import (
"gitlab.com/tokend/horizon/db2/history"
"gitlab.com/tokend/horizon/render/hal"
"gitlab.com/tokend/horizon/render/problem"
"gitlab.com/tokend/horizon/resource/reviewablerequest"
)
// ReviewableRequestShowAction renders a reviewable request found by its ID.
type ReviewableRequestShowAction struct {
Action
RequestID uint64
RequestType *int64
Record *history.ReviewableRequest
}
// JSON is a method for actions.JSON
func (action *ReviewableRequestShowAction) JSON() {
action.Do(
action.EnsureHistoryFreshness,
action.loadParams,
action.loadRecord,
action.checkAllowed,
func() {
res, err := reviewablerequest.PopulateReviewableRequest(action.Record)
if err != nil {
action.Log.WithError(err).Error("Failed to populate reviewable request")
action.Err = &problem.ServerError
return
}
if res != nil {
hal.Render(action.W, *res)
}
},
)
}
func (action *ReviewableRequestShowAction) loadParams() {
action.RequestID = action.GetUInt64("id")
action.RequestType = action.GetOptionalInt64("request_type")
}
func (action *ReviewableRequestShowAction) loadRecord() {
var err error
q := action.HistoryQ().ReviewableRequests()
if action.RequestType != nil {
q = q.ForType(*action.RequestType)
}
action.Record, err = q.ByID(action.RequestID)
if err != nil {
action.Log.WithError(err).WithField("request_id", action.RequestID).Error("failed to load reviewable request")
action.Err = &problem.ServerError
return
}
if action.Record == nil {
action.Err = &problem.NotFound
return
}
}
func (action *ReviewableRequestShowAction) checkAllowed() {
action.IsAllowed(action.Record.Requestor, action.Record.Reviewer)
}