Generic GRANT/REVOKE generation from ACL's complete.

Moved the owned concept to PgServerObject as it is needed for the generic
acl functionality that is also in PgServerObject.
This commit is contained in:
eelke 2018-12-25 13:17:04 +01:00
parent cc0b28e8e0
commit c2c01cf431
23 changed files with 358 additions and 312 deletions

View file

@ -3,56 +3,10 @@
#include <QString>
#include "PgObject.h"
#include "Pgsql_Value.h"
#include <vector>
#include "PgAcl.h"
#include <boost/optional.hpp>
enum class Privilege {
Select,
Update,
Insert,
Delete,
Truncate,
References,
Trigger,
Execute,
Usage,
Create,
Connect,
Temporary
};
char privilegeToChar(Privilege p);
enum class PrivValue {
No, Yes, YesWithGrant
};
class PgAcl {
public:
PgAcl() = default;
explicit PgAcl(const QString &acl);
void setFromString(const QString &acl);
PrivValue privilege(Privilege priv) const;
PrivValue privilege(char c) const;
const QString& grantee() const { return m_grantee; }
const QString& grantor() const { return m_grantor; }
QString singleString() const;
private:
QString m_grantee;
QString m_grantor;
QString m_privileges;
};
using AclList = std::vector<PgAcl>;
void operator<<(PgAcl &acl, const Pgsql::Value &v);
namespace Pgsql {
template <>
PgAcl StringToArrayElem<PgAcl>(std::string_view sv);
}
class PgAuthId;
/// Base object for objects that belong to a server
class PgServerObject: public PgObject {
@ -60,26 +14,36 @@ public:
using PgObject::PgObject;
void setOwnerOid(Oid oid);
Oid ownerOid() const;
QString ownerName() const;
const PgAuthId* owner() const;
QString alterOwnerSql(const QString& ident) const;
/**
* @brief setAcls Takes the acl array as stored by postgres as a single string
* and decodes it directly into an AclList.
* @param acls
*
* @brief setAcls
* @param acls Important: pass empty optional when acl IS NULL, pass empty list for empty array
*/
void setAcls(AclList acls);
void setAcls(boost::optional<AclList> acls);
QString aclString() const;
/**
* @brief grantSql
* @param all_pattern Used to recognize when a GRANT ALL can be generated but also to not consider irrelevant letters.
* @param grantee
* @param column
* @return
*/
QString grantSql(const QString &all_pattern, const QString &grantee, const QString &column) const;
QString grantSql() const;
/**
* @brief Returns a string containing all the possible privileges for this type of object.
*
* The default implementation returns an empty string.
*
* @return A string containing all posible privileges for this type of object.
*/
virtual QString aclAllPattern() const;
private:
AclList m_acls;
Oid m_ownerOid = InvalidOid;
const PgAuthId * m_owner;
boost::optional<AclList> m_acls;
};
#endif // PGSERVEROBJECT_H