mirror of
https://github.com/levinsv/pgadmin3.git
synced 2026-05-15 14:15:49 -06:00
PG16 support inherit_option, set_option
Добавлена поддержка новых опций для членов ролей.
This commit is contained in:
parent
d7f1687b7c
commit
d5388d72d7
3 changed files with 56 additions and 25 deletions
|
|
@ -443,7 +443,7 @@ void dlgRole::OnRoleAdd(wxCommandEvent &ev)
|
|||
{
|
||||
wxString roleName = lbRolesNotIn->GetString(pos);
|
||||
if (chkAdminOption->GetValue())
|
||||
roleName += PGROLE_ADMINOPTION;
|
||||
roleName += "(A)";
|
||||
lbRolesIn->Append(roleName);
|
||||
lbRolesNotIn->Delete(pos);
|
||||
}
|
||||
|
|
@ -459,11 +459,11 @@ void dlgRole::OnRoleRemove(wxCommandEvent &ev)
|
|||
int pos = lbRolesIn->GetSelection();
|
||||
if (pos >= 0)
|
||||
{
|
||||
wxString role = lbRolesIn->GetString(pos);
|
||||
if (role.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION)
|
||||
role = role.Left(role.Length() - PGROLE_ADMINOPTION_LEN);
|
||||
wxString roleName = lbRolesIn->GetString(pos);
|
||||
if (!pgRole::GetOptStr(roleName).IsEmpty())
|
||||
roleName = roleName.BeforeLast('(');
|
||||
|
||||
lbRolesNotIn->Append(role);
|
||||
lbRolesNotIn->Append(roleName);
|
||||
lbRolesIn->Delete(pos);
|
||||
}
|
||||
CheckChange();
|
||||
|
|
@ -725,15 +725,16 @@ wxString dlgRole::GetSql()
|
|||
else
|
||||
{
|
||||
bool admin = false;
|
||||
if (roleName.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION)
|
||||
wxString opt = pgRole::GetOptStr(roleName);
|
||||
if (!opt.IsEmpty())
|
||||
{
|
||||
admin = true;
|
||||
roleName = roleName.Left(roleName.Length() - PGROLE_ADMINOPTION_LEN);
|
||||
roleName = roleName.BeforeLast('(');
|
||||
}
|
||||
else
|
||||
{
|
||||
// new role membership without admin option
|
||||
index = tmpRoles.Index(roleName + PGROLE_ADMINOPTION);
|
||||
index = tmpRoles.Index(roleName + "(");
|
||||
if (index >= 0)
|
||||
{
|
||||
// old membership with admin option
|
||||
|
|
@ -755,7 +756,7 @@ wxString dlgRole::GetSql()
|
|||
+ wxT(" TO ") + qtIdent(name);
|
||||
|
||||
if (admin)
|
||||
sql += wxT(" WITH ADMIN OPTION");
|
||||
sql += opt;
|
||||
|
||||
sql += wxT(";\n");
|
||||
}
|
||||
|
|
@ -764,7 +765,11 @@ wxString dlgRole::GetSql()
|
|||
// check for removed roles
|
||||
for (pos = 0 ; pos < (int)tmpRoles.GetCount() ; pos++)
|
||||
{
|
||||
sql += wxT("REVOKE ") + qtIdent(tmpRoles.Item(pos))
|
||||
wxString roleName = tmpRoles.Item(pos);
|
||||
wxString opt=pgRole::GetOptStr(roleName);
|
||||
if (!opt.IsEmpty()) roleName = roleName.BeforeLast('(');
|
||||
|
||||
sql += wxT("REVOKE ") + qtIdent(roleName)
|
||||
+ wxT(" FROM ") + qtIdent(name) + wxT(";\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -816,9 +821,10 @@ wxString dlgRole::GetSql()
|
|||
{
|
||||
bool admin = false;
|
||||
roleName = lbRolesIn->GetString(pos);
|
||||
if (roleName.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION)
|
||||
wxString opt = pgRole::GetOptStr(roleName);
|
||||
if (!opt.IsEmpty())
|
||||
{
|
||||
roleName = roleName.Left(roleName.Length() - PGROLE_ADMINOPTION_LEN);
|
||||
roleName = roleName.BeforeLast('(');
|
||||
admin = true;
|
||||
|
||||
}
|
||||
|
|
@ -826,7 +832,7 @@ wxString dlgRole::GetSql()
|
|||
+ wxT(" TO ") + qtIdent(name);
|
||||
|
||||
if (admin)
|
||||
grants += wxT(" WITH ADMIN OPTION;\n");
|
||||
grants += opt;
|
||||
else
|
||||
grants += wxT(";\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,9 +165,11 @@ public:
|
|||
// Tree object creation
|
||||
void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0);
|
||||
void ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where);
|
||||
|
||||
|
||||
static wxString GetOptStr(wxString& rolename);
|
||||
// virtual methods
|
||||
wxString GetSql(ctlTree *browser);
|
||||
|
||||
pgObject *Refresh(ctlTree *browser, const wxTreeItemId item);
|
||||
bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded);
|
||||
|
||||
|
|
|
|||
|
|
@ -190,7 +190,20 @@ bool pgRole::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
|
|||
return server->ExecuteVoid(wxT("DROP ROLE ") + GetQuotedFullIdentifier() + wxT(";"));
|
||||
}
|
||||
|
||||
|
||||
wxString pgRole::GetOptStr(wxString& rolename) {
|
||||
wxString opt = rolename.AfterLast('(');
|
||||
if (opt==rolename) return wxEmptyString;
|
||||
wxString str;
|
||||
wxString delim = "";
|
||||
if (opt.Index('A') != wxNOT_FOUND) str += "ADMIN OPTION";
|
||||
if (!str.IsEmpty()) delim = ", ";
|
||||
if (opt.find("I") != wxNOT_FOUND) str +=delim+ "INHERIT true";
|
||||
if (opt.find("i") != wxNOT_FOUND) str += delim + "INHERIT false";
|
||||
if (!str.IsEmpty()) delim = ", ";
|
||||
if (opt.Index('s') != wxNOT_FOUND) str += delim + "SET false";
|
||||
if (!str.IsEmpty()) str = " WITH "+str;
|
||||
return str;
|
||||
}
|
||||
wxString pgRole::GetSql(ctlTree *browser)
|
||||
{
|
||||
if (sql.IsNull())
|
||||
|
|
@ -269,16 +282,17 @@ wxString pgRole::GetSql(ctlTree *browser)
|
|||
{
|
||||
wxString role = rolesIn.Item(index);
|
||||
bool admin = false;
|
||||
if (role.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION)
|
||||
wxString opt = GetOptStr(role);
|
||||
if (role.AfterLast('(')!=role)
|
||||
{
|
||||
admin = true;
|
||||
role = role.Left(role.Length() - PGROLE_ADMINOPTION_LEN);
|
||||
|
||||
role = role.BeforeLast('(');
|
||||
}
|
||||
sql += wxT("GRANT ") + qtIdent(role)
|
||||
+ wxT(" TO ") + GetQuotedIdentifier();
|
||||
|
||||
if (admin)
|
||||
sql += wxT(" WITH ADMIN OPTION");
|
||||
if (!opt.IsEmpty())
|
||||
sql += opt;
|
||||
|
||||
sql += wxT(";\n");
|
||||
}
|
||||
|
|
@ -473,12 +487,13 @@ void pgRole::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *proper
|
|||
{
|
||||
expandedKids = true;
|
||||
wxString rolesquery;
|
||||
|
||||
wxString fieldOpt = ", admin_option";
|
||||
if (GetConnection()->BackendMinimumVersion(16, 0)) fieldOpt += ", inherit_option, set_option";
|
||||
if (GetConnection()->BackendMinimumVersion(8, 2))
|
||||
rolesquery = wxT("SELECT rolname, admin_option,\n")
|
||||
rolesquery = "SELECT rolname"+ fieldOpt +",\n"
|
||||
wxT(" pg_catalog.shobj_description(r.oid, 'pg_authid') AS description\n");
|
||||
else
|
||||
rolesquery = wxT("SELECT rolname, admin_option\n");
|
||||
rolesquery = "SELECT rolname"+ fieldOpt +"\n";
|
||||
|
||||
rolesquery += wxT(" FROM pg_roles r\n")
|
||||
wxT(" JOIN pg_auth_members ON r.oid=roleid\n")
|
||||
|
|
@ -490,9 +505,17 @@ void pgRole::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *proper
|
|||
while (roles.RowsLeft())
|
||||
{
|
||||
wxString role = roles.GetVal(wxT("rolname"));
|
||||
wxString opt;
|
||||
if (roles.GetBool(wxT("admin_option")))
|
||||
role += PGROLE_ADMINOPTION;
|
||||
|
||||
opt += "A";
|
||||
if (GetConnection()->BackendMinimumVersion(16, 0)) {
|
||||
if (GetInherits() != roles.GetBool(wxT("inherit_option")))
|
||||
if (roles.GetBool(wxT("inherit_option"))) opt += "I"; else opt += "i";
|
||||
if (!roles.GetBool(wxT("set_option")))
|
||||
opt += "s";
|
||||
}
|
||||
if (!opt.IsEmpty()) opt = "(" + opt + ")";
|
||||
role += opt;
|
||||
rolesIn.Add(role);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue