1
0
mirror of https://github.com/altlinux/admc.git synced 2025-03-12 00:58:22 +03:00

Add policy edit action to policy OU results widget

This commit is contained in:
Semyon Knyazev 2024-11-14 18:53:57 +04:00
parent 93db14698c
commit b5da8c04a7
4 changed files with 96 additions and 72 deletions

View File

@ -358,78 +358,7 @@ void console_policy_load_item(QStandardItem *main_item, const AdObject &object)
void console_policy_edit(ConsoleWidget *console, const int item_type, const int dn_role) {
const QString dn = get_selected_target_dn(console, item_type, dn_role);
AdInterface ad;
bool ad_fail = ad_failed(ad, console);
if (ad_fail) {
return;
}
if (!current_dc_is_master_for_role(ad, FSMORole_PDCEmulation) && gpo_edit_without_PDC_disabled) {
QMessageBox::StandardButton answer = QMessageBox::question(console, QObject::tr("Edition is not available"),
QObject::tr("ADMC is connected to DC without the PDC-Emulator role - "
"group policy editing is prohibited by the setting. "
"Connect to PDC-Emulator?"));
if (answer == QMessageBox::Yes) {
connect_to_PDC_emulator(ad, console);
return;
}
else {
return;
}
}
// TODO: remove this when gpui is able to load
// policy name on their own
const QString policy_name = [&]() {
const AdObject object = ad.search_object(dn);
return object.get_string(ATTRIBUTE_DISPLAY_NAME);
}();
const QString path = [&]() {
const AdObject object = ad.search_object(dn);
QString filesys_path = object.get_string(ATTRIBUTE_GPC_FILE_SYS_PATH);
const QString current_dc = ad.get_dc();
filesys_path.replace(QString("\\"), QString("/"));
auto contents = filesys_path.split("/", Qt::KeepEmptyParts);
if (contents.size() > 3 && !current_dc.isEmpty()) {
contents[2] = current_dc;
}
filesys_path = contents.join("/");
filesys_path.prepend(QString("smb:"));
return filesys_path;
}();
auto process = new QProcess(console);
process->setProgram("gpui-main");
const QList<QString> args = {
QString("-p"),
path,
QString("-n"),
policy_name,
};
process->setArguments(args);
auto on_gpui_error = [console](QProcess::ProcessError error) {
const bool failed_to_start = (error == QProcess::FailedToStart);
if (failed_to_start) {
const QString error_text = QObject::tr("Failed to start GPUI. Check that it's installed.");
qDebug() << error_text;
g_status->add_message(error_text, StatusType_Error);
error_log({error_text}, console);
}
};
QObject::connect(
process, &QProcess::errorOccurred,
console, on_gpui_error);
process->start(QIODevice::ReadOnly);
console_policy_edit(dn, console);
}
void console_policy_rename(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role) {
@ -860,3 +789,78 @@ bool policy_is_disabled(QStandardItem *policy_item)
return is_disabled;
}
void console_policy_edit(const QString &policy_dn, ConsoleWidget *console) {
AdInterface ad;
bool ad_fail = ad_failed(ad, console);
if (ad_fail) {
return;
}
if (!current_dc_is_master_for_role(ad, FSMORole_PDCEmulation) && gpo_edit_without_PDC_disabled) {
QMessageBox::StandardButton answer = QMessageBox::question(console, QObject::tr("Edition is not available"),
QObject::tr("ADMC is connected to DC without the PDC-Emulator role - "
"group policy editing is prohibited by the setting. "
"Connect to PDC-Emulator?"));
if (answer == QMessageBox::Yes) {
connect_to_PDC_emulator(ad, console);
return;
}
else {
return;
}
}
// TODO: remove this when gpui is able to load
// policy name on their own
const QString policy_name = [&]() {
const AdObject object = ad.search_object(policy_dn);
return object.get_string(ATTRIBUTE_DISPLAY_NAME);
}();
const QString path = [&]() {
const AdObject object = ad.search_object(policy_dn);
QString filesys_path = object.get_string(ATTRIBUTE_GPC_FILE_SYS_PATH);
const QString current_dc = ad.get_dc();
filesys_path.replace(QString("\\"), QString("/"));
auto contents = filesys_path.split("/", Qt::KeepEmptyParts);
if (contents.size() > 3 && !current_dc.isEmpty()) {
contents[2] = current_dc;
}
filesys_path = contents.join("/");
filesys_path.prepend(QString("smb:"));
return filesys_path;
}();
auto process = new QProcess(console);
process->setProgram("gpui-main");
const QList<QString> args = {
QString("-p"),
path,
QString("-n"),
policy_name,
};
process->setArguments(args);
auto on_gpui_error = [console](QProcess::ProcessError error) {
const bool failed_to_start = (error == QProcess::FailedToStart);
if (failed_to_start) {
const QString error_text = QObject::tr("Failed to start GPUI. Check that it's installed.");
qDebug() << error_text;
g_status->add_message(error_text, StatusType_Error);
error_log({error_text}, console);
}
};
QObject::connect(
process, &QProcess::errorOccurred,
console, on_gpui_error);
process->start(QIODevice::ReadOnly);
}

