diff options
Diffstat (limited to 'modules/convert/package.go')
-rw-r--r-- | modules/convert/package.go | 22 |
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 |