Code clean up for new config options

This commit is contained in:
Unknwon 2016-08-12 02:29:29 -07:00
parent d0a0239bac
commit 15845cb287
17 changed files with 87 additions and 110 deletions

View file

@ -64,13 +64,8 @@ func NewBranchPost(ctx *context.Context, form auth.NewBranchForm) {
log.Error(4, "branch.GetCommit(): %v", err)
} else {
pc := &models.PushCommits{
Len: 1,
Commits: []*models.PushCommit{&models.PushCommit{
commit.ID.String(),
commit.Message(),
commit.Author.Email,
commit.Author.Name,
}},
Len: 1,
Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
}
oldCommitID := "0000000000000000000000000000000000000000" // New Branch so we use all 0s
newCommitID := commit.ID.String()

View file

@ -32,13 +32,8 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
log.Error(4, "branch.GetCommit(): %v", err)
} else {
pc := &models.PushCommits{
Len: 1,
Commits: []*models.PushCommit{&models.PushCommit{
commit.ID.String(),
commit.Message(),
commit.Author.Email,
commit.Author.Name,
}},
Len: 1,
Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
}
oldCommitID := ctx.Repo.CommitID
newCommitID := commit.ID.String()

View file

@ -89,7 +89,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...)
if err, content := template.ToUtf8WithErr(buf); err != nil {
if err, content := template.ToUTF8WithErr(buf); err != nil {
if err != nil {
log.Error(4, "Convert content encoding: %s", err)
}
@ -116,10 +116,10 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+branchName+"</strong>")
ctx.Data["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>")
ctx.Data["LastCommit"] = ctx.Repo.Commit.ID
ctx.Data["MdFileExtensions"] = strings.Join(setting.Markdown.MdFileExtensions, ",")
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Editor.LineWrapExtensions, ",")
ctx.Data["PreviewTabApis"] = strings.Join(setting.Editor.PreviewTabApis, ",")
ctx.Data["PreviewDiffUrl"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
ctx.Data["PreviewDiffURL"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
ctx.HTML(200, EDIT)
}
@ -176,10 +176,10 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
ctx.Data["CommitDirectlyToThisBranch"] = ctx.Tr("repo.commit_directly_to_this_branch", "<strong class=\"branch-name\">"+oldBranchName+"</strong>")
ctx.Data["CreateNewBranch"] = ctx.Tr("repo.create_new_branch", "<strong>"+ctx.Tr("repo.new_branch")+"</strong>")
ctx.Data["LastCommit"] = ctx.Repo.Commit.ID
ctx.Data["MdFileExtensions"] = strings.Join(setting.Markdown.MdFileExtensions, ",")
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Editor.LineWrapExtensions, ",")
ctx.Data["PreviewTabApis"] = strings.Join(setting.Editor.PreviewTabApis, ",")
ctx.Data["PreviewDiffUrl"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
ctx.Data["PreviewDiffURL"] = ctx.Repo.RepoLink + "/preview/" + branchName + "/" + treeName
if ctx.HasError() {
ctx.HTML(200, EDIT)
@ -293,13 +293,8 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
log.Error(4, "branch.GetCommit(): %v", err)
} else {
pc := &models.PushCommits{
Len: 1,
Commits: []*models.PushCommit{&models.PushCommit{
commit.ID.String(),
commit.Message(),
commit.Author.Email,
commit.Author.Name,
}},
Len: 1,
Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
}
oldCommitID := ctx.Repo.CommitID
newCommitID := commit.ID.String()

View file

@ -24,10 +24,10 @@ const (
func renderUploadSettings(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true
ctx.Data["IsUploadEnabled"] = setting.UploadEnabled
ctx.Data["UploadAllowedTypes"] = setting.UploadAllowedTypes
ctx.Data["UploadMaxSize"] = setting.UploadMaxSize
ctx.Data["UploadMaxFiles"] = setting.UploadMaxFiles
ctx.Data["IsUploadEnabled"] = setting.Repository.Upload.Enabled
ctx.Data["UploadAllowedTypes"] = strings.Join(setting.Repository.Upload.AllowedTypes, ",")
ctx.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize
ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
}
func UploadFile(ctx *context.Context) {
@ -154,13 +154,8 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
log.Error(4, "branch.GetCommit(): %v", err)
} else {
pc := &models.PushCommits{
Len: 1,
Commits: []*models.PushCommit{&models.PushCommit{
commit.ID.String(),
commit.Message(),
commit.Author.Email,
commit.Author.Name,
}},
Len: 1,
Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
}
oldCommitID := ctx.Repo.CommitID
newCommitID := commit.ID.String()
@ -184,7 +179,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
}
func UploadFileToServer(ctx *context.Context) {
if !setting.UploadEnabled {
if !setting.Repository.Upload.Enabled {
ctx.Error(404, "upload is not enabled")
return
}
@ -203,10 +198,9 @@ func UploadFileToServer(ctx *context.Context) {
}
fileType := http.DetectContentType(buf)
if len(setting.UploadAllowedTypes) > 0 {
allowedTypes := strings.Split(setting.UploadAllowedTypes, ",")
if len(setting.Repository.Upload.AllowedTypes) > 0 {
allowed := false
for _, t := range allowedTypes {
for _, t := range setting.Repository.Upload.AllowedTypes {
t := strings.Trim(t, " ")
if t == "*/*" || t == fileType {
allowed = true
@ -233,7 +227,7 @@ func UploadFileToServer(ctx *context.Context) {
}
func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) {
if !setting.UploadEnabled {
if !setting.Repository.Upload.Enabled {
ctx.Error(404, "upload is not enabled")
return
}

View file

@ -257,7 +257,7 @@ func Home(ctx *context.Context) {
ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
ctx.Data["NewFileLink"] = newFileLink + "/" + treename
if setting.UploadEnabled {
if !setting.Repository.Upload.Enabled {
ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename
}
}