Add admin UI listing all users.

This commit is contained in:
Mihai Parparita 2014-11-08 15:28:15 -08:00
parent d3655c14db
commit 0157ac3c46
3 changed files with 44 additions and 10 deletions

View file

@ -56,7 +56,8 @@ func init() {
router.HandleFunc("/account/set-initial-timezone", setInitialTimezoneHandler).Name("set-initial-timezone").Methods("POST")
router.HandleFunc("/account/delete", deleteAccountHandler).Name("delete-account").Methods("POST")
router.HandleFunc("/admin/digest", digestAdminHandler)
router.HandleFunc("/admin/users", usersAdminHandler)
router.HandleFunc("/admin/digest", digestAdminHandler).Name("digest-admin")
http.Handle("/", router)
}
@ -608,6 +609,46 @@ func deleteAccountHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
}
func usersAdminHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
accounts, err := getAllAccounts(c)
if err != nil {
c.Errorf("Error looking up accounts: %s", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
users := make([]map[string]interface{}, len(accounts))
for i := range accounts {
account := &accounts[i]
oauthTransport := githubOAuthTransport(c)
oauthTransport.Token = &account.OAuthToken
githubClient := github.NewClient(oauthTransport.Client())
user, _, err := githubClient.Users.Get("")
emailAddress, err := account.GetDigestEmailAddress(githubClient)
if err != nil {
emailAddress = err.Error()
}
repos, reposErr := getRepos(c, githubClient, account, user)
users[i] = map[string]interface{}{
"Account": account,
"User": user,
"EmailAddress": emailAddress,
"Repos": repos,
"ReposError": reposErr,
}
}
var data = map[string]interface{}{
"Users": users,
}
if err := templates["users-admin"].Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func digestAdminHandler(w http.ResponseWriter, r *http.Request) {
userId, err := strconv.Atoi(r.FormValue("user_id"))
if err != nil {

View file

@ -1,4 +1,4 @@
{{define "title"}}Admin{{end}}
{{define "title"}}Digest Admin{{end}}
{{define "body"}}

View file

@ -8,14 +8,7 @@
<div class="blurb">
You're signed in as
<a href="https://github.com/{{.User.Login}}"
title="{{.User.Name}}">
<img src="{{.User.AvatarURL}}"
width="20"
height="20"
border="0"
class="avatar">{{.User.Login}}
</a>
{{template "user" .User}}
(<form class="inline" method="POST" action="{{routeUrl "sign-out"}}"><input type="submit" class="inline" value="sign out"></form>).
You'll be getting a {{.SettingsSummary.Frequency}} digest of your past
GitHub activity in {{.SettingsSummary.RepositoryCount}} repositories sent to