aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorSergio Benitez <sbenitez@mit.edu>2015-09-09 13:44:51 -0700
committerSergio Benitez <sbenitez@mit.edu>2015-09-09 13:44:51 -0700
commit964d0262ff353db6a50ed5be83ebd22f71aa6e69 (patch)
tree8cbab6b6a9b4f62cbe9acb2a0b8752b531633362 /routers
parent079a2d68db5c843ef2dbba65aeca46d5887d6b02 (diff)
parentb75d0378cbbf0523963fd9bc749543244be7392b (diff)
downloadgitea-964d0262ff353db6a50ed5be83ebd22f71aa6e69.tar.gz
gitea-964d0262ff353db6a50ed5be83ebd22f71aa6e69.zip
Merged conflicts.
Diffstat (limited to 'routers')
-rw-r--r--routers/install.go11
-rw-r--r--routers/org/org.go11
-rw-r--r--routers/org/setting.go52
-rw-r--r--routers/repo/issue.go26
-rw-r--r--routers/repo/pull.go5
-rw-r--r--routers/repo/repo.go10
-rw-r--r--routers/user/setting.go54
7 files changed, 93 insertions, 76 deletions
diff --git a/routers/install.go b/routers/install.go
index 72c8b137b0..d9c5d51cac 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -85,7 +85,14 @@ func InstallInit(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("install.install")
ctx.Data["PageIsInstall"] = true
- ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"}
+ dbOpts := []string{"MySQL", "PostgreSQL"}
+ if models.EnableSQLite3 {
+ dbOpts = append(dbOpts, "SQLite3")
+ }
+ if models.EnableTidb {
+ dbOpts = append(dbOpts, "TiDB")
+ }
+ ctx.Data["DbOptions"] = dbOpts
}
func Install(ctx *middleware.Context) {
@@ -163,7 +170,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
// Pass basic check, now test configuration.
// Test database setting.
- dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "SQLite3": "sqlite3"}
+ dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "SQLite3": "sqlite3", "TiDB": "tidb"}
models.DbCfg.Type = dbTypes[form.DbType]
models.DbCfg.Host = form.DbHost
models.DbCfg.User = form.DbUser
diff --git a/routers/org/org.go b/routers/org/org.go
index ed4f2abdea..d1c1940cb9 100644
--- a/routers/org/org.go
+++ b/routers/org/org.go
@@ -59,25 +59,18 @@ func CreatePost(ctx *middleware.Context, form auth.CreateOrgForm) {
org := &models.User{
Name: form.OrgName,
- Email: form.Email,
IsActive: true,
Type: models.ORGANIZATION,
}
- var err error
- if err = models.CreateOrganization(org, ctx.User); err != nil {
+ if err := models.CreateOrganization(org, ctx.User); err != nil {
+ ctx.Data["Err_OrgName"] = true
switch {
case models.IsErrUserAlreadyExist(err):
- ctx.Data["Err_OrgName"] = true
ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), CREATE, &form)
- case models.IsErrEmailAlreadyUsed(err):
- ctx.Data["Err_Email"] = true
- ctx.RenderWithErr(ctx.Tr("form.email_been_used"), CREATE, &form)
case models.IsErrNameReserved(err):
- ctx.Data["Err_OrgName"] = true
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form)
case models.IsErrNamePatternNotAllowed(err):
- ctx.Data["Err_OrgName"] = true
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form)
default:
ctx.Handle(500, "CreateOrganization", err)
diff --git a/routers/org/setting.go b/routers/org/setting.go
index a15af26d43..9e26afa7d4 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -12,6 +12,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
+ "github.com/gogits/gogs/routers/user"
)
const (
@@ -38,47 +39,50 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) {
org := ctx.Org.Organization
// Check if organization name has been changed.
- if org.Name != form.OrgUserName {
- isExist, err := models.IsUserExist(org.Id, form.OrgUserName)
+ if org.Name != form.Name {
+ isExist, err := models.IsUserExist(org.Id, form.Name)
if err != nil {
ctx.Handle(500, "IsUserExist", err)
return
} else if isExist {
- ctx.Data["Err_UserName"] = true
+ ctx.Data["OrgName"] = true
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_OPTIONS, &form)
return
- } else if err = models.ChangeUserName(org, form.OrgUserName); err != nil {
+ } else if err = models.ChangeUserName(org, form.Name); err != nil {
if err == models.ErrUserNameIllegal {
- ctx.Data["Err_UserName"] = true
+ ctx.Data["OrgName"] = true
ctx.RenderWithErr(ctx.Tr("form.illegal_username"), SETTINGS_OPTIONS, &form)
} else {
ctx.Handle(500, "ChangeUserName", err)
}
return
}
- log.Trace("Organization name changed: %s -> %s", org.Name, form.OrgUserName)
- org.Name = form.OrgUserName
+ log.Trace("Organization name changed: %s -> %s", org.Name, form.Name)
+ org.Name = form.Name
}
- org.FullName = form.OrgFullName
- org.Email = form.Email
+ org.FullName = form.FullName
org.Description = form.Description
org.Website = form.Website
org.Location = form.Location
- org.Avatar = base.EncodeMd5(form.Avatar)
- org.AvatarEmail = form.Avatar
if err := models.UpdateUser(org); err != nil {
- if models.IsErrEmailAlreadyUsed(err) {
- ctx.Data["Err_Email"] = true
- ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_OPTIONS, &form)
- } else {
- ctx.Handle(500, "UpdateUser", err)
- }
+ ctx.Handle(500, "UpdateUser", err)
return
}
log.Trace("Organization setting updated: %s", org.Name)
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
- ctx.Redirect(setting.AppSubUrl + "/org/" + org.Name + "/settings")
+ ctx.Redirect(org.HomeLink() + "/settings")
+}
+
+func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
+ form.Enable = true
+ if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
+ ctx.Flash.Error(err.Error())
+ } else {
+ ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success"))
+ }
+
+ ctx.Redirect(ctx.Org.OrgLink + "/settings")
}
func SettingsDelete(ctx *middleware.Context) {
@@ -87,11 +91,19 @@ func SettingsDelete(ctx *middleware.Context) {
org := ctx.Org.Organization
if ctx.Req.Method == "POST" {
- // FIXME: validate password.
+ if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
+ if models.IsErrUserNotExist(err) {
+ ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
+ } else {
+ ctx.Handle(500, "UserSignIn", err)
+ }
+ return
+ }
+
if err := models.DeleteOrganization(org); err != nil {
if models.IsErrUserOwnRepos(err) {
ctx.Flash.Error(ctx.Tr("form.org_still_own_repo"))
- ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings/delete")
+ ctx.Redirect(org.HomeLink() + "/settings/delete")
} else {
ctx.Handle(500, "DeleteOrganization", err)
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index e821c130c4..e242dd0e5f 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -759,18 +759,6 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) {
return
}
- // Check if issue owner/poster changes the status of issue.
- if (ctx.Repo.IsOwner() || (ctx.IsSigned && issue.IsPoster(ctx.User.Id))) &&
- (form.Status == "reopen" || form.Status == "close") &&
- !(issue.IsPull && issue.HasMerged) {
- issue.Repo = ctx.Repo.Repository
- if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil {
- ctx.Handle(500, "ChangeStatus", err)
- return
- }
- log.Trace("%s Issue[%d] status changed: %v", ctx.Req.RequestURI, issue.ID, !issue.IsClosed)
- }
-
// Fix #321: Allow empty comments, as long as we have attachments.
if len(form.Content) == 0 && len(attachments) == 0 {
ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
@@ -820,8 +808,20 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) {
return
}
}
-
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
+
+ // Check if issue owner/poster changes the status of issue.
+ if (ctx.Repo.IsOwner() || (ctx.IsSigned && issue.IsPoster(ctx.User.Id))) &&
+ (form.Status == "reopen" || form.Status == "close") &&
+ !(issue.IsPull && issue.HasMerged) {
+ issue.Repo = ctx.Repo.Repository
+ if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil {
+ ctx.Handle(500, "ChangeStatus", err)
+ return
+ }
+ log.Trace("Issue[%d] status changed: %v", issue.ID, !issue.IsClosed)
+ }
+
ctx.Redirect(fmt.Sprintf("%s/issues/%d#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag()))
}
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 19f9f5b8e2..c1eec7cc2f 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -38,9 +38,8 @@ func getForkRepository(ctx *middleware.Context) *models.Repository {
return nil
}
- // Cannot fork bare repo.
- if forkRepo.IsBare {
- ctx.Handle(404, "", nil)
+ if !forkRepo.CanBeForked() {
+ ctx.Handle(404, "getForkRepository", nil)
return nil
}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 329bc93311..8a0c5f975c 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -28,11 +28,12 @@ const (
)
func checkContextUser(ctx *middleware.Context, uid int64) *models.User {
- if err := ctx.User.GetOrganizations(); err != nil {
- ctx.Handle(500, "GetOrganizations", err)
+ orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.Id, "updated")
+ if err != nil {
+ ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err)
return nil
}
- ctx.Data["Orgs"] = ctx.User.Orgs
+ ctx.Data["Orgs"] = orgs
// Not equal means current user is an organization.
if uid == ctx.User.Id || uid == 0 {
@@ -198,7 +199,8 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
}
if strings.Contains(err.Error(), "Authentication failed") ||
- strings.Contains(err.Error(), " not found") {
+ strings.Contains(err.Error(), " not found") ||
+ strings.Contains(err.Error(), "could not read Username") {
ctx.Data["Err_Auth"] = true
ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
return
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 8afc56ac49..c62a123d5b 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -5,6 +5,8 @@
package user
import (
+ "errors"
+ "fmt"
"io/ioutil"
"strings"
@@ -47,11 +49,11 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
}
// Check if user name has been changed.
- if ctx.User.Name != form.UserName {
- if err := models.ChangeUserName(ctx.User, form.UserName); err != nil {
+ if ctx.User.Name != form.Name {
+ if err := models.ChangeUserName(ctx.User, form.Name); err != nil {
switch {
case models.IsErrUserAlreadyExist(err):
- ctx.Flash.Error(ctx.Tr("form.username_been_taken"))
+ ctx.Flash.Error(ctx.Tr("form.name_been_taken"))
ctx.Redirect(setting.AppSubUrl + "/user/settings")
case models.IsErrEmailAlreadyUsed(err):
ctx.Flash.Error(ctx.Tr("form.email_been_used"))
@@ -67,16 +69,16 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
}
return
}
- log.Trace("User name changed: %s -> %s", ctx.User.Name, form.UserName)
- ctx.User.Name = form.UserName
+ log.Trace("User name changed: %s -> %s", ctx.User.Name, form.Name)
+ ctx.User.Name = form.Name
}
ctx.User.FullName = form.FullName
ctx.User.Email = form.Email
ctx.User.Website = form.Website
ctx.User.Location = form.Location
- ctx.User.Avatar = base.EncodeMd5(form.Avatar)
- ctx.User.AvatarEmail = form.Avatar
+ ctx.User.Avatar = base.EncodeMd5(form.Gravatar)
+ ctx.User.AvatarEmail = form.Gravatar
if err := models.UpdateUser(ctx.User); err != nil {
ctx.Handle(500, "UpdateUser", err)
return
@@ -87,45 +89,47 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
}
// FIXME: limit size.
-func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
- defer ctx.Redirect(setting.AppSubUrl + "/user/settings")
-
- ctx.User.UseCustomAvatar = form.Enable
+func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ctxUser *models.User) error {
+ ctxUser.UseCustomAvatar = form.Enable
if form.Avatar != nil {
fr, err := form.Avatar.Open()
if err != nil {
- ctx.Flash.Error(err.Error())
- return
+ return fmt.Errorf("Avatar.Open: %v", err)
}
data, err := ioutil.ReadAll(fr)
if err != nil {
- ctx.Flash.Error(err.Error())
- return
+ return fmt.Errorf("ReadAll: %v", err)
}
if _, ok := base.IsImageFile(data); !ok {
- ctx.Flash.Error(ctx.Tr("settings.uploaded_avatar_not_a_image"))
- return
+ return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image"))
}
- if err = ctx.User.UploadAvatar(data); err != nil {
- ctx.Flash.Error(err.Error())
- return
+ if err = ctxUser.UploadAvatar(data); err != nil {
+ return fmt.Errorf("UploadAvatar: %v", err)
}
} else {
// In case no avatar at all.
if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) {
- ctx.Flash.Error(ctx.Tr("settings.no_custom_avatar_available"))
- return
+ return errors.New(ctx.Tr("settings.no_custom_avatar_available"))
}
}
- if err := models.UpdateUser(ctx.User); err != nil {
+ if err := models.UpdateUser(ctxUser); err != nil {
+ return fmt.Errorf("UpdateUser: %v", err)
+ }
+
+ return nil
+}
+
+func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
+ if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil {
ctx.Flash.Error(err.Error())
- return
+ } else {
+ ctx.Flash.Success(ctx.Tr("settings.update_avatar_success"))
}
- ctx.Flash.Success(ctx.Tr("settings.update_avatar_success"))
+ ctx.Redirect(setting.AppSubUrl + "/user/settings")
}
func SettingsEmails(ctx *middleware.Context) {