Make PgAuthId inherit PgServerObject and related changes.

This commit is contained in:
eelke 2018-12-25 16:39:58 +01:00
parent c2c01cf431
commit 0b6c1a8544
8 changed files with 33 additions and 16 deletions

View file

@ -115,7 +115,7 @@ QVariant RolesTableModel::getData(const QModelIndex &index) const
const PgAuthId &authid = m_roles->getByIdx(index.row());
switch (index.column()) {
case NameCol:
v = authid.name;
v = authid.objectName();
break;
case SuperCol:
// todo lookup role name

View file

@ -4,6 +4,11 @@
#include "Pgsql_declare.h"
#include <QString>
/**
* @brief The PgAm class
*
* AM = Access Method, for indexes
*/
class PgAm {
public:
Oid oid;

View file

@ -1,3 +1,6 @@
#include "PgAuthId.h"
PgAuthId::PgAuthId() = default;
QString PgAuthId::typeName() const
{
return "ROLE";
}

View file

@ -1,16 +1,19 @@
#ifndef PGAUTHID_H
#define PGAUTHID_H
#include "PgServerObject.h"
#include <libpq-fe.h>
#include <QString>
#include <QDateTime>
class PgAuthId {
/**
* @brief The PgAuthId class
*
* An AuthId is a database role
*/
class PgAuthId: public PgServerObject {
public:
PgAuthId();
Oid oid = InvalidOid;
QString name;
bool super;
bool inherit;
bool createRole;
@ -21,12 +24,9 @@ public:
int connLimit;
QDateTime validUntil;
bool valid() const { return oid != InvalidOid; }
using PgServerObject::PgServerObject;
QString typeName() const override;
bool operator==(Oid _oid) const { return oid == _oid; }
bool operator==(const QString &n) const { return name == n; }
bool operator<(Oid _oid) const { return oid < _oid; }
bool operator<(const PgAuthId &rhs) const { return oid < rhs.oid; }
};
#endif // PGAUTHID_H

View file

@ -17,8 +17,10 @@ std::string PgAuthIdContainer::getLoadQuery() const
PgAuthId PgAuthIdContainer::loadElem(const Pgsql::Row &row)
{
Pgsql::Col col(row);
PgAuthId v;
col >> v.oid >> v.name >> v.super >> v.inherit >> v.createRole >> v.createDB
Oid oid = col.nextValue();
QString name = col.nextValue();
PgAuthId v(m_catalog, oid, name);
col >> v.super >> v.inherit >> v.createRole >> v.createDB
>> v.canlogin >> v.replication >> v.connLimit >> v.validUntil;
if (minimumVersion(90500))
col >> v.bypassRls;

View file

@ -32,7 +32,7 @@ QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid)
if (auth_ids) {
const PgAuthId* auth_id = auth_ids->getByKey(oid);
if (auth_id) {
name = auth_id->name;
name = auth_id->objectName();
}
}
return name;

View file

@ -17,9 +17,14 @@ Oid PgServerObject::ownerOid() const
return m_ownerOid;
}
bool PgServerObject::hasOwner() const
{
return m_ownerOid != InvalidOid;
}
QString PgServerObject::ownerName() const
{
return m_owner->name;
return m_owner->objectName();
}
const PgAuthId* PgServerObject::owner() const
@ -76,6 +81,7 @@ QString PgServerObject::grantSql() const
// PUBLIC, no priviliges
grant += PgAcl("=").sql(all_pattern, grant_on_object, column);
// owner no privileges
if (hasOwner())
grant += PgAcl(ownerName() + "=").sql(all_pattern, grant_on_object, column);
}
return grant;

View file

@ -16,6 +16,7 @@ public:
void setOwnerOid(Oid oid);
Oid ownerOid() const;
bool hasOwner() const;
QString ownerName() const;
const PgAuthId* owner() const;
QString alterOwnerSql(const QString& ident) const;