This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
handlers_admin.go
172 lines (136 loc) · 4.41 KB
/
handlers_admin.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
package main
import (
"net/http"
"strconv"
"strings"
"github.com/gorilla/mux"
"github.com/spf13/viper"
)
// handleAppStats gets the applications stats
func (s *server) handleAppStats() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
AppStats, err := s.database.GetAppStats()
if err != nil {
http.NotFound(w, r)
return
}
ActiveRetroUserCount := 0
for _, s := range h.arenas {
ActiveRetroUserCount = ActiveRetroUserCount + len(s)
}
AppStats.ActiveRetroCount = len(h.arenas)
AppStats.ActiveRetroUserCount = ActiveRetroUserCount
s.respondWithJSON(w, http.StatusOK, AppStats)
}
}
// handleGetRegisteredUsers gets a list of registered users
func (s *server) handleGetRegisteredUsers() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Limit, _ := strconv.Atoi(vars["limit"])
Offset, _ := strconv.Atoi(vars["offset"])
Users := s.database.GetRegisteredUsers(Limit, Offset)
s.respondWithJSON(w, http.StatusOK, Users)
}
}
// handleUserCreate registers a user as a registered user
func (s *server) handleUserCreate() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
keyVal := s.getJSONRequestBody(r, w)
UserName, UserEmail, UserPassword, accountErr := ValidateUserAccount(
keyVal["userName"].(string),
strings.ToLower(keyVal["userEmail"].(string)),
keyVal["userPassword1"].(string),
keyVal["userPassword2"].(string),
)
if accountErr != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
newUser, VerifyID, err := s.database.CreateUserRegistered(UserName, UserEmail, UserPassword, "")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
s.email.SendWelcome(UserName, UserEmail, VerifyID)
s.respondWithJSON(w, http.StatusOK, newUser)
}
}
// handleUserPromote handles promoting a user to ADMIN by ID
func (s *server) handleUserPromote() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
keyVal := s.getJSONRequestBody(r, w)
err := s.database.PromoteUser(keyVal["userId"].(string))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
return
}
}
// handleUserDemote handles demoting a user to REGISTERED by ID
func (s *server) handleUserDemote() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
keyVal := s.getJSONRequestBody(r, w)
err := s.database.DemoteUser(keyVal["userId"].(string))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
return
}
}
// handleCleanRetrospectives handles cleaning up old retrospectives (ADMIN Manaually Triggered)
func (s *server) handleCleanRetrospectives() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
DaysOld := viper.GetInt("config.cleanup_retrospectives_days_old")
err := s.database.CleanRetrospectives(DaysOld)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
return
}
}
// handleCleanGuests handles cleaning up old guests (ADMIN Manaually Triggered)
func (s *server) handleCleanGuests() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
DaysOld := viper.GetInt("config.cleanup_guests_days_old")
err := s.database.CleanGuests(DaysOld)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
return
}
}
// handleGetOrganizations gets a list of organizations
func (s *server) handleGetOrganizations() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Limit, _ := strconv.Atoi(vars["limit"])
Offset, _ := strconv.Atoi(vars["offset"])
Organizations := s.database.OrganizationList(Limit, Offset)
s.respondWithJSON(w, http.StatusOK, Organizations)
}
}
// handleGetTeams gets a list of teams
func (s *server) handleGetTeams() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Limit, _ := strconv.Atoi(vars["limit"])
Offset, _ := strconv.Atoi(vars["offset"])
Teams := s.database.TeamList(Limit, Offset)
s.respondWithJSON(w, http.StatusOK, Teams)
}
}
// handleGetAPIKeys gets a list of APIKeys
func (s *server) handleGetAPIKeys() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Limit, _ := strconv.Atoi(vars["limit"])
Offset, _ := strconv.Atoi(vars["offset"])
Teams := s.database.GetAPIKeys(Limit, Offset)
s.respondWithJSON(w, http.StatusOK, Teams)
}
}