diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/packages/package.go | 15 | ||||
-rw-r--r-- | routers/web/repo/packages.go | 1 | ||||
-rw-r--r-- | routers/web/user/package.go | 29 |
3 files changed, 43 insertions, 2 deletions
diff --git a/routers/api/v1/packages/package.go b/routers/api/v1/packages/package.go index f3aa19c319..038924737a 100644 --- a/routers/api/v1/packages/package.go +++ b/routers/api/v1/packages/package.go @@ -73,7 +73,12 @@ func ListPackages(ctx *context.APIContext) { apiPackages := make([]*api.Package, 0, len(pds)) for _, pd := range pds { - apiPackages = append(apiPackages, convert.ToPackage(pd)) + apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Error converting package for api", err) + return + } + apiPackages = append(apiPackages, apiPackage) } ctx.SetLinkHeader(int(count), listOptions.PageSize) @@ -115,7 +120,13 @@ func GetPackage(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - ctx.JSON(http.StatusOK, convert.ToPackage(ctx.Package.Descriptor)) + apiPackage, err := convert.ToPackage(ctx, ctx.Package.Descriptor, ctx.Doer) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Error converting package for api", err) + return + } + + ctx.JSON(http.StatusOK, apiPackage) } // DeletePackage deletes a package 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) } |