diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-12 20:35:35 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-12 20:35:35 -0400 |
commit | 90f6aa8cd19e489723ddffc40d6507782c29756c (patch) | |
tree | e247229573a4d32ca1d508619951a9868690840f /modules | |
parent | 23bba7633bbd8ae8f9f41404352c327f9e8c9fdc (diff) | |
download | gitea-90f6aa8cd19e489723ddffc40d6507782c29756c.tar.gz gitea-90f6aa8cd19e489723ddffc40d6507782c29756c.zip |
Add repo mirror and import
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/auth.go | 4 | ||||
-rw-r--r-- | modules/auth/repo.go | 42 | ||||
-rw-r--r-- | modules/middleware/repo.go | 24 |
3 files changed, 43 insertions, 27 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 4561dd831d..7329cbdcdf 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -130,7 +130,9 @@ func validate(errors *binding.Errors, data base.TmplData, form Form) { case binding.MaxSizeError: data["ErrorMsg"] = form.Name(field.Name) + " must contain at most " + getMinMaxSize(field) + " characters" case binding.EmailError: - data["ErrorMsg"] = form.Name(field.Name) + " is not valid" + data["ErrorMsg"] = form.Name(field.Name) + " is not a valid e-mail address" + case binding.UrlError: + data["ErrorMsg"] = form.Name(field.Name) + " is not a valid URL" default: data["ErrorMsg"] = "Unknown error: " + err } diff --git a/modules/auth/repo.go b/modules/auth/repo.go index 1c740bed19..aa94058f9d 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -18,11 +18,11 @@ import ( type CreateRepoForm struct { RepoName string `form:"repo" binding:"Required;AlphaDash"` - Private string `form:"private"` + Private bool `form:"private"` Description string `form:"desc" binding:"MaxSize(100)"` Language string `form:"language"` License string `form:"license"` - InitReadme string `form:"initReadme"` + InitReadme bool `form:"initReadme"` } func (f *CreateRepoForm) Name(field string) string { @@ -51,3 +51,41 @@ func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, con validate(errors, data, f) } + +type MigrateRepoForm struct { + Url string `form:"url" binding:"Url"` + AuthUserName string `form:"auth_username"` + AuthPasswd string `form:"auth_password"` + RepoName string `form:"repo" binding:"Required;AlphaDash"` + Mirror bool `form:"mirror"` + Private bool `form:"private"` + Description string `form:"desc" binding:"MaxSize(100)"` +} + +func (f *MigrateRepoForm) Name(field string) string { + names := map[string]string{ + "Url": "Migration URL", + "RepoName": "Repository name", + "Description": "Description", + } + return names[field] +} + +func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + if req.Method == "GET" || errors.Count() == 0 { + return + } + + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + data["HasError"] = true + AssignForm(f, data) + + if len(errors.Overall) > 0 { + for _, err := range errors.Overall { + log.Error("MigrateRepoForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 75d9f999c6..2a6d300e42 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -190,27 +190,3 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching } } - -func WriteAccess() martini.Handler { - return func(ctx *Context) { - if ctx.Repo.Repository.IsPrivate { - ctx.Repo.HasAccess = false - ctx.Data["HasAccess"] = false - if ctx.User == nil { - ctx.Handle(404, "WriteAccess", nil) - return - } - - hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+ctx.Repo.Repository.Name, models.AU_WRITABLE) - if err != nil { - ctx.Handle(500, "WriteAccess(HasAccess)", err) - return - } else if !hasAccess { - ctx.Handle(404, "WriteAccess(HasAccess)", nil) - return - } - } - ctx.Repo.HasAccess = true - ctx.Data["HasAccess"] = true - } -} |