From be68eef0df12b12a48cb6b308033eec68c16c6f7 Mon Sep 17 00:00:00 2001 From: The Anh Nguyen Date: Wed, 18 Dec 2024 16:25:59 +0700 Subject: [PATCH] Add comment field to parameters (#7845) * add comment field parameter * add comment into parameter * update Changelog * fix data search value * add comment to Parameter struct * add Comment in test * add Comment test system info * Add show/hide comment field in properties * update migration * chore: update migration files name --- CHANGELOG.md | 1 + lib/go-tc/parameters.go | 4 +++ ...21808014200_add_comment_parameter.down.sql | 18 +++++++++++ ...4121808014200_add_comment_parameter.up.sql | 18 +++++++++++ .../parameter/parameters.go | 32 +++++++++++++------ .../parameter/parameters_test.go | 4 +++ .../systeminfo/system_info_test.go | 5 +++ traffic_portal/.gitignore | 1 + .../form/parameter/form.parameter.tpl.html | 8 +++++ .../parameters/TableParametersController.js | 15 +++++++-- .../parameters/table.parameters.tpl.html | 4 ++- .../app/src/traffic_portal_properties.json | 7 ++++ 12 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql create mode 100644 traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index abdf411652..b03cb10fa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - [#8014](https://github.com/apache/trafficcontrol/pull/8014) *Traffic Ops* Added logs to indicate which mechanism a client used to login to TO. - [#7812](https://github.com/apache/trafficcontrol/pull/7812) *Traffic Portal*: Expose the `configUpdateFailed` and `revalUpdateFailed` fields on the server table. +- [#7845](https://github.com/apache/trafficcontrol/pull/7845) *Traffic Ops, Traffic Portal*: Add `comment` field to parameters - [#7870](https://github.com/apache/trafficcontrol/pull/7870) *Traffic Portal*: Adds a hyperlink to the DSR page to the DS itself for ease of navigation. - [#7896](https://github.com/apache/trafficcontrol/pull/7896) *ATC Build system*: Count commits since the last release, not commits - [#7927](https://github.com/apache/trafficcontrol/pull/7927) *Traffic Stats*: Migrate dynamic scripted Grafana Dashboards to Scenes diff --git a/lib/go-tc/parameters.go b/lib/go-tc/parameters.go index 3abc19e884..ebd887f162 100644 --- a/lib/go-tc/parameters.go +++ b/lib/go-tc/parameters.go @@ -53,6 +53,7 @@ type Parameter struct { Profiles json.RawMessage `json:"profiles" db:"profiles"` Secure bool `json:"secure" db:"secure"` Value string `json:"value" db:"value"` + Comment string `json:"comment" db:"comment"` } // ParameterNullable is exactly like Parameter except that its properties are @@ -68,6 +69,7 @@ type ParameterNullable struct { Profiles json.RawMessage `json:"profiles" db:"profiles"` Secure *bool `json:"secure" db:"secure"` Value *string `json:"value" db:"value"` + Comment *string `json:"comment" db:"comment"` } // ParametersResponseV5 is an alias for the latest minor version for the major version 5. @@ -95,6 +97,7 @@ type ParameterV50 struct { Profiles json.RawMessage `json:"profiles" db:"profiles"` Secure bool `json:"secure" db:"secure"` Value string `json:"value" db:"value"` + Comment string `json:"comment" db:"comment"` } // ParameterNullableV5 is an alias for the latest minor version for the major version 5. @@ -113,6 +116,7 @@ type ParameterNullableV50 struct { Profiles json.RawMessage `json:"profiles" db:"profiles"` Secure *bool `json:"secure" db:"secure"` Value *string `json:"value" db:"value"` + Comment *string `json:"comment" db:"comment"` } // ProfileParameterByName is a structure that's used to represent a Parameter diff --git a/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql new file mode 100644 index 0000000000..fd50f31b40 --- /dev/null +++ b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +ALTER TABLE public.parameter DROP column comment; diff --git a/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql new file mode 100644 index 0000000000..66d28c045a --- /dev/null +++ b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +ALTER TABLE public.parameter ADD COLUMN IF NOT EXISTS comment text; diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters.go b/traffic_ops/traffic_ops_golang/parameter/parameters.go index e447407999..6e3ae88dc5 100644 --- a/traffic_ops/traffic_ops_golang/parameter/parameters.go +++ b/traffic_ops/traffic_ops_golang/parameter/parameters.go @@ -48,6 +48,7 @@ const ( ConfigFileQueryParam = "configFile" IDQueryParam = "id" ValueQueryParam = "value" + CommentQueryParam = "comment" ) var ( @@ -86,6 +87,7 @@ func (v *TOParameter) ParamColumns() map[string]dbhelpers.WhereColumnInfo { NameQueryParam: {Column: "p.name"}, SecureQueryParam: {Column: "p.secure", Checker: api.IsBool}, ValueQueryParam: {Column: "p.value"}, + CommentQueryParam: {Column: "p.comment"}, } } func (v *TOParameter) UpdateQuery() string { return updateQuery() } @@ -216,11 +218,13 @@ func insertQuery() string { name, config_file, value, -secure) VALUES ( +secure, +comment) VALUES ( :name, :config_file, :value, -:secure) RETURNING id,last_updated` +:secure, +:comment) RETURNING id,last_updated` return query } @@ -233,6 +237,7 @@ p.last_updated, p.name, p.value, p.secure, +p.comment, COALESCE(array_to_json(array_agg(pr.name) FILTER (WHERE pr.name IS NOT NULL)), '[]') AS profiles FROM parameter p LEFT JOIN profile_parameter pp ON p.id = pp.parameter @@ -247,14 +252,15 @@ config_file=:config_file, id=:id, name=:name, value=:value, -secure=:secure +secure=:secure, +comment=:comment WHERE id=:id RETURNING last_updated` return query } // ParametersGroupBy ... func ParametersGroupBy() string { - groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name, p.value, p.secure` + groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name, p.value, p.secure, p.comment` return groupBy } @@ -282,6 +288,7 @@ func GetParameters(w http.ResponseWriter, r *http.Request) { NameQueryParam: {Column: "p.name"}, SecureQueryParam: {Column: "p.secure", Checker: api.IsBool}, ValueQueryParam: {Column: "p.value"}, + CommentQueryParam: {Column: "p.comment"}, } if _, ok := inf.Params["orderby"]; !ok { inf.Params["orderby"] = "name" @@ -316,7 +323,7 @@ func GetParameters(w http.ResponseWriter, r *http.Request) { params := tc.ParameterNullableV5{} paramsList := []tc.ParameterNullableV5{} for rows.Next() { - if err = rows.Scan(¶ms.ConfigFile, ¶ms.ID, ¶ms.LastUpdated, ¶ms.Name, ¶ms.Value, ¶ms.Secure, ¶ms.Profiles); err != nil { + if err = rows.Scan(¶ms.ConfigFile, ¶ms.ID, ¶ms.LastUpdated, ¶ms.Name, ¶ms.Value, ¶ms.Secure, ¶ms.Comment, ¶ms.Profiles); err != nil { api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("error getting parameter(s): %w", err)) return } @@ -389,10 +396,11 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) { name, config_file, value, - secure + secure, + comment ) VALUES ( - $1, $2, $3, $4 - ) RETURNING id, name, config_file, value, last_updated, secure + $1, $2, $3, $4, $5 + ) RETURNING id, name, config_file, value, last_updated, secure, comment ` err = tx.QueryRow( query, @@ -400,6 +408,7 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) { parameter.ConfigFile, parameter.Value, parameter.Secure, + parameter.Comment, ).Scan( &objParam.ID, @@ -408,6 +417,7 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) { &objParam.Value, &objParam.LastUpdated, &objParam.Secure, + &objParam.Comment, ) if err != nil { @@ -463,9 +473,10 @@ func UpdateParameter(w http.ResponseWriter, r *http.Request) { config_file = $1, name = $2, value = $3, - secure = $4 + secure = $4, + comment = $5 WHERE - p.id = $5 + p.id = $6 RETURNING p.id, p.last_updated @@ -477,6 +488,7 @@ func UpdateParameter(w http.ResponseWriter, r *http.Request) { parameter.Name, parameter.Value, parameter.Secure, + parameter.Comment, requestedID, ).Scan( ¶meter.ID, diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters_test.go b/traffic_ops/traffic_ops_golang/parameter/parameters_test.go index f806ffdb52..97213df84a 100644 --- a/traffic_ops/traffic_ops_golang/parameter/parameters_test.go +++ b/traffic_ops/traffic_ops_golang/parameter/parameters_test.go @@ -42,6 +42,7 @@ func getTestParameters() []tc.ParameterNullable { ID := 1 param := "paramname1" val := "val1" + cmt := "cmt" testParameter := tc.ParameterNullable{ ConfigFile: &configFile, @@ -51,6 +52,7 @@ func getTestParameters() []tc.ParameterNullable { Profiles: json.RawMessage(`["foo","bar"]`), Secure: &secureFlag, Value: &val, + Comment: &cmt, } parameters = append(parameters, testParameter) @@ -59,6 +61,7 @@ func getTestParameters() []tc.ParameterNullable { testParameter2.Value = &val testParameter2.ConfigFile = &configFile testParameter2.Profiles = json.RawMessage(`["foo","baz"]`) + testParameter2.Comment = &cmt parameters = append(parameters, testParameter2) return parameters @@ -88,6 +91,7 @@ func TestGetParameters(t *testing.T) { ts.Profiles, ts.Secure, ts.Value, + ts.Comment, ) } mock.ExpectBegin() diff --git a/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go b/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go index 658540284e..57e168b3ce 100644 --- a/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go +++ b/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go @@ -53,10 +53,12 @@ func TestGetSystemInfo(t *testing.T) { firstID := 1 firstName := "paramname1" firstVal := "val1" + firstCmt := "cmt1" secondID := 2 secondName := "paramname2" secondVal := "val2" + secondCmt := "cmt2" var sysInfoParameters = []tc.ParameterNullable{ tc.ParameterNullable{ @@ -67,6 +69,7 @@ func TestGetSystemInfo(t *testing.T) { Profiles: json.RawMessage(`["foo","bar"]`), Secure: &secure, Value: &firstVal, + Comment: &firstCmt, }, tc.ParameterNullable{ @@ -77,6 +80,7 @@ func TestGetSystemInfo(t *testing.T) { Profiles: json.RawMessage(`["foo","bar"]`), Secure: &secure, Value: &secondVal, + Comment: &secondCmt, }, } @@ -89,6 +93,7 @@ func TestGetSystemInfo(t *testing.T) { ts.Profiles, ts.Secure, ts.Value, + ts.Comment, ) } diff --git a/traffic_portal/.gitignore b/traffic_portal/.gitignore index b856303de5..d598874725 100644 --- a/traffic_portal/.gitignore +++ b/traffic_portal/.gitignore @@ -18,6 +18,7 @@ .tmp .sass-cache server/log/access.log +pnpm-lock.yaml node_modules app/dist Gemfile.lock diff --git a/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html b/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html index ac0db2b976..a00ef59f07 100644 --- a/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html +++ b/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html @@ -66,6 +66,14 @@ Required +
+ +
+ + Required + +
+