From 0b6c1a8544021a3c810e74b412d932ec20a6e5ef Mon Sep 17 00:00:00 2001 From: eelke Date: Tue, 25 Dec 2018 16:39:58 +0100 Subject: [PATCH] Make PgAuthId inherit PgServerObject and related changes. --- pglab/RolesTableModel.cpp | 2 +- pglablib/catalog/PgAm.h | 5 +++++ pglablib/catalog/PgAuthId.cpp | 5 ++++- pglablib/catalog/PgAuthId.h | 18 +++++++++--------- pglablib/catalog/PgAuthIdContainer.cpp | 6 ++++-- pglablib/catalog/PgDatabaseCatalog.cpp | 2 +- pglablib/catalog/PgServerObject.cpp | 10 ++++++++-- pglablib/catalog/PgServerObject.h | 1 + 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/pglab/RolesTableModel.cpp b/pglab/RolesTableModel.cpp index bd1c86a..4e0ac65 100644 --- a/pglab/RolesTableModel.cpp +++ b/pglab/RolesTableModel.cpp @@ -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 diff --git a/pglablib/catalog/PgAm.h b/pglablib/catalog/PgAm.h index 1eadad9..01487c3 100644 --- a/pglablib/catalog/PgAm.h +++ b/pglablib/catalog/PgAm.h @@ -4,6 +4,11 @@ #include "Pgsql_declare.h" #include +/** + * @brief The PgAm class + * + * AM = Access Method, for indexes + */ class PgAm { public: Oid oid; diff --git a/pglablib/catalog/PgAuthId.cpp b/pglablib/catalog/PgAuthId.cpp index 3c873cb..6bd35e3 100644 --- a/pglablib/catalog/PgAuthId.cpp +++ b/pglablib/catalog/PgAuthId.cpp @@ -1,3 +1,6 @@ #include "PgAuthId.h" -PgAuthId::PgAuthId() = default; +QString PgAuthId::typeName() const +{ + return "ROLE"; +} diff --git a/pglablib/catalog/PgAuthId.h b/pglablib/catalog/PgAuthId.h index c71c4f8..12d6e35 100644 --- a/pglablib/catalog/PgAuthId.h +++ b/pglablib/catalog/PgAuthId.h @@ -1,16 +1,19 @@ #ifndef PGAUTHID_H #define PGAUTHID_H +#include "PgServerObject.h" #include #include #include -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 diff --git a/pglablib/catalog/PgAuthIdContainer.cpp b/pglablib/catalog/PgAuthIdContainer.cpp index ce1d7ae..84d72ac 100644 --- a/pglablib/catalog/PgAuthIdContainer.cpp +++ b/pglablib/catalog/PgAuthIdContainer.cpp @@ -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; diff --git a/pglablib/catalog/PgDatabaseCatalog.cpp b/pglablib/catalog/PgDatabaseCatalog.cpp index 68290d4..9f60029 100644 --- a/pglablib/catalog/PgDatabaseCatalog.cpp +++ b/pglablib/catalog/PgDatabaseCatalog.cpp @@ -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; diff --git a/pglablib/catalog/PgServerObject.cpp b/pglablib/catalog/PgServerObject.cpp index 0691dc6..68eb505 100644 --- a/pglablib/catalog/PgServerObject.cpp +++ b/pglablib/catalog/PgServerObject.cpp @@ -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,7 +81,8 @@ QString PgServerObject::grantSql() const // PUBLIC, no priviliges grant += PgAcl("=").sql(all_pattern, grant_on_object, column); // owner no privileges - grant += PgAcl(ownerName() + "=").sql(all_pattern, grant_on_object, column); + if (hasOwner()) + grant += PgAcl(ownerName() + "=").sql(all_pattern, grant_on_object, column); } return grant; } diff --git a/pglablib/catalog/PgServerObject.h b/pglablib/catalog/PgServerObject.h index 654a722..d05c291 100644 --- a/pglablib/catalog/PgServerObject.h +++ b/pglablib/catalog/PgServerObject.h @@ -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;