Browse Source

Improve issue mail content

pull/61/head
Unknown 11 years ago
parent
commit
d9005ee970
  1. 2
      gogs.go
  2. 1
      models/repo.go
  3. 11
      modules/mailer/mail.go
  4. 4
      public/css/gogs.css
  5. 14
      routers/repo/issue.go
  6. 76
      routers/user/user.go
  7. 24
      web.go

2
gogs.go

@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition. // Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true const go12tag = true
const APP_VER = "0.2.0.0401 Alpha" const APP_VER = "0.2.0.0402 Alpha"
func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

1
models/repo.go

@ -513,6 +513,7 @@ func NotifyWatchers(act *Action) error {
continue continue
} }
act.Id = 0
act.UserId = watches[i].UserId act.UserId = watches[i].UserId
if _, err = orm.InsertOne(act); err != nil { if _, err = orm.InsertOne(act); err != nil {
return errors.New("repo.NotifyWatchers(create action): " + err.Error()) return errors.New("repo.NotifyWatchers(create action): " + err.Error())

11
modules/mailer/mail.go

@ -92,8 +92,8 @@ func SendActiveMail(r *middleware.Render, user *models.User) {
} }
// SendNotifyMail sends mail notification of all watchers. // SendNotifyMail sends mail notification of all watchers.
func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content string) error { func SendNotifyMail(user, owner *models.User, repo *models.Repository, issue *models.Issue) error {
watches, err := models.GetWatches(repoId) watches, err := models.GetWatches(repo.Id)
if err != nil { if err != nil {
return errors.New("mail.NotifyWatchers(get watches): " + err.Error()) return errors.New("mail.NotifyWatchers(get watches): " + err.Error())
} }
@ -101,7 +101,7 @@ func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content s
tos := make([]string, 0, len(watches)) tos := make([]string, 0, len(watches))
for i := range watches { for i := range watches {
uid := watches[i].UserId uid := watches[i].UserId
if userId == uid { if user.Id == uid {
continue continue
} }
u, err := models.GetUserById(uid) u, err := models.GetUserById(uid)
@ -115,7 +115,10 @@ func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content s
return nil return nil
} }
msg := NewMailMessageFrom(tos, userName, subject, content) subject := fmt.Sprintf("[%s] %s", repo.Name, issue.Name)
content := fmt.Sprintf("%s<br>-<br> <a href=\"%s%s/%s/issues/%d\">View it on Gogs</a>.",
issue.Content, base.AppUrl, owner.Name, repo.Name, issue.Index)
msg := NewMailMessageFrom(tos, user.Name, subject, content)
msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject) msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject)
SendAsync(&msg) SendAsync(&msg)
return nil return nil

4
public/css/gogs.css

