Browse Source

#1067: Deleting users should remove them from collaborator lists

- fix delete user but repository watches are not decreased
tags/v0.9.99
Unknwon 9 years ago
parent
commit
466facc009

+ 22
- 13
models/action.go View File

// Action represents user operation type and other information to repository., // Action represents user operation type and other information to repository.,
// it implemented interface base.Actioner so that can be used in template render. // it implemented interface base.Actioner so that can be used in template render.
type Action struct { type Action struct {
Id int64
UserId int64 // Receiver user id.
ID int64 `xorm:"pk autoincr"`
UserID int64 // Receiver user id.
OpType ActionType OpType ActionType
ActUserId int64 // Action user id.
ActUserID int64 // Action user id.
ActUserName string // Action user name. ActUserName string // Action user name.
ActEmail string ActEmail string
ActAvatar string `xorm:"-"` ActAvatar string `xorm:"-"`
RepoId int64
RepoID int64
RepoUserName string RepoUserName string
RepoName string RepoName string
RefName string RefName string
log.Debug("action.CommitRepoAction(updateIssuesCommit): ", err) log.Debug("action.CommitRepoAction(updateIssuesCommit): ", err)
} }


if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail,
OpType: opType, Content: string(bs), RepoId: repoId, RepoUserName: repoUserName,
RepoName: repoName, RefName: refName,
IsPrivate: repo.IsPrivate}); err != nil {
if err = NotifyWatchers(&Action{
ActUserID: userId,
ActUserName: userName,
ActEmail: actEmail,
OpType: opType,
Content: string(bs),
RepoID: repoId,
RepoUserName: repoUserName,
RepoName: repoName,
RefName: refName,
IsPrivate: repo.IsPrivate,
}); err != nil {
return errors.New("action.CommitRepoAction(NotifyWatchers): " + err.Error()) return errors.New("action.CommitRepoAction(NotifyWatchers): " + err.Error())


} }


func newRepoAction(e Engine, u *User, repo *Repository) (err error) { func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{ if err = notifyWatchers(e, &Action{
ActUserId: u.Id,
ActUserID: u.Id,
ActUserName: u.Name, ActUserName: u.Name,
ActEmail: u.Email, ActEmail: u.Email,
OpType: CREATE_REPO, OpType: CREATE_REPO,
RepoId: repo.Id,
RepoID: repo.Id,
RepoUserName: repo.Owner.Name, RepoUserName: repo.Owner.Name,
RepoName: repo.Name, RepoName: repo.Name,
IsPrivate: repo.IsPrivate}); err != nil {
IsPrivate: repo.IsPrivate,
}); err != nil {
return fmt.Errorf("notify watchers '%d/%s'", u.Id, repo.Id) return fmt.Errorf("notify watchers '%d/%s'", u.Id, repo.Id)
} }




func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repository) (err error) { func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repository) (err error) {
action := &Action{ action := &Action{
ActUserId: actUser.Id,
ActUserID: actUser.Id,
ActUserName: actUser.Name, ActUserName: actUser.Name,
ActEmail: actUser.Email, ActEmail: actUser.Email,
OpType: TRANSFER_REPO, OpType: TRANSFER_REPO,
RepoId: repo.Id,
RepoID: repo.Id,
RepoUserName: newOwner.Name, RepoUserName: newOwner.Name,
RepoName: repo.Name, RepoName: repo.Name,
IsPrivate: repo.IsPrivate, IsPrivate: repo.IsPrivate,

+ 53
- 0
models/error.go View File

"fmt" "fmt"
) )


// ____ ___
// | | \______ ___________
// | | / ___// __ \_ __ \
// | | /\___ \\ ___/| | \/
// |______//____ >\___ >__|
// \/ \/

type ErrUserOwnRepos struct {
UID int64
}

func IsErrUserOwnRepos(err error) bool {
_, ok := err.(ErrUserOwnRepos)
return ok
}

func (err ErrUserOwnRepos) Error() string {
return fmt.Sprintf("user still has ownership of repositories: [uid: %d]", err.UID)
}

type ErrUserHasOrgs struct {
UID int64
}

func IsErrUserHasOrgs(err error) bool {
_, ok := err.(ErrUserHasOrgs)
return ok
}

func (err ErrUserHasOrgs) Error() string {
return fmt.Sprintf("user still has membership of organizations: [uid: %d]", err.UID)
}

// ________ .__ __ .__
// \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
// / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
// / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
// \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
// \/ /_____/ \/ \/ \/ \/ \/

type ErrLastOrgOwner struct {
UID int64
}

func IsErrLastOrgOwner(err error) bool {
_, ok := err.(ErrLastOrgOwner)
return ok
}

func (err ErrLastOrgOwner) Error() string {
return fmt.Sprintf("user is the last member of owner team: [uid: %d]", err.UID)
}

// __________ .__ __ // __________ .__ __
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |

+ 13
- 22
models/org.go View File

ErrTeamAlreadyExist = errors.New("Team already exist") ErrTeamAlreadyExist = errors.New("Team already exist")
ErrTeamNotExist = errors.New("Team does not exist") ErrTeamNotExist = errors.New("Team does not exist")
ErrTeamNameIllegal = errors.New("Team name contains illegal characters") ErrTeamNameIllegal = errors.New("Team name contains illegal characters")
ErrLastOrgOwner = errors.New("The user to remove is the last member in owner team")
) )


