-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathevents.go
50 lines (38 loc) · 1.07 KB
/
events.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
package api
import (
"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"net/http"
"github.com/gorilla/context"
)
// nolint: gocyclo
func getEvents(w http.ResponseWriter, r *http.Request, limit int) {
user := context.Get(r, "user").(*db.User)
projectObj, exists := context.GetOk(r, "project")
var err error
var events []db.Event
if exists {
project := projectObj.(db.Project)
if !user.Admin { // check permissions to view events
_, err = helpers.Store(r).GetProjectUser(project.ID, user.ID)
}
if err != nil {
helpers.WriteError(w, err)
return
}
events, err = helpers.Store(r).GetEvents(project.ID, db.RetrieveQueryParams{Count: limit})
} else {
events, err = helpers.Store(r).GetUserEvents(user.ID, db.RetrieveQueryParams{Count: limit})
}
if err != nil {
helpers.WriteError(w, err)
return
}
helpers.WriteJSON(w, http.StatusOK, events)
}
func getLastEvents(w http.ResponseWriter, r *http.Request) {
getEvents(w, r, 200)
}
func getAllEvents(w http.ResponseWriter, r *http.Request) {
getEvents(w, r, 0)
}