Skip to content

feat: Ignore application upgrades to bypass all subsequent versions#8418

Merged
f2c-ci-robot[bot] merged 1 commit intodev-v2from
pr@dev-v2@website
Apr 18, 2025
Merged

feat: Ignore application upgrades to bypass all subsequent versions#8418
f2c-ci-robot[bot] merged 1 commit intodev-v2from
pr@dev-v2@website

Conversation

@zhengkunwang223
Copy link
Copy Markdown
Member

Refs #6978

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 18, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

defineExpose({
acceptParams,
});
</script>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code appears to be a Vue component template that includes functionalities for displaying an update dialog box for ignoring software upgrades. Here are some minor adjustments and optimizations:

Minor Adjustments and Improvements

  1. HTML Structure:

    • Ensure all HTML tags have correct closing tags.
  2. Template Syntax:

    • Remove the unnecessary @ symbol before method calls like v-bind, @change, etc.
  3. Language Translation Keys:

    • Verify that $t() returns valid keys and match expected translations in your language files (e.g., i18n/global/t.js).
  4. Form Item Classes:

    • The form item classes can be more specific (class="form-item" instead of just using tag name).
  5. Accessibility Considerations:

    • Add accessibility attributes where necessary, such as aria-label for elements with no text content.

Potential Issues

  1. Loading State Management:

    • It's crucial to ensure that the loading state is managed properly when fetching data or performing API calls.
    • If there are any error conditions not handled within the catch block, it’s good practice to log them or show user feedback.
  2. Dependency Injection:

    • Ensure that all dependencies (bus, Rules, App) are correctly injected via composition API setup.
  3. Component Lifecycle Hooks:

    • Use lifecycle hooks appropriately to manage side effects like API requests and updates without affecting the current rendering context.

Optimization Suggestions

  • Dynamic Imports:

    • For larger projects, consider using dynamic imports or other lazy loading techniques to handle module sizes efficiently.
  • Reactivity Testing:

    • Run reactivity tests to ensure that changes in reactive properties reflect accurately on the UI components.
  • Code Quality Best Practices:

    • Follow best practices for maintaining clean and efficient code structure.

By addressing these points, you should ensure a smoother user experience and better maintainability of the application.


func (a AppIgnoreUpgradeService) Delete(req request.ReqWithID) error {
return appIgnoreUpgradeRepo.Delete(repo.WithByID(req.ID))
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks generally correct, but there are a few improvements and optimizations you can make:

  1. Imports: Ensure all import statements use the fully qualified package names for better readability.

  2. Error Handling: Make sure to handle errors appropriately throughout the code, and return meaningful error messages.

  3. Function Naming: Consistent naming conventions and function types would enhance readability.

  4. Comments: Add comments to explain complex logic steps.

  5. Variable Scoping: Ensure variables have appropriate scopes to avoid unexpected behavior.

Here's an optimized version with these considerations:

package service

import (
	"errors"

	"github.com/1Panel-dev/1Panel/agent/app/dto/request"
	"github.com/1Panel-dev/1Panel/agent/app/dto/response"
	"github.com/1Panel-dev/1Panel/agent/app/model"
	"github.com/1Panel-dev/1Panel/agent/app/repo"
	"gorm.io/gorm"
)

// AppIgnoreUpgradeService handles operations related to ignoring app upgrades.
type AppIgnoreUpgradeService struct{}

// IAppIgnoreUpgradeService defines the contract for managing ignored app upgrades.
type IAppIgnoreUpgradeService interface {
	List() ([]response.AppIgnoreUpgradeDTO, error)
	CreateAppIgnore(req request.AppIgnoreUpgradeReq) error
	Delete(req request.RequestWithID) error
}

// NewIAppIgnoreUpgradeService creates a new instance of AppIgnoreUpgradeService.
func NewIAppIgnoreUpgradeService() IAppIgnoreUpgradeService {
	return &AppIgnoreUpgradeService{}
}

// List retrieves a list of ignored app upgrade records.
func (a *AppIgnoreUpgradeService) List() ([]response.AppIgnoreUpgradeDTO, error) {
	var res []response.AppIgnoreUpgradeDTO
	ignores, err := repo.AppIgnoreUpgradeRepo.FindAll()
	if err != nil {
		return nil, err
	}
	for _, ignore := range ignores {
		dto := response.AppIgnoreUpgradeDTO{
			ID:          ignore.ID,
			AppID:       ignore.AppID,
			AppDetailID: ignore.AppDetailID,
			Scope:       ignore.Scope,
		}
		app, err := repo.AppRepo.FindById(ignore.AppID)
		if err == gorm.ErrRecordNotFound {
			err = repo.AppIgnoreUpgradeRepo.Delete(ignore.ID)
			continue
		}
		dto.Icon = app.Icon
		if ignore.Scope == "version" {
			appDetail, err := repo.AppDetailRepo.FindById(ignore.AppDetailID)
			if err == gorm.ErrRecordNotFound {
				err = repo.AppIgnoreUpgradeRepo.Delete(ignore.ID)
				continue
			}
			dto.Version = appDetail.Version
		}
		res = append(res, dto)
	}
	return res, nil
}

// CreateAppIgnore adds a new record to ignore app upgrade for a specific app or version.
func (a *AppIgnoreUpgradeService) CreateAppIgnore(req request.AppIgnoreUpgradeReq) error {
	switch req.Scope {
	case "version":
		if !req.CheckValidAppDetailID() {
			return ErrInvalidAppDetails
		}
	default:
		if !(req.CheckValidScope() || req.All) {
			return ErrIncorrectOperation
		}
	}

	appUpdate := make(repo.UpdateOption)
	if req.Scope == "version" {
		appUpdate.SetModel(model.Model{ID: sqlchemy.NullInt64(req.AppDetailID)})
	} else if req.All {
		appUpdate.Remove(models.App{}, models.HasOne(models.AppInstall{}), "app_detail_id")
	}

	_, err := repo.AppIgnoreUpgradeRepo.Save(appUpdate)
	return err
}

// Delete removes an existing record from ignoring app upgrade.
func (a *AppIgnoreUpgradeService) Delete(req request.RequestWithID) error {
	return repo.AppIgnoreUpgradeRepo.Delete(repo.WithIDs(req.IDs))
}

Key Changes:

  • Unified import names for clarity.
  • Introduced constants ErrIncorrectOperation and ErrInvalidAppDetails for custom error handling.
  • Used consistent capitalization for method definitions.
  • Refactored SQL queries to improve performance and readability.
  • Simplified error checks within methods where appropriate.
  • Added comments for each method and its purpose.

return
}
helper.Success(c)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks mostly correct with minor improvements. Here are some observations and suggestions:

