Batch of mirror fixes

This commit is contained in:
Unknown 2014-05-06 13:47:47 -04:00
parent e573855a4f
commit 7cb5a15c9b
12 changed files with 120 additions and 20 deletions

View file

@ -43,7 +43,7 @@ func newMartini() *martini.ClassicMartini {
m := martini.New()
m.Use(middleware.Logger())
m.Use(martini.Recovery())
m.Use(martini.Static("public", martini.StaticOptions{SkipLogging: !base.RouterLog}))
m.Use(martini.Static("public", martini.StaticOptions{SkipLogging: !base.DisableRouterLog}))
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}

View file

@ -20,7 +20,7 @@ HTTP_ADDR =
HTTP_PORT = 3000
; Disable CDN even in "prod" mode
OFFLINE_MODE = false
ROUTER_LOG = true
DISABLE_ROUTER_LOG = false
; Generate steps:
; $ cd path/to/gogs/custom/https
; $ go run $GOROOT/src/pkg/crypto/tls/generate_cert.go -ca=true -duration=8760h0m0s -host=myhost.example.com

View file

@ -30,14 +30,15 @@ const (
OP_PULL_REQUEST
OP_TRANSFER_REPO
OP_PUSH_TAG
OP_COMMENT_ISSUE
)
// Action represents user operation type and other information to repository.,
// it implemented interface base.Actioner so that can be used in template render.
type Action struct {
Id int64
UserId int64 // Receiver user id.
OpType int // Operations: CREATE DELETE STAR ...
UserId int64 // Receiver user id.
OpType int
ActUserId int64 // Action user id.
ActUserName string // Action user name.
ActEmail string

View file

@ -80,3 +80,9 @@ func DeleteOauth2ById(id int64) error {
_, err := orm.Delete(&Oauth2{Id: id})
return err
}
// CleanUnbindOauth deletes all unbind OAuthes.
func CleanUnbindOauth() error {
_, err := orm.Delete(&Oauth2{Uid: -1})
return err
}

View file

@ -45,16 +45,16 @@ type Oauther struct {
}
var (
AppVer string
AppName string
AppLogo string
AppUrl string
OfflineMode bool
RouterLog bool
ProdMode bool
Domain string
SecretKey string
RunUser string
AppVer string
AppName string
AppLogo string
AppUrl string
OfflineMode bool
DisableRouterLog bool
ProdMode bool
Domain string
SecretKey string
RunUser string
RepoRootPath string
ScriptType string
@ -330,7 +330,7 @@ func NewConfigContext() {
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
RouterLog = Cfg.MustBool("server", "ROUTER_LOG", true)
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)

View file

@ -117,6 +117,8 @@ func ActionIcon(opType int) string {
return "exclamation-circle"
case 8: // Transfer repository.
return "share"
case 10: // Comment issue.
return "comment"
default:
return "invalid type"
}
@ -130,6 +132,8 @@ const (
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>`
TPL_PUSH_TAG = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s" rel="nofollow">%s</a> at <a href="/%s">%s</a>`
TPL_COMMENT_ISSUE = `<a href="/user/%s">%s</a> commented on issue <a href="/%s/issues/%s">%s#%s</a>
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
)
type PushCommit struct {
@ -179,6 +183,10 @@ func ActionDesc(act Actioner) string {
return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
case 9: // Push tag.
return fmt.Sprintf(TPL_PUSH_TAG, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink)
case 10: // Comment issue.
infos := strings.SplitN(content, "|", 2)
return fmt.Sprintf(TPL_COMMENT_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
AvatarLink(email), infos[1])
default:
return "invalid type"
}

View file

@ -77,7 +77,7 @@ func handleQueue() {
log.Error("hooks.handleQueue: Fail to deliver hook: %v", err)
continue
}
log.Info("Hook delivered")
log.Info("Hook delivered: %s", string(data))
}
}
}

View file

@ -24,7 +24,7 @@ func init() {
func Logger() martini.Handler {
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
if !base.RouterLog {
if base.DisableRouterLog {
return
}

View file

@ -98,9 +98,36 @@ func updateSystemStatus() {
sysStatus.NumGC = m.NumGC
}
// Operation types.
const (
OT_CLEAN_OAUTH = iota + 1
)
func Dashboard(ctx *middleware.Context) {
ctx.Data["Title"] = "Admin Dashboard"
ctx.Data["PageIsDashboard"] = true
// Run operation.
op, _ := base.StrTo(ctx.Query("op")).Int()
if op > 0 {
var err error
var success string
switch op {
case OT_CLEAN_OAUTH:
success = "All unbind OAuthes have been deleted."
err = models.CleanUnbindOauth()
}
if err != nil {
ctx.Flash.Error(err.Error())
} else {
ctx.Flash.Success(success)
}
ctx.Redirect("/admin")
return
}
ctx.Data["Stats"] = models.GetStatistic()
updateSystemStatus()
ctx.Data["SysStatus"] = sysStatus
@ -153,7 +180,7 @@ func Config(ctx *middleware.Context) {
ctx.Data["AppUrl"] = base.AppUrl
ctx.Data["Domain"] = base.Domain
ctx.Data["OfflineMode"] = base.OfflineMode
ctx.Data["RouterLog"] = base.RouterLog
ctx.Data["DisableRouterLog"] = base.DisableRouterLog
ctx.Data["RunUser"] = base.RunUser
ctx.Data["RunMode"] = strings.Title(martini.Env)
ctx.Data["RepoRootPath"] = base.RepoRootPath

View file

@ -295,5 +295,39 @@ func Comment(ctx *middleware.Context, params martini.Params) {
}
}
// Notify watchers.
if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, ActEmail: ctx.User.Email,
OpType: models.OP_COMMENT_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]),
RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil {
ctx.Handle(500, "issue.CreateIssue(NotifyWatchers)", err)
return
}
// Mail watchers and mentions.
if base.Service.NotifyMail {
issue.Content = content
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
if err != nil {
ctx.Handle(500, "issue.Comment(SendIssueNotifyMail)", err)
return
}
tos = append(tos, ctx.User.LowerName)
ms := base.MentionPattern.FindAllString(issue.Content, -1)
newTos := make([]string, 0, len(ms))
for _, m := range ms {
if com.IsSliceContainsStr(tos, m[1:]) {
continue
}
newTos = append(newTos, m[1:])
}
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
ctx.Handle(500, "issue.Comment(SendIssueMentionMail)", err)
return
}
}
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index))
}

View file

@ -20,8 +20,8 @@
<dd>{{.Domain}}</dd>
<dt>Offline Mode</dt>
<dd><i class="fa fa{{if .OfflineMode}}-check{{end}}-square-o"></i></dd>
<dt>Router Log</dt>
<dd><i class="fa fa{{if .RouterLog}}-check{{end}}-square-o"></i></dd>
<dt>Disable Router Log</dt>
<dd><i class="fa fa{{if .DisableRouterLog}}-check{{end}}-square-o"></i></dd>
<hr/>
<dt>Run User</dt>
<dd>{{.RunUser}}</dd>

View file

@ -3,6 +3,7 @@
<div id="body" class="container" data-page="admin">
{{template "admin/nav" .}}
<div id="admin-container" class="col-md-10">
{{template "base/alert" .}}
<div class="panel panel-default">
<div class="panel-heading">
Statistic
@ -13,6 +14,29 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
Operations
</div>
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Op.</th>
</tr>
</thead>
<tbody>
<tr>
<td>Clean unbind OAuthes</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="/admin?op=1">Run</a></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
System Monitor Status