This is an automated email from the ASF dual-hosted git repository.

shamrick pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new e24fcb619e Fix shared usernames display while retrieving CDN locks 
(#7231)
e24fcb619e is described below

commit e24fcb619ebada5333675b7871eeef79e48d10a9
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Thu Dec 8 09:58:45 2022 -0700

    Fix shared usernames display while retrieving CDN locks (#7231)
    
    * Fix shared usernames display while retrieving CDN locks
    
    * Adding changelog
---
 CHANGELOG.md                                               |  1 +
 traffic_ops/traffic_ops_golang/cdn_lock/cdn_lock.go        | 11 +++++------
 traffic_portal/app/src/common/modules/locks/locks.tpl.html |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3dd5d1675d..782a32c4e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#4654](https://github.com/apache/trafficcontrol/pull/4654) *Traffic Ops, 
Traffic Portal* Switched Delivery Service active state to a three-value system, 
adding a state that will be used to prevent cache servers from deploying DS 
configuration.
 
 ### Fixed
+- [#7231](https://github.com/apache/trafficcontrol/pull/7231) *Traffic Ops, 
Traffic Portal* Fixed `sharedUserNames` display while retrieving CDN locks.
 - [#7216](https://github.com/apache/trafficcontrol/pull/7216) *Traffic Portal* 
Fixed sort for Server's Capabilities Table
 - [#4428](https://github.com/apache/trafficcontrol/issues/4428) *Traffic Ops* 
Fixed Internal Server Error with POST to `profileparameters` when POST body is 
empty
 - [#7179](https://github.com/apache/trafficcontrol/issues/7179) *Traffic 
Portal* Fixed search filter for Delivery Service Table
diff --git a/traffic_ops/traffic_ops_golang/cdn_lock/cdn_lock.go 
b/traffic_ops/traffic_ops_golang/cdn_lock/cdn_lock.go
index a2d3220299..3e58b2ba9d 100644
--- a/traffic_ops/traffic_ops_golang/cdn_lock/cdn_lock.go
+++ b/traffic_ops/traffic_ops_golang/cdn_lock/cdn_lock.go
@@ -36,8 +36,7 @@ import (
        "github.com/lib/pq"
 )
 
-const readQuery = `SELECT username, cdn, message, soft, (select 
array_agg(u.username) AS shared_usernames from cdn_lock_user u join cdn_lock c 
on c.username = u.owner and c.cdn = u.cdn), last_updated FROM cdn_lock`
-
+const readQuery = `SELECT c.username, c.cdn, c.message, c.soft, 
c.last_updated, ARRAY_REMOVE(ARRAY_AGG(DISTINCT(u.username)), null) AS 
shared_usernames FROM cdn_lock_user u FULL JOIN cdn_lock c ON c.username = 
u.owner AND c.cdn = u.cdn`
 const insertQueryWithoutSharedUserNames = `INSERT INTO cdn_lock (username, 
cdn, message, soft) VALUES ($1, $2, $3, $4) RETURNING username, cdn, message, 
soft, last_updated`
 
 const insertQueryWithSharedUserNames = `WITH first_insert AS (
@@ -77,8 +76,8 @@ func Read(w http.ResponseWriter, r *http.Request) {
        defer inf.Close()
 
        cols := map[string]dbhelpers.WhereColumnInfo{
-               "cdn":      {Column: "cdn_lock.cdn", Checker: nil},
-               "username": {Column: "cdn_lock.username", Checker: nil},
+               "cdn":      {Column: "c.cdn", Checker: nil},
+               "username": {Column: "c.username", Checker: nil},
        }
 
        where, orderBy, pagination, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, cols)
@@ -90,7 +89,7 @@ func Read(w http.ResponseWriter, r *http.Request) {
        }
 
        cdnLock := []tc.CDNLock{}
-       query := readQuery + where + orderBy + pagination
+       query := readQuery + where + orderBy + pagination + " GROUP BY c.cdn"
        rows, err := inf.Tx.NamedQuery(query, queryValues)
        if err != nil {
                api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, 
errors.New("querying cdn locks: "+err.Error()))
@@ -100,7 +99,7 @@ func Read(w http.ResponseWriter, r *http.Request) {
 
        for rows.Next() {
                var cLock tc.CDNLock
-               if err = rows.Scan(&cLock.UserName, &cLock.CDN, &cLock.Message, 
&cLock.Soft, pq.Array(&cLock.SharedUserNames), &cLock.LastUpdated); err != nil {
+               if err = rows.Scan(&cLock.UserName, &cLock.CDN, &cLock.Message, 
&cLock.Soft, &cLock.LastUpdated, pq.Array(&cLock.SharedUserNames)); err != nil {
                        api.HandleErr(w, r, tx, http.StatusInternalServerError, 
nil, errors.New("scanning cdn locks: "+err.Error()))
                        return
                }
diff --git a/traffic_portal/app/src/common/modules/locks/locks.tpl.html 
b/traffic_portal/app/src/common/modules/locks/locks.tpl.html
index 8a1341f457..0917c392f3 100644
--- a/traffic_portal/app/src/common/modules/locks/locks.tpl.html
+++ b/traffic_portal/app/src/common/modules/locks/locks.tpl.html
@@ -18,6 +18,6 @@ under the License.
 <div id="locksContainer">
     <div class="alert alert-dark" ng-repeat="l in locks">
         <button type="button" class="close" title="Unlock {{l.cdn}}" 
ng-click="confirmUnlock(l)"><i class="fa fa-unlock"></i></button>
-        <div ng-bind-html="l.cdn + ' is ' + ((l.soft) ? 'soft' : 'hard') + ' 
locked by ' + l.userName + ' (' + l.message + ')' + ' and shared by ' + 
((l.sharedUserNames) ? l.sharedUserNames : 'no one else') | 
linky:'_blank'"></div>
+        <div ng-bind-html="l.cdn + ' is ' + ((l.soft) ? 'soft' : 'hard') + ' 
locked by ' + l.userName + ' (' + l.message + ')' + ' and shared by ' + 
((l.sharedUserNames && (l.sharedUserNames).length != 0) ? l.sharedUserNames : 
'no one else') | linky:'_blank'"></div>
     </div>
 </div>

Reply via email to