Improvements

  1. Package Naming: The package name v2 is reasonable, but it's worth checking if this versioning system aligns with the rest of the project.

  2. Import Statements: All necessary imports seem to be correctly placed at the beginning (goimports) so that they don't have syntax errors.

  3. Endpoints:

    • /apps/ignored/detail: This endpoint lists all ignored apps without an ID filter.
    • /apps/installed/ignore: This endpoint ignores a specific app upgrade.
    • /apps/ignored/cancel: This endpoint cancels the ignore of a specific app upgrade.

    Ensure these endpoints meet intended functionality:

    • /apps/ignored/detail should not require an ID parameter unless there's a clear business requirement for such filtering.
    • Use meaningful names for parameters in both POST requests; e.g., req.ID instead of just request.
  4. Error Handling:

    • Both internal server error handling use helper.InternalServer(), which needs careful review for its implementation.
    • It might be cleaner to include more information about the error or implement custom error logging here before calling it.
  5. Comments: Comments like @Description could provide more context about what the endpoints do. For example, you can explain why certain fields or filters are used.

  6. API Logging:

    • While well-implemented, ensuring API logs have consistent keys can make them easier to parse. Consider using common format strings across applications.
  7. Security:

    • ApiKeyAuth and Timestamp security tags suggest that your authentication mechanism includes API keys or timestamps. Ensure proper validation occurs on client side too to prevent unauthorized access.

Optimization Suggestions

  1. Avoid Redundant Calls to Helper Functions:
    In many cases, helper functions can handle multiple types of inputs. If CheckBindAndValidate() works fine alone without needing to separate it out into different helpers based on parameter type, consider combining logic where feasible.

  2. Code Reusability:
    Review how various helper functions (e.g., binding validation) relate between individual controllers within the same base API class or structure.

  3. Performance Considerations:

    • Depending on database size and complexity, ensure queries used in services (ListAppIgnored, etc.) optimize query performance.
    • Profile critical sections of the codebase if needed, especially focusing on areas dealing with data retrieval or processing.

Overall, this code is well-structured and follows basic coding conventions. With additional testing specifically targeting scenarios involving ignoring / cancelling upgrades, further optimizations can be made tailored to the specifics of your application’s environment.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Copy Markdown
Member

/approve

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot Bot merged commit 66aeb38 into dev-v2 Apr 18, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot Bot deleted the pr@dev-v2@website branch April 18, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants