1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-20 10:04:05 +03:00

Add support of policy item link indicator icons with enforcing and disabling.

- Link indicator icon ("mail-forward" from theme) is added to policy item
  left bottom corner. Indicator is displayed only for OU's child policy items.
- Policy item icon changes appearance (fades) after group policy link disabling.
- Enforced policy indicator is added. Indicator ("stop" from theme) appears in
  the right bottom policy item's icon corner after policy "Enforced" setting.
This commit is contained in:
Evgeny Sinelnikov 2023-03-21 06:07:13 +04:00
parent 3bc908d49d
commit a08ce21001
8 changed files with 186 additions and 16 deletions

View File

@ -28,13 +28,13 @@
#include "console_impls/policy_ou_impl.h"
#include "console_impls/policy_root_impl.h"
#include "globals.h"
#include "gplink.h"
#include "policy_results_widget.h"
#include "properties_dialog.h"
#include "rename_policy_dialog.h"
#include "select_object_dialog.h"
#include "status.h"
#include "utils.h"
#include "console_widget/console_tree_item_icons.h"
#include <QAction>
#include <QDebug>
@ -59,6 +59,9 @@ PolicyImpl::PolicyImpl(ConsoleWidget *console_arg)
connect(
edit_action, &QAction::triggered,
this, &PolicyImpl::on_edit);
connect(
policy_results, &PolicyResultsWidget::policy_gplink_option_changed,
this, &PolicyImpl::update_policy_item_data);
}
bool PolicyImpl::can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) {
@ -206,16 +209,102 @@ void PolicyImpl::on_edit() {
console_policy_edit(console, ItemType_Policy, PolicyRole_DN);
}
void PolicyImpl::update_policy_item_data(const QString &policy_dn, const QString &ou_dn, bool is_checked, GplinkOption option) {
//Group Policy Objects item index
QModelIndex gp_objects_index = console->search_item(QModelIndex(), {ItemType_PolicyRoot});
QModelIndex ou_dn_item_index = console->search_item(gp_objects_index, PolicyOURole_DN,
ou_dn, {ItemType_PolicyOU});
QModelIndex target_policy_index = console->search_item(ou_dn_item_index, PolicyRole_DN,
policy_dn, {ItemType_Policy});
if (!target_policy_index.isValid())
return;
QStandardItem *policy_ou_item = console->get_item(ou_dn_item_index);
set_policy_item_icon(target_policy_index, is_checked, option);
update_ou_item_gpo_lists_data(policy_dn, policy_ou_item, is_checked, option);
}
void PolicyImpl::set_policy_item_icon(const QModelIndex &policy_index, bool is_checked, GplinkOption option)
{
QStandardItem *target_policy_item = console->get_item(policy_index);
if (target_policy_item->parent()->data(ConsoleRole_Type) != ItemType_PolicyOU)
return;
if (option == GplinkOption_Enforced) {
set_enforced_policy_icon(target_policy_item, is_checked);
} else if (option == GplinkOption_Disabled) {
set_disabled_policy_icon(target_policy_item, is_checked);
}
}
void update_ou_item_gpo_lists_data(const QString &policy_dn, QStandardItem *policy_ou_item, bool is_checked, GplinkOption option) {
PolicyOURole ou_role_from_option;
if (option == GplinkOption_Disabled)
ou_role_from_option = PolicyOURole_Disabled_GPO_List;
else if (option == GplinkOption_Enforced)
ou_role_from_option = PolicyOURole_Enforced_GPO_List;
else return;
QStringList target_option_policy_dn_list = policy_ou_item->data(ou_role_from_option).
toStringList();
if (is_checked)
target_option_policy_dn_list.append(policy_dn);
else
target_option_policy_dn_list.removeAll(policy_dn);
policy_ou_item->setData(target_option_policy_dn_list,
ou_role_from_option);
}
void set_policy_icon(QStandardItem *policy_item, bool is_enforced, bool is_disabled) {
if (is_enforced) {
if (!is_disabled)
policy_item->setIcon(get_console_tree_item_icon(ItemIconType_Policy_Enforced));
else
policy_item->setIcon(get_console_tree_item_icon(ItemIconType_Policy_Enforced_Disabled));
} else {
if (!is_disabled)
policy_item->setIcon(get_console_tree_item_icon(ItemIconType_Policy_Link));
else
policy_item->setIcon(get_console_tree_item_icon(ItemIconType_Policy_Link_Disabled));
}
}
void set_enforced_policy_icon(QStandardItem *policy_item, bool is_enforced) {
bool is_disabled = policy_is_disabled(policy_item);
set_policy_icon(policy_item, is_enforced, is_disabled);
}
void set_disabled_policy_icon(QStandardItem *policy_item, bool is_disabled)
{
bool is_enforced = policy_is_enforced(policy_item);
set_policy_icon(policy_item, is_enforced, is_disabled);
}
void console_policy_load(const QList<QStandardItem *> &row, const AdObject &object) {
QStandardItem *main_item = row[0];
console_policy_load_item(main_item, object);
}
void console_policy_load_item(QStandardItem *main_item, const AdObject &object) {
const QIcon icon = get_object_icon(object);
main_item->setIcon(icon);
main_item->setData(object.get_dn(), PolicyRole_DN);
if (main_item->parent() != nullptr &&
main_item->parent()->data(ConsoleRole_Type).toInt() == ItemType_PolicyOU) {
bool is_enforced = policy_is_enforced(main_item);
bool is_disabled = policy_is_disabled(main_item);
set_policy_icon(main_item, is_enforced, is_disabled);
} else {
main_item->setIcon(get_object_icon(object));
}
const QString display_name = object.get_string(ATTRIBUTE_DISPLAY_NAME);
main_item->setText(display_name);
}
@ -666,3 +755,21 @@ void console_policy_update_policy_results(ConsoleWidget *console, PolicyResultsW
policy_results->update(results_gpo);
}
}
bool policy_is_enforced(QStandardItem *policy_item)
{
bool is_enforced = false;
is_enforced = policy_item->parent()->data(PolicyOURole_Enforced_GPO_List)
.toStringList().contains(policy_item->data(PolicyRole_DN).toString());
return is_enforced;
}
bool policy_is_disabled(QStandardItem *policy_item)
{
bool is_disabled = false;
is_disabled = policy_item->parent()->data(PolicyOURole_Disabled_GPO_List)
.toStringList().contains(policy_item->data(PolicyRole_DN).toString());
return is_disabled;
}

