Stat repo scoping
Statistical queries are now scoped to repos that user have access to
This commit is contained in:
+4
-4
@@ -6,25 +6,25 @@ import (
|
||||
"github.com/localhots/empact/db"
|
||||
)
|
||||
|
||||
func apiOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiUserOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, _ := parseRequest(w, r)
|
||||
orgs := db.UserOrgs(req.login)
|
||||
req.respondWith(orgs)
|
||||
}
|
||||
|
||||
func apiTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiOrgTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
teams := db.OrgTeams(stat.Org)
|
||||
req.respondWith(teams)
|
||||
}
|
||||
|
||||
func apiUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiOrgUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
users := db.OrgUsers(stat.Org)
|
||||
req.respondWith(users)
|
||||
}
|
||||
|
||||
func apiReposHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiOrgReposHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
repos := db.OrgRepos(stat.Org)
|
||||
req.respondWith(repos)
|
||||
|
||||
+8
-1
@@ -41,7 +41,14 @@ func parseRequest(w http.ResponseWriter, r *http.Request) (*request, *statReques
|
||||
token: token,
|
||||
login: login,
|
||||
}
|
||||
return req, parseStatRequest(r)
|
||||
sr := parseStatRequest(r)
|
||||
|
||||
// XXX: Hack for demo account
|
||||
if req.login == "" {
|
||||
req.login = "andrewarrow"
|
||||
}
|
||||
|
||||
return req, sr
|
||||
}
|
||||
|
||||
func (r *request) authorize(token, login string) {
|
||||
|
||||
+4
-4
@@ -22,10 +22,10 @@ func init() {
|
||||
http.HandleFunc("/auth/callback", authCallbackHandler)
|
||||
|
||||
http.HandleFunc("/api/", authHandler)
|
||||
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
||||
http.HandleFunc("/api/teams", apiTeamsHandler)
|
||||
http.HandleFunc("/api/users", apiUsersHandler)
|
||||
http.HandleFunc("/api/repos", apiReposHandler)
|
||||
http.HandleFunc("/api/orgs", apiUserOrgsHandler)
|
||||
http.HandleFunc("/api/teams", apiOrgTeamsHandler)
|
||||
http.HandleFunc("/api/users", apiOrgUsersHandler)
|
||||
http.HandleFunc("/api/repos", apiOrgReposHandler)
|
||||
http.HandleFunc("/api/weeks", apiOrgWeekRangeHandler)
|
||||
|
||||
http.HandleFunc("/api/stat/orgs/top", statOrgTopHandler)
|
||||
|
||||
+8
-8
@@ -9,48 +9,48 @@ import (
|
||||
|
||||
func statOrgTopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatOrgTop(structs.Map(stat))
|
||||
top := db.StatOrgTop(req.login, structs.Map(stat))
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
func statOrgActivityHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
activity := db.StatOrgActivity(structs.Map(stat))
|
||||
activity := db.StatOrgActivity(req.login, structs.Map(stat))
|
||||
req.respondWith(activity)
|
||||
}
|
||||
|
||||
func statTeamTopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatTeamTop(structs.Map(stat))
|
||||
top := db.StatTeamTop(req.login, structs.Map(stat))
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
func statTeamActivityHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
activity := db.StatTeamActivity(structs.Map(stat))
|
||||
activity := db.StatTeamActivity(req.login, structs.Map(stat))
|
||||
req.respondWith(activity)
|
||||
}
|
||||
|
||||
func statUserTopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatUserTop(structs.Map(stat))
|
||||
top := db.StatUserTop(req.login, structs.Map(stat))
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
func statUserActivityHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
activity := db.StatUserActivity(structs.Map(stat))
|
||||
activity := db.StatUserActivity(req.login, structs.Map(stat))
|
||||
req.respondWith(activity)
|
||||
}
|
||||
|
||||
func statRepoTopHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
top := db.StatRepoTop(structs.Map(stat))
|
||||
top := db.StatRepoTop(req.login, structs.Map(stat))
|
||||
req.respondWith(top)
|
||||
}
|
||||
|
||||
func statRepoActivityHandler(w http.ResponseWriter, r *http.Request) {
|
||||
req, stat := parseRequest(w, r)
|
||||
activity := db.StatRepoActivity(structs.Map(stat))
|
||||
activity := db.StatRepoActivity(req.login, structs.Map(stat))
|
||||
req.respondWith(activity)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user