Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit be68eef

Browse files
authored
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
1 parent 6306793 commit be68eef

File tree

12 files changed

+103
-14
lines changed

12 files changed

+103
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
77
### Added
88
- [#8014](https://github.com/apache/trafficcontrol/pull/8014) *Traffic Ops* Added logs to indicate which mechanism a client used to login to TO.
99
- [#7812](https://github.com/apache/trafficcontrol/pull/7812) *Traffic Portal*: Expose the `configUpdateFailed` and `revalUpdateFailed` fields on the server table.
10+
- [#7845](https://github.com/apache/trafficcontrol/pull/7845) *Traffic Ops, Traffic Portal*: Add `comment` field to parameters
1011
- [#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.
1112
- [#7896](https://github.com/apache/trafficcontrol/pull/7896) *ATC Build system*: Count commits since the last release, not commits
1213
- [#7927](https://github.com/apache/trafficcontrol/pull/7927) *Traffic Stats*: Migrate dynamic scripted Grafana Dashboards to Scenes

lib/go-tc/parameters.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Parameter struct {
5353
Profiles json.RawMessage `json:"profiles" db:"profiles"`
5454
Secure bool `json:"secure" db:"secure"`
5555
Value string `json:"value" db:"value"`
56+
Comment string `json:"comment" db:"comment"`
5657
}
5758

5859
// ParameterNullable is exactly like Parameter except that its properties are
@@ -68,6 +69,7 @@ type ParameterNullable struct {
6869
Profiles json.RawMessage `json:"profiles" db:"profiles"`
6970
Secure *bool `json:"secure" db:"secure"`
7071
Value *string `json:"value" db:"value"`
72+
Comment *string `json:"comment" db:"comment"`
7173
}
7274

7375
// ParametersResponseV5 is an alias for the latest minor version for the major version 5.
@@ -95,6 +97,7 @@ type ParameterV50 struct {
9597
Profiles json.RawMessage `json:"profiles" db:"profiles"`
9698
Secure bool `json:"secure" db:"secure"`
9799
Value string `json:"value" db:"value"`
100+
Comment string `json:"comment" db:"comment"`
98101
}
99102

100103
// ParameterNullableV5 is an alias for the latest minor version for the major version 5.
@@ -113,6 +116,7 @@ type ParameterNullableV50 struct {
113116
Profiles json.RawMessage `json:"profiles" db:"profiles"`
114117
Secure *bool `json:"secure" db:"secure"`
115118
Value *string `json:"value" db:"value"`
119+
Comment *string `json:"comment" db:"comment"`
116120
}
117121

118122
// ProfileParameterByName is a structure that's used to represent a Parameter
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
18+
ALTER TABLE public.parameter DROP column comment;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
18+
ALTER TABLE public.parameter ADD COLUMN IF NOT EXISTS comment text;

traffic_ops/traffic_ops_golang/parameter/parameters.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
ConfigFileQueryParam = "configFile"
4949
IDQueryParam = "id"
5050
ValueQueryParam = "value"
51+
CommentQueryParam = "comment"
5152
)
5253

5354
var (
@@ -86,6 +87,7 @@ func (v *TOParameter) ParamColumns() map[string]dbhelpers.WhereColumnInfo {
8687
NameQueryParam: {Column: "p.name"},
8788
SecureQueryParam: {Column: "p.secure", Checker: api.IsBool},
8889
ValueQueryParam: {Column: "p.value"},
90+
CommentQueryParam: {Column: "p.comment"},
8991
}
9092
}
9193
func (v *TOParameter) UpdateQuery() string { return updateQuery() }
@@ -216,11 +218,13 @@ func insertQuery() string {
216218
name,
217219
config_file,
218220
value,
219-
secure) VALUES (
221+
secure,
222+
comment) VALUES (
220223
:name,
221224
:config_file,
222225
:value,
223-
:secure) RETURNING id,last_updated`
226+
:secure,
227+
:comment) RETURNING id,last_updated`
224228
return query
225229
}
226230

@@ -233,6 +237,7 @@ p.last_updated,
233237
p.name,
234238
p.value,
235239
p.secure,
240+
p.comment,
236241
COALESCE(array_to_json(array_agg(pr.name) FILTER (WHERE pr.name IS NOT NULL)), '[]') AS profiles
237242
FROM parameter p
238243
LEFT JOIN profile_parameter pp ON p.id = pp.parameter
@@ -247,14 +252,15 @@ config_file=:config_file,
247252
id=:id,
248253
name=:name,
249254
value=:value,
250-
secure=:secure
255+
secure=:secure,
256+
comment=:comment
251257
WHERE id=:id RETURNING last_updated`
252258
return query
253259
}
254260

255261
// ParametersGroupBy ...
256262
func ParametersGroupBy() string {
257-
groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name, p.value, p.secure`
263+
groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name, p.value, p.secure, p.comment`
258264
return groupBy
259265
}
260266

@@ -282,6 +288,7 @@ func GetParameters(w http.ResponseWriter, r *http.Request) {
282288
NameQueryParam: {Column: "p.name"},
283289
SecureQueryParam: {Column: "p.secure", Checker: api.IsBool},
284290
ValueQueryParam: {Column: "p.value"},
291+
CommentQueryParam: {Column: "p.comment"},
285292
}
286293
if _, ok := inf.Params["orderby"]; !ok {
287294
inf.Params["orderby"] = "name"
@@ -316,7 +323,7 @@ func GetParameters(w http.ResponseWriter, r *http.Request) {
316323
params := tc.ParameterNullableV5{}
317324
paramsList := []tc.ParameterNullableV5{}
318325
for rows.Next() {
319-
if err = rows.Scan(&params.ConfigFile, &params.ID, &params.LastUpdated, &params.Name, &params.Value, &params.Secure, &params.Profiles); err != nil {
326+
if err = rows.Scan(&params.ConfigFile, &params.ID, &params.LastUpdated, &params.Name, &params.Value, &params.Secure, &params.Comment, &params.Profiles); err != nil {
320327
api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("error getting parameter(s): %w", err))
321328
return
322329
}
@@ -389,17 +396,19 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) {
389396
name,
390397
config_file,
391398
value,
392-
secure
399+
secure,
400+
comment
393401
) VALUES (
394-
$1, $2, $3, $4
395-
) RETURNING id, name, config_file, value, last_updated, secure
402+
$1, $2, $3, $4, $5
403+
) RETURNING id, name, config_file, value, last_updated, secure, comment
396404
`
397405
err = tx.QueryRow(
398406
query,
399407
parameter.Name,
400408
parameter.ConfigFile,
401409
parameter.Value,
402410
parameter.Secure,
411+
parameter.Comment,
403412
).Scan(
404413

405414
&objParam.ID,
@@ -408,6 +417,7 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) {
408417
&objParam.Value,
409418
&objParam.LastUpdated,
410419
&objParam.Secure,
420+
&objParam.Comment,
411421
)
412422

413423
if err != nil {
@@ -463,9 +473,10 @@ func UpdateParameter(w http.ResponseWriter, r *http.Request) {
463473
config_file = $1,
464474
name = $2,
465475
value = $3,
466-
secure = $4
476+
secure = $4,
477+
comment = $5
467478
WHERE
468-
p.id = $5
479+
p.id = $6
469480
RETURNING
470481
p.id,
471482
p.last_updated
@@ -477,6 +488,7 @@ func UpdateParameter(w http.ResponseWriter, r *http.Request) {
477488
parameter.Name,
478489
parameter.Value,
479490
parameter.Secure,
491+
parameter.Comment,
480492
requestedID,
481493
).Scan(
482494
&parameter.ID,

traffic_ops/traffic_ops_golang/parameter/parameters_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func getTestParameters() []tc.ParameterNullable {
4242
ID := 1
4343
param := "paramname1"
4444
val := "val1"
45+
cmt := "cmt"
4546

4647
testParameter := tc.ParameterNullable{
4748
ConfigFile: &configFile,
@@ -51,6 +52,7 @@ func getTestParameters() []tc.ParameterNullable {
5152
Profiles: json.RawMessage(`["foo","bar"]`),
5253
Secure: &secureFlag,
5354
Value: &val,
55+
Comment: &cmt,
5456
}
5557
parameters = append(parameters, testParameter)
5658

@@ -59,6 +61,7 @@ func getTestParameters() []tc.ParameterNullable {
5961
testParameter2.Value = &val
6062
testParameter2.ConfigFile = &configFile
6163
testParameter2.Profiles = json.RawMessage(`["foo","baz"]`)
64+
testParameter2.Comment = &cmt
6265
parameters = append(parameters, testParameter2)
6366

6467
return parameters
@@ -88,6 +91,7 @@ func TestGetParameters(t *testing.T) {
8891
ts.Profiles,
8992
ts.Secure,
9093
ts.Value,
94+
ts.Comment,
9195
)
9296
}
9397
mock.ExpectBegin()

traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ func TestGetSystemInfo(t *testing.T) {
5353
firstID := 1
5454
firstName := "paramname1"
5555
firstVal := "val1"
56+
firstCmt := "cmt1"
5657

5758
secondID := 2
5859
secondName := "paramname2"
5960
secondVal := "val2"
61+
secondCmt := "cmt2"
6062

6163
var sysInfoParameters = []tc.ParameterNullable{
6264
tc.ParameterNullable{
@@ -67,6 +69,7 @@ func TestGetSystemInfo(t *testing.T) {
6769
Profiles: json.RawMessage(`["foo","bar"]`),
6870
Secure: &secure,
6971
Value: &firstVal,
72+
Comment: &firstCmt,
7073
},
7174

7275
tc.ParameterNullable{
@@ -77,6 +80,7 @@ func TestGetSystemInfo(t *testing.T) {
7780
Profiles: json.RawMessage(`["foo","bar"]`),
7881
Secure: &secure,
7982
Value: &secondVal,
83+
Comment: &secondCmt,
8084
},
8185
}
8286

@@ -89,6 +93,7 @@ func TestGetSystemInfo(t *testing.T) {
8993
ts.Profiles,
9094
ts.Secure,
9195
ts.Value,
96+
ts.Comment,
9297
)
9398
}
9499

traffic_portal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
.tmp
1919
.sass-cache
2020
server/log/access.log
21+
pnpm-lock.yaml
2122
node_modules
2223
app/dist
2324
Gemfile.lock

traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
<small class="input-error" ng-show="hasPropertyError(parameterForm.secure, 'required')">Required</small>
6767
</div>
6868
</div>
69+
<div class="form-group" ng-class="{'has-error': hasError(parameterForm.comment), 'has-feedback': hasError(parameterForm.comment)}">
70+
<label class="control-label col-md-2 col-sm-2 col-xs-12">Comment</label>
71+
<div class="col-md-10 col-sm-10 col-xs-12">
72+
<textarea name="value" type="text" class="form-control" ng-model="parameter.comment" rows="10" autofocus></textarea>
73+
<small class="input-error" ng-show="hasPropertyError(parameterForm.comment, 'required')">Required</small>
74+
<span ng-show="hasError(parameterForm.comment)" class="form-control-feedback"><i class="fa fa-times"></i></span>
75+
</div>
76+
</div>
6977
<div class="modal-footer">
7078
<button type="button" class="btn btn-danger" ng-show="!settings.isNew" ng-click="confirmDelete(parameter)">Delete</button>
7179
<button type="button" class="btn btn-success" ng-disabled="parameterForm.$pristine || parameterForm.$invalid" ng-click="confirmSave(parameter)">{{settings.saveLabel}}</button>

traffic_portal/app/src/common/modules/table/parameters/TableParametersController.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
* @param {import("../../../api/ParameterService")} parameterService
2828
* @param {import("../../../api/ProfileService")} profileService
2929
* @param {import("../../../models/MessageModel")} messageModel
30+
* @param {import("../../../models/PropertiesModel")} propertiesModel
3031
*/
31-
var TableParametersController = function(parameters, $scope, $state, $uibModal, $window, locationUtils, parameterService, profileService, messageModel) {
32+
var TableParametersController = function(parameters, $scope, $state, $uibModal, $window, locationUtils, parameterService, profileService, messageModel, propertiesModel) {
3233

3334
let parametersTable;
3435

@@ -96,7 +97,8 @@ var TableParametersController = function(parameters, $scope, $state, $uibModal,
9697
{ "name": "Config File", "visible": true, "searchable": true },
9798
{ "name": "Value", "visible": true, "searchable": true },
9899
{ "name": "Secure", "visible": true, "searchable": true },
99-
{ "name": "Profiles", "visible": true, "searchable": true }
100+
{ "name": "Profiles", "visible": true, "searchable": true },
101+
{ "name": "Comment", "visible": true, "searchable": true }
100102
];
101103

102104
$scope.contextMenuItems = [
@@ -153,6 +155,13 @@ var TableParametersController = function(parameters, $scope, $state, $uibModal,
153155
return true;
154156
};
155157

158+
$scope.show = function (colName) {
159+
if (colName === "Comment") {
160+
return propertiesModel.properties.parameters.comment.show;
161+
}
162+
return true;
163+
}
164+
156165
angular.element(document).ready(function () {
157166
parametersTable = $('#parametersTable').DataTable({
158167
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
@@ -175,5 +184,5 @@ var TableParametersController = function(parameters, $scope, $state, $uibModal,
175184

176185
};
177186

178-
TableParametersController.$inject = ['parameters', '$scope', '$state', '$uibModal', '$window', 'locationUtils', 'parameterService', 'profileService', 'messageModel'];
187+
TableParametersController.$inject = ['parameters', '$scope', '$state', '$uibModal', '$window', 'locationUtils', 'parameterService', 'profileService', 'messageModel', 'propertiesModel'];
179188
module.exports = TableParametersController;

0 commit comments

Comments
 (0)