#1067: Deleting users should remove them from collaborator lists

- fix delete user but repository watches are not decreased
This commit is contained in:
Unknwon 2015-03-17 21:51:39 -04:00
parent 33894591a6
commit 466facc009
13 changed files with 175 additions and 109 deletions

View file

@ -61,14 +61,14 @@ func init() {
// 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 ID int64 `xorm:"pk autoincr"`
UserId int64 // Receiver user id. 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
@ -319,10 +319,18 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
log.Debug("action.CommitRepoAction(updateIssuesCommit): ", err) log.Debug("action.CommitRepoAction(updateIssuesCommit): ", err)
} }
if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail, if err = NotifyWatchers(&Action{
OpType: opType, Content: string(bs), RepoId: repoId, RepoUserName: repoUserName, ActUserID: userId,
RepoName: repoName, RefName: refName, ActUserName: userName,
IsPrivate: repo.IsPrivate}); err != nil { 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())
} }
@ -443,14 +451,15 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
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)
} }
@ -465,11 +474,11 @@ func NewRepoAction(u *User, repo *Repository) (err error) {
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,

View file

@ -8,6 +8,59 @@ import (
"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)
}
// __________ .__ __ // __________ .__ __
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |

View file

@ -18,7 +18,6 @@ var (
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.
@ -339,18 +338,20 @@ func RemoveOrgUser(orgId, uid int64) error {
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.
@ -360,49 +361,39 @@ func RemoveOrgUser(orgId, uid int64) error {
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 { } else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id=?", orgId); err != nil {
sess.Rollback()
return err return err
} }
// Delete all repository accesses. // Delete all repository accesses.
if err = org.GetRepositories(); err != nil { access := &Access{UserID: u.Id}
sess.Rollback()
return err
}
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 { } else if err = watchRepo(sess, u.Id, repo.Id, false); err != nil {
sess.Rollback()
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
} }
@ -902,7 +893,7 @@ func removeTeamMember(e Engine, orgId, teamId, uid int64) error {
// 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--

View file

@ -819,9 +819,9 @@ func DeleteRepository(uid, repoID int64, userName string) error {
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
@ -1190,9 +1190,9 @@ func (repo *Repository) DeleteCollaborator(u *User) (err error) {
// Watch is connection request for receiving repository notification. // Watch is connection request for receiving repository notification.
type Watch struct { type Watch struct {
Id int64 ID int64 `xorm:"pk autoincr"`
UserId int64 `xorm:"UNIQUE(watch)"` UserID int64 `xorm:"UNIQUE(watch)"`
RepoId 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.
@ -1206,7 +1206,7 @@ func watchRepo(e Engine, uid, repoId int64, watch bool) (err error) {
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)
@ -1229,7 +1229,7 @@ func WatchRepo(uid, repoId int64, watch bool) (err error) {
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
} }
@ -1240,24 +1240,24 @@ func GetWatchers(rid int64) ([]*Watch, error) {
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.ID = 0
act.UserId = watches[i].UserId 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)
} }

View file

@ -36,8 +36,6 @@ const (
) )
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")
@ -432,55 +430,75 @@ func UpdateUser(u *User) error {
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}
}
// 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)
}
repoIDs := make([]int64, 0, len(watches))
for i := range watches {
repoIDs = append(repoIDs, watches[i].RepoID)
} }
// FIXME: check issues, other repos' commits // FIXME: check issues, other repos' commits
// FIXME: roll backable in some point.
// Delete all followers. sess := x.NewSession()
if _, err = x.Delete(&Follow{FollowId: u.Id}); err != nil { defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err return err
} }
// Delete oauth2.
if _, err = x.Delete(&Oauth2{Uid: 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 feeds.
if _, err = x.Delete(&Action{UserId: u.Id}); err != nil { // 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 return err
} }
// Delete all watches.
if _, err = x.Delete(&Watch{UserId: u.Id}); err != nil {
return err
}
// Delete all accesses.
if _, err = x.Delete(&Access{UserID: u.Id}); err != nil {
return err
}
// Delete all alternative email addresses
if _, err = x.Delete(&EmailAddress{Uid: u.Id}); 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 {
@ -489,13 +507,16 @@ func DeleteUser(u *User) error {
} }
} }
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 sess.Commit()
return err
} }
// DeleteInactivateUsers deletes all inactivate users and email addresses. // DeleteInactivateUsers deletes all inactivate users and email addresses.
@ -777,8 +798,8 @@ func SearchUserByName(opt SearchOption) (us []*User, err error) {
// 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)"` UserID int64 `xorm:"unique(follow)"`
FollowId int64 `xorm:"unique(follow)"` FollowID int64 `xorm:"unique(follow)"`
} }
// FollowUser marks someone be another's follower. // FollowUser marks someone be another's follower.
@ -787,7 +808,7 @@ func FollowUser(userId int64, followId int64) (err error) {
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
} }
@ -812,7 +833,7 @@ func UnFollowUser(userId int64, unFollowId int64) (err error) {
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
} }

View file

@ -163,7 +163,7 @@ func SendIssueNotifyMail(u, owner *models.User, repo *models.Repository, issue *
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
} }

View file

@ -222,11 +222,11 @@ func DeleteUser(ctx *middleware.Context) {
} }
if err = models.DeleteUser(u); err != nil { if err = models.DeleteUser(u); err != nil {
switch err { switch {
case models.ErrUserOwnRepos: 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:

View file

@ -61,14 +61,14 @@ func MembersAction(ctx *middleware.Context) {
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

View file

@ -87,13 +87,12 @@ func SettingsDelete(ctx *middleware.Context) {
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 { if models.IsErrUserOwnRepos(err) {
case models.ErrUserOwnRepos:
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 {

View file

@ -91,7 +91,7 @@ func TeamsAction(ctx *middleware.Context) {
} }
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)

View file

@ -270,12 +270,12 @@ func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
} }
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,
@ -845,12 +845,12 @@ func Comment(ctx *middleware.Context) {
// 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,
} }

View file

@ -104,7 +104,7 @@ func Dashboard(ctx *middleware.Context) {
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
@ -216,7 +216,7 @@ func Profile(ctx *middleware.Context) {
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

View file

@ -451,20 +451,13 @@ func SettingsDelete(ctx *middleware.Context) {
ctx.Data["PageIsSettingsDelete"] = true ctx.Data["PageIsSettingsDelete"] = true
if ctx.Req.Method == "POST" { if ctx.Req.Method == "POST" {
// tmpUser := models.User{ // FIXME: validate password.
// 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 {
if err := models.DeleteUser(ctx.User); err != nil { if err := models.DeleteUser(ctx.User); err != nil {
switch err { switch {
case models.ErrUserOwnRepos: 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: