]> source.dussan.org Git - gitea.git/commitdiff
Batch of mirror fixes
authorUnknown <joe2010xtmf@163.com>
Tue, 6 May 2014 17:47:47 +0000 (13:47 -0400)
committerUnknown <joe2010xtmf@163.com>
Tue, 6 May 2014 17:47:47 +0000 (13:47 -0400)
12 files changed:
cmd/web.go
conf/app.ini
models/action.go
models/oauth2.go
modules/base/conf.go
modules/base/template.go
modules/hooks/hooks.go
modules/middleware/logger.go
routers/admin/admin.go
routers/repo/issue.go
templates/admin/config.tmpl
templates/admin/dashboard.tmpl

index 74da86d40ee9492cb2b4e9387925da673a92936c..0b8c9b11b0b7d3b83258abd2ba41e7da74a3b50f 100644 (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}
index 77b808611393862d5fff0d0d6b65fc8bb35326f3..4f76db4deef022bcc14849e1fee44a3397a95c00 100644 (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
index 231a7a548511384e90adb6ab9890325b8048df5b..ef9e260a0b2dcc04fba1ce3231fe052701db8aab 100644 (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
index 97ba519c57afabd977b805ed618810d2ad153f02..61044d6882ace40c869eb34c1bafcda4d81ecb0c 100644 (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
+}
index 73552732b1deaa0360cec2f09ff17cd1000bb5b1..cbd6532ba7d58ddc4a5551ddd206be64fbfe6dce 100644 (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)
index a69a54618d1a7feecd4c4fee163d3f5f774a1fa0..135be107f22e8d5da14d2d1b1cbcb3571fe994b2 100644 (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"
        }
index 2b53dbfbbda3bf379737dd27d4e6c3704f5b1813..a3a59454e254957be8f3c42d8ee1197292ae98c1 100644 (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))
                }
        }
 }
index d815b90c262389c03dea346ab1993b0f7618aabe..1ee030a08dd5577b03198f2409ae806a22d5178a 100644 (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
                }
 
index 96721bfdebfc6bd35ef30d558f998c53e5ce0443..910027881dabbe6ea902a62f8795ce5dd620e0d2 100644 (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
index 4e2076620d55ce0863f3e3d5294e51a17e632a68..2bd2f33a1be783ce3896826312717f83d0b12a0e 100644 (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))
 }
index 8ba6b60cd51fb8f5ed7f5e7f2c45f4b03ebadd98..96565bac87faa732e6b4c3c6b2dcfff2e75943d0 100644 (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>
index 76539842d2fa2198d1ad28d53e5fec62c737f52b..e8dca09e578cf2ec90a0f0f7feeb13d432a723e6 100644 (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
             </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