diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 23 | ||||
-rw-r--r-- | models/org.go | 23 | ||||
-rw-r--r-- | models/repo.go | 7 | ||||
-rw-r--r-- | models/user.go | 6 |
4 files changed, 40 insertions, 19 deletions
diff --git a/models/action.go b/models/action.go index 33d5246e..8d7dd6fa 100644 --- a/models/action.go +++ b/models/action.go @@ -593,12 +593,29 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error } // GetFeeds returns action list of given user in given context. -func GetFeeds(uid, offset int64, isProfile bool) ([]*Action, error) { +// userID is the user who's requesting, ctxUserID is the user/org that is requested. +// userID can be -1, if isProfile is true or in order to skip the permission check. +func GetFeeds(ctxUserID, userID, offset int64, isProfile bool) ([]*Action, error) { actions := make([]*Action, 0, 20) - sess := x.Limit(20, int(offset)).Desc("id").Where("user_id=?", uid) + sess := x.Limit(20, int(offset)).Desc("id").Where("user_id=?", ctxUserID) if isProfile { - sess.And("is_private=?", false).And("act_user_id=?", uid) + sess.And("is_private=?", false).And("act_user_id=?", ctxUserID) + } else if ctxUserID != -1 { + ctxUser := &User{Id: ctxUserID} + if err := ctxUser.GetUserRepositories(userID); err != nil { + return nil, err + } + + var repoIDs []int64 + for _, repo := range ctxUser.Repos { + repoIDs = append(repoIDs, repo.ID) + } + + if len(repoIDs) > 0 { + sess.In("repo_id", repoIDs) + } } + err := sess.Find(&actions) return actions, err } diff --git a/models/org.go b/models/org.go index 020284d8..de66af66 100644 --- a/models/org.go +++ b/models/org.go @@ -254,24 +254,27 @@ func IsPublicMembership(orgId, uid int64) bool { return has } -func getPublicOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { +func getOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { orgs := make([]*User, 0, 10) - return orgs, sess.Where("`org_user`.uid=?", userID).And("`org_user`.is_public=?", true). + return orgs, sess.Where("`org_user`.uid=?", userID). Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs) } -// GetPublicOrgsByUserID returns a list of organizations that the given user ID -// has joined publicly. -func GetPublicOrgsByUserID(userID int64) ([]*User, error) { +// GetOrgsByUserID returns a list of organizations that the given user ID +// has joined. +func GetOrgsByUserID(userID int64) ([]*User, error) { sess := x.NewSession() - return getPublicOrgsByUserID(sess, userID) + return getOrgsByUserID(sess, userID) } -// GetPublicOrgsByUserID returns a list of organizations that the given user ID -// has joined publicly, ordered descending by the given condition. -func GetPublicOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) { +// GetOrgsByUserIDDesc returns a list of organizations that the given user ID +// has joined, ordered descending by the given condition. +func GetOrgsByUserIDDesc(userID int64, desc string, all bool) ([]*User, error) { sess := x.NewSession() - return getPublicOrgsByUserID(sess.Desc(desc), userID) + if !all { + sess.And("`org_user`.is_public=?", true) + } + return getOrgsByUserID(sess.Desc(desc), userID) } func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { diff --git a/models/repo.go b/models/repo.go index be9e3fd7..a08d3a4d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -414,7 +414,8 @@ func (repo *Repository) ComposePayload() *api.PayloadRepo { Email: repo.MustOwner().Email, UserName: repo.MustOwner().Name, }, - Private: repo.IsPrivate, + Private: repo.IsPrivate, + DefaultBranch: repo.DefaultBranch, } } @@ -1101,11 +1102,13 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { return fmt.Errorf("transferRepoAction: %v", err) } - // Change repository directory name. + // Rename remote repository to new path and delete local copy. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil { return fmt.Errorf("rename repository directory: %v", err) } + RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath()) + // Rename remote wiki repository to new path and delete local copy. wikiPath := WikiPath(owner.Name, repo.Name) if com.IsExist(wikiPath) { RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath()) diff --git a/models/user.go b/models/user.go index 09ad74d7..7a881759 100644 --- a/models/user.go +++ b/models/user.go @@ -247,8 +247,6 @@ func (u *User) RelAvatarLink() string { } return "/avatars/" + com.ToStr(u.Id) - case setting.Service.EnableCacheAvatar: - return "/avatar/" + u.Avatar } return setting.GravatarSource + u.Avatar } @@ -493,7 +491,7 @@ func CreateUser(u *User) (err error) { u.LowerName = strings.ToLower(u.Name) u.AvatarEmail = u.Email - u.Avatar = avatar.HashEmail(u.AvatarEmail) + u.Avatar = base.HashEmail(u.AvatarEmail) u.Rands = GetUserSalt() u.Salt = GetUserSalt() u.EncodePasswd() @@ -628,7 +626,7 @@ func updateUser(e Engine, u *User) error { if len(u.AvatarEmail) == 0 { u.AvatarEmail = u.Email } - u.Avatar = avatar.HashEmail(u.AvatarEmail) + u.Avatar = base.HashEmail(u.AvatarEmail) } u.LowerName = strings.ToLower(u.Name) |