diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-05-07 18:21:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-07 18:21:15 +0200 |
commit | 8adba93498ccdde7edcb54e10f6a3d176c3815c4 (patch) | |
tree | e48b5809a0a76ca8c2087d373d00a225b713ebb3 /routers/web | |
parent | 38d72d40f132df8a6e90063f3e96a80048bf299e (diff) | |
download | gitea-8adba93498ccdde7edcb54e10f6a3d176c3815c4.tar.gz gitea-8adba93498ccdde7edcb54e10f6a3d176c3815c4.zip |
Hide private repositories in packages (#19584)
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/packages.go | 1 | ||||
-rw-r--r-- | routers/web/user/package.go | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/routers/web/repo/packages.go b/routers/web/repo/packages.go index b4db2d5787..03ea4fc5f4 100644 --- a/routers/web/repo/packages.go +++ b/routers/web/repo/packages.go @@ -62,6 +62,7 @@ func Packages(ctx *context.Context) { ctx.Data["HasPackages"] = hasPackages ctx.Data["PackageDescriptors"] = pds ctx.Data["Total"] = total + ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5) pager.AddParam(ctx, "q", "Query") diff --git a/routers/web/user/package.go b/routers/web/user/package.go index 04b4e1e8ec..1c33998db9 100644 --- a/routers/web/user/package.go +++ b/routers/web/user/package.go @@ -58,6 +58,23 @@ func ListPackages(ctx *context.Context) { return } + repositoryAccessMap := make(map[int64]bool) + for _, pd := range pds { + if pd.Repository == nil { + continue + } + if _, has := repositoryAccessMap[pd.Repository.ID]; has { + continue + } + + permission, err := models.GetUserRepoPermission(ctx, pd.Repository, ctx.Doer) + if err != nil { + ctx.ServerError("GetUserRepoPermission", err) + return + } + repositoryAccessMap[pd.Repository.ID] = permission.HasAccess() + } + hasPackages, err := packages_model.HasOwnerPackages(ctx, ctx.ContextUser.ID) if err != nil { ctx.ServerError("HasOwnerPackages", err) @@ -72,6 +89,7 @@ func ListPackages(ctx *context.Context) { ctx.Data["HasPackages"] = hasPackages ctx.Data["PackageDescriptors"] = pds ctx.Data["Total"] = total + ctx.Data["RepositoryAccessMap"] = repositoryAccessMap pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5) pager.AddParam(ctx, "q", "Query") @@ -157,6 +175,17 @@ func ViewPackageVersion(ctx *context.Context) { ctx.Data["CanWritePackages"] = ctx.Package.AccessMode >= perm.AccessModeWrite || ctx.IsUserSiteAdmin() + hasRepositoryAccess := false + if pd.Repository != nil { + permission, err := models.GetUserRepoPermission(ctx, pd.Repository, ctx.Doer) + if err != nil { + ctx.ServerError("GetUserRepoPermission", err) + return + } + hasRepositoryAccess = permission.HasAccess() + } + ctx.Data["HasRepositoryAccess"] = hasRepositoryAccess + ctx.HTML(http.StatusOK, tplPackagesView) } |