mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Add basic admin UI for viewing the digest as another user.
This commit is contained in:
parent
c4e55c5553
commit
1b3f91363f
4 changed files with 62 additions and 3 deletions
|
|
@ -10,6 +10,9 @@ handlers:
|
||||||
- url: /digest/cron
|
- url: /digest/cron
|
||||||
script: _go_app
|
script: _go_app
|
||||||
login: admin
|
login: admin
|
||||||
|
- url: /admin/.*
|
||||||
|
script: _go_app
|
||||||
|
login: admin
|
||||||
- url: /.*
|
- url: /.*
|
||||||
script: _go_app
|
script: _go_app
|
||||||
secure: always
|
secure: always
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DisplayDateFormat = "3:04pm"
|
DisplayDateFormat = "3:04pm"
|
||||||
DisplayDateTooltipFormat = "Monday January 2 3:04pm"
|
DisplayDateTooltipFormat = "Monday January 2 3:04pm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"appengine"
|
"appengine"
|
||||||
"appengine/mail"
|
"appengine/mail"
|
||||||
|
|
@ -50,11 +51,15 @@ func init() {
|
||||||
|
|
||||||
router = mux.NewRouter()
|
router = mux.NewRouter()
|
||||||
router.HandleFunc("/", indexHandler).Name("index")
|
router.HandleFunc("/", indexHandler).Name("index")
|
||||||
router.HandleFunc("/digest/send", sendDigestHandler).Name("send-digest").Methods("POST")
|
|
||||||
router.HandleFunc("/digest/cron", digestCronHandler)
|
|
||||||
router.HandleFunc("/session/sign-in", signInHandler).Name("sign-in")
|
router.HandleFunc("/session/sign-in", signInHandler).Name("sign-in")
|
||||||
router.HandleFunc("/session/sign-out", signOutHandler).Name("sign-out")
|
router.HandleFunc("/session/sign-out", signOutHandler).Name("sign-out")
|
||||||
router.HandleFunc("/github/callback", githubOAuthCallbackHandler)
|
router.HandleFunc("/github/callback", githubOAuthCallbackHandler)
|
||||||
|
|
||||||
|
router.HandleFunc("/digest/send", sendDigestHandler).Name("send-digest").Methods("POST")
|
||||||
|
router.HandleFunc("/digest/cron", digestCronHandler)
|
||||||
|
|
||||||
|
router.HandleFunc("/admin/digest", digestAdminHandler)
|
||||||
http.Handle("/", router)
|
http.Handle("/", router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,6 +247,39 @@ func githubOAuthCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
|
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func digestAdminHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userId, err := strconv.Atoi(r.FormValue("user_id"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c := appengine.NewContext(r)
|
||||||
|
account, err := getAccount(c, userId)
|
||||||
|
if account == nil {
|
||||||
|
http.Error(w, "Couldn't find account", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oauthTransport := githubOAuthTransport(c)
|
||||||
|
oauthTransport.Token = &account.OAuthToken
|
||||||
|
githubClient := github.NewClient(oauthTransport.Client())
|
||||||
|
|
||||||
|
digest, err := newDigest(githubClient, account)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
var data = map[string]interface{}{
|
||||||
|
"Digest": digest,
|
||||||
|
}
|
||||||
|
if err := templates.ExecuteTemplate(w, "digest-admin", data); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func githubOAuthTransport(c appengine.Context) *oauth.Transport {
|
func githubOAuthTransport(c appengine.Context) *oauth.Transport {
|
||||||
appengineTransport := &urlfetch.Transport{Context: c}
|
appengineTransport := &urlfetch.Transport{Context: c}
|
||||||
cachingTransport := &CachingTransport{
|
cachingTransport := &CachingTransport{
|
||||||
|
|
|
||||||
18
app/templates/digest-admin.html
Normal file
18
app/templates/digest-admin.html
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
{{define "digest-admin"}}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>GitHop Admin</title>
|
||||||
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
|
<link rel="stylesheet" href="/static/digest.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>GitHop Admin</h1>
|
||||||
|
|
||||||
|
{{template "digest" .Digest}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
{{end}}
|
||||||
Loading…
Reference in a new issue