View File

@ -89,6 +89,7 @@ void console_policy_load(const QList<QStandardItem *> &row, const AdObject &obje
void console_policy_load_item(QStandardItem *item, const AdObject &object);
QList<QString> console_policy_search_attributes();
void console_policy_edit(ConsoleWidget *console, const int item_type, const int dn_role);
void console_policy_edit(const QString &policy_dn, ConsoleWidget *console);
void console_policy_rename(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role);
void console_policy_add_link(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role);
void console_policy_delete(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role);

View File

@ -38,6 +38,7 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *
auto move_down_action = new QAction(tr("Move down"), this);
set_all_checked_action = new QAction(tr("Set all"), this);
set_all_unchecked_action = new QAction(tr("Unset all"), this);
edit_policy_action = new QAction(tr("Edit..."), this);
context_menu = new QMenu(this);
context_menu->addAction(remove_link_action);
@ -45,6 +46,7 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *
context_menu->addAction(move_down_action);
context_menu->addAction(set_all_checked_action);
context_menu->addAction(set_all_unchecked_action);
context_menu->addAction(edit_policy_action);
model = new DragDropLinksModel(gplink, 0, LinkedPoliciesColumn_COUNT, this);
set_horizontal_header_labels_from_map(model,
@ -100,6 +102,9 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *
connect(
set_all_unchecked_action, &QAction::triggered,
this, &LinkedPoliciesWidget::on_set_unchecked_all);
connect(
edit_policy_action, &QAction::triggered,
this, &LinkedPoliciesWidget::on_edit_policy);
connect(model, &DragDropLinksModel::link_orders_changed, [this](const Gplink &gplink_arg) {
AdInterface ad;
@ -123,6 +128,7 @@ LinkedPoliciesWidget::LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *
emit gplink_changed(scope_tree_ou_index);
});
}
LinkedPoliciesWidget::~LinkedPoliciesWidget()
@ -215,6 +221,9 @@ void LinkedPoliciesWidget::open_context_menu(const QPoint &pos) {
set_all_unchecked_action->setVisible(false);
}
const bool multiple_selection = ui->view->get_selected_indexes().size() > 1;
edit_policy_action->setVisible(!multiple_selection);
const QPoint global_pos = ui->view->current_view()->mapToGlobal(pos);
context_menu->popup(global_pos);
}
@ -439,3 +448,10 @@ void LinkedPoliciesWidget::on_set_unchecked_all() {
}
set_all_column_check_state(column_data.toInt(), false);
}
void LinkedPoliciesWidget::on_edit_policy() {
const QModelIndex index = ui->view->get_selected_indexes()[0];
const QString policy_dn = index.data(LinkedPoliciesRole_DN).toString();
console_policy_edit(policy_dn, console);
}

View File

@ -14,6 +14,7 @@ class ADMCTestPolicyOUResultsWidget;
class AdObject;
class AdInterface;
class DragDropLinksModel;
class QAction;
namespace Ui {
class LinkedPoliciesWidget;
@ -43,6 +44,7 @@ private:
QMenu *context_menu;
QAction *set_all_checked_action;
QAction *set_all_unchecked_action;
QAction *edit_policy_action;
void on_item_changed(QStandardItem *item);
void open_context_menu(const QPoint &pos);
@ -57,6 +59,7 @@ private:
void set_all_column_check_state(int column, bool checked);
void on_set_checked_all();
void on_set_unchecked_all();
void on_edit_policy();
};
#endif // LINKED_POLICIES_WIDGET_H