|
@@ -26,10 +26,10 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
- EDIT_FILE = "repo/editor/edit"
|
|
|
|
- EDIT_DIFF_PREVIEW = "repo/editor/diff_preview"
|
|
|
|
- DELETE_FILE = "repo/editor/delete"
|
|
|
|
- UPLOAD_FILE = "repo/editor/upload"
|
|
|
|
|
|
+ tmplEditorEdit = "repo/editor/edit"
|
|
|
|
+ tmplEditorDiffPreview = "repo/editor/diff_preview"
|
|
|
|
+ tmplEditorDelete = "repo/editor/delete"
|
|
|
|
+ tmplEditorUpload = "repo/editor/upload"
|
|
)
|
|
)
|
|
|
|
|
|
// getParentTreeFields returns list of parent tree names and corresponding tree paths
|
|
// getParentTreeFields returns list of parent tree names and corresponding tree paths
|
|
@@ -114,7 +114,7 @@ func editFile(c *context.Context, isNewFile bool) {
|
|
c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
|
|
c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
|
|
c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", conf.Server.Subpath, c.Repo.Repository.FullName())
|
|
c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", conf.Server.Subpath, c.Repo.Repository.FullName())
|
|
|
|
|
|
- c.Success(EDIT_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorEdit)
|
|
}
|
|
}
|
|
|
|
|
|
func EditFile(c *context.Context) {
|
|
func EditFile(c *context.Context) {
|
|
@@ -160,20 +160,20 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
|
|
c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
|
|
c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
|
|
|
|
|
|
if c.HasError() {
|
|
if c.HasError() {
|
|
- c.Success(EDIT_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorEdit)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
if len(f.TreePath) == 0 {
|
|
if len(f.TreePath) == 0 {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.filename_cannot_be_empty"), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.filename_cannot_be_empty"), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
if oldBranchName != branchName {
|
|
if oldBranchName != branchName {
|
|
if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
|
|
if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
|
|
c.FormErr("NewBranchName")
|
|
c.FormErr("NewBranchName")
|
|
- c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -194,17 +194,17 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
|
|
if index != len(treeNames)-1 {
|
|
if index != len(treeNames)-1 {
|
|
if !entry.IsTree() {
|
|
if !entry.IsTree() {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if entry.IsSymlink() {
|
|
if entry.IsSymlink() {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.file_is_a_symlink", part), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.file_is_a_symlink", part), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
} else if entry.IsTree() {
|
|
} else if entry.IsTree() {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.filename_is_a_directory", part), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.filename_is_a_directory", part), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -215,7 +215,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
|
|
if err != nil {
|
|
if err != nil {
|
|
if gitutil.IsErrRevisionNotExist(err) {
|
|
if gitutil.IsErrRevisionNotExist(err) {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), tmplEditorEdit, &f)
|
|
} else {
|
|
} else {
|
|
c.Error(err, "get tree entry")
|
|
c.Error(err, "get tree entry")
|
|
}
|
|
}
|
|
@@ -230,7 +230,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
|
|
|
|
|
|
for _, file := range files {
|
|
for _, file := range files {
|
|
if file == f.TreePath {
|
|
if file == f.TreePath {
|
|
- c.RenderWithErr(c.Tr("repo.editor.file_changed_while_editing", c.Repo.RepoLink+"/compare/"+lastCommit+"..."+c.Repo.CommitID), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.file_changed_while_editing", c.Repo.RepoLink+"/compare/"+lastCommit+"..."+c.Repo.CommitID), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -248,7 +248,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
|
|
}
|
|
}
|
|
if entry != nil {
|
|
if entry != nil {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.file_already_exists", f.TreePath), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.file_already_exists", f.TreePath), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -279,7 +279,7 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
|
|
}); err != nil {
|
|
}); err != nil {
|
|
log.Error("Failed to update repo file: %v", err)
|
|
log.Error("Failed to update repo file: %v", err)
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.fail_to_update_file", f.TreePath, errors.InternalServerError), EDIT_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.fail_to_update_file", f.TreePath, errors.InternalServerError), tmplEditorEdit, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -322,7 +322,7 @@ func DiffPreviewPost(c *context.Context, f form.EditPreviewDiff) {
|
|
}
|
|
}
|
|
c.Data["File"] = diff.Files[0]
|
|
c.Data["File"] = diff.Files[0]
|
|
|
|
|
|
- c.Success(EDIT_DIFF_PREVIEW)
|
|
|
|
|
|
+ c.Success(tmplEditorDiffPreview)
|
|
}
|
|
}
|
|
|
|
|
|
func DeleteFile(c *context.Context) {
|
|
func DeleteFile(c *context.Context) {
|
|
@@ -333,7 +333,7 @@ func DeleteFile(c *context.Context) {
|
|
c.Data["commit_message"] = ""
|
|
c.Data["commit_message"] = ""
|
|
c.Data["commit_choice"] = "direct"
|
|
c.Data["commit_choice"] = "direct"
|
|
c.Data["new_branch_name"] = ""
|
|
c.Data["new_branch_name"] = ""
|
|
- c.Success(DELETE_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorDelete)
|
|
}
|
|
}
|
|
|
|
|
|
func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
|
|
func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
|
|
@@ -355,14 +355,14 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
|
|
c.Data["new_branch_name"] = branchName
|
|
c.Data["new_branch_name"] = branchName
|
|
|
|
|
|
if c.HasError() {
|
|
if c.HasError() {
|
|
- c.Success(DELETE_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorDelete)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
if oldBranchName != branchName {
|
|
if oldBranchName != branchName {
|
|
if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
|
|
if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
|
|
c.FormErr("NewBranchName")
|
|
c.FormErr("NewBranchName")
|
|
- c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), DELETE_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), tmplEditorDelete, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -385,7 +385,7 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
|
|
Message: message,
|
|
Message: message,
|
|
}); err != nil {
|
|
}); err != nil {
|
|
log.Error("Failed to delete repo file: %v", err)
|
|
log.Error("Failed to delete repo file: %v", err)
|
|
- c.RenderWithErr(c.Tr("repo.editor.fail_to_delete_file", c.Repo.TreePath, errors.InternalServerError), DELETE_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.fail_to_delete_file", c.Repo.TreePath, errors.InternalServerError), tmplEditorDelete, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -421,7 +421,7 @@ func UploadFile(c *context.Context) {
|
|
c.Data["commit_message"] = ""
|
|
c.Data["commit_message"] = ""
|
|
c.Data["commit_choice"] = "direct"
|
|
c.Data["commit_choice"] = "direct"
|
|
c.Data["new_branch_name"] = ""
|
|
c.Data["new_branch_name"] = ""
|
|
- c.Success(UPLOAD_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorUpload)
|
|
}
|
|
}
|
|
|
|
|
|
func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
|
|
func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
|
|
@@ -452,14 +452,14 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
|
|
c.Data["new_branch_name"] = branchName
|
|
c.Data["new_branch_name"] = branchName
|
|
|
|
|
|
if c.HasError() {
|
|
if c.HasError() {
|
|
- c.Success(UPLOAD_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorUpload)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
if oldBranchName != branchName {
|
|
if oldBranchName != branchName {
|
|
if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
|
|
if _, err := c.Repo.Repository.GetBranch(branchName); err == nil {
|
|
c.FormErr("NewBranchName")
|
|
c.FormErr("NewBranchName")
|
|
- c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), UPLOAD_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.branch_already_exists", branchName), tmplEditorUpload, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -481,7 +481,7 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
|
|
// User can only upload files to a directory.
|
|
// User can only upload files to a directory.
|
|
if !entry.IsTree() {
|
|
if !entry.IsTree() {
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), UPLOAD_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.directory_is_a_file", part), tmplEditorUpload, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -506,7 +506,7 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
|
|
}); err != nil {
|
|
}); err != nil {
|
|
log.Error("Failed to upload files: %v", err)
|
|
log.Error("Failed to upload files: %v", err)
|
|
c.FormErr("TreePath")
|
|
c.FormErr("TreePath")
|
|
- c.RenderWithErr(c.Tr("repo.editor.unable_to_upload_files", f.TreePath, errors.InternalServerError), UPLOAD_FILE, &f)
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("repo.editor.unable_to_upload_files", f.TreePath, errors.InternalServerError), tmplEditorUpload, &f)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -578,6 +578,7 @@ func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
|
|
c.Status(http.StatusNoContent)
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// CreateDatacite is GIN specific code
|
|
func CreateDatacite(c *context.Context) {
|
|
func CreateDatacite(c *context.Context) {
|
|
dcname := path.Join("conf/datacite/datacite.yml")
|
|
dcname := path.Join("conf/datacite/datacite.yml")
|
|
treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
|
|
treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
|
|
@@ -604,5 +605,5 @@ func CreateDatacite(c *context.Context) {
|
|
c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
|
|
c.Data["PreviewableFileModes"] = strings.Join(conf.Repository.Editor.PreviewableFileModes, ",")
|
|
c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", conf.Server.Subpath, c.Repo.Repository.FullName())
|
|
c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", conf.Server.Subpath, c.Repo.Repository.FullName())
|
|
|
|
|
|
- c.Success(EDIT_FILE)
|
|
|
|
|
|
+ c.Success(tmplEditorEdit)
|
|
}
|
|
}
|