mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Hide the "Details" link of commit status when the user cannot access actions (#30156)
Fix #26685 If a commit status comes from Gitea Actions and the user cannot access the repo's actions unit (the user does not have the permission or the actions unit is disabled), a 404 page will occur after clicking the "Details" link. We should hide the "Details" link in this case. <img src="https://github.com/go-gitea/gitea/assets/15528715/68361714-b784-4bb5-baab-efde4221f466" width="400px" />
This commit is contained in:
		| @@ -16,6 +16,7 @@ import ( | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	git_model "code.gitea.io/gitea/models/git" | ||||
| 	repo_model "code.gitea.io/gitea/models/repo" | ||||
| 	unit_model "code.gitea.io/gitea/models/unit" | ||||
| 	user_model "code.gitea.io/gitea/models/user" | ||||
| 	"code.gitea.io/gitea/modules/base" | ||||
| 	"code.gitea.io/gitea/modules/charset" | ||||
| @@ -81,7 +82,7 @@ func Commits(ctx *context.Context) { | ||||
| 		ctx.ServerError("CommitsByRange", err) | ||||
| 		return | ||||
| 	} | ||||
| 	ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository) | ||||
| 	ctx.Data["Commits"] = processGitCommits(ctx, commits) | ||||
|  | ||||
| 	ctx.Data["Username"] = ctx.Repo.Owner.Name | ||||
| 	ctx.Data["Reponame"] = ctx.Repo.Repository.Name | ||||
| @@ -199,7 +200,7 @@ func SearchCommits(ctx *context.Context) { | ||||
| 		return | ||||
| 	} | ||||
| 	ctx.Data["CommitCount"] = len(commits) | ||||
| 	ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository) | ||||
| 	ctx.Data["Commits"] = processGitCommits(ctx, commits) | ||||
|  | ||||
| 	ctx.Data["Keyword"] = query | ||||
| 	if all { | ||||
| @@ -242,7 +243,7 @@ func FileHistory(ctx *context.Context) { | ||||
| 		ctx.ServerError("CommitsByFileAndRange", err) | ||||
| 		return | ||||
| 	} | ||||
| 	ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository) | ||||
| 	ctx.Data["Commits"] = processGitCommits(ctx, commits) | ||||
|  | ||||
| 	ctx.Data["Username"] = ctx.Repo.Owner.Name | ||||
| 	ctx.Data["Reponame"] = ctx.Repo.Repository.Name | ||||
| @@ -353,6 +354,9 @@ func Diff(ctx *context.Context) { | ||||
| 	if err != nil { | ||||
| 		log.Error("GetLatestCommitStatus: %v", err) | ||||
| 	} | ||||
| 	if !ctx.Repo.CanRead(unit_model.TypeActions) { | ||||
| 		git_model.CommitStatusesHideActionsURL(ctx, statuses) | ||||
| 	} | ||||
|  | ||||
| 	ctx.Data["CommitStatus"] = git_model.CalcCommitStatus(statuses) | ||||
| 	ctx.Data["CommitStatuses"] = statuses | ||||
| @@ -433,3 +437,14 @@ func RawDiff(ctx *context.Context) { | ||||
| 		return | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) []*git_model.SignCommitWithStatuses { | ||||
| 	commits := git_model.ConvertFromGitCommit(ctx, gitCommits, ctx.Repo.Repository) | ||||
| 	if !ctx.Repo.CanRead(unit_model.TypeActions) { | ||||
| 		for _, commit := range commits { | ||||
| 			commit.Status.HideActionsURL(ctx) | ||||
| 			git_model.CommitStatusesHideActionsURL(ctx, commit.Statuses) | ||||
| 		} | ||||
| 	} | ||||
| 	return commits | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user