mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-20 16:38:44 +03:00
Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (#34053) (#34065)
Backport #34053 When a team have no code unit permission of a repository, the member of the team should not view activity contributors, recent commits and code frequrency. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@ -34,7 +34,7 @@ func CodeFrequencyData(ctx *context.Context) {
|
|||||||
ctx.Status(http.StatusAccepted)
|
ctx.Status(http.StatusAccepted)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.ServerError("GetCodeFrequencyData", err)
|
ctx.ServerError("GetContributorStats", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
|
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,10 @@
|
|||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
contributors_service "code.gitea.io/gitea/services/repository"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -26,16 +24,3 @@ func RecentCommits(ctx *context.Context) {
|
|||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplRecentCommits)
|
ctx.HTML(http.StatusOK, tplRecentCommits)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecentCommitsData returns JSON of recent commits data
|
|
||||||
func RecentCommitsData(ctx *context.Context) {
|
|
||||||
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
|
|
||||||
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
|
|
||||||
ctx.Status(http.StatusAccepted)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.ServerError("RecentCommitsData", err)
|
|
||||||
} else {
|
|
||||||
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1454,6 +1454,8 @@ func registerWebRoutes(m *web.Router) {
|
|||||||
m.Group("/{username}/{reponame}/activity", func() {
|
m.Group("/{username}/{reponame}/activity", func() {
|
||||||
m.Get("", repo.Activity)
|
m.Get("", repo.Activity)
|
||||||
m.Get("/{period}", repo.Activity)
|
m.Get("/{period}", repo.Activity)
|
||||||
|
|
||||||
|
m.Group("", func() {
|
||||||
m.Group("/contributors", func() {
|
m.Group("/contributors", func() {
|
||||||
m.Get("", repo.Contributors)
|
m.Get("", repo.Contributors)
|
||||||
m.Get("/data", repo.ContributorsData)
|
m.Get("/data", repo.ContributorsData)
|
||||||
@ -1464,10 +1466,11 @@ func registerWebRoutes(m *web.Router) {
|
|||||||
})
|
})
|
||||||
m.Group("/recent-commits", func() {
|
m.Group("/recent-commits", func() {
|
||||||
m.Get("", repo.RecentCommits)
|
m.Get("", repo.RecentCommits)
|
||||||
m.Get("/data", repo.RecentCommitsData)
|
m.Get("/data", repo.CodeFrequencyData) // "recent-commits" also uses the same data as "code-frequency"
|
||||||
})
|
})
|
||||||
|
}, reqRepoCodeReader)
|
||||||
},
|
},
|
||||||
optSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases),
|
optSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypeCode, unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases),
|
||||||
context.RepoRef(), repo.MustBeNotEmpty,
|
context.RepoRef(), repo.MustBeNotEmpty,
|
||||||
)
|
)
|
||||||
// end "/{username}/{reponame}/activity"
|
// end "/{username}/{reponame}/activity"
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
{{$canReadCode := $.Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
|
||||||
|
|
||||||
<div class="ui fluid vertical menu">
|
<div class="ui fluid vertical menu">
|
||||||
<a class="{{if .PageIsPulse}}active {{end}}item" href="{{.RepoLink}}/activity">
|
<a class="{{if .PageIsPulse}}active {{end}}item" href="{{.RepoLink}}/activity">
|
||||||
{{ctx.Locale.Tr "repo.activity.navbar.pulse"}}
|
{{ctx.Locale.Tr "repo.activity.navbar.pulse"}}
|
||||||
</a>
|
</a>
|
||||||
|
{{if $canReadCode}}
|
||||||
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
|
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
|
||||||
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
|
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
|
||||||
</a>
|
</a>
|
||||||
@ -11,4 +14,5 @@
|
|||||||
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
|
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
|
||||||
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
|
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
|
||||||
</a>
|
</a>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user