@ -1235,9 +1235,9 @@ html, body {
/* admin dashboard/configuration */ /* admin dashboard/configuration */
.admin-dl-horizontal > dt { .admin-dl-horizontal > dt {
width: 320px; width: 220px;
} }
.admin-dl-horizontal > dd { .admin-dl-horizontal > dd {
margin-left: 340px; margin-left: 240px;
} }

14
routers/repo/issue.go

@ -31,7 +31,8 @@ func Issues(ctx *middleware.Context) {
ctx.Data["IssueCreatedCount"] = 0 ctx.Data["IssueCreatedCount"] = 0
var posterId int64 = 0 var posterId int64 = 0
if ctx.Query("type") == "created_by" { isCreatedBy := ctx.Query("type") == "created_by"
if isCreatedBy {
if !ctx.IsSigned { if !ctx.IsSigned {
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI))
ctx.Redirect("/user/login/", 302) ctx.Redirect("/user/login/", 302)
@ -53,6 +54,7 @@ func Issues(ctx *middleware.Context) {
} }
var createdByCount int var createdByCount int
showIssues := make([]models.Issue, 0, len(issues))
// Get posters. // Get posters.
for i := range issues { for i := range issues {
u, err := models.GetUserById(issues[i].PosterId) u, err := models.GetUserById(issues[i].PosterId)
@ -60,13 +62,17 @@ func Issues(ctx *middleware.Context) {
ctx.Handle(200, "issue.Issues(get poster): %v", err) ctx.Handle(200, "issue.Issues(get poster): %v", err)
return return
} }
issues[i].Poster = u if isCreatedBy && u.Id != posterId {
continue
}
if u.Id == posterId { if u.Id == posterId {
createdByCount++ createdByCount++
} }
issues[i].Poster = u
showIssues = append(showIssues, issues[i])
} }
ctx.Data["Issues"] = issues ctx.Data["Issues"] = showIssues
ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues
ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues
ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues
@ -107,7 +113,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
// Mail watchers. // Mail watchers.
if base.Service.NotifyMail { if base.Service.NotifyMail {
if err = mailer.SendNotifyMail(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.Name, ctx.Repo.Repository.Name, issue.Name, issue.Content); err != nil { if err = mailer.SendNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue); err != nil {
ctx.Handle(200, "issue.CreateIssue", err) ctx.Handle(200, "issue.CreateIssue", err)
return return
} }

76
routers/user/user.go

@ -5,14 +5,14 @@
package user package user
import ( import (
"encoding/json" // "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"code.google.com/p/goauth2/oauth"
// "code.google.com/p/goauth2/oauth"
"github.com/go-martini/martini" "github.com/go-martini/martini"
"github.com/martini-contrib/oauth2" // "github.com/martini-contrib/oauth2"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
@ -78,41 +78,41 @@ func Profile(ctx *middleware.Context, params martini.Params) {
} }
// github && google && ... // github && google && ...
func SocialSignIn(tokens oauth2.Tokens) { // func SocialSignIn(tokens oauth2.Tokens) {
transport := &oauth.Transport{} // transport := &oauth.Transport{}
transport.Token = &oauth.Token{ // transport.Token = &oauth.Token{
AccessToken: tokens.Access(), // AccessToken: tokens.Access(),
RefreshToken: tokens.Refresh(), // RefreshToken: tokens.Refresh(),
Expiry: tokens.ExpiryTime(), // Expiry: tokens.ExpiryTime(),
Extra: tokens.ExtraData(), // Extra: tokens.ExtraData(),
} // }
// Github API refer: https://developer.github.com/v3/users/ // // Github API refer: https://developer.github.com/v3/users/
// FIXME: need to judge url // // FIXME: need to judge url
type GithubUser struct { // type GithubUser struct {
Id int `json:"id"` // Id int `json:"id"`
Name string `json:"login"` // Name string `json:"login"`
Email string `json:"email"` // Email string `json:"email"`
} // }
// Make the request. // // Make the request.
scope := "https://api.github.com/user" // scope := "https://api.github.com/user"
r, err := transport.Client().Get(scope) // r, err := transport.Client().Get(scope)
if err != nil { // if err != nil {
log.Error("connect with github error: %s", err) // log.Error("connect with github error: %s", err)
// FIXME: handle error page // // FIXME: handle error page
return // return
} // }
defer r.Body.Close() // defer r.Body.Close()
user := &GithubUser{} // user := &GithubUser{}
err = json.NewDecoder(r.Body).Decode(user) // err = json.NewDecoder(r.Body).Decode(user)
if err != nil { // if err != nil {
log.Error("Get: %s", err) // log.Error("Get: %s", err)
} // }
log.Info("login: %s", user.Name) // log.Info("login: %s", user.Name)
// FIXME: login here, user email to check auth, if not registe, then generate a uniq username // // FIXME: login here, user email to check auth, if not registe, then generate a uniq username
} // }
func SignIn(ctx *middleware.Context, form auth.LogInForm) { func SignIn(ctx *middleware.Context, form auth.LogInForm) {
ctx.Data["Title"] = "Log In" ctx.Data["Title"] = "Log In"

24
web.go

@ -11,8 +11,8 @@ import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/go-martini/martini" "github.com/go-martini/martini"
"github.com/martini-contrib/oauth2" // "github.com/martini-contrib/oauth2"
"github.com/martini-contrib/sessions" // "github.com/martini-contrib/sessions"
"github.com/gogits/binding" "github.com/gogits/binding"
@ -60,15 +60,15 @@ func runWeb(*cli.Context) {
// Middlewares. // Middlewares.
m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}})) m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}}))
scope := "https://api.github.com/user" // scope := "https://api.github.com/user"
oauth2.PathCallback = "/oauth2callback" // oauth2.PathCallback = "/oauth2callback"
m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123")))) // m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
m.Use(oauth2.Github(&oauth2.Options{ // m.Use(oauth2.Github(&oauth2.Options{
ClientId: "09383403ff2dc16daaa1", // ClientId: "09383403ff2dc16daaa1",
ClientSecret: "5f6e7101d30b77952aab22b75eadae17551ea6b5", // ClientSecret: "5f6e7101d30b77952aab22b75eadae17551ea6b5",
RedirectURL: base.AppUrl + oauth2.PathCallback, // RedirectURL: base.AppUrl + oauth2.PathCallback,
Scopes: []string{scope}, // Scopes: []string{scope},
})) // }))
m.Use(middleware.InitContext()) m.Use(middleware.InitContext())
@ -92,7 +92,7 @@ func runWeb(*cli.Context) {
m.Get("/avatar/:hash", avt.ServeHTTP) m.Get("/avatar/:hash", avt.ServeHTTP)
m.Group("/user", func(r martini.Router) { m.Group("/user", func(r martini.Router) {
r.Any("/login/github", user.SocialSignIn) // r.Any("/login/github", user.SocialSignIn)
r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
r.Any("/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) r.Any("/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
}, reqSignOut) }, reqSignOut)

Loading…
Cancel
Save