// IsOwnedBy returns true if given user is in the owner team. // IsOwnedBy returns true if given user is in the owner team.


has, err := x.Where("uid=?", uid).And("org_id=?", orgId).Get(ou) has, err := x.Where("uid=?", uid).And("org_id=?", orgId).Get(ou)
if err != nil { if err != nil {
return err
return fmt.Errorf("get org-user: %v", err)
} else if !has { } else if !has {
return nil return nil
} }


u, err := GetUserById(uid) u, err := GetUserById(uid)
if err != nil { if err != nil {
return err
return fmt.Errorf("GetUserById: %v", err)
} }
org, err := GetUserById(orgId) org, err := GetUserById(orgId)
if err != nil { if err != nil {
return err
return fmt.Errorf("get organization: %v", err)
} else if err = org.GetRepositories(); err != nil {
return fmt.Errorf("GetRepositories: %v", err)
} }


// Check if the user to delete is the last member in owner team. // Check if the user to delete is the last member in owner team.
return err return err
} }
if t.NumMembers == 1 { if t.NumMembers == 1 {
return ErrLastOrgOwner
return ErrLastOrgOwner{UID: uid}
} }
} }


sess := x.NewSession() sess := x.NewSession()
defer sess.Close()
defer sessionRelease(sess)
if err := sess.Begin(); err != nil { if err := sess.Begin(); err != nil {
return err return err
} }


if _, err := sess.Id(ou.ID).Delete(ou); err != nil { if _, err := sess.Id(ou.ID).Delete(ou); err != nil {
sess.Rollback()
return err return err
} else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id = ?", orgId); err != nil {
sess.Rollback()
} else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgId); err != nil {
return err return err
} }


// Delete all repository accesses. // Delete all repository accesses.
if err = org.GetRepositories(); err != nil {
sess.Rollback()
return err
}
access := &Access{
UserID: u.Id,
}
access := &Access{UserID: u.Id}
for _, repo := range org.Repos { for _, repo := range org.Repos {
access.RepoID = repo.Id access.RepoID = repo.Id
if _, err = sess.Delete(access); err != nil { if _, err = sess.Delete(access); err != nil {
sess.Rollback()
return err return err
} else if err = WatchRepo(u.Id, repo.Id, false); err != nil {
sess.Rollback()
} else if err = watchRepo(sess, u.Id, repo.Id, false); err != nil {
return err return err
} }
} }


