diff options
author | Joe Chen <jc@unknwon.io> | 2022-10-22 14:41:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-22 14:41:40 +0800 |
commit | c502dc6ed888a4cf2c8b36176585f4166536ab6d (patch) | |
tree | 71e3f758069dc2435eecb88ae786b2efaaa972f9 /internal/route | |
parent | 260e990be75885e1a560df449dacdeecafeffdcf (diff) |
refactor(db): move some methods from `user.go` to `users.go` (#7195)
Diffstat (limited to 'internal/route')
-rw-r--r-- | internal/route/admin/orgs.go | 2 | ||||
-rw-r--r-- | internal/route/admin/users.go | 2 | ||||
-rw-r--r-- | internal/route/api/v1/org/org.go | 2 | ||||
-rw-r--r-- | internal/route/api/v1/user/user.go | 2 | ||||
-rw-r--r-- | internal/route/home.go | 4 | ||||
-rw-r--r-- | internal/route/org/org.go | 2 | ||||
-rw-r--r-- | internal/route/repo/pull.go | 2 | ||||
-rw-r--r-- | internal/route/repo/repo.go | 8 | ||||
-rw-r--r-- | internal/route/repo/setting.go | 3 | ||||
-rw-r--r-- | internal/route/user/profile.go | 2 |
10 files changed, 15 insertions, 14 deletions
diff --git a/internal/route/admin/orgs.go b/internal/route/admin/orgs.go index fd034027..06aa74be 100644 --- a/internal/route/admin/orgs.go +++ b/internal/route/admin/orgs.go @@ -21,7 +21,7 @@ func Organizations(c *context.Context) { c.Data["PageIsAdminOrganizations"] = true route.RenderUserSearch(c, &route.UserSearchOptions{ - Type: db.UserOrganization, + Type: db.UserTypeOrganization, Counter: db.CountOrganizations, Ranger: db.Organizations, PageSize: conf.UI.Admin.OrgPagingNum, diff --git a/internal/route/admin/users.go b/internal/route/admin/users.go index e4e0a6d6..ef890e7d 100644 --- a/internal/route/admin/users.go +++ b/internal/route/admin/users.go @@ -30,7 +30,7 @@ func Users(c *context.Context) { c.Data["PageIsAdminUsers"] = true route.RenderUserSearch(c, &route.UserSearchOptions{ - Type: db.UserIndividual, + Type: db.UserTypeIndividual, Counter: db.CountUsers, Ranger: db.ListUsers, PageSize: conf.UI.Admin.UserPagingNum, diff --git a/internal/route/api/v1/org/org.go b/internal/route/api/v1/org/org.go index 7a7de50e..4d987dbf 100644 --- a/internal/route/api/v1/org/org.go +++ b/internal/route/api/v1/org/org.go @@ -27,7 +27,7 @@ func CreateOrgForUser(c *context.APIContext, apiForm api.CreateOrgOption, user * Website: apiForm.Website, Location: apiForm.Location, IsActive: true, - Type: db.UserOrganization, + Type: db.UserTypeOrganization, } if err := db.CreateOrganization(org, user); err != nil { if db.IsErrUserAlreadyExist(err) || diff --git a/internal/route/api/v1/user/user.go b/internal/route/api/v1/user/user.go index c57f8fed..2b26a282 100644 --- a/internal/route/api/v1/user/user.go +++ b/internal/route/api/v1/user/user.go @@ -19,7 +19,7 @@ import ( func Search(c *context.APIContext) { opts := &db.SearchUserOptions{ Keyword: c.Query("q"), - Type: db.UserIndividual, + Type: db.UserTypeIndividual, PageSize: com.StrTo(c.Query("limit")).MustInt(), } if opts.PageSize == 0 { diff --git a/internal/route/home.go b/internal/route/home.go index b1e2cc7a..51c7b54b 100644 --- a/internal/route/home.go +++ b/internal/route/home.go @@ -138,7 +138,7 @@ func ExploreUsers(c *context.Context) { c.Data["PageIsExploreUsers"] = true RenderUserSearch(c, &UserSearchOptions{ - Type: db.UserIndividual, + Type: db.UserTypeIndividual, Counter: db.CountUsers, Ranger: db.ListUsers, PageSize: conf.UI.ExplorePagingNum, @@ -153,7 +153,7 @@ func ExploreOrganizations(c *context.Context) { c.Data["PageIsExploreOrganizations"] = true RenderUserSearch(c, &UserSearchOptions{ - Type: db.UserOrganization, + Type: db.UserTypeOrganization, Counter: db.CountOrganizations, Ranger: db.Organizations, PageSize: conf.UI.ExplorePagingNum, diff --git a/internal/route/org/org.go b/internal/route/org/org.go index 424cbd15..badd0d81 100644 --- a/internal/route/org/org.go +++ b/internal/route/org/org.go @@ -32,7 +32,7 @@ func CreatePost(c *context.Context, f form.CreateOrg) { org := &db.User{ Name: f.OrgName, IsActive: true, - Type: db.UserOrganization, + Type: db.UserTypeOrganization, } if err := db.CreateOrganization(org, c.User); err != nil { diff --git a/internal/route/repo/pull.go b/internal/route/repo/pull.go index 68389532..d65b1e10 100644 --- a/internal/route/repo/pull.go +++ b/internal/route/repo/pull.go @@ -135,7 +135,7 @@ func ForkPost(c *context.Context, f form.CreateRepo) { c.Data["Err_RepoName"] = true switch { case db.IsErrReachLimitOfRepo(err): - c.RenderWithErr(c.Tr("repo.form.reach_limit_of_creation", c.User.RepoCreationNum()), FORK, &f) + c.RenderWithErr(c.Tr("repo.form.reach_limit_of_creation", err.(db.ErrReachLimitOfRepo).Limit), FORK, &f) case db.IsErrRepoAlreadyExist(err): c.RenderWithErr(c.Tr("repo.settings.new_owner_has_same_repo"), FORK, &f) case db.IsErrNameNotAllowed(err): diff --git a/internal/route/repo/repo.go b/internal/route/repo/repo.go index c1fb327b..943540c8 100644 --- a/internal/route/repo/repo.go +++ b/internal/route/repo/repo.go @@ -86,10 +86,10 @@ func Create(c *context.Context) { c.Success(CREATE) } -func handleCreateError(c *context.Context, owner *db.User, err error, name, tpl string, form interface{}) { +func handleCreateError(c *context.Context, err error, name, tpl string, form interface{}) { switch { case db.IsErrReachLimitOfRepo(err): - c.RenderWithErr(c.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form) + c.RenderWithErr(c.Tr("repo.form.reach_limit_of_creation", err.(db.ErrReachLimitOfRepo).Limit), tpl, form) case db.IsErrRepoAlreadyExist(err): c.Data["Err_RepoName"] = true c.RenderWithErr(c.Tr("form.repo_name_been_taken"), tpl, form) @@ -141,7 +141,7 @@ func CreatePost(c *context.Context, f form.CreateRepo) { } } - handleCreateError(c, ctxUser, err, "CreatePost", CREATE, &f) + handleCreateError(c, err, "CreatePost", CREATE, &f) } func Migrate(c *context.Context) { @@ -227,7 +227,7 @@ func MigratePost(c *context.Context, f form.MigrateRepo) { return } - handleCreateError(c, ctxUser, err, "MigratePost", MIGRATE, &f) + handleCreateError(c, err, "MigratePost", MIGRATE, &f) } func Action(c *context.Context) { diff --git a/internal/route/repo/setting.go b/internal/route/repo/setting.go index 8c706981..a977fcc8 100644 --- a/internal/route/repo/setting.go +++ b/internal/route/repo/setting.go @@ -22,6 +22,7 @@ import ( "gogs.io/gogs/internal/form" "gogs.io/gogs/internal/osutil" "gogs.io/gogs/internal/tool" + "gogs.io/gogs/internal/userutil" ) const ( @@ -269,7 +270,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) { log.Trace("Repository deleted: %s/%s", c.Repo.Owner.Name, repo.Name) c.Flash.Success(c.Tr("repo.settings.deletion_success")) - c.Redirect(c.Repo.Owner.DashboardLink()) + c.Redirect(userutil.DashboardURLPath(c.Repo.Owner.Name, c.Repo.Owner.IsOrganization())) case "delete-wiki": if !c.Repo.IsOwner() { diff --git a/internal/route/user/profile.go b/internal/route/user/profile.go index 25127028..783fb63c 100644 --- a/internal/route/user/profile.go +++ b/internal/route/user/profile.go @@ -118,7 +118,7 @@ func Action(c *context.Context, puser *context.ParamsUser) { redirectTo := c.Query("redirect_to") if !tool.IsSameSiteURLPath(redirectTo) { - redirectTo = puser.HomeLink() + redirectTo = puser.HomeURLPath() } c.Redirect(redirectTo) } |