Browse Source

random: some code simplify

pull/4584/head
Unknwon 8 years ago
parent
commit
ab2197bc75
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 6
      models/action.go
  2. 8
      models/repo.go
  3. 62
      routes/repo/setting.go
  4. 33
      templates/repo/settings/options.tmpl

6
models/action.go

@ -73,10 +73,10 @@ func init() {
// it implemented interface base.Actioner so that can be used in template render.
type Action struct {
ID int64
UserID int64 // Receiver user id.
UserID int64 // Receiver user ID
OpType ActionType
ActUserID int64 // Action user id.
ActUserName string // Action user name.
ActUserID int64 // Doer user OD
ActUserName string // Doer user name
ActAvatar string `xorm:"-"`
RepoID int64 `xorm:"INDEX"`
RepoUserName string

8
models/repo.go

@ -1339,14 +1339,14 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
return fmt.Errorf("getOwner: %v", err)
}
if repo.Owner.IsOrganization() {
// Organization repository need to recalculate access table when visivility is changed.
// Organization repository need to recalculate access table when visivility is changed
if err = repo.recalculateTeamAccesses(e, 0); err != nil {
return fmt.Errorf("recalculateTeamAccesses: %v", err)
}
}
// Create/Remove git-daemon-export-ok for git-daemon...
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
// Create/Remove git-daemon-export-ok for git-daemon
daemonExportFile := path.Join(repo.RepoPath(), "git-daemon-export-ok")
if repo.IsPrivate && com.IsExist(daemonExportFile) {
if err = os.Remove(daemonExportFile); err != nil {
log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
@ -1372,7 +1372,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
// Change visibility of generated actions
if _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{IsPrivate: repo.IsPrivate}); err != nil {
return fmt.Errorf("change action visibility of repository [id: %d]: %v", repo.ID, err)
return fmt.Errorf("change action visibility of repository: %v", err)
}
}

62
routes/repo/setting.go

@ -32,21 +32,21 @@ const (
)
func Settings(c *context.Context) {
c.Data["Title"] = c.Tr("repo.settings")
c.Data["PageIsSettingsOptions"] = true
c.HTML(200, SETTINGS_OPTIONS)
c.Title("repo.settings")
c.PageIs("SettingsOptions")
c.Success(SETTINGS_OPTIONS)
}
func SettingsPost(c *context.Context, f form.RepoSetting) {
c.Data["Title"] = c.Tr("repo.settings")
c.Data["PageIsSettingsOptions"] = true
c.Title("repo.settings")
c.PageIs("SettingsOptions")
repo := c.Repo.Repository
switch c.Query("action") {
case "update":
if c.HasError() {
c.HTML(200, SETTINGS_OPTIONS)
c.Success(SETTINGS_OPTIONS)
return
}
@ -57,7 +57,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
if repo.LowerName != strings.ToLower(newRepoName) {
isNameChanged = true
if err := models.ChangeRepositoryName(c.Repo.Owner, repo.Name, newRepoName); err != nil {
c.Data["Err_RepoName"] = true
c.FormErr("RepoName")
switch {
case models.IsErrRepoAlreadyExist(err):
c.RenderWithErr(c.Tr("form.repo_name_been_taken"), SETTINGS_OPTIONS, &f)
@ -66,7 +66,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case models.IsErrNamePatternNotAllowed(err):
c.RenderWithErr(c.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), SETTINGS_OPTIONS, &f)
default:
c.Handle(500, "ChangeRepositoryName", err)
c.ServerError("ChangeRepositoryName", err)
}
return
}
@ -88,14 +88,14 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
visibilityChanged := repo.IsPrivate != f.Private
repo.IsPrivate = f.Private
if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
c.Handle(500, "UpdateRepository", err)
c.ServerError("UpdateRepository", err)
return
}
log.Trace("Repository basic settings updated: %s/%s", c.Repo.Owner.Name, repo.Name)
if isNameChanged {
if err := models.RenameRepoAction(c.User, oldRepoName, repo); err != nil {
log.Error(4, "RenameRepoAction: %v", err)
log.Error(2, "RenameRepoAction: %v", err)
}
}
@ -104,7 +104,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case "mirror":
if !repo.IsMirror {
c.Handle(404, "", nil)
c.NotFound()
return
}
@ -113,12 +113,12 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
c.Repo.Mirror.Interval = f.Interval
c.Repo.Mirror.NextUpdate = time.Now().Add(time.Duration(f.Interval) * time.Hour)
if err := models.UpdateMirror(c.Repo.Mirror); err != nil {
c.Handle(500, "UpdateMirror", err)
c.ServerError("UpdateMirror", err)
return
}
}
if err := c.Repo.Mirror.SaveAddress(f.MirrorAddress); err != nil {
c.Handle(500, "SaveAddress", err)
c.ServerError("SaveAddress", err)
return
}
@ -127,7 +127,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case "mirror-sync":
if !repo.IsMirror {
c.Handle(404, "", nil)
c.NotFound()
return
}
@ -149,7 +149,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
repo.EnablePulls = f.EnablePulls
if err := models.UpdateRepository(repo, false); err != nil {
c.Handle(500, "UpdateRepository", err)
c.ServerError("UpdateRepository", err)
return
}
log.Trace("Repository advanced settings updated: %s/%s", c.Repo.Owner.Name, repo.Name)
@ -159,7 +159,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case "convert":
if !c.Repo.IsOwner() {
c.Error(404)
c.NotFound()
return
}
if repo.Name != f.RepoName {
@ -169,22 +169,22 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
if c.Repo.Owner.IsOrganization() {
if !c.Repo.Owner.IsOwnedBy(c.User.ID) {
c.Error(404)
c.NotFound()
return
}
}
if !repo.IsMirror {
c.Error(404)
c.NotFound()
return
}
repo.IsMirror = false
if _, err := models.CleanUpMigrateInfo(repo); err != nil {
c.Handle(500, "CleanUpMigrateInfo", err)
c.ServerError("CleanUpMigrateInfo", err)
return
} else if err = models.DeleteMirrorByRepoID(c.Repo.Repository.ID); err != nil {
c.Handle(500, "DeleteMirrorByRepoID", err)
c.ServerError("DeleteMirrorByRepoID", err)
return
}
log.Trace("Repository converted from mirror to regular: %s/%s", c.Repo.Owner.Name, repo.Name)
@ -193,7 +193,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case "transfer":
if !c.Repo.IsOwner() {
c.Error(404)
c.NotFound()
return
}
if repo.Name != f.RepoName {
@ -203,7 +203,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
if c.Repo.Owner.IsOrganization() && !c.User.IsAdmin {
if !c.Repo.Owner.IsOwnedBy(c.User.ID) {
c.Error(404)
c.NotFound()
return
}
}
@ -211,7 +211,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
newOwner := c.Query("new_owner_name")
isExist, err := models.IsUserExist(0, newOwner)
if err != nil {
c.Handle(500, "IsUserExist", err)
c.ServerError("IsUserExist", err)
return
} else if !isExist {
c.RenderWithErr(c.Tr("form.enterred_invalid_owner_name"), SETTINGS_OPTIONS, nil)
@ -222,7 +222,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
if models.IsErrRepoAlreadyExist(err) {
c.RenderWithErr(c.Tr("repo.settings.new_owner_has_same_repo"), SETTINGS_OPTIONS, nil)
} else {
c.Handle(500, "TransferOwnership", err)
c.ServerError("TransferOwnership", err)
}
return
}
@ -232,7 +232,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case "delete":
if !c.Repo.IsOwner() {
c.Error(404)
c.NotFound()
return
}
if repo.Name != f.RepoName {
@ -242,13 +242,13 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
if c.Repo.Owner.IsOrganization() && !c.User.IsAdmin {
if !c.Repo.Owner.IsOwnedBy(c.User.ID) {
c.Error(404)
c.NotFound()
return
}
}
if err := models.DeleteRepository(c.Repo.Owner.ID, repo.ID); err != nil {
c.Handle(500, "DeleteRepository", err)
c.ServerError("DeleteRepository", err)
return
}
log.Trace("Repository deleted: %s/%s", c.Repo.Owner.Name, repo.Name)
@ -258,7 +258,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
case "delete-wiki":
if !c.Repo.IsOwner() {
c.Error(404)
c.NotFound()
return
}
if repo.Name != f.RepoName {
@ -268,7 +268,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
if c.Repo.Owner.IsOrganization() && !c.User.IsAdmin {
if !c.Repo.Owner.IsOwnedBy(c.User.ID) {
c.Error(404)
c.NotFound()
return
}
}
@ -278,7 +278,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
repo.EnableWiki = false
if err := models.UpdateRepository(repo, false); err != nil {
c.Handle(500, "UpdateRepository", err)
c.ServerError("UpdateRepository", err)
return
}
@ -286,7 +286,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
c.Redirect(c.Repo.RepoLink + "/settings")
default:
c.Handle(404, "", nil)
c.NotFound()
}
}

33
templates/repo/settings/options.tmpl

@ -6,11 +6,11 @@
{{template "repo/settings/navbar" .}}
<div class="twelve wide column content">
{{template "base/alert" .}}
<h4 class="ui top attached header">
<div class="ui top attached header">
{{.i18n.Tr "repo.settings.basic_settings"}}
</h4>
</div>
<div class="ui attached segment">
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form" action="{{.Link}}" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="update">
<div class="required field {{if .Err_RepoName}}error{{end}}">
@ -43,11 +43,11 @@
</div>
{{if .Repository.IsMirror}}
<h4 class="ui top attached header">
<div class="ui top attached header">
{{.i18n.Tr "repo.settings.mirror_settings"}}
</h4>
</div>
<div class="ui attached segment">
<form class="ui form" method="post">
<form class="ui form" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="mirror">
<div class="inline field {{if .Err_EnablePrune}}error{{end}}">
@ -74,7 +74,7 @@
<div class="ui divider"></div>
<form class="ui form" method="post">
<form class="ui form" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="mirror-sync">
<div class="inline field">
@ -88,11 +88,11 @@
</div>
{{end}}
<h4 class="ui top attached header">
<div class="ui top attached header">
{{.i18n.Tr "repo.settings.advanced_settings"}}
</h4>
</div>
<div class="ui attached segment">
<form class="ui form" method="post">
<form class="ui form" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="advanced">
@ -199,7 +199,6 @@
</div>
{{end}}
<div class="ui divider"></div>
<div class="field">
<button class="ui green button">{{$.i18n.Tr "repo.settings.update_settings"}}</button>
</div>
@ -207,9 +206,9 @@
</div>
{{if .IsRepositoryOwner}}
<h4 class="ui top attached warning header">
<div class="ui top attached warning header">
{{.i18n.Tr "repo.settings.danger_zone"}}
</h4>
</div>
<div class="ui attached warning table danger segment">
{{if .Repository.IsMirror}}
<div class="item">
@ -276,7 +275,7 @@
<div class="ui warning message text left">
{{.i18n.Tr "repo.settings.convert_notices_1" | Safe}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form" action="{{.Link}}" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="convert">
<div class="field">
@ -308,7 +307,7 @@
{{.i18n.Tr "repo.settings.transfer_notices_1" | Safe}} <br>
{{.i18n.Tr "repo.settings.transfer_notices_2" | Safe}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form" action="{{.Link}}" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="transfer">
<div class="field">
@ -346,7 +345,7 @@
{{.i18n.Tr "repo.settings.delete_notices_fork_1" | Safe}}
{{end}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form" action="{{.Link}}" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="delete">
<div class="field">
@ -378,7 +377,7 @@
{{.i18n.Tr "repo.settings.delete_notices_1" | Safe}}<br>
{{.i18n.Tr "repo.settings.wiki_delete_notices_1" .Repository.Name | Safe}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form" action="{{.Link}}" method="POST">
{{.CSRFTokenHTML}}
<input type="hidden" name="action" value="delete-wiki">
<div class="field">

Loading…
Cancel
Save