// Delete member in his/her teams. // Delete member in his/her teams.
ts, err := GetUserTeams(org.Id, u.Id)
teams, err := getUserTeams(sess, org.Id, u.Id)
if err != nil { if err != nil {
return err return err
} }
for _, t := range ts {
for _, t := range teams {
if err = removeTeamMember(sess, org.Id, t.ID, u.Id); err != nil { if err = removeTeamMember(sess, org.Id, t.ID, u.Id); err != nil {
return err return err
} }


// Check if the user to delete is the last member in owner team. // Check if the user to delete is the last member in owner team.
if t.IsOwnerTeam() && t.NumMembers == 1 { if t.IsOwnerTeam() && t.NumMembers == 1 {
return ErrLastOrgOwner
return ErrLastOrgOwner{UID: uid}
} }


t.NumMembers-- t.NumMembers--

+ 13
- 13
models/repo.go View File

return err return err
} else if _, err = sess.Delete(&Access{RepoID: repo.Id}); err != nil { } else if _, err = sess.Delete(&Access{RepoID: repo.Id}); err != nil {
return err return err
} else if _, err = sess.Delete(&Action{RepoId: repo.Id}); err != nil {
} else if _, err = sess.Delete(&Action{RepoID: repo.Id}); err != nil {
return err return err
} else if _, err = sess.Delete(&Watch{RepoId: repoID}); err != nil {
} else if _, err = sess.Delete(&Watch{RepoID: repoID}); err != nil {
return err return err
} else if _, err = sess.Delete(&Mirror{RepoId: repoID}); err != nil { } else if _, err = sess.Delete(&Mirror{RepoId: repoID}); err != nil {
return err return err


// Watch is connection request for receiving repository notification. // Watch is connection request for receiving repository notification.
type Watch struct { type Watch struct {
Id int64
UserId int64 `xorm:"UNIQUE(watch)"`
RepoId int64 `xorm:"UNIQUE(watch)"`
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"UNIQUE(watch)"`
RepoID int64 `xorm:"UNIQUE(watch)"`
} }


// IsWatching checks if user has watched given repository. // IsWatching checks if user has watched given repository.
if IsWatching(uid, repoId) { if IsWatching(uid, repoId) {
return nil return nil
} }
if _, err = e.Insert(&Watch{RepoId: repoId, UserId: uid}); err != nil {
if _, err = e.Insert(&Watch{RepoID: repoId, UserID: uid}); err != nil {
return err return err
} }
_, err = e.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoId) _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoId)
if _, err = e.Delete(&Watch{0, uid, repoId}); err != nil { if _, err = e.Delete(&Watch{0, uid, repoId}); err != nil {
return err return err
} }
_, err = e.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoId)
_, err = e.Exec("UPDATE `repository` SET num_watches=num_watches-1 WHERE id=?", repoId)
} }
return err return err
} }


func getWatchers(e Engine, rid int64) ([]*Watch, error) { func getWatchers(e Engine, rid int64) ([]*Watch, error) {
watches := make([]*Watch, 0, 10) watches := make([]*Watch, 0, 10)
err := e.Find(&watches, &Watch{RepoId: rid})
err := e.Find(&watches, &Watch{RepoID: rid})
return watches, err return watches, err
} }




func notifyWatchers(e Engine, act *Action) error { func notifyWatchers(e Engine, act *Action) error {
// Add feeds for user self and all watchers. // Add feeds for user self and all watchers.
watches, err := getWatchers(e, act.RepoId)
watches, err := getWatchers(e, act.RepoID)
if err != nil { if err != nil {
return fmt.Errorf("get watchers: %v", err) return fmt.Errorf("get watchers: %v", err)
} }


// Add feed for actioner. // Add feed for actioner.
act.UserId = act.ActUserId
act.UserID = act.ActUserID
if _, err = e.InsertOne(act); err != nil { if _, err = e.InsertOne(act); err != nil {
return fmt.Errorf("insert new actioner: %v", err) return fmt.Errorf("insert new actioner: %v", err)
} }


for i := range watches { for i := range watches {
if act.ActUserId == watches[i].UserId {
if act.ActUserID == watches[i].UserID {
continue continue
} }


act.Id = 0
act.UserId = watches[i].UserId
act.ID = 0
act.UserID = watches[i].UserID
if _, err = e.InsertOne(act); err != nil { if _, err = e.InsertOne(act); err != nil {
return fmt.Errorf("insert new action: %v", err) return fmt.Errorf("insert new action: %v", err)
} }

+ 54
- 33
models/user.go View File

) )


var ( var (
ErrUserOwnRepos = errors.New("User still have ownership of repositories")
ErrUserHasOrgs = errors.New("User still have membership of organization")
ErrUserAlreadyExist = errors.New("User already exist") ErrUserAlreadyExist = errors.New("User already exist")
ErrUserNotExist = errors.New("User does not exist") ErrUserNotExist = errors.New("User does not exist")
ErrUserNotKeyOwner = errors.New("User does not the owner of public key") ErrUserNotKeyOwner = errors.New("User does not the owner of public key")
return err return err
} }


// DeleteBeans deletes all given beans, beans should contain delete conditions.
func DeleteBeans(e Engine, beans ...interface{}) (err error) {
for i := range beans {
if _, err = e.Delete(beans[i]); err != nil {
return err
}
}
return nil
}

// FIXME: need some kind of mechanism to record failure. HINT: system notice // FIXME: need some kind of mechanism to record failure. HINT: system notice
// DeleteUser completely and permanently deletes everything of user. // DeleteUser completely and permanently deletes everything of user.
func DeleteUser(u *User) error { func DeleteUser(u *User) error {
// Check ownership of repository. // Check ownership of repository.
count, err := GetRepositoryCount(u) count, err := GetRepositoryCount(u)
if err != nil { if err != nil {
return errors.New("GetRepositoryCount: " + err.Error())
return fmt.Errorf("GetRepositoryCount: %v", err)
} else if count > 0 { } else if count > 0 {
return ErrUserOwnRepos
return ErrUserOwnRepos{UID: u.Id}
} }


// Check membership of organization. // Check membership of organization.
count, err = u.GetOrganizationCount() count, err = u.GetOrganizationCount()
if err != nil { if err != nil {
return errors.New("GetOrganizationCount: " + err.Error())
return fmt.Errorf("GetOrganizationCount: %v", err)
} else if count > 0 { } else if count > 0 {
return ErrUserHasOrgs
return ErrUserHasOrgs{UID: u.Id}
} }


// FIXME: check issues, other repos' commits
// FIXME: roll backable in some point.

// Delete all followers.
if _, err = x.Delete(&Follow{FollowId: u.Id}); err != nil {
return err
// Get watches before session.
watches := make([]*Watch, 0, 10)
if err = x.Where("user_id=?", u.Id).Find(&watches); err != nil {
return fmt.Errorf("get all watches: %v", err)
} }
// Delete oauth2.
if _, err = x.Delete(&Oauth2{Uid: u.Id}); err != nil {
return err
repoIDs := make([]int64, 0, len(watches))
for i := range watches {
repoIDs = append(repoIDs, watches[i].RepoID)
} }
// Delete all feeds.
if _, err = x.Delete(&Action{UserId: u.Id}); err != nil {
return err
}
// Delete all watches.
if _, err = x.Delete(&Watch{UserId: u.Id}); err != nil {
// FIXME: check issues, other repos' commits
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err return err
} }
// Delete all accesses.
if _, err = x.Delete(&Access{UserID: u.Id}); err != nil {

if err = DeleteBeans(sess,
&Follow{FollowID: u.Id},
&Oauth2{Uid: u.Id},
&Action{UserID: u.Id},
&Access{UserID: u.Id},
&Collaboration{UserID: u.Id},
&EmailAddress{Uid: u.Id},
&Watch{UserID: u.Id},
); err != nil {
return err return err
} }
// Delete all alternative email addresses
if _, err = x.Delete(&EmailAddress{Uid: u.Id}); err != nil {
return err

// Decrease all watch numbers.
for i := range repoIDs {
if _, err = sess.Exec("UPDATE `repository` SET num_watches=num_watches-1 WHERE id=?", repoIDs[i]); err != nil {
return err
}
} }

// Delete all SSH keys. // Delete all SSH keys.
keys := make([]*PublicKey, 0, 10) keys := make([]*PublicKey, 0, 10)
if err = x.Find(&keys, &PublicKey{OwnerId: u.Id}); err != nil {
if err = sess.Find(&keys, &PublicKey{OwnerId: u.Id}); err != nil {
return err return err
} }
for _, key := range keys { for _, key := range keys {
} }
} }


if _, err = sess.Delete(u); err != nil {
return err
}

// Delete user directory. // Delete user directory.
if err = os.RemoveAll(UserPath(u.Name)); err != nil { if err = os.RemoveAll(UserPath(u.Name)); err != nil {
return err return err
} }


_, err = x.Delete(u)
return err
return sess.Commit()
} }


// DeleteInactivateUsers deletes all inactivate users and email addresses. // DeleteInactivateUsers deletes all inactivate users and email addresses.
// Follow is connection request for receiving user notification. // Follow is connection request for receiving user notification.
type Follow struct { type Follow struct {
Id int64 Id int64
UserId int64 `xorm:"unique(follow)"`
FollowId int64 `xorm:"unique(follow)"`
UserID int64 `xorm:"unique(follow)"`
FollowID int64 `xorm:"unique(follow)"`
} }


// FollowUser marks someone be another's follower. // FollowUser marks someone be another's follower.
defer sess.Close() defer sess.Close()
sess.Begin() sess.Begin()


if _, err = sess.Insert(&Follow{UserId: userId, FollowId: followId}); err != nil {
if _, err = sess.Insert(&Follow{UserID: userId, FollowID: followId}); err != nil {
sess.Rollback() sess.Rollback()
return err return err
} }
defer session.Close() defer session.Close()
session.Begin() session.Begin()


if _, err = session.Delete(&Follow{UserId: userId, FollowId: unFollowId}); err != nil {
if _, err = session.Delete(&Follow{UserID: userId, FollowID: unFollowId}); err != nil {
session.Rollback() session.Rollback()
return err return err
} }

+ 1
- 1
modules/mailer/mail.go View File



tos := make([]string, 0, len(ws)) tos := make([]string, 0, len(ws))
for i := range ws { for i := range ws {
uid := ws[i].UserId
uid := ws[i].UserID
if u.Id == uid { if u.Id == uid {
continue continue
} }

+ 3
- 3
routers/admin/users.go View File

} }


if err = models.DeleteUser(u); err != nil { 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.Flash.Error(ctx.Tr("admin.users.still_own_repo"))
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) 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.Flash.Error(ctx.Tr("admin.users.still_has_org"))
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid")) ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
default: default:

+ 2
- 2
routers/org/members.go View File

return return
} }
err = org.RemoveMember(uid) err = org.RemoveMember(uid)
if err == models.ErrLastOrgOwner {
if models.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
ctx.Redirect(ctx.Org.OrgLink + "/members") ctx.Redirect(ctx.Org.OrgLink + "/members")
return return
} }
case "leave": case "leave":
err = org.RemoveMember(ctx.User.Id) err = org.RemoveMember(ctx.User.Id)
if err == models.ErrLastOrgOwner {
if models.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
ctx.Redirect(ctx.Org.OrgLink + "/members") ctx.Redirect(ctx.Org.OrgLink + "/members")
return return

+ 3
- 4
routers/org/setting.go View File



org := ctx.Org.Organization org := ctx.Org.Organization
if ctx.Req.Method == "POST" { if ctx.Req.Method == "POST" {
// TODO: validate password.
// FIXME: validate password.
if err := models.DeleteOrganization(org); err != nil { 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.Flash.Error(ctx.Tr("form.org_still_own_repo"))
ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings/delete") ctx.Redirect(setting.AppSubUrl + "/org/" + org.LowerName + "/settings/delete")
default:
} else {
ctx.Handle(500, "DeleteOrganization", err) ctx.Handle(500, "DeleteOrganization", err)
} }
} else { } else {

+ 1
- 1
routers/org/teams.go View File

} }


if err != nil { if err != nil {
if err == models.ErrLastOrgOwner {
if models.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
} else { } else {
log.Error(3, "Action(%s): %v", ctx.Params(":action"), err) log.Error(3, "Action(%s): %v", ctx.Params(":action"), err)

+ 4
- 4
routers/repo/issue.go View File

} }


act := &models.Action{ act := &models.Action{
ActUserId: ctx.User.Id,
ActUserID: ctx.User.Id,
ActUserName: ctx.User.Name, ActUserName: ctx.User.Name,
ActEmail: ctx.User.Email, ActEmail: ctx.User.Email,
OpType: models.CREATE_ISSUE, OpType: models.CREATE_ISSUE,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),
RepoId: ctx.Repo.Repository.Id,
RepoID: ctx.Repo.Repository.Id,
RepoUserName: ctx.Repo.Owner.Name, RepoUserName: ctx.Repo.Owner.Name,
RepoName: ctx.Repo.Repository.Name, RepoName: ctx.Repo.Repository.Name,
RefName: ctx.Repo.BranchName, RefName: ctx.Repo.BranchName,


// Notify watchers. // Notify watchers.
act := &models.Action{ act := &models.Action{
ActUserId: ctx.User.Id,
ActUserID: ctx.User.Id,
ActUserName: ctx.User.LowerName, ActUserName: ctx.User.LowerName,
ActEmail: ctx.User.Email, ActEmail: ctx.User.Email,
OpType: models.COMMENT_ISSUE, OpType: models.COMMENT_ISSUE,
Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]), 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, RepoUserName: ctx.Repo.Owner.LowerName,
RepoName: ctx.Repo.Repository.LowerName, RepoName: ctx.Repo.Repository.LowerName,
} }

+ 2
- 2
routers/user/home.go View File

for _, act := range actions { for _, act := range actions {
if act.IsPrivate { if act.IsPrivate {
// This prevents having to retrieve the repository for each action // 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 act.RepoUserName != ctx.User.LowerName {
if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has {
continue continue
continue continue
} }
// This prevents having to retrieve the repository for each action // 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 act.RepoUserName != ctx.User.LowerName {
if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has { if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has {
continue continue

+ 4
- 11
routers/user/setting.go View File

ctx.Data["PageIsSettingsDelete"] = true ctx.Data["PageIsSettingsDelete"] = true


if ctx.Req.Method == "POST" { 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 { 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.Flash.Error(ctx.Tr("form.still_own_repo"))
ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") ctx.Redirect(setting.AppSubUrl + "/user/settings/delete")
case models.ErrUserHasOrgs:
case models.IsErrUserHasOrgs(err):
ctx.Flash.Error(ctx.Tr("form.still_has_org")) ctx.Flash.Error(ctx.Tr("form.still_has_org"))
ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") ctx.Redirect(setting.AppSubUrl + "/user/settings/delete")
default: default:

Loading…
Cancel
Save