aboutsummaryrefslogtreecommitdiffstats
path: root/modules/convert/package.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-05-07 18:21:15 +0200
committerGitHub <noreply@github.com>2022-05-07 18:21:15 +0200
commit8adba93498ccdde7edcb54e10f6a3d176c3815c4 (patch)
treee48b5809a0a76ca8c2087d373d00a225b713ebb3 /modules/convert/package.go
parent38d72d40f132df8a6e90063f3e96a80048bf299e (diff)
downloadgitea-8adba93498ccdde7edcb54e10f6a3d176c3815c4.tar.gz
gitea-8adba93498ccdde7edcb54e10f6a3d176c3815c4.zip
Hide private repositories in packages (#19584)
Diffstat (limited to 'modules/convert/package.go')
-rw-r--r--modules/convert/package.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/modules/convert/package.go b/modules/convert/package.go
index 681219ca1a..a4ea41d522 100644
--- a/modules/convert/package.go
+++ b/modules/convert/package.go
@@ -5,28 +5,38 @@
package convert
import (
+ "context"
+
+ "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/packages"
- "code.gitea.io/gitea/models/perm"
+ user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
)
// ToPackage convert a packages.PackageDescriptor to api.Package
-func ToPackage(pd *packages.PackageDescriptor) *api.Package {
+func ToPackage(ctx context.Context, pd *packages.PackageDescriptor, doer *user_model.User) (*api.Package, error) {
var repo *api.Repository
if pd.Repository != nil {
- repo = ToRepo(pd.Repository, perm.AccessModeNone)
+ permission, err := models.GetUserRepoPermission(ctx, pd.Repository, doer)
+ if err != nil {
+ return nil, err
+ }
+
+ if permission.HasAccess() {
+ repo = ToRepo(pd.Repository, permission.AccessMode)
+ }
}
return &api.Package{
ID: pd.Version.ID,
- Owner: ToUser(pd.Owner, nil),
+ Owner: ToUser(pd.Owner, doer),
Repository: repo,
- Creator: ToUser(pd.Creator, nil),
+ Creator: ToUser(pd.Creator, doer),
Type: string(pd.Package.Type),
Name: pd.Package.Name,
Version: pd.Version.Version,
CreatedAt: pd.Version.CreatedUnix.AsTime(),
- }
+ }, nil
}
// ToPackageFile converts packages.PackageFileDescriptor to api.PackageFile