mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 05:53:23 +09:00
chore: enable forcetypeassert linter, fix issues (#38804)
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert) linter to prevent unchecked type assertions. ~650 issues fixed, most fixes were clean, some use `setting.PanicInDevOrTesting`. The only behaviour changes are where code would previously send a 500 error or panic, a 4xx error is now emitted. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -75,6 +75,7 @@ import (
|
||||
"gitea.dev/modules/json"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/optional"
|
||||
"gitea.dev/modules/reqctx"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/storage"
|
||||
"gitea.dev/modules/util"
|
||||
@@ -98,7 +99,7 @@ type ArtifactContext struct {
|
||||
|
||||
func init() {
|
||||
web.RegisterResponseStatusProvider[*ArtifactContext](func(req *http.Request) web_types.ResponseStatusProvider {
|
||||
return req.Context().Value(artifactContextKey).(*ArtifactContext)
|
||||
return reqctx.MustContextValue[*ArtifactContext](req.Context(), artifactContextKey)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st
|
||||
readers := make([]io.Reader, 0, len(allChunks))
|
||||
closeReaders := func() {
|
||||
for _, r := range readers {
|
||||
_ = r.(io.Closer).Close() // it guarantees to be io.Closer by the following loop's Open function
|
||||
_ = r.(io.Closer).Close() //nolint:forcetypeassert // it guarantees to be io.Closer by the following loop's Open function
|
||||
}
|
||||
readers = nil
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func SearchPackages(ctx *context.Context) {
|
||||
crates = append(crates, &SearchResultCrate{
|
||||
Name: pd.Package.Name,
|
||||
LatestVersion: pd.Version.Version,
|
||||
Description: pd.Metadata.(*cargo_module.Metadata).Description,
|
||||
Description: packages_model.DescriptorMetadata[*cargo_module.Metadata](pd).Description,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,12 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := verifySignedHeaders(req, version, pub.(*rsa.PublicKey)); err != nil {
|
||||
rsaPub, ok := pub.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
return nil, errors.New("public key is not a RSA key")
|
||||
}
|
||||
|
||||
if err := verifySignedHeaders(req, version, rsaPub); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func PackagesUniverse(ctx *context.Context) {
|
||||
LocationType: "opscode",
|
||||
LocationPath: baseURL,
|
||||
DownloadURL: fmt.Sprintf("%s/cookbooks/%s/versions/%s/download", baseURL, url.PathEscape(pd.Package.Name), pd.Version.Version),
|
||||
Dependencies: pd.Metadata.(*chef_module.Metadata).Dependencies,
|
||||
Dependencies: packages_model.DescriptorMetadata[*chef_module.Metadata](pd).Dependencies,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func EnumeratePackages(ctx *context.Context) {
|
||||
|
||||
items := make([]*Item, 0, len(pds))
|
||||
for _, pd := range pds {
|
||||
metadata := pd.Metadata.(*chef_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*chef_module.Metadata](pd)
|
||||
|
||||
items = append(items, &Item{
|
||||
CookbookName: pd.Package.Name,
|
||||
@@ -193,7 +193,7 @@ func PackageMetadata(ctx *context.Context) {
|
||||
|
||||
latest := pds[len(pds)-1]
|
||||
|
||||
metadata := latest.Metadata.(*chef_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*chef_module.Metadata](latest)
|
||||
|
||||
ctx.JSON(http.StatusOK, &Result{
|
||||
Name: latest.Package.Name,
|
||||
@@ -241,7 +241,7 @@ func PackageVersionMetadata(ctx *context.Context) {
|
||||
|
||||
baseURL := fmt.Sprintf("%sapi/packages/%s/chef/api/v1/cookbooks/%s", setting.AppURL, ctx.Package.Owner.Name, url.PathEscape(pd.Package.Name))
|
||||
|
||||
metadata := pd.Metadata.(*chef_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*chef_module.Metadata](pd)
|
||||
|
||||
ctx.JSON(http.StatusOK, &Result{
|
||||
Version: pd.Version.Version,
|
||||
|
||||
@@ -50,7 +50,7 @@ func createSearchResultResponse(total int64, pds []*packages_model.PackageDescri
|
||||
for _, pd := range pds {
|
||||
results = append(results, &SearchResult{
|
||||
Name: pd.Package.Name,
|
||||
Description: pd.Metadata.(*composer_module.Metadata).Description,
|
||||
Description: packages_model.DescriptorMetadata[*composer_module.Metadata](pd).Description,
|
||||
Downloads: pd.Version.DownloadCount,
|
||||
})
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func createPackageMetadataResponse(ctx *context.Context, registryURL string, pds
|
||||
Version: pd.Version.Version,
|
||||
Type: packageType,
|
||||
Created: pd.Version.CreatedUnix.AsLocalTime(),
|
||||
Metadata: pd.Metadata.(*composer_module.Metadata),
|
||||
Metadata: packages_model.DescriptorMetadata[*composer_module.Metadata](pd),
|
||||
Dist: Dist{
|
||||
Type: "zip",
|
||||
URL: fmt.Sprintf("%s/files/%s/%s/%s", registryURL, url.PathEscape(pd.Package.LowerName), url.PathEscape(pd.Version.LowerVersion), url.PathEscape(pd.Files[0].File.LowerName)),
|
||||
|
||||
@@ -103,6 +103,14 @@ func ExtractPathParameters(ctx *context.Context) {
|
||||
ctx.Data[packageReferenceKey] = pref
|
||||
}
|
||||
|
||||
func getRecipeReference(ctx *context.Context) *conan_module.RecipeReference {
|
||||
return ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference) //nolint:forcetypeassert // must be valid
|
||||
}
|
||||
|
||||
func getPackageReference(ctx *context.Context) *conan_module.PackageReference {
|
||||
return ctx.Data[packageReferenceKey].(*conan_module.PackageReference) //nolint:forcetypeassert // must be valid
|
||||
}
|
||||
|
||||
// Ping reports the server capabilities
|
||||
func Ping(ctx *context.Context) {
|
||||
ctx.RespHeader().Add("X-Conan-Server-Capabilities", "revisions") // complex_search,checksum_deploy,matrix_params
|
||||
@@ -164,20 +172,20 @@ func CheckCredentials(ctx *context.Context) {
|
||||
|
||||
// RecipeSnapshot displays the recipe files with their md5 hash
|
||||
func RecipeSnapshot(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
serveSnapshot(ctx, rref.AsKey())
|
||||
}
|
||||
|
||||
// RecipeSnapshot displays the package files with their md5 hash
|
||||
func PackageSnapshot(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
serveSnapshot(ctx, pref.AsKey())
|
||||
}
|
||||
|
||||
func serveSnapshot(ctx *context.Context, fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeConan, rref.Name, rref.Version)
|
||||
if err != nil {
|
||||
@@ -217,7 +225,7 @@ func serveSnapshot(ctx *context.Context, fileKey string) {
|
||||
|
||||
// RecipeDownloadURLs displays the recipe files with their download url
|
||||
func RecipeDownloadURLs(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
serveDownloadURLs(
|
||||
ctx,
|
||||
@@ -228,7 +236,7 @@ func RecipeDownloadURLs(ctx *context.Context) {
|
||||
|
||||
// PackageDownloadURLs displays the package files with their download url
|
||||
func PackageDownloadURLs(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
serveDownloadURLs(
|
||||
ctx,
|
||||
@@ -238,7 +246,7 @@ func PackageDownloadURLs(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func serveDownloadURLs(ctx *context.Context, fileKey, downloadURL string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeConan, rref.Name, rref.Version)
|
||||
if err != nil {
|
||||
@@ -274,7 +282,7 @@ func serveDownloadURLs(ctx *context.Context, fileKey, downloadURL string) {
|
||||
|
||||
// RecipeUploadURLs displays the upload urls for the provided recipe files
|
||||
func RecipeUploadURLs(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
serveUploadURLs(
|
||||
ctx,
|
||||
@@ -285,7 +293,7 @@ func RecipeUploadURLs(ctx *context.Context) {
|
||||
|
||||
// PackageUploadURLs displays the upload urls for the provided package files
|
||||
func PackageUploadURLs(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
serveUploadURLs(
|
||||
ctx,
|
||||
@@ -315,21 +323,21 @@ func serveUploadURLs(ctx *context.Context, fileFilter container.Set[string], upl
|
||||
|
||||
// UploadRecipeFile handles the upload of a recipe file
|
||||
func UploadRecipeFile(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
uploadFile(ctx, recipeFileList, rref.AsKey())
|
||||
}
|
||||
|
||||
// UploadPackageFile handles the upload of a package file
|
||||
func UploadPackageFile(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
uploadFile(ctx, packageFileList, pref.AsKey())
|
||||
}
|
||||
|
||||
func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
filename := ctx.PathParam("filename")
|
||||
if !fileFilter.Contains(filename) {
|
||||
@@ -454,20 +462,20 @@ func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey
|
||||
|
||||
// DownloadRecipeFile serves the content of the requested recipe file
|
||||
func DownloadRecipeFile(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
downloadFile(ctx, recipeFileList, rref.AsKey())
|
||||
}
|
||||
|
||||
// DownloadPackageFile serves the content of the requested package file
|
||||
func DownloadPackageFile(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
downloadFile(ctx, packageFileList, pref.AsKey())
|
||||
}
|
||||
|
||||
func downloadFile(ctx *context.Context, fileFilter container.Set[string], fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
filename := ctx.PathParam("filename")
|
||||
if !fileFilter.Contains(filename) {
|
||||
@@ -503,7 +511,7 @@ func downloadFile(ctx *context.Context, fileFilter container.Set[string], fileKe
|
||||
|
||||
// DeleteRecipeV1 deletes the requested recipe(s)
|
||||
func DeleteRecipeV1(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
if err := deleteRecipeOrPackage(ctx, rref, true, nil, false); err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, conan_model.ErrPackageReferenceNotExist) {
|
||||
@@ -518,7 +526,7 @@ func DeleteRecipeV1(ctx *context.Context) {
|
||||
|
||||
// DeleteRecipeV2 deletes the requested recipe(s) respecting its revisions
|
||||
func DeleteRecipeV2(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
if err := deleteRecipeOrPackage(ctx, rref, rref.Revision == "", nil, false); err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, conan_model.ErrPackageReferenceNotExist) {
|
||||
@@ -533,7 +541,7 @@ func DeleteRecipeV2(ctx *context.Context) {
|
||||
|
||||
// DeletePackageV1 deletes the requested package(s)
|
||||
func DeletePackageV1(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
type PackageReferences struct {
|
||||
References []string `json:"package_ids"`
|
||||
@@ -582,8 +590,8 @@ func DeletePackageV1(ctx *context.Context) {
|
||||
|
||||
// DeletePackageV2 deletes the requested package(s) respecting its revisions
|
||||
func DeletePackageV2(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
if pref != nil { // has package reference
|
||||
if err := deleteRecipeOrPackage(ctx, rref, false, pref, pref.Revision == ""); err != nil {
|
||||
@@ -693,7 +701,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef
|
||||
|
||||
// ListRecipeRevisions gets a list of all recipe revisions
|
||||
func ListRecipeRevisions(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
revisions, err := conan_model.GetRecipeRevisions(ctx, ctx.Package.Owner.ID, rref)
|
||||
if err != nil {
|
||||
@@ -706,7 +714,7 @@ func ListRecipeRevisions(ctx *context.Context) {
|
||||
|
||||
// ListPackageRevisions gets a list of all package revisions
|
||||
func ListPackageRevisions(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
revisions, err := conan_model.GetPackageRevisions(ctx, ctx.Package.Owner.ID, pref)
|
||||
if err != nil {
|
||||
@@ -742,7 +750,7 @@ func listRevisions(ctx *context.Context, revisions []*conan_model.PropertyValue)
|
||||
|
||||
// LatestRecipeRevision gets the latest recipe revision
|
||||
func LatestRecipeRevision(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
revision, err := conan_model.GetLastRecipeRevision(ctx, ctx.Package.Owner.ID, rref)
|
||||
if err != nil {
|
||||
@@ -759,7 +767,7 @@ func LatestRecipeRevision(ctx *context.Context) {
|
||||
|
||||
// LatestPackageRevision gets the latest package revision
|
||||
func LatestPackageRevision(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
revision, err := conan_model.GetLastPackageRevision(ctx, ctx.Package.Owner.ID, pref)
|
||||
if err != nil {
|
||||
@@ -776,20 +784,20 @@ func LatestPackageRevision(ctx *context.Context) {
|
||||
|
||||
// ListRecipeRevisionFiles gets a list of all recipe revision files
|
||||
func ListRecipeRevisionFiles(ctx *context.Context) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
listRevisionFiles(ctx, rref.AsKey())
|
||||
}
|
||||
|
||||
// ListPackageRevisionFiles gets a list of all package revision files
|
||||
func ListPackageRevisionFiles(ctx *context.Context) {
|
||||
pref := ctx.Data[packageReferenceKey].(*conan_module.PackageReference)
|
||||
pref := getPackageReference(ctx)
|
||||
|
||||
listRevisionFiles(ctx, pref.AsKey())
|
||||
}
|
||||
|
||||
func listRevisionFiles(ctx *context.Context, fileKey string) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, ctx.Package.Owner.ID, packages_model.TypeConan, rref.Name, rref.Version)
|
||||
if err != nil {
|
||||
|
||||
@@ -72,7 +72,7 @@ func SearchPackagesV2(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func searchPackages(ctx *context.Context, searchAllRevisions bool) {
|
||||
rref := ctx.Data[recipeReferenceKey].(*conan_module.RecipeReference)
|
||||
rref := getRecipeReference(ctx)
|
||||
|
||||
if !searchAllRevisions && rref.Revision == "" {
|
||||
lastRevision, err := conan_model.GetLastRecipeRevision(ctx, ctx.Package.Owner.ID, rref)
|
||||
|
||||
@@ -138,7 +138,7 @@ func EnumeratePackages(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
versionMetadata := pd.Metadata.(*conda_module.VersionMetadata)
|
||||
versionMetadata := packages_model.DescriptorMetadata[*conda_module.VersionMetadata](pd)
|
||||
|
||||
pi := &PackageInfo{
|
||||
Name: pd.PackageProperties.GetByName(conda_module.PropertyName),
|
||||
|
||||
@@ -93,7 +93,7 @@ func enumeratePackages(ctx *context.Context, format string, opts *cran_model.Sea
|
||||
}
|
||||
}
|
||||
|
||||
metadata := pd.Metadata.(*cran_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*cran_module.Metadata](pd)
|
||||
|
||||
fmt.Fprintln(w, "Package:", pd.Package.Name)
|
||||
fmt.Fprintln(w, "Version:", pd.Version.Version)
|
||||
|
||||
@@ -45,7 +45,7 @@ func createPackageMetadataResponse(registryURL string, pds []*packages_model.Pac
|
||||
|
||||
latest := pds[len(pds)-1]
|
||||
|
||||
metadata := latest.Metadata.(*npm_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*npm_module.Metadata](latest)
|
||||
|
||||
return &npm_module.PackageMetadata{
|
||||
ID: latest.Package.Name,
|
||||
@@ -67,7 +67,7 @@ func createPackageMetadataResponse(registryURL string, pds []*packages_model.Pac
|
||||
func createPackageMetadataVersion(registryURL string, pd *packages_model.PackageDescriptor) *npm_module.PackageMetadataVersion {
|
||||
hashBytes, _ := hex.DecodeString(pd.Files[0].Blob.HashSHA512)
|
||||
|
||||
metadata := pd.Metadata.(*npm_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*npm_module.Metadata](pd)
|
||||
|
||||
return &npm_module.PackageMetadataVersion{
|
||||
ID: fmt.Sprintf("%s@%s", pd.Package.Name, pd.Version.Version),
|
||||
@@ -107,7 +107,7 @@ func createPackageMetadataVersion(registryURL string, pd *packages_model.Package
|
||||
func createPackageSearchResponse(pds []*packages_model.PackageDescriptor, total int64) *npm_module.PackageSearch {
|
||||
objects := make([]*npm_module.PackageSearchObject, 0, len(pds))
|
||||
for _, pd := range pds {
|
||||
metadata := pd.Metadata.(*npm_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*npm_module.Metadata](pd)
|
||||
|
||||
scope := metadata.Scope
|
||||
if scope == "" {
|
||||
|
||||
@@ -332,12 +332,8 @@ func createFeedResponse(l *linkBuilder, totalEntries int64, pds []*packages_mode
|
||||
}
|
||||
}
|
||||
|
||||
func createEntryResponse(l *linkBuilder, pd *packages_model.PackageDescriptor) *FeedEntry {
|
||||
return createEntry(l, pd, true)
|
||||
}
|
||||
|
||||
func createEntry(l *linkBuilder, pd *packages_model.PackageDescriptor, withNamespace bool) *FeedEntry {
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](pd)
|
||||
|
||||
id := l.GetPackageMetadataURL(pd.Package.Name, pd.Version.Version)
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ func createRegistrationIndexResponse(l *linkBuilder, pds []*packages_model.Packa
|
||||
}
|
||||
|
||||
func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageDescriptor) *RegistrationIndexPageItem {
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](pd)
|
||||
|
||||
return &RegistrationIndexPageItem{
|
||||
RegistrationLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
|
||||
@@ -120,7 +120,7 @@ func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageD
|
||||
CatalogLeafURL: l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version),
|
||||
Authors: metadata.Authors,
|
||||
Copyright: metadata.Copyright,
|
||||
DependencyGroups: createDependencyGroups(pd),
|
||||
DependencyGroups: createDependencyGroups(metadata),
|
||||
Description: metadata.Description,
|
||||
IconURL: metadata.IconURL,
|
||||
ID: pd.Package.Name,
|
||||
@@ -139,9 +139,7 @@ func createRegistrationIndexPageItem(l *linkBuilder, pd *packages_model.PackageD
|
||||
}
|
||||
}
|
||||
|
||||
func createDependencyGroups(pd *packages_model.PackageDescriptor) []*PackageDependencyGroup {
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
|
||||
func createDependencyGroups(metadata *nuget_module.Metadata) []*PackageDependencyGroup {
|
||||
dependencyGroups := make([]*PackageDependencyGroup, 0, len(metadata.Dependencies))
|
||||
for k, v := range metadata.Dependencies {
|
||||
dependencies := make([]*PackageDependency, 0, len(v))
|
||||
@@ -172,7 +170,7 @@ type RegistrationLeafResponse struct {
|
||||
func createRegistrationLeafResponse(l *linkBuilder, pd *packages_model.PackageDescriptor) *RegistrationLeafResponse {
|
||||
registrationLeafURL := l.GetRegistrationLeafURL(pd.Package.Name, pd.Version.Version)
|
||||
packageDownloadURL := l.GetPackageDownloadURL(pd.Package.Name, pd.Version.Version)
|
||||
metadata := pd.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](pd)
|
||||
return &RegistrationLeafResponse{
|
||||
RegistrationLeafURL: registrationLeafURL,
|
||||
RegistrationIndexURL: l.GetRegistrationIndexURL(pd.Package.Name),
|
||||
@@ -182,7 +180,7 @@ func createRegistrationLeafResponse(l *linkBuilder, pd *packages_model.PackageDe
|
||||
CatalogLeafURL: registrationLeafURL,
|
||||
Authors: metadata.Authors,
|
||||
Copyright: metadata.Copyright,
|
||||
DependencyGroups: createDependencyGroups(pd),
|
||||
DependencyGroups: createDependencyGroups(metadata),
|
||||
Description: metadata.Description,
|
||||
IconURL: metadata.IconURL,
|
||||
ID: pd.Package.Name,
|
||||
@@ -290,13 +288,13 @@ func createSearchResult(l *linkBuilder, pds []*packages_model.PackageDescriptor)
|
||||
})
|
||||
}
|
||||
|
||||
metadata := latest.Metadata.(*nuget_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*nuget_module.Metadata](latest)
|
||||
|
||||
return &SearchResult{
|
||||
Authors: metadata.Authors,
|
||||
Copyright: metadata.Copyright,
|
||||
Description: metadata.Description,
|
||||
DependencyGroups: createDependencyGroups(latest),
|
||||
DependencyGroups: createDependencyGroups(metadata),
|
||||
IconURL: metadata.IconURL,
|
||||
ID: latest.Package.Name,
|
||||
IsPrerelease: latest.Version.IsPrerelease(),
|
||||
|
||||
@@ -267,9 +267,10 @@ func RegistrationLeafV2(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := createEntryResponse(
|
||||
resp := createEntry(
|
||||
&linkBuilder{Base: setting.AppURL + "api/packages/" + ctx.Package.Owner.Name + "/nuget"},
|
||||
pd,
|
||||
true,
|
||||
)
|
||||
|
||||
xmlResponse(ctx, http.StatusOK, resp)
|
||||
|
||||
@@ -67,7 +67,7 @@ func packageDescriptorToMetadata(baseURL string, pd *packages_model.PackageDescr
|
||||
Version: pd.Version.Version,
|
||||
ArchiveURL: fmt.Sprintf("%s/files/%s.tar.gz", baseURL, url.PathEscape(pd.Version.Version)),
|
||||
Published: pd.Version.CreatedUnix.AsLocalTime(),
|
||||
Pubspec: pd.Metadata.(*pub_module.Metadata).Pubspec,
|
||||
Pubspec: packages_model.DescriptorMetadata[*pub_module.Metadata](pd).Pubspec,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ func enumeratePackages(ctx *context.Context, filename string, pvs []*packages_mo
|
||||
Name: "Gem::Version",
|
||||
Value: []string{p.Version.Version},
|
||||
},
|
||||
p.Metadata.(*rubygems_module.Metadata).Platform,
|
||||
packages_model.DescriptorMetadata[*rubygems_module.Metadata](p).Platform,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func ServePackageSpecification(ctx *context.Context) {
|
||||
zw := zlib.NewWriter(ctx.Resp)
|
||||
defer zw.Close()
|
||||
|
||||
metadata := pd.Metadata.(*rubygems_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*rubygems_module.Metadata](pd)
|
||||
|
||||
// create a Ruby Gem::Specification object
|
||||
spec := &rubygems_module.RubyUserDef{
|
||||
@@ -405,7 +405,7 @@ func makePackageVersionDependency(ctx *context.Context, version *packages_model.
|
||||
return "", err
|
||||
}
|
||||
|
||||
metadata := pd.Metadata.(*rubygems_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*rubygems_module.Metadata](pd)
|
||||
fullFilename := makeGemFullFileName(pd.Package.Name, version.Version, metadata.Platform)
|
||||
file, err := packages_model.GetFileForVersionByName(ctx, version.ID, fullFilename, "")
|
||||
if err != nil {
|
||||
|
||||
@@ -197,7 +197,7 @@ func PackageVersionMetadata(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
metadata := pd.Metadata.(*swift_module.Metadata)
|
||||
metadata := packages_model.DescriptorMetadata[*swift_module.Metadata](pd)
|
||||
repositoryURLs := make([]string, 0, len(pd.VersionProperties))
|
||||
for _, property := range pd.VersionProperties {
|
||||
if property.Name == swift_module.PropertyRepositoryURL {
|
||||
@@ -278,7 +278,7 @@ func DownloadManifest(ctx *context.Context) {
|
||||
swiftVersion = swift_module.TrimmedVersionString(v)
|
||||
}
|
||||
}
|
||||
m, ok := pd.Metadata.(*swift_module.Metadata).Manifests[swiftVersion]
|
||||
m, ok := packages_model.DescriptorMetadata[*swift_module.Metadata](pd).Manifests[swiftVersion]
|
||||
if !ok {
|
||||
setResponseHeaders(ctx.Resp, &headers{
|
||||
Status: http.StatusSeeOther,
|
||||
|
||||
@@ -130,7 +130,7 @@ func EnumeratePackageVersions(ctx *context.Context) {
|
||||
|
||||
ctx.JSON(http.StatusOK, &packageMetadata{
|
||||
Name: pds[0].Package.Name,
|
||||
Description: pds[len(pds)-1].Metadata.(*vagrant_module.Metadata).Description,
|
||||
Description: packages_model.DescriptorMetadata[*vagrant_module.Metadata](pds[len(pds)-1]).Description,
|
||||
Versions: versions,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func ListCronTasks(ctx *context.APIContext) {
|
||||
count := len(tasks)
|
||||
|
||||
listOpts := utils.GetListOptions(ctx)
|
||||
tasks = util.PaginateSlice(tasks, listOpts.Page, listOpts.PageSize).(cron.TaskTable)
|
||||
tasks = util.PaginateSlice(tasks, listOpts.Page, listOpts.PageSize)
|
||||
|
||||
res := make([]structs.Cron, len(tasks))
|
||||
for i, task := range tasks {
|
||||
|
||||
@@ -137,7 +137,7 @@ func CreateHook(ctx *context.APIContext) {
|
||||
// "201":
|
||||
// "$ref": "#/responses/Hook"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateHookOption)
|
||||
form := web.GetForm[*api.CreateHookOption](ctx)
|
||||
|
||||
utils.AddSystemHook(ctx, form)
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func EditHook(ctx *context.APIContext) {
|
||||
// "200":
|
||||
// "$ref": "#/responses/Hook"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditHookOption)
|
||||
form := web.GetForm[*api.EditHookOption](ctx)
|
||||
|
||||
// TODO in body params
|
||||
hookID := ctx.PathParamInt64("id")
|
||||
|
||||
@@ -44,7 +44,7 @@ func CreateOrg(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
||||
form := web.GetForm[*api.CreateOrgOption](ctx)
|
||||
|
||||
visibility := api.VisibleTypePublic
|
||||
if form.Visibility != "" {
|
||||
|
||||
@@ -43,7 +43,7 @@ func CreateRepo(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||
form := web.GetForm[*api.CreateRepoOption](ctx)
|
||||
|
||||
repo.CreateUserRepo(ctx, ctx.ContextUser, *form)
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func CreateUser(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateUserOption)
|
||||
form := web.GetForm[*api.CreateUserOption](ctx)
|
||||
|
||||
u := &user_model.User{
|
||||
Name: form.Username,
|
||||
@@ -190,7 +190,7 @@ func EditUser(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditUserOption)
|
||||
form := web.GetForm[*api.EditUserOption](ctx)
|
||||
|
||||
authOpts := &user_service.UpdateAuthOptions{
|
||||
LoginSource: optional.FromNonDefault(form.SourceID),
|
||||
@@ -340,7 +340,7 @@ func CreatePublicKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||
form := web.GetForm[*api.CreateKeyOption](ctx)
|
||||
|
||||
user.CreateUserPublicKey(ctx, *form, ctx.ContextUser.ID)
|
||||
}
|
||||
@@ -551,7 +551,7 @@ func RenameUser(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
newName := web.GetForm(ctx).(*api.RenameUserOption).NewName
|
||||
newName := web.GetForm[*api.RenameUserOption](ctx).NewName
|
||||
|
||||
// Check if username has been changed
|
||||
if err := user_service.RenameUser(ctx, ctx.ContextUser, newName, ctx.Doer); err != nil {
|
||||
|
||||
@@ -66,7 +66,7 @@ func AddUserBadges(ctx *context.APIContext) {
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
form := web.GetForm(ctx).(*api.UserBadgeOption)
|
||||
form := web.GetForm[*api.UserBadgeOption](ctx)
|
||||
badges := prepareBadgesForReplaceOrAdd(*form)
|
||||
|
||||
if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil {
|
||||
@@ -102,7 +102,7 @@ func DeleteUserBadges(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.UserBadgeOption)
|
||||
form := web.GetForm[*api.UserBadgeOption](ctx)
|
||||
badges := prepareBadgesForReplaceOrAdd(*form)
|
||||
|
||||
if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil {
|
||||
|
||||
@@ -396,7 +396,7 @@ func reqUsersExploreEnabled() func(ctx *context.APIContext) {
|
||||
|
||||
func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
|
||||
return func(ctx *context.APIContext) {
|
||||
if ctx.IsSigned && setting.Service.EnableReverseProxyAuthAPI && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName {
|
||||
if ctx.IsSigned && setting.Service.EnableReverseProxyAuthAPI && ctx.Data["AuthedMethod"] == auth.ReverseProxyMethodName {
|
||||
return
|
||||
}
|
||||
if !ctx.IsBasicAuth {
|
||||
|
||||
@@ -33,7 +33,7 @@ func Markup(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.MarkupOption)
|
||||
form := web.GetForm[*api.MarkupOption](ctx)
|
||||
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
|
||||
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func Markdown(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.MarkdownOption)
|
||||
form := web.GetForm[*api.MarkdownOption](ctx)
|
||||
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
|
||||
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, "")
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
|
||||
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
|
||||
|
||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("secretname"), opt.Data, opt.Description)
|
||||
if err != nil {
|
||||
@@ -373,7 +373,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
|
||||
// "500":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateVariableOption)
|
||||
opt := web.GetForm[*api.CreateVariableOption](ctx)
|
||||
|
||||
ownerID := ctx.Org.Organization.ID
|
||||
variableName := ctx.PathParam("variablename")
|
||||
@@ -437,7 +437,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
|
||||
opt := web.GetForm[*api.UpdateVariableOption](ctx)
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
OwnerID: ctx.Org.Organization.ID,
|
||||
|
||||
@@ -35,7 +35,7 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/empty"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
|
||||
form := web.GetForm[*api.UpdateUserAvatarOption](ctx)
|
||||
|
||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||
if err != nil {
|
||||
|
||||
@@ -113,7 +113,7 @@ func CreateHook(ctx *context.APIContext) {
|
||||
utils.AddOwnerHook(
|
||||
ctx,
|
||||
ctx.ContextUser,
|
||||
web.GetForm(ctx).(*api.CreateHookOption),
|
||||
web.GetForm[*api.CreateHookOption](ctx),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func EditHook(ctx *context.APIContext) {
|
||||
utils.EditOwnerHook(
|
||||
ctx,
|
||||
ctx.ContextUser,
|
||||
web.GetForm(ctx).(*api.EditHookOption),
|
||||
web.GetForm[*api.EditHookOption](ctx),
|
||||
ctx.PathParamInt64("id"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func CreateLabel(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.CreateLabelOption)
|
||||
form := web.GetForm[*api.CreateLabelOption](ctx)
|
||||
form.Color = strings.Trim(form.Color, " ")
|
||||
color, err := label.NormalizeColor(form.Color)
|
||||
if err != nil {
|
||||
@@ -189,7 +189,7 @@ func EditLabel(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.EditLabelOption)
|
||||
form := web.GetForm[*api.EditLabelOption](ctx)
|
||||
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrOrgLabelNotExist(err) {
|
||||
|
||||
@@ -261,7 +261,7 @@ func Create(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
||||
form := web.GetForm[*api.CreateOrgOption](ctx)
|
||||
if !ctx.Doer.CanCreateOrganization() {
|
||||
ctx.APIError(http.StatusForbidden, "not allowed to create org")
|
||||
return
|
||||
@@ -358,7 +358,7 @@ func Rename(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.RenameOrgOption)
|
||||
form := web.GetForm[*api.RenameOrgOption](ctx)
|
||||
orgUser := ctx.Org.Organization.AsUser()
|
||||
if err := user_service.RenameUser(ctx, orgUser, form.NewName, ctx.Doer); err != nil {
|
||||
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
|
||||
@@ -397,7 +397,7 @@ func Edit(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditOrgOption)
|
||||
form := web.GetForm[*api.EditOrgOption](ctx)
|
||||
|
||||
if err := org.UpdateOrgEmailAddress(ctx, ctx.Org.Organization, form.Email); err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
|
||||
@@ -214,7 +214,7 @@ func CreateTeam(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.CreateTeamOption)
|
||||
form := web.GetForm[*api.CreateTeamOption](ctx)
|
||||
teamPermission := perm.ParseAccessMode(string(form.Permission), perm.AccessModeNone, perm.AccessModeAdmin)
|
||||
team := &organization.Team{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
@@ -282,7 +282,7 @@ func EditTeam(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditTeamOption)
|
||||
form := web.GetForm[*api.EditTeamOption](ctx)
|
||||
team := ctx.Org.Team
|
||||
if err := team.LoadUnits(ctx); err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
|
||||
@@ -135,7 +135,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
|
||||
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
|
||||
|
||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, 0, repo.ID, ctx.PathParam("secretname"), opt.Data, opt.Description)
|
||||
if err != nil {
|
||||
@@ -346,7 +346,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
|
||||
// "500":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateVariableOption)
|
||||
opt := web.GetForm[*api.CreateVariableOption](ctx)
|
||||
|
||||
repoID := ctx.Repo.Repository.ID
|
||||
variableName := ctx.PathParam("variablename")
|
||||
@@ -413,7 +413,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
|
||||
opt := web.GetForm[*api.UpdateVariableOption](ctx)
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
@@ -1170,7 +1170,7 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
workflowID := ctx.PathParam("workflow_id")
|
||||
opt := web.GetForm(ctx).(*api.CreateActionWorkflowDispatch)
|
||||
opt := web.GetForm[*api.CreateActionWorkflowDispatch](ctx)
|
||||
if opt.Ref == "" {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "ref is required parameter")
|
||||
return
|
||||
|
||||
@@ -40,7 +40,7 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/empty"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.UpdateRepoAvatarOption)
|
||||
form := web.GetForm[*api.UpdateRepoAvatarOption](ctx)
|
||||
|
||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||
if err != nil {
|
||||
|
||||
@@ -212,7 +212,7 @@ func CreateBranch(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateBranchRepoOption)
|
||||
opt := web.GetForm[*api.CreateBranchRepoOption](ctx)
|
||||
|
||||
var oldCommit *git.Commit
|
||||
var err error
|
||||
@@ -426,7 +426,7 @@ func UpdateBranch(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.UpdateBranchRepoOption)
|
||||
opt := web.GetForm[*api.UpdateBranchRepoOption](ctx)
|
||||
|
||||
branchName := ctx.PathParam("*")
|
||||
repo := ctx.Repo.Repository
|
||||
@@ -443,14 +443,14 @@ func UpdateBranch(ctx *context.APIContext) {
|
||||
|
||||
// permission check has been done in api.go
|
||||
if err := repo_service.UpdateBranch(ctx, repo, ctx.Repo.GitRepo, ctx.Doer, branchName, opt.NewCommitID, opt.OldCommitID, opt.Force); err != nil {
|
||||
var errPushRejected *git.ErrPushRejected
|
||||
switch {
|
||||
case git_model.IsErrBranchNotExist(err):
|
||||
ctx.APIErrorNotFound()
|
||||
case errors.Is(err, util.ErrInvalidArgument):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
|
||||
case git.IsErrPushRejected(err):
|
||||
rej := err.(*git.ErrPushRejected)
|
||||
ctx.APIError(http.StatusForbidden, rej.Message)
|
||||
case errors.As(err, &errPushRejected):
|
||||
ctx.APIError(http.StatusForbidden, errPushRejected.Message)
|
||||
default:
|
||||
ctx.APIErrorInternal(err)
|
||||
}
|
||||
@@ -499,7 +499,7 @@ func RenameBranch(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.RenameBranchRepoOption)
|
||||
opt := web.GetForm[*api.RenameBranchRepoOption](ctx)
|
||||
|
||||
oldName := ctx.PathParam("*")
|
||||
repo := ctx.Repo.Repository
|
||||
@@ -654,7 +654,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateBranchProtectionOption)
|
||||
form := web.GetForm[*api.CreateBranchProtectionOption](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
ruleName := form.RuleName
|
||||
@@ -875,7 +875,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/validationError"
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
|
||||
form := web.GetForm[*api.EditBranchProtectionOption](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.PathParam("*")
|
||||
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
||||
@@ -1292,7 +1292,7 @@ func UpdateBranchProtectionPriories(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/validationError"
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
form := web.GetForm(ctx).(*api.UpdateBranchProtectionPriories)
|
||||
form := web.GetForm[*api.UpdateBranchProtectionPriories](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil {
|
||||
@@ -1331,7 +1331,7 @@ func MergeUpstream(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/error"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.MergeUpstreamRequest)
|
||||
form := web.GetForm[*api.MergeUpstreamRequest](ctx)
|
||||
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch, form.FfOnly)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
|
||||
@@ -162,7 +162,7 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.AddCollaboratorOption)
|
||||
form := web.GetForm[*api.AddCollaboratorOption](ctx)
|
||||
|
||||
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
||||
if err != nil {
|
||||
|
||||
+23
-26
@@ -323,14 +323,19 @@ func base64Reader(s string) (io.ReadSeeker, error) {
|
||||
}
|
||||
|
||||
func ReqChangeRepoFileOptionsAndCheck(ctx *context.APIContext) {
|
||||
commonOpts := web.GetForm(ctx).(api.FileOptionsInterface).GetFileOptions()
|
||||
commonOpts := web.GetForm[api.FileOptionsInterface](ctx).GetFileOptions()
|
||||
commonOpts.BranchName = util.IfZero(commonOpts.BranchName, ctx.Repo.Repository.DefaultBranch)
|
||||
commonOpts.NewBranchName = util.IfZero(commonOpts.NewBranchName, commonOpts.BranchName)
|
||||
if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, commonOpts.NewBranchName) && !ctx.IsUserSiteAdmin() {
|
||||
ctx.APIError(http.StatusForbidden, "user should have a permission to write to the target branch")
|
||||
return
|
||||
}
|
||||
changeFileOpts := &files_service.ChangeRepoFilesOptions{
|
||||
}
|
||||
|
||||
// getAPIChangeRepoFileOptions requires ReqChangeRepoFileOptionsAndCheck to have run, it fills in the branch defaults
|
||||
func getAPIChangeRepoFileOptions[T api.FileOptionsInterface](ctx *context.APIContext) (apiOpts T, opts *files_service.ChangeRepoFilesOptions) {
|
||||
apiOpts = web.GetForm[T](ctx)
|
||||
commonOpts := apiOpts.GetFileOptions()
|
||||
opts = &files_service.ChangeRepoFilesOptions{
|
||||
Message: commonOpts.Message,
|
||||
OldBranch: commonOpts.BranchName,
|
||||
NewBranch: commonOpts.NewBranchName,
|
||||
@@ -349,17 +354,13 @@ func ReqChangeRepoFileOptionsAndCheck(ctx *context.APIContext) {
|
||||
},
|
||||
Signoff: commonOpts.Signoff,
|
||||
}
|
||||
if changeFileOpts.Dates.Author.IsZero() {
|
||||
changeFileOpts.Dates.Author = time.Now()
|
||||
if opts.Dates.Author.IsZero() {
|
||||
opts.Dates.Author = time.Now()
|
||||
}
|
||||
if changeFileOpts.Dates.Committer.IsZero() {
|
||||
changeFileOpts.Dates.Committer = time.Now()
|
||||
if opts.Dates.Committer.IsZero() {
|
||||
opts.Dates.Committer = time.Now()
|
||||
}
|
||||
ctx.Data["__APIChangeRepoFilesOptions"] = changeFileOpts
|
||||
}
|
||||
|
||||
func getAPIChangeRepoFileOptions[T api.FileOptionsInterface](ctx *context.APIContext) (apiOpts T, opts *files_service.ChangeRepoFilesOptions) {
|
||||
return web.GetForm(ctx).(T), ctx.Data["__APIChangeRepoFilesOptions"].(*files_service.ChangeRepoFilesOptions)
|
||||
return apiOpts, opts
|
||||
}
|
||||
|
||||
// ChangeFiles handles API call for modifying multiple files
|
||||
@@ -574,9 +575,8 @@ func UpdateFile(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func handleChangeRepoFilesError(ctx *context.APIContext, err error) {
|
||||
if git.IsErrPushRejected(err) {
|
||||
err := err.(*git.ErrPushRejected)
|
||||
ctx.APIError(http.StatusForbidden, err.Message)
|
||||
if errPushRejected, ok := err.(*git.ErrPushRejected); ok {
|
||||
ctx.APIError(http.StatusForbidden, errPushRejected.Message)
|
||||
return
|
||||
}
|
||||
if files_service.IsErrUserCannotCommit(err) || pull_service.IsErrFilePathProtected(err) {
|
||||
@@ -896,7 +896,12 @@ func GetFileContentsGet(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
// The POST method requires "write" permission, so we also support this "GET" method
|
||||
handleGetFileContents(ctx)
|
||||
opts := &api.GetFilesOptions{}
|
||||
if err := json.Unmarshal(util.UnsafeStringToBytes(ctx.FormString("body")), opts); err != nil {
|
||||
ctx.APIError(http.StatusBadRequest, "invalid body parameter")
|
||||
return
|
||||
}
|
||||
handleGetFileContents(ctx, opts)
|
||||
}
|
||||
|
||||
func GetFileContentsPost(ctx *context.APIContext) {
|
||||
@@ -940,18 +945,10 @@ func GetFileContentsPost(ctx *context.APIContext) {
|
||||
// This is actually a "read" request, but we need to accept a "files" list, then POST method seems easy to use.
|
||||
// But the permission system requires that the caller must have "write" permission to use POST method.
|
||||
// At the moment, there is no other way to get around the permission check, so there is a "GET" workaround method above.
|
||||
handleGetFileContents(ctx)
|
||||
handleGetFileContents(ctx, web.GetForm[*api.GetFilesOptions](ctx))
|
||||
}
|
||||
|
||||
func handleGetFileContents(ctx *context.APIContext) {
|
||||
opts, ok := web.GetForm(ctx).(*api.GetFilesOptions)
|
||||
if !ok {
|
||||
err := json.Unmarshal(util.UnsafeStringToBytes(ctx.FormString("body")), &opts)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusBadRequest, "invalid body parameter")
|
||||
return
|
||||
}
|
||||
}
|
||||
func handleGetFileContents(ctx *context.APIContext, opts *api.GetFilesOptions) {
|
||||
refCommit := resolveRefCommit(ctx, ctx.FormTrim("ref"))
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
||||
@@ -148,7 +148,7 @@ func CreateFork(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateForkOption)
|
||||
form := web.GetForm[*api.CreateForkOption](ctx)
|
||||
forkOwner := ctx.Doer // user/org that will own the fork
|
||||
if form.Organization != nil {
|
||||
org := prepareDoerCreateRepoInOrg(ctx, *form.Organization)
|
||||
|
||||
@@ -126,7 +126,7 @@ func EditGitHook(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditGitHookOption)
|
||||
form := web.GetForm[*api.EditGitHookOption](ctx)
|
||||
hookID := ctx.PathParam("id")
|
||||
hook, err := git.GetHook(ctx.Repo.GitRepo, hookID)
|
||||
if err != nil {
|
||||
|
||||
@@ -226,7 +226,7 @@ func CreateHook(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
utils.AddRepoHook(ctx, web.GetForm(ctx).(*api.CreateHookOption))
|
||||
utils.AddRepoHook(ctx, web.GetForm[*api.CreateHookOption](ctx))
|
||||
}
|
||||
|
||||
// EditHook modify a hook of a repository
|
||||
@@ -262,7 +262,7 @@ func EditHook(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/Hook"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.EditHookOption)
|
||||
form := web.GetForm[*api.EditHookOption](ctx)
|
||||
hookID := ctx.PathParamInt64("id")
|
||||
utils.EditRepoHook(ctx, form, hookID)
|
||||
}
|
||||
|
||||
@@ -631,7 +631,7 @@ func CreateIssue(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateIssueOption)
|
||||
form := web.GetForm[*api.CreateIssueOption](ctx)
|
||||
var deadlineUnix timeutil.TimeStamp
|
||||
if form.Deadline != nil && ctx.Repo.Permission.CanWrite(unit.TypeIssues) {
|
||||
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
|
||||
@@ -759,7 +759,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||
// "412":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditIssueOption)
|
||||
form := web.GetForm[*api.EditIssueOption](ctx)
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
@@ -1012,7 +1012,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.EditDeadlineOption)
|
||||
form := web.GetForm[*api.EditDeadlineOption](ctx)
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
|
||||
@@ -60,7 +60,7 @@ func AddIssueAssignees(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.IssueAssigneesOption)
|
||||
opts := web.GetForm[*api.IssueAssigneesOption](ctx)
|
||||
updateIssueAssignees(ctx, *opts, true)
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func DeleteIssueAssignees(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.IssueAssigneesOption)
|
||||
opts := web.GetForm[*api.IssueAssigneesOption](ctx)
|
||||
updateIssueAssignees(ctx, *opts, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ func EditIssueAttachment(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// do changes to attachment. only meaningful change is name.
|
||||
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
|
||||
form := web.GetForm[*api.EditAttachmentOptions](ctx)
|
||||
if form.Name != "" {
|
||||
attachment.Name = form.Name
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ func CreateIssueComment(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
|
||||
form := web.GetForm[*api.CreateIssueCommentOption](ctx)
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
@@ -511,7 +511,7 @@ func EditIssueComment(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditIssueCommentOption)
|
||||
form := web.GetForm[*api.EditIssueCommentOption](ctx)
|
||||
editIssueComment(ctx, *form)
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ func EditIssueCommentDeprecated(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditIssueCommentOption)
|
||||
form := web.GetForm[*api.EditIssueCommentOption](ctx)
|
||||
editIssueComment(ctx, *form)
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
|
||||
form := web.GetForm[*api.EditAttachmentOptions](ctx)
|
||||
if form.Name != "" {
|
||||
attach.Name = form.Name
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ func CreateIssueDependency(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// and <Form> represents the dependency
|
||||
form := web.GetForm(ctx).(*api.IssueMeta)
|
||||
form := web.GetForm[*api.IssueMeta](ctx)
|
||||
dependency := getFormIssue(ctx, form)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -244,7 +244,7 @@ func RemoveIssueDependency(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// and <Form> represents the dependency
|
||||
form := web.GetForm(ctx).(*api.IssueMeta)
|
||||
form := web.GetForm[*api.IssueMeta](ctx)
|
||||
dependency := getFormIssue(ctx, form)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -404,7 +404,7 @@ func CreateIssueBlocking(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.IssueMeta)
|
||||
form := web.GetForm[*api.IssueMeta](ctx)
|
||||
target := getFormIssue(ctx, form)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -461,7 +461,7 @@ func RemoveIssueBlocking(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.IssueMeta)
|
||||
form := web.GetForm[*api.IssueMeta](ctx)
|
||||
target := getFormIssue(ctx, form)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
||||
@@ -103,7 +103,7 @@ func AddIssueLabels(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.IssueLabelsOption)
|
||||
form := web.GetForm[*api.IssueLabelsOption](ctx)
|
||||
issue, labels, err := prepareForReplaceOrAdd(ctx, *form)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -232,7 +232,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.IssueLabelsOption)
|
||||
form := web.GetForm[*api.IssueLabelsOption](ctx)
|
||||
issue, labels, err := prepareForReplaceOrAdd(ctx, *form)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -50,7 +50,7 @@ func LockIssue(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
reason := web.GetForm(ctx).(*api.LockIssueOption).Reason
|
||||
reason := web.GetForm[*api.LockIssueOption](ctx).Reason
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
|
||||
@@ -135,7 +135,7 @@ func PostIssueCommentReaction(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
form := web.GetForm[*api.EditReactionOption](ctx)
|
||||
|
||||
changeIssueCommentReaction(ctx, *form, true)
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func DeleteIssueCommentReaction(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
form := web.GetForm[*api.EditReactionOption](ctx)
|
||||
|
||||
changeIssueCommentReaction(ctx, *form, false)
|
||||
}
|
||||
@@ -364,7 +364,7 @@ func PostIssueReaction(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
form := web.GetForm[*api.EditReactionOption](ctx)
|
||||
changeIssueReaction(ctx, *form, true)
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ func DeleteIssueReaction(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
form := web.GetForm[*api.EditReactionOption](ctx)
|
||||
changeIssueReaction(ctx, *form, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ func AddTime(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.AddTimeOption)
|
||||
form := web.GetForm[*api.AddTimeOption](ctx)
|
||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
|
||||
@@ -231,7 +231,7 @@ func CreateDeployKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||
form := web.GetForm[*api.CreateKeyOption](ctx)
|
||||
content, err := asymkey_model.CheckPublicKeyString(form.Key)
|
||||
if err != nil {
|
||||
HandleCheckKeyStringError(ctx, err)
|
||||
|
||||
@@ -145,7 +145,7 @@ func CreateLabel(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateLabelOption)
|
||||
form := web.GetForm[*api.CreateLabelOption](ctx)
|
||||
|
||||
color, err := label.NormalizeColor(form.Color)
|
||||
if err != nil {
|
||||
@@ -207,7 +207,7 @@ func EditLabel(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditLabelOption)
|
||||
form := web.GetForm[*api.EditLabelOption](ctx)
|
||||
l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
|
||||
@@ -56,7 +56,7 @@ func Migrate(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.MigrateRepoOptions)
|
||||
form := web.GetForm[*api.MigrateRepoOptions](ctx)
|
||||
|
||||
// get repoOwner
|
||||
var (
|
||||
@@ -217,6 +217,11 @@ func Migrate(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err error) {
|
||||
var (
|
||||
errNameReserved db.ErrNameReserved
|
||||
errNameCharsNotAllowed db.ErrNameCharsNotAllowed
|
||||
errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
)
|
||||
switch {
|
||||
case repo_model.IsErrRepoAlreadyExist(err):
|
||||
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
|
||||
@@ -228,12 +233,12 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Remote visit required two factors authentication.")
|
||||
case repo_model.IsErrReachLimitOfRepo(err):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
|
||||
case db.IsErrNameReserved(err):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
|
||||
case db.IsErrNameCharsNotAllowed(err):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", errNameReserved.Name))
|
||||
case errors.As(err, &errNameCharsNotAllowed):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", errNameCharsNotAllowed.Name))
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", errNamePatternNotAllowed.Pattern))
|
||||
case git.IsErrInvalidCloneAddr(err):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
|
||||
case base.IsErrNotSupported(err):
|
||||
@@ -253,8 +258,7 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
|
||||
}
|
||||
|
||||
func handleRemoteAddrError(ctx *context.APIContext, err error) {
|
||||
if git.IsErrInvalidCloneAddr(err) {
|
||||
addrErr := err.(*git.ErrInvalidCloneAddr)
|
||||
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
|
||||
switch {
|
||||
case addrErr.IsURLError:
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "The provided URL is invalid.")
|
||||
|
||||
@@ -147,7 +147,7 @@ func CreateMilestone(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/Milestone"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.CreateMilestoneOption)
|
||||
form := web.GetForm[*api.CreateMilestoneOption](ctx)
|
||||
|
||||
var deadlineUnix int64
|
||||
if form.Deadline != nil {
|
||||
@@ -207,7 +207,7 @@ func EditMilestone(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/Milestone"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.EditMilestoneOption)
|
||||
form := web.GetForm[*api.EditMilestoneOption](ctx)
|
||||
milestone := getMilestoneByIDOrName(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
||||
@@ -291,7 +291,7 @@ func AddPushMirror(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
pushMirror := web.GetForm(ctx).(*api.CreatePushMirrorOption)
|
||||
pushMirror := web.GetForm[*api.CreatePushMirrorOption](ctx)
|
||||
CreatePushMirror(ctx, pushMirror)
|
||||
}
|
||||
|
||||
@@ -403,8 +403,7 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro
|
||||
}
|
||||
|
||||
func HandleRemoteAddressError(ctx *context.APIContext, err error) {
|
||||
if git.IsErrInvalidCloneAddr(err) {
|
||||
addrErr := err.(*git.ErrInvalidCloneAddr)
|
||||
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
|
||||
switch {
|
||||
case addrErr.IsProtocolInvalid:
|
||||
ctx.APIError(http.StatusBadRequest, "Invalid mirror protocol")
|
||||
|
||||
@@ -404,7 +404,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := *web.GetForm(ctx).(*api.CreatePullRequestOption)
|
||||
form := *web.GetForm[*api.CreatePullRequestOption](ctx)
|
||||
if form.Head == form.Base {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Invalid PullRequest: There are no changes between the head and the base")
|
||||
return
|
||||
@@ -628,7 +628,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditPullRequestOption)
|
||||
form := web.GetForm[*api.EditPullRequestOption](ctx)
|
||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
if issues_model.IsErrPullRequestNotExist(err) {
|
||||
@@ -922,7 +922,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*forms.MergePullRequestForm)
|
||||
form := web.GetForm[*forms.MergePullRequestForm](ctx)
|
||||
|
||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
@@ -1044,21 +1044,17 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||
if err := pull_service.Merge(ctx, pr, ctx.Doer, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
|
||||
if pull_service.IsErrInvalidMergeStyle(err) {
|
||||
ctx.APIError(http.StatusMethodNotAllowed, fmt.Sprintf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||
} else if pull_service.IsErrMergeConflicts(err) {
|
||||
conflictError := err.(pull_service.ErrMergeConflicts)
|
||||
} else if conflictError, ok := err.(pull_service.ErrMergeConflicts); ok {
|
||||
ctx.JSON(http.StatusConflict, conflictError)
|
||||
} else if pull_service.IsErrRebaseConflicts(err) {
|
||||
conflictError := err.(pull_service.ErrRebaseConflicts)
|
||||
} else if conflictError, ok := err.(pull_service.ErrRebaseConflicts); ok {
|
||||
ctx.JSON(http.StatusConflict, conflictError)
|
||||
} else if pull_service.IsErrMergeUnrelatedHistories(err) {
|
||||
conflictError := err.(pull_service.ErrMergeUnrelatedHistories)
|
||||
} else if conflictError, ok := err.(pull_service.ErrMergeUnrelatedHistories); ok {
|
||||
ctx.JSON(http.StatusConflict, conflictError)
|
||||
} else if git.IsErrPushOutOfDate(err) {
|
||||
ctx.APIError(http.StatusConflict, "merge push out of date")
|
||||
} else if pull_service.IsErrSHADoesNotMatch(err) {
|
||||
ctx.APIError(http.StatusConflict, "head out of date")
|
||||
} else if git.IsErrPushRejected(err) {
|
||||
errPushRej := err.(*git.ErrPushRejected)
|
||||
} else if errPushRej, ok := err.(*git.ErrPushRejected); ok {
|
||||
if len(errPushRej.Message) == 0 {
|
||||
ctx.APIError(http.StatusConflict, "PushRejected without remote error message")
|
||||
} else {
|
||||
|
||||
@@ -252,7 +252,7 @@ func CreatePullReviewCommentReply(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.CreatePullReviewCommentReplyOptions)
|
||||
opts := web.GetForm[*api.CreatePullReviewCommentReplyOptions](ctx)
|
||||
|
||||
parent := getPullReviewCommentToResolve(ctx)
|
||||
if parent == nil {
|
||||
@@ -499,7 +499,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.CreatePullReviewOptions)
|
||||
opts := web.GetForm[*api.CreatePullReviewOptions](ctx)
|
||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
@@ -622,7 +622,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.SubmitPullReviewOptions)
|
||||
opts := web.GetForm[*api.SubmitPullReviewOptions](ctx)
|
||||
review, pr, isWrong := prepareSingleReview(ctx)
|
||||
if isWrong {
|
||||
return
|
||||
@@ -792,7 +792,7 @@ func CreateReviewRequests(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.PullReviewRequestOptions)
|
||||
opts := web.GetForm[*api.PullReviewRequestOptions](ctx)
|
||||
apiReviewRequest(ctx, *opts, true)
|
||||
}
|
||||
|
||||
@@ -834,7 +834,7 @@ func DeleteReviewRequests(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
opts := web.GetForm(ctx).(*api.PullReviewRequestOptions)
|
||||
opts := web.GetForm[*api.PullReviewRequestOptions](ctx)
|
||||
apiReviewRequest(ctx, *opts, false)
|
||||
}
|
||||
|
||||
@@ -1014,7 +1014,7 @@ func DismissPullReview(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
opts := web.GetForm(ctx).(*api.DismissPullReviewOptions)
|
||||
opts := web.GetForm[*api.DismissPullReviewOptions](ctx)
|
||||
dismissReview(ctx, opts.Message, true, opts.Priors)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func canAccessReleaseDraft(ctx *context.APIContext) bool {
|
||||
return true
|
||||
}
|
||||
// the request is from an access token with scope
|
||||
scope := ctx.Data["ApiTokenScope"].(auth_model.AccessTokenScope)
|
||||
scope := ctx.Data["ApiTokenScope"].(auth_model.AccessTokenScope) //nolint:forcetypeassert // must exist
|
||||
requiredScopes := auth_model.GetRequiredScopes(auth_model.Write, auth_model.AccessTokenScopeCategoryRepository)
|
||||
allow, _ := scope.HasScope(requiredScopes...) // err (invalid token) can be safely ignored
|
||||
return allow
|
||||
@@ -244,7 +244,7 @@ func CreateRelease(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateReleaseOption)
|
||||
form := web.GetForm[*api.CreateReleaseOption](ctx)
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "repo is empty")
|
||||
return
|
||||
@@ -346,7 +346,7 @@ func EditRelease(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditReleaseOption)
|
||||
form := web.GetForm[*api.EditReleaseOption](ctx)
|
||||
id := ctx.PathParamInt64("id")
|
||||
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||
|
||||
@@ -310,7 +310,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
|
||||
form := web.GetForm[*api.EditAttachmentOptions](ctx)
|
||||
|
||||
// Check if release exists an load release
|
||||
releaseID := ctx.PathParamInt64("id")
|
||||
|
||||
@@ -298,7 +298,7 @@ func Create(ctx *context.APIContext) {
|
||||
// description: The repository with the same name already exists.
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||
opt := web.GetForm[*api.CreateRepoOption](ctx)
|
||||
if ctx.Doer.IsOrganization() {
|
||||
// Shouldn't reach this condition, but just in case.
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "not allowed creating repository for organization")
|
||||
@@ -342,7 +342,7 @@ func Generate(ctx *context.APIContext) {
|
||||
// description: The repository with the same name already exists.
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.GenerateRepoOption)
|
||||
form := web.GetForm[*api.GenerateRepoOption](ctx)
|
||||
|
||||
if !ctx.Repo.Repository.IsTemplate {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "this is not a template repo")
|
||||
@@ -484,7 +484,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||
opt := web.GetForm[*api.CreateRepoOption](ctx)
|
||||
orgName := ctx.PathParam("org")
|
||||
org := prepareDoerCreateRepoInOrg(ctx, orgName)
|
||||
if ctx.Written() {
|
||||
@@ -603,7 +603,7 @@ func Edit(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := *web.GetForm(ctx).(*api.EditRepoOption)
|
||||
opts := *web.GetForm[*api.EditRepoOption](ctx)
|
||||
|
||||
if err := updateBasicProperties(ctx, opts); err != nil {
|
||||
return
|
||||
|
||||
@@ -52,7 +52,7 @@ func NewCommitStatus(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateStatusOption)
|
||||
form := web.GetForm[*api.CreateStatusOption](ctx)
|
||||
sha := ctx.PathParam("sha")
|
||||
if len(sha) == 0 {
|
||||
ctx.APIError(http.StatusBadRequest, "sha not provided")
|
||||
|
||||
@@ -194,7 +194,7 @@ func CreateTag(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/validationError"
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
form := web.GetForm(ctx).(*api.CreateTagOption)
|
||||
form := web.GetForm[*api.CreateTagOption](ctx)
|
||||
|
||||
// If target is not provided use default branch
|
||||
if len(form.Target) == 0 {
|
||||
@@ -411,7 +411,7 @@ func CreateTagProtection(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateTagProtectionOption)
|
||||
form := web.GetForm[*api.CreateTagProtectionOption](ctx)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
namePattern := strings.TrimSpace(form.NamePattern)
|
||||
@@ -522,7 +522,7 @@ func EditTagProtection(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
form := web.GetForm(ctx).(*api.EditTagProtectionOption)
|
||||
form := web.GetForm[*api.EditTagProtectionOption](ctx)
|
||||
|
||||
id := ctx.PathParamInt64("id")
|
||||
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
||||
|
||||
@@ -101,7 +101,7 @@ func UpdateTopics(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/invalidTopicsError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.RepoTopicOptions)
|
||||
form := web.GetForm[*api.RepoTopicOptions](ctx)
|
||||
topicNames := form.Topics
|
||||
validTopics, invalidTopics := repo_model.SanitizeAndValidateTopics(topicNames)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ func Transfer(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.TransferRepoOption)
|
||||
opts := web.GetForm[*api.TransferRepoOption](ctx)
|
||||
|
||||
newOwner, err := user_model.GetUserByName(ctx, opts.NewOwner)
|
||||
if err != nil {
|
||||
|
||||
@@ -55,7 +55,7 @@ func NewWikiPage(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
|
||||
form := web.GetForm[*api.CreateWikiPageOptions](ctx)
|
||||
|
||||
if util.IsEmptyString(form.Title) {
|
||||
ctx.APIError(http.StatusBadRequest, "title is required")
|
||||
@@ -133,7 +133,7 @@ func EditWikiPage(ctx *context.APIContext) {
|
||||
// "423":
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
|
||||
form := web.GetForm[*api.CreateWikiPageOptions](ctx)
|
||||
|
||||
oldWikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("pageName"))
|
||||
newWikiName := wiki_service.UserTitleToWebPath("", form.Title)
|
||||
|
||||
@@ -478,7 +478,7 @@ func CreateProject(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
scope := projectScopeFromContext(ctx)
|
||||
form := web.GetForm(ctx).(*api.CreateProjectOption)
|
||||
form := web.GetForm[*api.CreateProjectOption](ctx)
|
||||
|
||||
templateType, err := convert.ProjectTemplateTypeFromString(form.TemplateType)
|
||||
if err != nil {
|
||||
@@ -611,7 +611,7 @@ func EditProject(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditProjectOption)
|
||||
form := web.GetForm[*api.EditProjectOption](ctx)
|
||||
if form.Title != nil && util.IsEmptyString(*form.Title) {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "title must not be empty")
|
||||
return
|
||||
@@ -951,7 +951,7 @@ func CreateProjectColumn(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateProjectColumnOption)
|
||||
form := web.GetForm[*api.CreateProjectColumnOption](ctx)
|
||||
column := &project_model.Column{
|
||||
Title: form.Title,
|
||||
Color: form.Color,
|
||||
@@ -1185,7 +1185,7 @@ func EditProjectColumn(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditProjectColumnOption)
|
||||
form := web.GetForm[*api.EditProjectColumnOption](ctx)
|
||||
if form.Title != nil {
|
||||
if util.IsEmptyString(*form.Title) {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "title must not be empty")
|
||||
@@ -1529,7 +1529,7 @@ func MoveProjectColumns(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.MoveProjectColumnsOption)
|
||||
form := web.GetForm[*api.MoveProjectColumnsOption](ctx)
|
||||
columns, err := project_model.GetColumns(ctx, project.ID, db.ListOptionsAll)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
@@ -2097,7 +2097,7 @@ func MoveProjectIssue(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.MoveProjectIssueOption)
|
||||
form := web.GetForm[*api.MoveProjectIssueOption](ctx)
|
||||
column, err := project_model.GetColumnByIDAndProjectID(ctx, form.ColumnID, project.ID)
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectColumnNotExist(err) {
|
||||
|
||||
@@ -131,7 +131,7 @@ func UpdateRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditActionRunnerOption)
|
||||
form := web.GetForm[*api.EditActionRunnerOption](ctx)
|
||||
if form.Disabled == nil {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "[Disabled]: Required")
|
||||
return
|
||||
|
||||
@@ -48,7 +48,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
|
||||
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
|
||||
|
||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data, opt.Description)
|
||||
if err != nil {
|
||||
@@ -134,7 +134,7 @@ func CreateVariable(ctx *context.APIContext) {
|
||||
// "409":
|
||||
// description: variable name already exists.
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateVariableOption)
|
||||
opt := web.GetForm[*api.CreateVariableOption](ctx)
|
||||
|
||||
ownerID := ctx.Doer.ID
|
||||
variableName := ctx.PathParam("variablename")
|
||||
@@ -193,7 +193,7 @@ func UpdateVariable(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
|
||||
opt := web.GetForm[*api.UpdateVariableOption](ctx)
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
OwnerID: ctx.Doer.ID,
|
||||
|
||||
@@ -98,7 +98,7 @@ func CreateAccessToken(ctx *context.APIContext) {
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
|
||||
form := web.GetForm[*api.CreateAccessTokenOption](ctx)
|
||||
|
||||
t := &auth_model.AccessToken{
|
||||
UID: ctx.ContextUser.ID,
|
||||
@@ -242,7 +242,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
data := web.GetForm[*api.CreateOAuth2ApplicationOptions](ctx)
|
||||
if invalidURI := forms.DetectInvalidOAuth2ApplicationRedirectURI(data.RedirectURIs); invalidURI != "" {
|
||||
ctx.APIError(http.StatusBadRequest, "invalid redirect URI: "+invalidURI)
|
||||
return
|
||||
@@ -406,7 +406,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.PathParamInt64("id")
|
||||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
data := web.GetForm[*api.CreateOAuth2ApplicationOptions](ctx)
|
||||
if invalidURI := forms.DetectInvalidOAuth2ApplicationRedirectURI(data.RedirectURIs); invalidURI != "" {
|
||||
ctx.APIError(http.StatusBadRequest, "invalid redirect URI: "+invalidURI)
|
||||
return
|
||||
|
||||
@@ -28,7 +28,7 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
|
||||
form := web.GetForm[*api.UpdateUserAvatarOption](ctx)
|
||||
|
||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||
if err != nil {
|
||||
|
||||
@@ -63,15 +63,15 @@ func AddEmail(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateEmailOption)
|
||||
form := web.GetForm[*api.CreateEmailOption](ctx)
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Email list empty")
|
||||
return
|
||||
}
|
||||
|
||||
if err := user_service.AddEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
|
||||
if errEmailAlreadyUsed, ok := err.(user_model.ErrEmailAlreadyUsed); ok {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+errEmailAlreadyUsed.Email)
|
||||
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
|
||||
email := ""
|
||||
if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
|
||||
@@ -125,7 +125,7 @@ func DeleteEmail(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.DeleteEmailOption)
|
||||
form := web.GetForm[*api.DeleteEmailOption](ctx)
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.Status(http.StatusNoContent)
|
||||
return
|
||||
|
||||
@@ -187,7 +187,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.VerifyGPGKeyOption)
|
||||
form := web.GetForm[*api.VerifyGPGKeyOption](ctx)
|
||||
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
||||
|
||||
@@ -248,7 +248,7 @@ func CreateGPGKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateGPGKeyOption)
|
||||
form := web.GetForm[*api.CreateGPGKeyOption](ctx)
|
||||
CreateUserGPGKey(ctx, *form, ctx.Doer.ID)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func CreateHook(ctx *context.APIContext) {
|
||||
utils.AddOwnerHook(
|
||||
ctx,
|
||||
ctx.Doer,
|
||||
web.GetForm(ctx).(*api.CreateHookOption),
|
||||
web.GetForm[*api.CreateHookOption](ctx),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func EditHook(ctx *context.APIContext) {
|
||||
utils.EditOwnerHook(
|
||||
ctx,
|
||||
ctx.Doer,
|
||||
web.GetForm(ctx).(*api.EditHookOption),
|
||||
web.GetForm[*api.EditHookOption](ctx),
|
||||
ctx.PathParamInt64("id"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ func CreatePublicKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||
form := web.GetForm[*api.CreateKeyOption](ctx)
|
||||
CreateUserPublicKey(ctx, *form, ctx.Doer.ID)
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
||||
// "200":
|
||||
// "$ref": "#/responses/UserSettings"
|
||||
|
||||
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
||||
form := web.GetForm[*api.UserSettingsOptions](ctx)
|
||||
|
||||
opts := &user_service.UpdateOptions{
|
||||
FullName: optional.FromPtr(form.FullName),
|
||||
|
||||
@@ -24,7 +24,7 @@ func AuthShared(ctx *context.Base, sessionStore auth_service.SessionStore, authM
|
||||
if ctx.Locale.Language() != ar.Doer.Language {
|
||||
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
|
||||
}
|
||||
ar.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth_service.BasicMethodName
|
||||
ar.IsBasicAuth = ctx.Data["AuthedMethod"] == auth_service.BasicMethodName
|
||||
|
||||
ctx.Data["IsSigned"] = true
|
||||
ctx.Data[middleware.ContextDataKeySignedUser] = ar.Doer
|
||||
|
||||
@@ -95,7 +95,7 @@ func RequestContextHandler() func(h http.Handler) http.Handler {
|
||||
// The "req" might have changed due to the new "req.WithContext" calls
|
||||
// For example: in NewBaseContext, a new "req" with context is created, and the multipart-form is parsed there.
|
||||
// So we always use the latest "req" from the data store.
|
||||
ctxReq := ds.GetContextValue(httplib.RequestContextKey).(*http.Request)
|
||||
ctxReq := ds.GetContextValue(httplib.RequestContextKey).(*http.Request) //nolint:forcetypeassert // must be valid
|
||||
if ctxReq.MultipartForm != nil {
|
||||
_ = ctxReq.MultipartForm.RemoveAll() // remove the temp files buffered to tmp directory
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func SubmitInstall(ctx *context.Context) {
|
||||
|
||||
var err error
|
||||
|
||||
form := *web.GetForm(ctx).(*forms.InstallForm)
|
||||
form := *web.GetForm[*forms.InstallForm](ctx)
|
||||
|
||||
// fix form values
|
||||
if form.AppURL != "" && form.AppURL[len(form.AppURL)-1] != '/' {
|
||||
@@ -524,7 +524,7 @@ func SubmitInstall(ctx *context.Context) {
|
||||
|
||||
// Now get the http.Server from this request and shut it down
|
||||
// NB: This is not our hammerable graceful shutdown this is http.Server.Shutdown
|
||||
srv := ctx.Value(http.ServerContextKey).(*http.Server)
|
||||
srv := ctx.Value(http.ServerContextKey).(*http.Server) //nolint:forcetypeassert // must exist
|
||||
if err := srv.Shutdown(graceful.GetManager().HammerContext()); err != nil {
|
||||
log.Error("Unable to shutdown the install server! Error: %v", err)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func hookPostReceiveSyncDatabaseBranches(ctx *gitea_context.PrivateContext, opts
|
||||
|
||||
// HookPostReceive updates services and users
|
||||
func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
||||
opts := web.GetForm(ctx).(*private.HookOptions)
|
||||
opts := web.GetForm[*private.HookOptions](ctx)
|
||||
if opts.IsWiki {
|
||||
setting.PanicInDevOrTesting("wiki hook-post-receive is not supported")
|
||||
return
|
||||
|
||||
@@ -107,7 +107,7 @@ func (ctx *preReceiveContext) AssertCreatePullRequest() bool {
|
||||
|
||||
// HookPreReceive checks whether a individual commit is acceptable
|
||||
func HookPreReceive(ctx *gitea_context.PrivateContext) {
|
||||
opts := web.GetForm(ctx).(*private.HookOptions)
|
||||
opts := web.GetForm[*private.HookOptions](ctx)
|
||||
|
||||
ourCtx := &preReceiveContext{
|
||||
PrivateContext: ctx,
|
||||
@@ -224,17 +224,17 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID string, r
|
||||
if protectBranch.RequireSignedCommits {
|
||||
err := verifyCommits(ctx, oldCommitID, newCommitID, gitRepo, ctx.env)
|
||||
if err != nil {
|
||||
if !isErrUnverifiedCommit(err) {
|
||||
errUnverified, ok := err.(*errUnverifiedCommit)
|
||||
if !ok {
|
||||
log.Error("Unable to check commits from %s to %s in %-v: %v", oldCommitID, newCommitID, repo, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: fmt.Sprintf("Unable to check commits from %s to %s: %v", oldCommitID, newCommitID, err),
|
||||
})
|
||||
return
|
||||
}
|
||||
unverifiedCommit := err.(*errUnverifiedCommit).sha
|
||||
log.Warn("Forbidden: Branch: %s in %-v is protected from unverified commit %s", branchName, repo, unverifiedCommit)
|
||||
log.Warn("Forbidden: Branch: %s in %-v is protected from unverified commit %s", branchName, repo, errUnverified.sha)
|
||||
ctx.JSON(http.StatusForbidden, private.Response{
|
||||
UserMsg: fmt.Sprintf("branch %s is protected from unverified commit %s", branchName, unverifiedCommit),
|
||||
UserMsg: fmt.Sprintf("branch %s is protected from unverified commit %s", branchName, errUnverified.sha),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -250,7 +250,8 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID string, r
|
||||
if len(globs) > 0 {
|
||||
_, err := pull_service.CheckFileProtection(ctx, gitRepo, branchName, oldCommitID, newCommitID, globs, 1, ctx.env)
|
||||
if err != nil {
|
||||
if !pull_service.IsErrFilePathProtected(err) {
|
||||
errFilePathProtected, ok := errors.AsType[pull_service.ErrFilePathProtected](err)
|
||||
if !ok {
|
||||
log.Error("Unable to check file protection for commits from %s to %s in %-v: %v", oldCommitID, newCommitID, repo, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: fmt.Sprintf("Unable to check file protection for commits from %s to %s: %v", oldCommitID, newCommitID, err),
|
||||
@@ -259,7 +260,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID string, r
|
||||
}
|
||||
|
||||
changedProtectedfiles = true
|
||||
protectedFilePath = err.(pull_service.ErrFilePathProtected).Path
|
||||
protectedFilePath = errFilePathProtected.Path
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
// HookProcReceive proc-receive hook - only handles agit Proc-Receive requests at present
|
||||
func HookProcReceive(ctx *gitea_context.PrivateContext) {
|
||||
opts := web.GetForm(ctx).(*private.HookOptions)
|
||||
opts := web.GetForm[*private.HookOptions](ctx)
|
||||
if !git.DefaultFeatures().SupportProcReceive {
|
||||
ctx.Status(http.StatusNotFound)
|
||||
return
|
||||
|
||||
@@ -33,7 +33,7 @@ func ReloadTemplates(ctx *context.PrivateContext) {
|
||||
|
||||
// FlushQueues flushes all the Queues
|
||||
func FlushQueues(ctx *context.PrivateContext) {
|
||||
opts := web.GetForm(ctx).(*private.FlushOptions)
|
||||
opts := web.GetForm[*private.FlushOptions](ctx)
|
||||
if opts.NonBlocking {
|
||||
// Save the hammer ctx here - as a new one is created each time you call this.
|
||||
baseCtx := graceful.GetManager().HammerContext()
|
||||
@@ -102,7 +102,7 @@ func RemoveLogger(ctx *context.PrivateContext) {
|
||||
|
||||
// AddLogger adds a logger
|
||||
func AddLogger(ctx *context.PrivateContext) {
|
||||
opts := web.GetForm(ctx).(*private.LoggerOptions)
|
||||
opts := web.GetForm[*private.LoggerOptions](ctx)
|
||||
|
||||
if len(opts.Logger) == 0 {
|
||||
opts.Logger = log.DEFAULT
|
||||
|
||||
@@ -20,7 +20,7 @@ func SSHLog(ctx *context.PrivateContext) {
|
||||
return
|
||||
}
|
||||
|
||||
opts := web.GetForm(ctx).(*private.SSHLogOption)
|
||||
opts := web.GetForm[*private.SSHLogOption](ctx)
|
||||
|
||||
if opts.IsError {
|
||||
log.Error("ssh: %v", opts.Message)
|
||||
|
||||
@@ -153,7 +153,7 @@ func SystemStatus(ctx *context.Context) {
|
||||
|
||||
// DashboardPost run an admin operation
|
||||
func DashboardPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AdminDashboardForm)
|
||||
form := web.GetForm[*forms.AdminDashboardForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
|
||||
ctx.Data["PageIsAdminDashboard"] = true
|
||||
updateSystemStatus()
|
||||
|
||||
+14
-18
@@ -235,7 +235,7 @@ func parseSSPIConfig(ctx *context.Context, form forms.AuthenticationForm) (*sspi
|
||||
|
||||
// NewAuthSourcePost response for adding an auth source
|
||||
func NewAuthSourcePost(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.AuthenticationForm)
|
||||
form := *web.GetForm[*forms.AuthenticationForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
|
||||
@@ -268,8 +268,8 @@ func NewAuthSourcePost(ctx *context.Context) {
|
||||
EmailDomain: form.PAMEmailDomain,
|
||||
}
|
||||
case auth.OAuth2:
|
||||
config = parseOAuth2Config(form)
|
||||
oauth2Config := config.(*oauth2.Source)
|
||||
oauth2Config := parseOAuth2Config(form)
|
||||
config = oauth2Config
|
||||
if oauth2Config.Provider == "openidConnect" {
|
||||
discoveryURL, err := url.Parse(oauth2Config.OpenIDConnectAutoDiscoveryURL)
|
||||
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
|
||||
@@ -310,13 +310,12 @@ func NewAuthSourcePost(ctx *context.Context) {
|
||||
TwoFactorPolicy: form.TwoFactorPolicy,
|
||||
Cfg: config,
|
||||
}); err != nil {
|
||||
if auth.IsErrSourceAlreadyExist(err) {
|
||||
if errExist, ok := errors.AsType[auth.ErrSourceAlreadyExist](err); ok {
|
||||
ctx.Data["Err_Name"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthNew, form)
|
||||
} else if oauth2.IsErrOpenIDConnectInitialize(err) {
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", errExist.Name), tplAuthNew, form)
|
||||
} else if errInit, ok := err.(oauth2.ErrOpenIDConnectInitialize); ok {
|
||||
ctx.Data["Err_DiscoveryURL"] = true
|
||||
unwrapped := err.(oauth2.ErrOpenIDConnectInitialize).Unwrap()
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.unable_to_initialize_openid", unwrapped), tplAuthNew, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.unable_to_initialize_openid", errInit.Unwrap()), tplAuthNew, form)
|
||||
} else {
|
||||
ctx.ServerError("auth.CreateSource", err)
|
||||
}
|
||||
@@ -348,12 +347,9 @@ func EditAuthSource(ctx *context.Context) {
|
||||
ctx.Data["HasTLS"] = source.HasTLS()
|
||||
|
||||
if source.IsOAuth2() {
|
||||
type Named interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](source)
|
||||
for _, provider := range oauth2providers {
|
||||
if provider.Name() == source.Cfg.(Named).Name() {
|
||||
if provider.Name() == oauth2Source.Name() {
|
||||
ctx.Data["CurrentOAuth2Provider"] = provider
|
||||
break
|
||||
}
|
||||
@@ -365,7 +361,7 @@ func EditAuthSource(ctx *context.Context) {
|
||||
|
||||
// EditAuthSourcePost response for editing auth source
|
||||
func EditAuthSourcePost(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.AuthenticationForm)
|
||||
form := *web.GetForm[*forms.AuthenticationForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
|
||||
@@ -398,8 +394,8 @@ func EditAuthSourcePost(ctx *context.Context) {
|
||||
EmailDomain: form.PAMEmailDomain,
|
||||
}
|
||||
case auth.OAuth2:
|
||||
config = parseOAuth2Config(form)
|
||||
oauth2Config := config.(*oauth2.Source)
|
||||
oauth2Config := parseOAuth2Config(form)
|
||||
config = oauth2Config
|
||||
if oauth2Config.Provider == "openidConnect" {
|
||||
discoveryURL, err := url.Parse(oauth2Config.OpenIDConnectAutoDiscoveryURL)
|
||||
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
|
||||
@@ -425,9 +421,9 @@ func EditAuthSourcePost(ctx *context.Context) {
|
||||
source.Cfg = config
|
||||
source.TwoFactorPolicy = form.TwoFactorPolicy
|
||||
if err := auth.UpdateSource(ctx, source); err != nil {
|
||||
if auth.IsErrSourceAlreadyExist(err) {
|
||||
if errExist, ok := errors.AsType[auth.ErrSourceAlreadyExist](err); ok {
|
||||
ctx.Data["Err_Name"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthEdit, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("admin.auths.login_source_exist", errExist.Name), tplAuthEdit, form)
|
||||
} else if oauth2.IsErrOpenIDConnectInitialize(err) {
|
||||
ctx.Flash.Error(err.Error(), true)
|
||||
ctx.Data["Err_DiscoveryURL"] = true
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewBadge(ctx *context.Context) {
|
||||
|
||||
// NewBadgePost response for adding a new badge
|
||||
func NewBadgePost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AdminCreateBadgeForm)
|
||||
form := web.GetForm[*forms.AdminCreateBadgeForm](ctx)
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
@@ -100,12 +100,11 @@ func ViewBadge(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.badges.details")
|
||||
ctx.Data["PageIsAdminBadges"] = true
|
||||
|
||||
prepareBadgeInfo(ctx)
|
||||
badge := prepareBadgeInfo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
badge := ctx.Data["Badge"].(*user_model.Badge)
|
||||
opts := &user_model.GetBadgeUsersOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: 1,
|
||||
@@ -143,7 +142,7 @@ func EditBadgePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AdminEditBadgeForm)
|
||||
form := web.GetForm[*forms.AdminEditBadgeForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.JSONError(ctx.GetErrMsg())
|
||||
return
|
||||
|
||||
@@ -103,7 +103,7 @@ func NewUser(ctx *context.Context) {
|
||||
|
||||
// NewUserPost response for adding a new user
|
||||
func NewUserPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AdminCreateUserForm)
|
||||
form := web.GetForm[*forms.AdminCreateUserForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
||||
ctx.Data["PageIsAdminUsers"] = true
|
||||
ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode
|
||||
@@ -171,6 +171,9 @@ func NewUserPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if err := user_model.AdminCreateUser(ctx, u, &user_model.Meta{}, overwriteDefault); err != nil {
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
var errNameCharsNotAllowed db.ErrNameCharsNotAllowed
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
@@ -181,15 +184,15 @@ func NewUserPost(ctx *context.Context) {
|
||||
case user_model.IsErrEmailInvalid(err), user_model.IsErrEmailCharIsNotSupported(err):
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.email_invalid"), tplUserNew, &form)
|
||||
case db.IsErrNameReserved(err):
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tplUserNew, &form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", errNameReserved.Name), tplUserNew, &form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
|
||||
case db.IsErrNameCharsNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tplUserNew, &form)
|
||||
case errors.As(err, &errNameCharsNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tplUserNew, &form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", errNameCharsNotAllowed.Name), tplUserNew, &form)
|
||||
default:
|
||||
ctx.ServerError("CreateUser", err)
|
||||
}
|
||||
@@ -336,7 +339,7 @@ func EditUserPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AdminEditUserForm)
|
||||
form := web.GetForm[*forms.AdminEditUserForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(http.StatusOK, tplUserEdit)
|
||||
return
|
||||
@@ -522,7 +525,7 @@ func AvatarPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.AvatarForm)
|
||||
form := web.GetForm[*forms.AvatarForm](ctx)
|
||||
if err := user_setting.UpdateAvatarSetting(ctx, form, u); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
} else {
|
||||
|
||||
+8
-10
@@ -41,17 +41,16 @@ func TwoFactor(ctx *context.Context) {
|
||||
|
||||
// TwoFactorPost validates a user's two-factor authentication token.
|
||||
func TwoFactorPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
|
||||
form := web.GetForm[*forms.TwoFactorAuthForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("twofa")
|
||||
|
||||
// Ensure user is in a 2FA session.
|
||||
idSess := ctx.Session.Get("twofaUid")
|
||||
if idSess == nil {
|
||||
id, hasSession := ctx.Session.Get("twofaUid").(int64)
|
||||
if !hasSession {
|
||||
ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
|
||||
return
|
||||
}
|
||||
|
||||
id := idSess.(int64)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
@@ -66,7 +65,7 @@ func TwoFactorPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if ok {
|
||||
remember := ctx.Session.Get("twofaRemember").(bool)
|
||||
remember := ctx.Session.Get("twofaRemember").(bool) //nolint:forcetypeassert // must exist
|
||||
u, err := user_model.GetUserByID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
@@ -105,17 +104,16 @@ func TwoFactorScratch(ctx *context.Context) {
|
||||
|
||||
// TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
|
||||
func TwoFactorScratchPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.TwoFactorScratchAuthForm)
|
||||
form := web.GetForm[*forms.TwoFactorScratchAuthForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("twofa_scratch")
|
||||
|
||||
// Ensure user is in a 2FA session.
|
||||
idSess := ctx.Session.Get("twofaUid")
|
||||
if idSess == nil {
|
||||
id, hasSession := ctx.Session.Get("twofaUid").(int64)
|
||||
if !hasSession {
|
||||
ctx.ServerError("UserSignIn", errors.New("not in 2FA session"))
|
||||
return
|
||||
}
|
||||
|
||||
id := idSess.(int64)
|
||||
twofa, err := auth.GetTwoFactorByUID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
@@ -135,7 +133,7 @@ func TwoFactorScratchPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
remember := ctx.Session.Get("twofaRemember").(bool)
|
||||
remember := ctx.Session.Get("twofaRemember").(bool) //nolint:forcetypeassert // must exist
|
||||
u, err := user_model.GetUserByID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.ServerError("UserSignIn", err)
|
||||
|
||||
@@ -293,7 +293,7 @@ func SignInPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.SignInForm)
|
||||
form := web.GetForm[*forms.SignInForm](ctx)
|
||||
|
||||
if setting.Service.EnableCaptcha && setting.Service.RequireCaptchaForLogin {
|
||||
context.VerifyCaptcha(ctx, tplSignIn, form)
|
||||
@@ -535,7 +535,7 @@ func SignUpPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.RegisterForm)
|
||||
form := web.GetForm[*forms.RegisterForm](ctx)
|
||||
|
||||
// Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
|
||||
if setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration {
|
||||
@@ -651,6 +651,9 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
|
||||
}
|
||||
|
||||
// handle error with template
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
var errNameCharsNotAllowed db.ErrNameCharsNotAllowed
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
@@ -664,15 +667,15 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
|
||||
case user_model.IsErrEmailInvalid(err):
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.email_invalid"), tpl, form)
|
||||
case db.IsErrNameReserved(err):
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_reserved", errNameReserved.Name), tpl, form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
|
||||
case db.IsErrNameCharsNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tpl, form)
|
||||
case errors.As(err, &errNameCharsNotAllowed):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tpl, form)
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("user.form.name_chars_not_allowed", errNameCharsNotAllowed.Name), tpl, form)
|
||||
default:
|
||||
ctx.ServerError("CreateUser", err)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func handleSignInError(ctx *context.Context, userName string, ptrForm any, tmpl
|
||||
|
||||
// LinkAccountPostSignIn handle the coupling of external account with another account using signIn
|
||||
func LinkAccountPostSignIn(ctx *context.Context) {
|
||||
signInForm := web.GetForm(ctx).(*forms.SignInForm)
|
||||
signInForm := web.GetForm[*forms.SignInForm](ctx)
|
||||
|
||||
ctx.Data["LinkAccountModeSignIn"] = true
|
||||
|
||||
@@ -176,7 +176,7 @@ func oauth2LinkAccount(ctx *context.Context, u *user_model.User, linkAccountData
|
||||
|
||||
// LinkAccountPostRegister handle the creation of a new account for an external account using signUp
|
||||
func LinkAccountPostRegister(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.RegisterForm)
|
||||
form := web.GetForm[*forms.RegisterForm](ctx)
|
||||
|
||||
ctx.Data["LinkAccountModeRegister"] = true
|
||||
|
||||
@@ -253,7 +253,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
|
||||
ctx.ServerError("GetSourceByID", err)
|
||||
return
|
||||
}
|
||||
source := authSource.Cfg.(*oauth2.Source)
|
||||
source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
if err := syncGroupsToTeams(ctx, source, &linkAccountData.GothUser, u); err != nil {
|
||||
ctx.ServerError("SyncGroupsToTeams", err)
|
||||
return
|
||||
|
||||
@@ -56,13 +56,15 @@ func SignInOAuth(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = authSource.Cfg.(*oauth2.Source).Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
if err = oauth2Source.Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
if strings.Contains(err.Error(), "no provider for ") {
|
||||
if err = oauth2.ResetOAuth2(ctx); err != nil {
|
||||
ctx.ServerError("SignIn", err)
|
||||
return
|
||||
}
|
||||
if err = authSource.Cfg.(*oauth2.Source).Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
if err = oauth2Source.Callout(ctx.Req, ctx.Resp); err != nil {
|
||||
ctx.ServerError("SignIn", err)
|
||||
}
|
||||
return
|
||||
@@ -100,8 +102,7 @@ func SignInOAuthCallback(ctx *context.Context) {
|
||||
|
||||
u, gothUser, err := oAuth2UserLoginCallback(ctx, authSource, ctx.Req, ctx.Resp)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserProhibitLogin(err) {
|
||||
uplerr := err.(user_model.ErrUserProhibitLogin)
|
||||
if uplerr, ok := err.(user_model.ErrUserProhibitLogin); ok {
|
||||
log.Info("Failed authentication attempt for %s from %s: %v", uplerr.Name, ctx.RemoteAddr(), err)
|
||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
||||
@@ -188,7 +189,7 @@ func SignInOAuthCallback(ctx *context.Context) {
|
||||
IsActive: optional.Some(!setting.OAuth2Client.RegisterEmailConfirm && !setting.Service.RegisterManualConfirm),
|
||||
}
|
||||
|
||||
source := authSource.Cfg.(*oauth2.Source)
|
||||
source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
linkAccountData := &LinkAccountData{authSource.ID, gothUser}
|
||||
if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingDisabled {
|
||||
@@ -368,7 +369,8 @@ func handleOAuth2SignIn(ctx *context.Context, authSource *auth.Source, u *user_m
|
||||
}
|
||||
}
|
||||
|
||||
oauth2Source := authSource.Cfg.(*oauth2.Source)
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
groupTeamMapping, err := auth_module.UnmarshalGroupTeamMapping(oauth2Source.GroupTeamMap)
|
||||
if err != nil {
|
||||
ctx.ServerError("UnmarshalGroupTeamMapping", err)
|
||||
@@ -458,7 +460,7 @@ func handleOAuth2SignIn(ctx *context.Context, authSource *auth.Source, u *user_m
|
||||
// OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
|
||||
// login the user
|
||||
func oAuth2UserLoginCallback(ctx *context.Context, authSource *auth.Source, request *http.Request, response http.ResponseWriter) (*user_model.User, goth.User, error) {
|
||||
oauth2Source := authSource.Cfg.(*oauth2.Source)
|
||||
oauth2Source := auth.MustSourceCfg[*oauth2.Source](authSource)
|
||||
|
||||
// Make sure that the response is not an error response.
|
||||
errorName := request.FormValue("error")
|
||||
|
||||
@@ -172,7 +172,7 @@ func IntrospectOAuth(ctx *context.Context) {
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.IntrospectTokenForm)
|
||||
form := web.GetForm[*forms.IntrospectTokenForm](ctx)
|
||||
token, err := oauth2_provider.ParseToken(form.Token, oauth2_provider.DefaultSigningKey)
|
||||
if err != nil {
|
||||
// RFC 7662 returns inactive token metadata for invalid/unknown tokens.
|
||||
@@ -221,7 +221,7 @@ func oauthDoerAuthorizePreCheck(ctx *context.Context, formState string) bool {
|
||||
|
||||
// AuthorizeOAuth manages authorize requests
|
||||
func AuthorizeOAuth(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AuthorizationForm)
|
||||
form := web.GetForm[*forms.AuthorizationForm](ctx)
|
||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||
return
|
||||
}
|
||||
@@ -399,7 +399,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
||||
|
||||
// GrantApplicationOAuth manages the post request submitted when a user grants access to an application
|
||||
func GrantApplicationOAuth(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.GrantApplicationForm)
|
||||
form := web.GetForm[*forms.GrantApplicationForm](ctx)
|
||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||
return
|
||||
}
|
||||
@@ -498,7 +498,7 @@ func OIDCKeys(ctx *context.Context) {
|
||||
|
||||
// AccessTokenOAuth manages all access token requests by the client
|
||||
func AccessTokenOAuth(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.AccessTokenForm)
|
||||
form := *web.GetForm[*forms.AccessTokenForm](ctx)
|
||||
// if there is no ClientID or ClientSecret in the request body, fill these fields by the Authorization header and ensure the provided field matches the Authorization header
|
||||
if form.ClientID == "" || form.ClientSecret == "" {
|
||||
if authHeader := ctx.Req.Header.Get("Authorization"); authHeader != "" {
|
||||
|
||||
@@ -101,7 +101,7 @@ func allowedOpenIDURI(uri string) (err error) {
|
||||
|
||||
// SignInOpenIDPost response for openid sign in request
|
||||
func SignInOpenIDPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.SignInOpenIDForm)
|
||||
form := web.GetForm[*forms.SignInOpenIDForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("sign_in")
|
||||
ctx.Data["PageIsSignIn"] = true
|
||||
ctx.Data["PageIsLoginOpenID"] = true
|
||||
@@ -293,7 +293,7 @@ func ConnectOpenID(ctx *context.Context) {
|
||||
|
||||
// ConnectOpenIDPost handles submission of a form to connect an OpenID URI to an existing account
|
||||
func ConnectOpenIDPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.ConnectOpenIDForm)
|
||||
form := web.GetForm[*forms.ConnectOpenIDForm](ctx)
|
||||
oid := prepareConnectOpenIDPageData(ctx)
|
||||
if oid == "" {
|
||||
return
|
||||
@@ -366,7 +366,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*forms.SignUpOpenIDForm)
|
||||
form := web.GetForm[*forms.SignUpOpenIDForm](ctx)
|
||||
|
||||
if setting.Service.AllowOnlyInternalRegistration {
|
||||
ctx.HTTPError(http.StatusForbidden)
|
||||
|
||||
@@ -265,7 +265,7 @@ func MustChangePassword(ctx *context.Context) {
|
||||
// MustChangePasswordPost response for updating a user's password after their
|
||||
// account was created by an admin
|
||||
func MustChangePasswordPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.MustChangePasswordForm)
|
||||
form := web.GetForm[*forms.MustChangePasswordForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
||||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
|
||||
if ctx.HasError() {
|
||||
|
||||
@@ -31,12 +31,13 @@ func WebAuthn(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// Ensure user is in a 2FA session.
|
||||
if ctx.Session.Get("twofaUid") == nil {
|
||||
idSess, ok := ctx.Session.Get("twofaUid").(int64)
|
||||
if !ok {
|
||||
ctx.ServerError("UserSignIn", errors.New("not in WebAuthn session"))
|
||||
return
|
||||
}
|
||||
|
||||
hasTwoFactor, err := auth.HasTwoFactorByUID(ctx, ctx.Session.Get("twofaUid").(int64))
|
||||
hasTwoFactor, err := auth.HasTwoFactorByUID(ctx, idSess)
|
||||
if err != nil {
|
||||
ctx.ServerError("HasTwoFactorByUID", err)
|
||||
return
|
||||
@@ -265,7 +266,7 @@ func WebAuthnLoginAssertionPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
remember := ctx.Session.Get("twofaRemember").(bool)
|
||||
remember := ctx.Session.Get("twofaRemember").(bool) //nolint:forcetypeassert // must exist
|
||||
handleSignInFull(ctx, user, remember)
|
||||
_ = ctx.Session.Delete("twofaUid")
|
||||
ctx.JSONRedirect(consumeAuthRedirectLink(ctx))
|
||||
|
||||
@@ -522,7 +522,7 @@ func fillViewRunResponseCurrentJob(ctx *context.Context, resp *actions.ViewRespo
|
||||
}
|
||||
}
|
||||
|
||||
req := web.GetForm(ctx).(*actions.ViewRequest)
|
||||
req := web.GetForm[*actions.ViewRequest](ctx)
|
||||
var mockLogOptions []generateMockStepsLogOptions
|
||||
resp.State.CurrentJob.Steps = append(resp.State.CurrentJob.Steps, &actions.ViewJobStep{
|
||||
Summary: "step 0 (mock slow)",
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// Markup render markup document to HTML
|
||||
func Markup(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*api.MarkupOption)
|
||||
form := web.GetForm[*api.MarkupOption](ctx)
|
||||
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
|
||||
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func Create(ctx *context.Context) {
|
||||
|
||||
// CreatePost response for create organization
|
||||
func CreatePost(ctx *context.Context) {
|
||||
form := *web.GetForm(ctx).(*forms.CreateOrgForm)
|
||||
form := *web.GetForm[*forms.CreateOrgForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("new_org")
|
||||
|
||||
if !ctx.Doer.CanCreateOrganization() {
|
||||
@@ -63,13 +63,15 @@ func CreatePost(ctx *context.Context) {
|
||||
|
||||
if err := organization.CreateOrganization(ctx, org, ctx.Doer); err != nil {
|
||||
ctx.Data["Err_OrgName"] = true
|
||||
var errNameReserved db.ErrNameReserved
|
||||
var errNamePatternNotAllowed db.ErrNamePatternNotAllowed
|
||||
switch {
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
|
||||
case db.IsErrNameReserved(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_reserved", err.(db.ErrNameReserved).Name), tplCreateOrg, &form)
|
||||
case db.IsErrNamePatternNotAllowed(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
|
||||
case errors.As(err, &errNameReserved):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_reserved", errNameReserved.Name), tplCreateOrg, &form)
|
||||
case errors.As(err, &errNamePatternNotAllowed):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.name_pattern_not_allowed", errNamePatternNotAllowed.Pattern), tplCreateOrg, &form)
|
||||
case organization.IsErrUserNotAllowedCreateOrg(err):
|
||||
ctx.RenderWithErrDeprecated(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form)
|
||||
default:
|
||||
|
||||
@@ -96,16 +96,15 @@ func DeleteLabel(ctx *context.Context) {
|
||||
|
||||
// InitializeLabels init labels for an organization
|
||||
func InitializeLabels(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
|
||||
form := web.GetForm[*forms.InitializeLabelsForm](ctx)
|
||||
if ctx.HasError() {
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/labels")
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo_module.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
|
||||
if label.IsErrTemplateLoad(err) {
|
||||
originalErr := err.(label.ErrTemplateLoad).OriginalError
|
||||
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
|
||||
if errTemplateLoad, ok := err.(label.ErrTemplateLoad); ok {
|
||||
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, errTemplateLoad.OriginalError))
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func RenderNewProject(ctx *context.Context) {
|
||||
|
||||
// NewProjectPost creates a new project
|
||||
func NewProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
||||
form := web.GetForm[*forms.CreateProjectForm](ctx)
|
||||
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
|
||||
if _, err := shared_user.RenderUserOrgHeader(ctx); err != nil {
|
||||
ctx.ServerError("RenderUserOrgHeader", err)
|
||||
@@ -253,7 +253,7 @@ func RenderEditProject(ctx *context.Context) {
|
||||
|
||||
// EditProjectPost response for editing a project
|
||||
func EditProjectPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateProjectForm)
|
||||
form := web.GetForm[*forms.CreateProjectForm](ctx)
|
||||
projectID := ctx.PathParamInt64("id")
|
||||
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
|
||||
ctx.Data["PageIsEditProjects"] = true
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user