Make PgAuthId inherit PgServerObject and related changes.
This commit is contained in:
parent
c2c01cf431
commit
0b6c1a8544
8 changed files with 33 additions and 16 deletions
|
|
@ -4,6 +4,11 @@
|
|||
#include "Pgsql_declare.h"
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* @brief The PgAm class
|
||||
*
|
||||
* AM = Access Method, for indexes
|
||||
*/
|
||||
class PgAm {
|
||||
public:
|
||||
Oid oid;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
#include "PgAuthId.h"
|
||||
|
||||
PgAuthId::PgAuthId() = default;
|
||||
QString PgAuthId::typeName() const
|
||||
{
|
||||
return "ROLE";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue