Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4989907

Browse files
lunnywxiaoguang
andauthored
Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (#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 <[email protected]>
1 parent bf9500b commit 4989907

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

routers/web/repo/code_frequency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func CodeFrequencyData(ctx *context.Context) {
3434
ctx.Status(http.StatusAccepted)
3535
return
3636
}
37-
ctx.ServerError("GetCodeFrequencyData", err)
37+
ctx.ServerError("GetContributorStats", err)
3838
} else {
3939
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
4040
}

routers/web/repo/recent_commits.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
package repo
55

66
import (
7-
"errors"
87
"net/http"
98

109
"code.gitea.io/gitea/modules/templates"
1110
"code.gitea.io/gitea/services/context"
12-
contributors_service "code.gitea.io/gitea/services/repository"
1311
)
1412

1513
const (
@@ -26,16 +24,3 @@ func RecentCommits(ctx *context.Context) {
2624

2725
ctx.HTML(http.StatusOK, tplRecentCommits)
2826
}
29-
30-
// RecentCommitsData returns JSON of recent commits data
31-
func RecentCommitsData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
33-
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
34-
ctx.Status(http.StatusAccepted)
35-
return
36-
}
37-
ctx.ServerError("RecentCommitsData", err)
38-
} else {
39-
ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
40-
}
41-
}

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ func registerRoutes(m *web.Router) {
14881488
})
14891489
m.Group("/recent-commits", func() {
14901490
m.Get("", repo.RecentCommits)
1491-
m.Get("/data", repo.RecentCommitsData)
1491+
m.Get("/data", repo.CodeFrequencyData) // "recent-commits" also uses the same data as "code-frequency"
14921492
})
14931493
}, reqUnitCodeReader)
14941494
},

templates/repo/navbar.tmpl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
{{$canReadCode := $.Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
2+
13
<div class="ui fluid vertical menu">
24
<a class="{{if .PageIsPulse}}active {{end}}item" href="{{.RepoLink}}/activity">
35
{{ctx.Locale.Tr "repo.activity.navbar.pulse"}}
46
</a>
5-
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
6-
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
7-
</a>
8-
<a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
9-
{{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
10-
</a>
11-
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
12-
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
13-
</a>
7+
{{if $canReadCode}}
8+
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
9+
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
10+
</a>
11+
<a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
12+
{{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
13+
</a>
14+
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
15+
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
16+
</a>
17+
{{end}}
1418
</div>

0 commit comments

Comments
 (0)