diff --git a/cmd/gitea-cli/cmd/upload.go b/cmd/gitea-cli/cmd/upload.go index 1161d9689b..dfe6bea6d0 100644 --- a/cmd/gitea-cli/cmd/upload.go +++ b/cmd/gitea-cli/cmd/upload.go @@ -368,7 +368,7 @@ func uploadChunks(ctx context.Context, server, token string, session *UploadSess // Start workers for range parallel { wg.Add(1) - go func() { + go func() { //nolint:waitgroup // Using separate error channel for first-error semantics defer wg.Done() for job := range jobs { err := uploadChunk(server, token, session.ID, job.number, job.data) diff --git a/modules/health/health.go b/modules/health/health.go index 888b5dcc2a..2718375701 100644 --- a/modules/health/health.go +++ b/modules/health/health.go @@ -6,6 +6,7 @@ package health import ( "context" + "maps" "runtime" "sync" "time" @@ -107,10 +108,7 @@ func (m *Manager) UnregisterChecker(name string) { // Check performs all health checks func (m *Manager) Check(ctx context.Context, includeSystem bool) *Response { m.mu.RLock() - checkers := make(map[string]Checker) - for k, v := range m.checkers { - checkers[k] = v - } + checkers := maps.Clone(m.checkers) m.mu.RUnlock() response := &Response{ diff --git a/modules/pages/config.go b/modules/pages/config.go index 0c68850805..3c92779fb0 100644 --- a/modules/pages/config.go +++ b/modules/pages/config.go @@ -6,6 +6,7 @@ package pages import ( "crypto/sha256" "encoding/hex" + "slices" "gopkg.in/yaml.v3" ) @@ -253,10 +254,5 @@ func ValidTemplates() []string { // IsValidTemplate checks if a template name is valid func IsValidTemplate(name string) bool { - for _, t := range ValidTemplates() { - if t == name { - return true - } - } - return false + return slices.Contains(ValidTemplates(), name) } diff --git a/modules/webhook/retry.go b/modules/webhook/retry.go index aa11286d2c..981714c44e 100644 --- a/modules/webhook/retry.go +++ b/modules/webhook/retry.go @@ -7,6 +7,7 @@ import ( "context" "math" "math/rand" + "slices" "sync" "time" @@ -278,13 +279,7 @@ func (q *RetryQueue) isRetryable(statusCode int, err error) bool { return true } - for _, code := range q.config.RetryableStatusCodes { - if statusCode == code { - return true - } - } - - return false + return slices.Contains(q.config.RetryableStatusCodes, statusCode) } func (q *RetryQueue) calculateDelay(attemptNumber int) time.Duration { diff --git a/routers/api/v1/org/profile.go b/routers/api/v1/org/profile.go index 542c9d81d9..e2a0c4d911 100644 --- a/routers/api/v1/org/profile.go +++ b/routers/api/v1/org/profile.go @@ -148,32 +148,8 @@ func ListPublicMembersWithRoles(ctx *context.APIContext) { ctx.JSON(http.StatusOK, apiPublicMembers) } -// SetPublicMembership sets the public visibility of a member -func SetPublicMembership(ctx *context.APIContext) { - // swagger:operation PUT /orgs/{org}/public_members/{username} organization orgSetPublicMembership - // --- - // summary: Set public membership visibility for a user - // produces: - // - application/json - // parameters: - // - name: org - // in: path - // description: name of the organization - // type: string - // required: true - // - name: username - // in: path - // description: username of the user - // type: string - // required: true - // responses: - // "204": - // "$ref": "#/responses/empty" - // "403": - // "$ref": "#/responses/forbidden" - // "404": - // "$ref": "#/responses/notFound" - +// setPublicMembershipVisibility is a helper for setting member public visibility +func setPublicMembershipVisibility(ctx *context.APIContext, visible bool) { username := ctx.PathParam("username") // Users can only change their own visibility @@ -211,7 +187,7 @@ func SetPublicMembership(ctx *context.APIContext) { return } - if err := organization.SetMemberPublicVisibility(ctx, ctx.Org.Organization.ID, user.ID, true); err != nil { + if err := organization.SetMemberPublicVisibility(ctx, ctx.Org.Organization.ID, user.ID, visible); err != nil { ctx.APIErrorInternal(err) return } @@ -219,6 +195,35 @@ func SetPublicMembership(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } +// SetPublicMembership sets the public visibility of a member +func SetPublicMembership(ctx *context.APIContext) { + // swagger:operation PUT /orgs/{org}/public_members/{username} organization orgSetPublicMembership + // --- + // summary: Set public membership visibility for a user + // produces: + // - application/json + // parameters: + // - name: org + // in: path + // description: name of the organization + // type: string + // required: true + // - name: username + // in: path + // description: username of the user + // type: string + // required: true + // responses: + // "204": + // "$ref": "#/responses/empty" + // "403": + // "$ref": "#/responses/forbidden" + // "404": + // "$ref": "#/responses/notFound" + + setPublicMembershipVisibility(ctx, true) +} + // RemovePublicMembership removes the public visibility of a member func RemovePublicMembership(ctx *context.APIContext) { // swagger:operation DELETE /orgs/{org}/public_members/{username} organization orgRemovePublicMembership @@ -245,47 +250,5 @@ func RemovePublicMembership(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - username := ctx.PathParam("username") - - // Users can only change their own visibility - if ctx.Doer.Name != username { - isOwner, err := organization.IsOrganizationOwner(ctx, ctx.Org.Organization.ID, ctx.Doer.ID) - if err != nil { - ctx.APIErrorInternal(err) - return - } - if !isOwner { - ctx.APIError(http.StatusForbidden, "You can only change your own public membership visibility") - return - } - } - - // Get the user - user, err := user_model.GetUserByName(ctx, username) - if err != nil { - if user_model.IsErrUserNotExist(err) { - ctx.APIErrorNotFound("GetUserByName", err) - return - } - ctx.APIErrorInternal(err) - return - } - - // Verify user is a member - isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Organization.ID, user.ID) - if err != nil { - ctx.APIErrorInternal(err) - return - } - if !isMember { - ctx.APIErrorNotFound() - return - } - - if err := organization.SetMemberPublicVisibility(ctx, ctx.Org.Organization.ID, user.ID, false); err != nil { - ctx.APIErrorInternal(err) - return - } - - ctx.Status(http.StatusNoContent) + setPublicMembershipVisibility(ctx, false) }