View File

@ -31,6 +31,7 @@
#include "console_widget/console_widget.h"
#include <QProcess>
#include "gplink.h"
class QStandardItem;
class AdObject;
@ -69,6 +70,7 @@ public:
private slots:
void on_add_link();
void on_edit();
void update_policy_item_data(const QString &policy_dn, const QString &ou_dn, bool is_checked, GplinkOption option);
private:
PolicyResultsWidget *policy_results;
@ -76,6 +78,7 @@ private:
QAction *edit_action;
void on_gpui_error(QProcess::ProcessError error);
void set_policy_item_icon(const QModelIndex &policy_index, bool is_checked, GplinkOption option);
};
void console_policy_load(const QList<QStandardItem *> &row, const AdObject &object);
@ -87,4 +90,11 @@ void console_policy_add_link(const QList<ConsoleWidget *> &console_list, PolicyR
void console_policy_delete(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role);
void console_policy_properties(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role);
bool policy_is_enforced(QStandardItem *policy_item);
bool policy_is_disabled(QStandardItem *policy_item);
void set_policy_icon(QStandardItem *policy_item, bool is_enforced, bool is_disabled);
void set_enforced_policy_icon(QStandardItem *policy_item, bool is_enforced);
void set_disabled_policy_icon(QStandardItem *policy_item, bool is_disabled);
void update_ou_item_gpo_lists_data(const QString &policy_dn, QStandardItem *policy_ou_item, bool is_checked, GplinkOption option);
#endif /* POLICY_IMPL_H */

View File

@ -116,14 +116,11 @@ void PolicyOUImpl::fetch(const QModelIndex &index) {
// Add policies linked to this OU
if (!is_domain) {
const QList<QString> gpo_list = [&]() {
const AdObject parent_object = ad.search_object(dn);
const QString gplink_string = parent_object.get_string(ATTRIBUTE_GPLINK);
const Gplink gplink = Gplink(gplink_string);
const QList<QString> out = gplink.get_gpo_list();
return out;
}();
const AdObject parent_object = ad.search_object(dn);
const QString gplink_string = parent_object.get_string(ATTRIBUTE_GPLINK);
const Gplink gplink = Gplink(gplink_string);
const QList<QString> gpo_list = gplink.get_gpo_list();
update_ou_enforced_and_disabled_policies(gplink, index);
policy_ou_impl_add_objects_from_dns(console, ad, gpo_list, index);
}
@ -475,6 +472,21 @@ void PolicyOUImpl::update_gp_options_check_state() const {
change_gp_options_action->setChecked(checked);
}
void PolicyOUImpl::update_ou_enforced_and_disabled_policies(const Gplink &gplink, const QModelIndex &ou_index) {
QStandardItem *ou_scope_item = console->get_item(ou_index);
QStringList enforced_gpo_dn_list;
QStringList disabled_gpo_dn_list;
for (QString gpo_dn : gplink.get_gpo_list()) {
if (gplink.get_option(gpo_dn, GplinkOption_Enforced))
enforced_gpo_dn_list.append(gpo_dn);
if (gplink.get_option(gpo_dn, GplinkOption_Disabled))
disabled_gpo_dn_list.append(gpo_dn);
}
ou_scope_item->setData(enforced_gpo_dn_list, PolicyOURole_Enforced_GPO_List);
ou_scope_item->setData(disabled_gpo_dn_list, PolicyOURole_Disabled_GPO_List);
}
void policy_ou_impl_load_item_data(QStandardItem *item, const AdObject &object) {
const QIcon icon = get_object_icon(object);
item->setIcon(icon);

View File

@ -36,6 +36,9 @@
enum PolicyOURole {
PolicyOURole_DN = MyConsoleRole_LAST + 1,
PolicyOURole_Enforced_GPO_List,
PolicyOURole_Disabled_GPO_List,
PolicyOURole_Inheritance_Block,
PolicyOURole_LAST,
};
@ -43,6 +46,7 @@ enum PolicyOURole {
class AdInterface;
class AdObject;
class PolicyOUResultsWidget;
class Gplink;
class PolicyOUImpl final : public ConsoleImpl {
Q_OBJECT
@ -84,6 +88,7 @@ private:
void find_gpo();
void change_gp_options();
void update_gp_options_check_state() const;
void update_ou_enforced_and_disabled_policies(const Gplink &gplink, const QModelIndex &ou_index);
};
void policy_ou_impl_load_row(const QList<QStandardItem *> row, const AdObject &object);

View File

@ -30,10 +30,10 @@
#include "console_widget/console_widget.h"
#include "console_widget/results_view.h"
#include "globals.h"
#include "gplink.h"
#include "settings.h"
#include "status.h"
#include "utils.h"
#include "console_widget/console_tree_item_icons.h"
#include <QAction>
#include <QHeaderView>
@ -184,7 +184,12 @@ void PolicyOUResultsWidget::on_item_changed(QStandardItem *item) {
const QString gplink_string = gplink.to_string();
ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink_string);
bool success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink_string);
if (success) {
change_policy_icon(gpo_dn, is_checked, option);
update_gpo_lists_data(gpo_dn, is_checked, option);
}
g_status->display_ad_messages(ad, this);
@ -234,6 +239,30 @@ void PolicyOUResultsWidget::modify_gplink(void (*modify_function)(Gplink &, cons
hide_busy_indicator();
}
void PolicyOUResultsWidget::change_policy_icon(const QString &policy_dn, bool is_checked, GplinkOption option) {
QModelIndex target_policy_index = console->search_item(console->get_current_scope_item(),
PolicyRole_DN,
policy_dn,
{ItemType_Policy});
if (!target_policy_index.isValid())
return;
if (option == GplinkOption_Disabled)
{
set_disabled_policy_icon(console->get_item(target_policy_index), is_checked);
}
else if (option == GplinkOption_Enforced)
{
set_enforced_policy_icon(console->get_item(target_policy_index), is_checked);
}
}
void PolicyOUResultsWidget::update_gpo_lists_data(const QString &policy_dn, bool is_checked, GplinkOption option) {
QStandardItem *current_ou_item = console->get_item(console->get_current_scope_item());
update_ou_item_gpo_lists_data(policy_dn, current_ou_item, is_checked, option);
}
void PolicyOUResultsWidget::remove_link() {
// NOTE: save gpo dn list before they are removed in
// modify_gplink()
@ -344,8 +373,7 @@ void PolicyOUResultsWidget::reload_gplink() {
row[PolicyOUResultsColumn_Name]->setText(name);
set_data_for_row(row, gpo_dn, PolicyOUResultsRole_DN);
const QIcon icon = get_object_icon(gpo_object);
row[0]->setIcon(icon);
row[0]->setIcon(get_console_tree_item_icon(ItemIconType_Policy_Link));
for (const auto column : option_columns) {
QStandardItem *item = row[column];

View File

@ -70,6 +70,8 @@ private:
void move_down();
void reload_gplink();
void modify_gplink(void (*modify_function)(Gplink &, const QString &));
void change_policy_icon(const QString &policy_dn, bool is_checked, GplinkOption option);
void update_gpo_lists_data(const QString &policy_dn, bool is_checked, GplinkOption option);
friend ADMCTestPolicyOUResultsWidget;
};

View File

@ -27,7 +27,6 @@
#include "console_widget/console_widget.h"
#include "console_widget/results_view.h"
#include "globals.h"
#include "gplink.h"
#include "settings.h"
#include "status.h"
#include "utils.h"
@ -235,6 +234,8 @@ void PolicyResultsWidget::on_item_changed(QStandardItem *item) {
if (success) {
model->setData(index, updated_gplink_string, PolicyResultsRole_GplinkString);
emit policy_gplink_option_changed(gpo, dn, is_checked, option);
} else {
const Qt::CheckState undo_check_state = [&]() {
if (item->checkState() == Qt::Checked) {

View File

@ -26,6 +26,7 @@
*/
#include <QWidget>
#include "gplink.h"
class QStandardItemModel;
class QStandardItem;
@ -56,6 +57,10 @@ public:
QString get_current_gpo() const;
signals:
void policy_gplink_option_changed(const QString &policy_dn, const QString &ou_dn,
bool is_checked, GplinkOption option);
private:
QStandardItemModel *model;
QString gpo;