diff options
-rw-r--r-- | conf/locale/locale_en-US.ini | 2 | ||||
-rw-r--r-- | conf/locale/locale_zh-CN.ini | 2 | ||||
-rw-r--r-- | models/action.go | 23 | ||||
-rw-r--r-- | models/repo.go | 25 | ||||
-rw-r--r-- | routers/repo/setting.go | 2 | ||||
-rw-r--r-- | templates/user/dashboard/dashboard.tmpl | 43 | ||||
-rw-r--r-- | templates/user/dashboard/feeds.tmpl | 2 |
7 files changed, 34 insertions, 65 deletions
diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 6595cbe4..5d9f2214 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -574,7 +574,7 @@ create_repo = created repository <a href="%s/%s">%s</a> commit_repo = pushed to <a href="%s/%s/src/%s">%s</a> at <a href="%s/%s">%s</a> create_issue = opened issue <a href="%s/%s/issues/%s">%s#%s</a> comment_issue = commented on issue <a href="%s/%s/issues/%s">%s#%s</a> -transfer_repo = transfered repository <code>%s</code> to <a href="%s%s">%s</a> +transfer_repo = transfered repository <code>%s</code> to <a href="/%s%s">%s</a> [tool] ago = ago diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 9b337621..b21fa573 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -572,7 +572,7 @@ create_repo = 创建了仓库 <a href="%s/%s">%s</a> commit_repo = 推送了 <a href="%s/%s/src/%s">%s</a> 分支的代码到 <a href="%s/%s">%s</a> create_issue = 创建了工单 <a href="%s/%s/issues/%s">%s#%s</a> comment_issue = 评论了工单 <a href="%s/%s/issues/%s">%s#%s</a> -transfer_repo = 将仓库 <code>%s</code> 转移至 <a href="%s%s">%s</a> +transfer_repo = 将仓库 <code>%s</code> 转移至 <a href="/%s%s">%s</a> [tool] ago = 之前 diff --git a/models/action.go b/models/action.go index 46500a92..9bd9da67 100644 --- a/models/action.go +++ b/models/action.go @@ -350,14 +350,29 @@ func NewRepoAction(u *User, repo *Repository) (err error) { // TransferRepoAction adds new action for transfering repository. func TransferRepoAction(u, newUser *User, repo *Repository) (err error) { - if err = NotifyWatchers(&Action{ActUserId: u.Id, ActUserName: u.Name, ActEmail: u.Email, - OpType: TRANSFER_REPO, RepoId: repo.Id, RepoUserName: newUser.Name, - RepoName: repo.Name, - IsPrivate: repo.IsPrivate}); err != nil { + action := &Action{ + ActUserId: u.Id, + ActUserName: u.Name, + ActEmail: u.Email, + OpType: TRANSFER_REPO, + RepoId: repo.Id, + RepoUserName: newUser.Name, + RepoName: repo.Name, + IsPrivate: repo.IsPrivate, + Content: path.Join(repo.Owner.LowerName, repo.LowerName), + } + if err = NotifyWatchers(action); err != nil { log.Error(4, "NotifyWatchers: %d/%s", u.Id, repo.Name) return err } + // Remove watch for organization. + if repo.Owner.IsOrganization() { + if err = WatchRepo(repo.Owner.Id, repo.Id, false); err != nil { + log.Error(4, "WatchRepo", err) + } + } + log.Trace("action.TransferRepoAction: %s/%s", u.Name, repo.Name) return err } diff --git a/models/repo.go b/models/repo.go index 8e7ab96b..a157b001 100644 --- a/models/repo.go +++ b/models/repo.go @@ -669,22 +669,23 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { return err } - curRepoLink := path.Join(u.LowerName, repo.LowerName) + owner := repo.Owner + oldRepoLink := path.Join(owner.LowerName, repo.LowerName) // Delete all access first if current owner is an organization. - if u.IsOrganization() { - if _, err = sess.Where("repo_name=?", curRepoLink).Delete(new(Access)); err != nil { + if owner.IsOrganization() { + if _, err = sess.Where("repo_name=?", oldRepoLink).Delete(new(Access)); err != nil { sess.Rollback() return fmt.Errorf("fail to delete current accesses: %v", err) } } else { - if _, err = sess.Where("repo_name=?", curRepoLink).And("user_name=?", u.LowerName). + if _, err = sess.Where("repo_name=?", oldRepoLink).And("user_name=?", owner.LowerName). Update(&Access{UserName: newUser.LowerName}); err != nil { sess.Rollback() return err } } - if _, err = sess.Where("repo_name=?", curRepoLink). + if _, err = sess.Where("repo_name=?", oldRepoLink). Update(&Access{RepoName: path.Join(newUser.LowerName, repo.LowerName)}); err != nil { sess.Rollback() return err @@ -703,7 +704,7 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { return err } - if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", u.Id); err != nil { + if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", owner.Id); err != nil { sess.Rollback() return err } @@ -758,7 +759,7 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { } // Change repository directory name. - if err = os.Rename(RepoPath(u.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil { + if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newUser.Name, repo.Name)); err != nil { sess.Rollback() return err } @@ -767,14 +768,8 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) error { return err } - // Add watch of new owner to repository. - if !newUser.IsOrganization() { - if err = WatchRepo(newUser.Id, repo.Id, true); err != nil { - log.Error(4, "WatchRepo", err) - } - } - if err = WatchRepo(u.Id, repo.Id, false); err != nil { - log.Error(4, "WatchRepo2", err) + if err = WatchRepo(newUser.Id, repo.Id, true); err != nil { + log.Error(4, "WatchRepo", err) } if err = TransferRepoAction(u, newUser, repo); err != nil { diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 137d104f..17ea3a44 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -112,7 +112,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } else if !isExist { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), SETTINGS_OPTIONS, nil) return - } else if err = models.TransferOwnership(ctx.Repo.Owner, newOwner, ctx.Repo.Repository); err != nil { + } else if err = models.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository); err != nil { if err == models.ErrRepoAlreadyExist { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), SETTINGS_OPTIONS, nil) } else { diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index b14b79e3..02c0102e 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -5,48 +5,7 @@ <div id="dashboard" class="container"> {{template "ng/base/alert" .}} <div id="dashboard-news" class="left grid-2-3"> - {{range .Feeds}} - <div class="news clear"> - <div class="avatar left"> - <img class="avatar-30" src="{{AvatarLink .GetActEmail}}" alt=""> - </div> - <div class="content left {{if eq .GetOpType 5}}push-news{{end}} grid-4-5"> - <p class="text-bold"> - <a href="{{AppSubUrl}}/{{.GetActUserName}}">{{.GetActUserName}}</a> - {{if eq .GetOpType 1}} - {{$.i18n.Tr "action.create_repo" AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} - {{else if eq .GetOpType 5}} - {{$.i18n.Tr "action.commit_repo" AppSubUrl .GetRepoLink .GetBranch .GetBranch AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} - {{else if eq .GetOpType 6}} - {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.create_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} - {{else if eq .GetOpType 8}} - {{$.i18n.Tr "action.transfer_repo" .GetRepoName AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} - {{else if eq .GetOpType 10}} - {{ $index := index .GetIssueInfos 0}} - {{$.i18n.Tr "action.comment_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} - {{end}} - </p> - {{if eq .GetOpType 5}} - <div class="news-content content"> - <ul class="list-no-style"> - {{ $push := ActionContent2Commits .}} - {{ $repoLink := .GetRepoLink}} - {{range $push.Commits}} - <li><img class="avatar-16" src="{{AvatarLink .AuthorEmail}}?s=16"> <a href="{{AppSubUrl}}/{{$repoLink}}/commit/{{.Sha1}}">{{ShortSha .Sha1}}</a> <span class="text-truncate grid-4-5">{{.Message}}</span></li> - {{end}} - </ul> - </div> - {{else if eq .GetOpType 6}} - <p class="news-content comment-news">{{index .GetIssueInfos 1}}</p> - {{else if eq .GetOpType 10}} - <p class="news-content comment-news">{{index .GetIssueInfos 1}}</p> - {{end}} - <p class="news-time text-italic">{{TimeSince .GetCreate $.i18n.Lang}}</p> - </div> - <i class="mega-octicon octicon-{{ActionIcon .GetOpType}} right"></i> - </div> - {{end}} + {{template "user/dashboard/feeds" .}} </div> <div class="right grid-1-3" id="dashboard-sidebar"> <ul id="dashboard-sidebar-menu" class="menu menu-line"> diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 3eb80361..4c05440b 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -14,7 +14,7 @@ {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.create_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} {{else if eq .GetOpType 8}} - {{$.i18n.Tr "action.transfer_repo" .GetRepoName AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} + {{$.i18n.Tr "action.transfer_repo" .GetContent AppSubUrl .GetRepoLink .GetRepoLink | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.comment_issue" AppSubUrl .GetRepoLink $index .GetRepoLink $index | Str2html}} |