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()); const PgAuthId &authid = m_roles->getByIdx(index.row());
switch (index.column()) { switch (index.column()) {
case NameCol: case NameCol:
v = authid.name; v = authid.objectName();
break; break;
case SuperCol: case SuperCol:
// todo lookup role name // todo lookup role name

View file

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

View file

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

View file

@ -1,16 +1,19 @@
#ifndef PGAUTHID_H #ifndef PGAUTHID_H
#define PGAUTHID_H #define PGAUTHID_H
#include "PgServerObject.h"
#include <libpq-fe.h> #include <libpq-fe.h>
#include <QString> #include <QString>
#include <QDateTime> #include <QDateTime>
class PgAuthId { /**
* @brief The PgAuthId class
*
* An AuthId is a database role
*/
class PgAuthId: public PgServerObject {
public: public:
PgAuthId();
Oid oid = InvalidOid;
QString name;
bool super; bool super;
bool inherit; bool inherit;
bool createRole; bool createRole;
@ -21,12 +24,9 @@ public:
int connLimit; int connLimit;
QDateTime validUntil; 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 #endif // PGAUTHID_H

View file

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

View file

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

View file

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

View file

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