Fix blank audit log names

The GWT UI fell back to displaying email addresses (everything before
the @) if a user did not have a name or username.

This change adds the same fallback to PolyGerrit.

Bug: Issue 7989
Change-Id: Ieff1cc6a0faf9ecb1aafebf91d86f91ab89582f1
This commit is contained in:
Becky Siegel
2017-12-20 17:19:51 -08:00
parent 670b3d6ed7
commit d8e1b270b5
2 changed files with 32 additions and 15 deletions

View File

@@ -83,11 +83,7 @@
_getNameForUser(account) {
const accountId = account._account_id ? ' (' +
account._account_id + ')' : '';
if (account && account.username) {
return account.username + accountId;
} else if (account && account.name) {
return account.name + accountId;
}
return this._getNameForMember(account) + accountId;
},
_getNameForMember(account) {
@@ -95,6 +91,8 @@
return account.name;
} else if (account && account.username) {
return account.username;
} else if (account && account.email) {
return account.email.split('@')[0];
}
},
});

View File

@@ -47,8 +47,8 @@ limitations under the License.
_account_id: 12,
},
};
assert.deepEqual(
element._getNameForMember(account.member, false), 'test-user');
assert.equal(element._getNameForMember(account.member, false),
'test-user');
account = {
member: {
@@ -56,8 +56,14 @@ limitations under the License.
_account_id: 12,
},
};
assert.deepEqual(
element._getNameForMember(account.member), 'test-name');
assert.equal(element._getNameForMember(account.member), 'test-name');
account = {
user: {
email: 'test-email@gmail.com',
},
};
assert.equal(element._getNameForMember(account.user), 'test-email');
});
});
@@ -69,8 +75,7 @@ limitations under the License.
_account_id: 12,
},
};
assert.deepEqual(
element._getNameForUser(account.user), 'test-user (12)');
assert.equal(element._getNameForUser(account.user), 'test-user (12)');
account = {
user: {
@@ -78,8 +83,15 @@ limitations under the License.
_account_id: 12,
},
};
assert.deepEqual(
element._getNameForUser(account.user), 'test-name (12)');
assert.equal(element._getNameForUser(account.user), 'test-name (12)');
account = {
user: {
email: 'test-email@gmail.com',
_account_id: 12,
},
};
assert.equal(element._getNameForUser(account.user), 'test-email (12)');
});
test('test _account_id not present', () => {
@@ -88,14 +100,21 @@ limitations under the License.
username: 'test-user',
},
};
assert.deepEqual(element._getNameForUser(account.user), 'test-user');
assert.equal(element._getNameForUser(account.user), 'test-user');
account = {
user: {
name: 'test-name',
},
};
assert.deepEqual(element._getNameForUser(account.user), 'test-name');
assert.equal(element._getNameForUser(account.user), 'test-name');
account = {
user: {
email: 'test-email@gmail.com',
},
};
assert.equal(element._getNameForUser(account.user), 'test-email');
});
});
});