85 lines
1.6 KiB
C++
85 lines
1.6 KiB
C++
#ifndef PGSERVEROBJECT_H
|
|
#define PGSERVEROBJECT_H
|
|
|
|
#include <QString>
|
|
#include "PgObject.h"
|
|
#include "Pgsql_Value.h"
|
|
#include <vector>
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
/// Base object for objects that belong to a server
|
|
class PgServerObject: public PgObject {
|
|
public:
|
|
using PgObject::PgObject;
|
|
|
|
|
|
|
|
/**
|
|
* @brief setAcls Takes the acl array as stored by postgres as a single string
|
|
* and decodes it directly into an AclList.
|
|
* @param acls
|
|
*
|
|
*/
|
|
void setAcls(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;
|
|
|
|
private:
|
|
AclList m_acls;
|
|
};
|
|
|
|
#endif // PGSERVEROBJECT_H
|