Gerrit: Store full user details in server

This is needed for REST, which never returns user name (only account id,
full name and email)

Change-Id: Ia4e3cca15a80a26b26f5f69edfc83a18e4c1fa1b
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Orgad Shaneh
2017-02-25 22:24:45 +02:00
committed by Orgad Shaneh
parent bae0f1406e
commit 0995cf22ab
6 changed files with 32 additions and 20 deletions

View File

@@ -240,7 +240,7 @@ void GerritDialog::updateRemotes()
while (mapIt.hasNext()) {
mapIt.next();
GerritServer server;
if (!server.fillFromRemote(mapIt.value(), m_parameters->server.user))
if (!server.fillFromRemote(mapIt.value(), m_parameters->server.user.userName))
continue;
// Only Ssh is currently supported. In order to extend support for http[s],
// we need to move this logic to the model, and attempt connection to each

View File

@@ -169,10 +169,10 @@ QString GerritPatchSet::approvalsColumn() const
return result;
}
bool GerritPatchSet::hasApproval(const QString &userName) const
bool GerritPatchSet::hasApproval(const GerritUser &user) const
{
return Utils::contains(approvals, [&userName](const GerritApproval &a) {
return a.reviewer.userName == userName;
return Utils::contains(approvals, [&user](const GerritApproval &a) {
return a.reviewer.isSameAs(user);
});
}
@@ -501,7 +501,7 @@ void GerritModel::refresh(const QSharedPointer<GerritServer> &server, const QStr
QString realQuery = query.trimmed();
if (realQuery.isEmpty()) {
realQuery = "status:open";
const QString user = m_server->user;
const QString user = m_server->user.userName;
if (!user.isEmpty())
realQuery += QString(" (owner:%1 OR reviewer:%1)").arg(user);
}
@@ -693,11 +693,11 @@ QList<QStandardItem *> GerritModel::changeToRow(const GerritChangePtr &c) const
row[ApprovalsColumn]->setText(c->currentPatchSet.approvalsColumn());
// Mark changes awaiting action using a bold font.
bool bold = false;
if (c->owner.userName == m_server->user) { // Owned changes: Review != 0,1. Submit or amend.
if (c->owner.isSameAs(m_server->user)) { // Owned changes: Review != 0,1. Submit or amend.
const int level = c->currentPatchSet.approvalLevel();
bold = level != 0 && level != 1;
} else { // Changes pending for review: No review yet.
bold = !m_server->user.isEmpty() && !c->currentPatchSet.hasApproval(m_server->user);
bold = !c->currentPatchSet.hasApproval(m_server->user);
}
if (bold) {
QFont font = row.first()->font();

View File

@@ -54,7 +54,7 @@ public:
GerritPatchSet() : patchSetNumber(1) {}
QString approvalsToHtml() const;
QString approvalsColumn() const;
bool hasApproval(const QString &userName) const;
bool hasApproval(const GerritUser &user) const;
int approvalLevel() const;
QString ref;

View File

@@ -128,7 +128,7 @@ GerritParameters GerritOptionsWidget::parameters() const
void GerritOptionsWidget::setParameters(const GerritParameters &p)
{
m_hostLineEdit->setText(p.server.host);
m_userLineEdit->setText(p.server.user);
m_userLineEdit->setText(p.server.user.userName);
m_sshChooser->setPath(p.ssh);
m_curlChooser->setPath(p.curl);
m_portSpinBox->setValue(p.server.port);

View File

@@ -77,6 +77,15 @@ static inline QString detectSsh()
return detectApp("ssh");
}
bool GerritUser::isSameAs(const GerritUser &other) const
{
if (!userName.isEmpty() && !other.userName.isEmpty())
return userName == other.userName;
if (!fullName.isEmpty() && !other.fullName.isEmpty())
return fullName == other.fullName;
return false;
}
GerritServer::GerritServer()
: host(defaultHostC)
, port(defaultPort)
@@ -84,18 +93,19 @@ GerritServer::GerritServer()
}
GerritServer::GerritServer(const QString &host, unsigned short port,
const QString &user, HostType type)
const QString &userName, HostType type)
: host(host)
, user(user)
, port(port)
, type(type)
{}
{
user.userName = userName;
}
bool GerritServer::operator==(const GerritServer &other) const
{
if (port && other.port && port != other.port)
return false;
return host == other.host && user == other.user && type == other.type;
return host == other.host && user.isSameAs(other.user) && type == other.type;
}
void GerritParameters::setPortFlagBySshType()
@@ -116,7 +126,7 @@ GerritParameters::GerritParameters()
QString GerritServer::sshHostArgument() const
{
return user.isEmpty() ? host : (user + '@' + host);
return user.userName.isEmpty() ? host : (user.userName + '@' + host);
}
QString GerritServer::url() const
@@ -151,7 +161,7 @@ bool GerritServer::fillFromRemote(const QString &remote, const QString &defaultU
else
return false;
const QString userName = match.captured("user");
user = userName.isEmpty() ? defaultUser : userName;
user.userName = userName.isEmpty() ? defaultUser : userName;
host = match.captured("host");
port = match.captured("port").toUShort();
if (host.contains("github.com")) // Clearly not gerrit
@@ -168,7 +178,7 @@ void GerritParameters::toSettings(QSettings *s) const
{
s->beginGroup(settingsGroupC);
s->setValue(hostKeyC, server.host);
s->setValue(userKeyC, server.user);
s->setValue(userKeyC, server.user.userName);
s->setValue(portKeyC, server.port);
s->setValue(portFlagKeyC, portFlag);
s->setValue(sshKeyC, ssh);
@@ -188,7 +198,7 @@ void GerritParameters::fromSettings(const QSettings *s)
{
const QString rootKey = QLatin1String(settingsGroupC) + '/';
server.host = s->value(rootKey + hostKeyC, defaultHostC).toString();
server.user = s->value(rootKey + userKeyC, QString()).toString();
server.user.userName = s->value(rootKey + userKeyC, QString()).toString();
ssh = s->value(rootKey + sshKeyC, QString()).toString();
curl = s->value(rootKey + curlKeyC).toString();
server.port = s->value(rootKey + portKeyC, QVariant(int(defaultPort))).toInt();
@@ -204,7 +214,7 @@ void GerritParameters::fromSettings(const QSettings *s)
bool GerritParameters::isValid() const
{
return !server.host.isEmpty() && !server.user.isEmpty() && !ssh.isEmpty();
return !server.host.isEmpty() && !server.user.userName.isEmpty() && !ssh.isEmpty();
}
} // namespace Internal

View File

@@ -35,6 +35,8 @@ namespace Internal {
class GerritUser
{
public:
bool isSameAs(const GerritUser &other) const;
QString userName;
QString fullName;
QString email;
@@ -51,14 +53,14 @@ public:
};
GerritServer();
GerritServer(const QString &host, unsigned short port, const QString &user, HostType type);
GerritServer(const QString &host, unsigned short port, const QString &userName, HostType type);
bool operator==(const GerritServer &other) const;
QString sshHostArgument() const;
QString url() const;
bool fillFromRemote(const QString &remote, const QString &defaultUser);
QString host;
QString user;
GerritUser user;
unsigned short port = 0;
HostType type = Ssh;
};