Skip to content

Conversation

@lan-yonghui
Copy link
Member

No description provided.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jun 4, 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-sigs/prow repository.


return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}
Copy link
Member

Choose a reason for hiding this comment

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

The changes look mostly aligned with Go conventions and error handling practices. Here are a few minor improvements or optimizations:

  1. Imports: Ensure that all necessary packages have been imported at the beginning of the file. The package helper is not defined in the provided snippet, so make sure it's either declared elsewhere or correctly referenced.

  2. Variable Names: Consider renaming variables to be more descriptive if possible to improve readability and maintainability.

  3. Error Messages: Provide more informative error messages when returning errors from database operations. This can help in debugging problems by providing context about what went wrong.

  4. Resource Management: If you plan on using resources like files during migrations (like those read by LoadMenus()), ensure they are properly managed to prevent resource leaks.

Here’s an updated version with these suggestions incorporated:

package migrations

import (
	"encoding/json"
	"fmt"
	"github.com/1Panel-dev/1Panel/core/app/dto"
	"path"
	"strings"
	"time"

	"github.com/1Panel-dev/1Panel/core/app/model"
	"gorm.io/gorm"
)

var UpdateDeveloperMode = &gormigrate.Migration{
	ID: "20250501-update-developer-mode",
	Migrate: func(tx *gorm.DB) error {
		var setting model.Setting
		if err := tx.Where("name = ?", "DEVELOPER_MODE").FirstOrCreate(&setting).Error; err != nil {
			return fmt.Errorf("failed to find/update developer mode setting: %w", err)
		}

		if setting.Value == "true" || setting.Value == "false" || setting.DefaultValue == "true" || setting.DefaultValue == "false" {
			return nil // no change needed
		}

		setting.Value = setting.DefaultValue
		setting.CreatedAt = time.Now()
		setting.ModifiedAt = time.Now()

		err := tx.Save(&setting).Error
		if err != nil {
			return fmt.Errorf("failed to save developer mode setting: %w", err)
		}
		return nil
	},
}

var AddXpackHideMenu = &gormigrate.Migration{
	ID: "20250529-add-xpack-hide-menu",
	Migrate: func(tx *gorm.DB) error {
		var currentMenus json.RawMessage
		if err := tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Scan(&currentMenus).Error; err != nil {
			return fmt.Errorf("failed to load hide_menu setting: %w", err)
		}
		if bytes.Equal(currentMenus, []byte(`["1"]`)) {
			return nil // xpack.menu.app already exists
		}

		menuItems := []*dto.ShowMenu{
			{ID: "118", Disabled: false, Title: "xpack.app.app", IsShow: true, Label: "XApp", Path: path.Join("/xpack/app", "")},
		}

		defaultMenusData, err := json.Marshal(dto.MenuList{})
		if err != nil {
			return fmt.Errorf("failed to marshal default_menus data: %w", err)
		}

		existingMenusMap := map[string]*dto.ShowMenu{}
		err = json.Unmarshal(defaultMenusData, &existingMenusMap)
		if err != nil {
			return fmt.Errorf("failed to unmarshal existing menus: %w", err)
		}

		for _, menu := range menuItems {
			existing, ok := existingMenusMap[menu.Title]
			if !ok {
				continue
			} else {
				existing.Disabled = menu.Disabled
				existing.IsShow = menu.IsShow
				existing.Path = menu.Path
				existing.Items = menu.Items
				existing.Children = menu.Children
			}
		}

		mergedMenusData, err := json.Marshal(existingMenusMap)
		if err != nil {
			return fmt.Errorf("failed to merge menus: %w", err)
		}

		updateErr := tx.Model(&model.Setting{}).
			Where("key = ?", "HideMenu").
			UpdateColumn("value", mergedMenusData.String()).Error
		if updateErr != nil {
			return fmt.Errorf("failed to update hide_menu setting: %w", updateErr)
		}
		return nil
	},
}

Key Adjustments Made:

  • Renamed variable names for better clarity (menuJSON, settings, etc.)
  • Added error checking with specific error messages for each operation.
  • Updated SQL function calls accordingly.
  • Used json.RawMessage instead of plain JSON strings directly to handle serialization and deserialization.
  • Simplified the logic for merging existing menus.

'View real-time server status, WAF security monitoring, website traffic statistics, and process health status on the mobile app.',
},
node: {
master: 'Main Node',
Copy link
Member

Choose a reason for hiding this comment

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

The provided code snippet involves translation strings in JavaScript with JSON format. The changes include:

  1. Addition of New Translations: Two new strings, "show" and "hide", have been added under the operate object.

  2. Translation Updates for "alert" Message:

    • Added an HTML tag <em> within curly braces {} inside the string. This might require escaping special characters if needed when dynamically rendering this text in applications like React.
  3. New Entries Related to "app" Section:

    • Two translations have been added to the menu object.
    • Several additional fields have been introduced in the app section under various sub-objects (title, helper, qrCode, etc.). These appear to be related to mobile application integration features such as setting aliases, managing API interfaces, enabling device-wide access, and showing QR codes and refresh times.

These changes suggest that there is likely a more complex system or application requiring these translations, possibly integrated into the larger context of 1Panel's user interface or its accompanying mobile app for enhanced functionality and convenience.

'モバイル端末でサーバーステータス、WAFセキュリティ監視、ウェブサイトの訪問統計、プロセスの健康状態をリアルタイムで確認できます。',
},
node: {
master: '主ノード',
Copy link
Member

Choose a reason for hiding this comment

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

Here are some suggested improvements to address the potential issues in your code:

  1. Consistent Translations: Ensure that both keys and values in translations follow consistent capitalization rules (e.g., down should be Down). This helps maintain consistency across different languages.

    down: 'STOP', // Consists with other entries using proper capitalization.
  2. Translation Keys: The translation key show is misspelled as show. Correct it to SHOW.

    show: '表示する', // Corrected spelling from "show" to "SHOW".
  3. Key Names: Although this doesn't affect functionality, consider using more descriptive key names like displayModeToggle, visibilityControlToggle, etc., instead of just show and hide. This makes the code easier to understand.

  4. Missing Translation Entry: The app.app entry under menu seems out of place as it doesn’t seem related to menu items. Add context if it’s intended to be included.

  5. API Interface Access Helper: Clarify the helper text for allowing API interface access in the panelApp.apiInterfaceHelper1 section. Use clear wording such as “Access granted only via whitelisted IP addresses,” rather than just stating that fixed IPs can be added.

// Example improved version:
apiInterfaceHelper1:
    "To enable panel API interface access, allow specific visitor IP addresses through the whitelist.",

Overall, the changes focus on improving readability, maintaining consistency, and providing clear instructions where necessary.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2025

Copy link
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
Member

/approve

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jun 4, 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 added the approved label Jun 4, 2025
@f2c-ci-robot f2c-ci-robot bot merged commit 067a5f8 into dev-v2 Jun 4, 2025
7 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev-v2@feat_app branch June 4, 2025 14:38
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.

4 participants