diff options
author | Unknwon <u@gogs.io> | 2015-03-17 21:51:39 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-03-17 21:51:39 -0400 |
commit | 466facc0097bf636b6a945a0daebb7c4c5c33c91 (patch) | |
tree | 614c2782ff5b59dd40cea9a9caadb93d46570258 /routers | |
parent | 33894591a6d391674e938d018801d88d0011f0b7 (diff) | |
download | gitea-466facc0097bf636b6a945a0daebb7c4c5c33c91.tar.gz gitea-466facc0097bf636b6a945a0daebb7c4c5c33c91.zip |
#1067: Deleting users should remove them from collaborator lists
- fix delete user but repository watches are not decreased
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/users.go | 6 | ||||
-rw-r--r-- | routers/org/members.go | 4 | ||||
-rw-r--r-- | routers/org/setting.go | 7 | ||||
-rw-r--r-- | routers/org/teams.go | 2 | ||||
-rw-r--r-- | routers/repo/issue.go | 8 | ||||
-rw-r--r-- | routers/user/home.go | 4 | ||||
-rw-r--r-- | routers/user/setting.go | 15 |
7 files changed, 19 insertions, 27 deletions
diff --git a/routers/admin/users.go b/routers/admin/users.go index 4f57407a2a..ddd12a8b22 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -222,11 +222,11 @@ func DeleteUser(ctx *middleware.Context) { } if err = models.DeleteUser(u); err != nil { - switch err { - case models.ErrUserOwnRepos: + switch { + case models.IsErrUserOwnRepos(err): ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo")) ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) - case models.ErrUserHasOrgs: + case models.IsErrUserHasOrgs(err): ctx.Flash.Error(ctx.Tr("admin.users.still_has_org")) ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) default: diff --git a/routers/org/members.go b/routers/org/members.go index f571e334e1..c8c90cfe48 100644 --- a/routers/org/members.go +++ b/routers/org/members.go @@ -61,14 +61,14 @@ func MembersAction(ctx *middleware.Context) { return } err = org.RemoveMember(uid) - if err == models.ErrLastOrgOwner { + if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Redirect(ctx.Org.OrgLink + "/members") return } case "leave": err = org.RemoveMember(ctx.User.Id) - if err == models.ErrLastOrgOwner { + if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Redirect(ctx.Org.OrgLink + "/members") return diff --git a/routers/org/setting.go b/routers/org/setting.go index c638a032e7..8bc6a2a96a 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -87,13 +87,12 @@ func SettingsDelete(ctx *middleware.Context) { org := ctx.Org.Organization if ctx.Req.Method == "POST" { - // TODO: validate password. + // FIXME: validate password. if err := models.DeleteOrganization(org); err != nil { - switch err { - case models.ErrUserOwnRepos: + if models.IsErrUserOwnRepos(err) { ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings/delete") - default: + } else { ctx.Handle(500, "DeleteOrganization", err) } } else { diff --git a/routers/org/teams.go b/routers/org/teams.go index 40345cf7c6..7436e30ee0 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -91,7 +91,7 @@ func TeamsAction(ctx *middleware.Context) { } if err != nil { - if err == models.ErrLastOrgOwner { + if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) } else { log.Error(3, "Action(%s): %v", ctx.Params(":action"), err) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index abe33bebf3..294d3d2844 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -270,12 +270,12 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { } act := &models.Action{ - ActUserId: ctx.User.Id, + ActUserID: ctx.User.Id, ActUserName: ctx.User.Name, ActEmail: ctx.User.Email, OpType: models.CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), - RepoId: ctx.Repo.Repository.Id, + RepoID: ctx.Repo.Repository.Id, RepoUserName: ctx.Repo.Owner.Name, RepoName: ctx.Repo.Repository.Name, RefName: ctx.Repo.BranchName, @@ -845,12 +845,12 @@ func Comment(ctx *middleware.Context) { // Notify watchers. act := &models.Action{ - ActUserId: ctx.User.Id, + ActUserID: ctx.User.Id, ActUserName: ctx.User.LowerName, ActEmail: ctx.User.Email, OpType: models.COMMENT_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]), - RepoId: ctx.Repo.Repository.Id, + RepoID: ctx.Repo.Repository.Id, RepoUserName: ctx.Repo.Owner.LowerName, RepoName: ctx.Repo.Repository.LowerName, } diff --git a/routers/user/home.go b/routers/user/home.go index d690b3a7c5..86e907e349 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -104,7 +104,7 @@ func Dashboard(ctx *middleware.Context) { for _, act := range actions { if act.IsPrivate { // This prevents having to retrieve the repository for each action - repo := &models.Repository{Id: act.RepoId, IsPrivate: true} + repo := &models.Repository{Id: act.RepoID, IsPrivate: true} if act.RepoUserName != ctx.User.LowerName { if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { continue @@ -216,7 +216,7 @@ func Profile(ctx *middleware.Context) { continue } // This prevents having to retrieve the repository for each action - repo := &models.Repository{Id: act.RepoId, IsPrivate: true} + repo := &models.Repository{Id: act.RepoID, IsPrivate: true} if act.RepoUserName != ctx.User.LowerName { if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { continue diff --git a/routers/user/setting.go b/routers/user/setting.go index a44d3b7e5d..8d8ad0ad8e 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -451,20 +451,13 @@ func SettingsDelete(ctx *middleware.Context) { ctx.Data["PageIsSettingsDelete"] = true if ctx.Req.Method == "POST" { - // tmpUser := models.User{ - // Passwd: ctx.Query("password"), - // Salt: ctx.User.Salt, - // } - // tmpUser.EncodePasswd() - // if tmpUser.Passwd != ctx.User.Passwd { - // ctx.Flash.Error("Password is not correct. Make sure you are owner of this account.") - // } else { + // FIXME: validate password. if err := models.DeleteUser(ctx.User); err != nil { - switch err { - case models.ErrUserOwnRepos: + switch { + case models.IsErrUserOwnRepos(err): ctx.Flash.Error(ctx.Tr("form.still_own_repo")) ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") - case models.ErrUserHasOrgs: + case models.IsErrUserHasOrgs(err): ctx.Flash.Error(ctx.Tr("form.still_has_org")) ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") default: |