mirror of
https://github.com/altlinux/admc.git
synced 2025-01-09 05:18:22 +03:00
add single versions of search_items()
use it where single results are expected add missing validity check to console_object_move_and_rename()
This commit is contained in:
parent
aa0379c84b
commit
29be65a42b
@ -141,13 +141,9 @@ void AllPoliciesFolderImpl::create_policy() {
|
||||
|
||||
QModelIndex get_all_policies_folder_index(ConsoleWidget *console) {
|
||||
const QModelIndex policy_tree_root = get_policy_tree_root(console);
|
||||
const QList<QModelIndex> index_list = console->search_items(policy_tree_root, {ItemType_AllPoliciesFolder});
|
||||
|
||||
if (!index_list.isEmpty()) {
|
||||
return index_list[0];
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
const QModelIndex out = console->search_item(policy_tree_root, {ItemType_AllPoliciesFolder});
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void all_policies_folder_impl_add_objects(ConsoleWidget *console, const QList<AdObject> &object_list, const QModelIndex &parent) {
|
||||
|
@ -48,11 +48,7 @@ QList<int> FindRootImpl::default_columns() const {
|
||||
}
|
||||
|
||||
QModelIndex get_find_tree_root(ConsoleWidget *console) {
|
||||
const QList<QModelIndex> index_list = console->search_items(QModelIndex(), {ItemType_FindRoot});
|
||||
const QModelIndex out = console->search_item(QModelIndex(), {ItemType_FindRoot});
|
||||
|
||||
if (!index_list.isEmpty()) {
|
||||
return index_list[0];
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -583,15 +583,12 @@ void console_object_properties(ConsoleWidget *console, ConsoleWidget *buddy_cons
|
||||
|
||||
for (const AdObject &object : object_list) {
|
||||
const QString dn = object.get_dn();
|
||||
const QList<QModelIndex> object_index_list = target_console->search_items(root_index, update_dn_role, dn, {item_type});
|
||||
const QModelIndex object_index = target_console->search_item(root_index, update_dn_role, dn, {item_type});
|
||||
|
||||
if (object_index_list.isEmpty()) {
|
||||
continue;
|
||||
if (object_index.isValid()) {
|
||||
const QList<QStandardItem *> object_row = target_console->get_row(object_index);
|
||||
console_object_load(object_row, object);
|
||||
}
|
||||
|
||||
const QModelIndex object_index = object_index_list[0];
|
||||
const QList<QStandardItem *> object_row = target_console->get_row(object_index);
|
||||
console_object_load(object_row, object);
|
||||
}
|
||||
};
|
||||
|
||||
@ -608,17 +605,14 @@ void console_object_properties(ConsoleWidget *console, ConsoleWidget *buddy_cons
|
||||
if (!policy_root.isValid()) {
|
||||
for (const AdObject &object : object_list) {
|
||||
const QString dn = object.get_dn();
|
||||
const QList<QModelIndex> object_index_list = target_console->search_items(policy_root, PolicyOURole_DN, dn, {ItemType_PolicyOU});
|
||||
const QModelIndex object_index = target_console->search_item(policy_root, PolicyOURole_DN, dn, {ItemType_PolicyOU});
|
||||
|
||||
if (object_index_list.isEmpty()) {
|
||||
continue;
|
||||
if (object_index.isValid()) {
|
||||
const QList<QStandardItem *> object_row = target_console->get_row(object_index);
|
||||
console_object_load(object_row, object);
|
||||
|
||||
policy_ou_impl_load_row(object_row, object);
|
||||
}
|
||||
|
||||
const QModelIndex object_index = object_index_list[0];
|
||||
const QList<QStandardItem *> object_row = target_console->get_row(object_index);
|
||||
console_object_load(object_row, object);
|
||||
|
||||
policy_ou_impl_load_row(object_row, object);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1065,10 +1059,9 @@ void console_object_create(ConsoleWidget *console, ConsoleWidget *buddy_console,
|
||||
auto apply_changes = [&](ConsoleWidget *target_console) {
|
||||
const QModelIndex object_root = get_object_tree_root(target_console);
|
||||
if (object_root.isValid()) {
|
||||
const QList<QModelIndex> parent_object_list = target_console->search_items(object_root, ObjectRole_DN, parent_dn, {ItemType_Object});
|
||||
const QModelIndex parent_object = target_console->search_item(object_root, ObjectRole_DN, parent_dn, {ItemType_Object});
|
||||
|
||||
if (!parent_object_list.isEmpty()) {
|
||||
const QModelIndex parent_object = parent_object_list[0];
|
||||
if (parent_object.isValid()) {
|
||||
object_impl_add_objects_to_console_from_dns(target_console, ad_inner, {created_dn}, parent_object);
|
||||
}
|
||||
}
|
||||
@ -1085,11 +1078,9 @@ void console_object_create(ConsoleWidget *console, ConsoleWidget *buddy_console,
|
||||
// Apply changes to policy tree
|
||||
const QModelIndex policy_root = get_policy_tree_root(target_console);
|
||||
if (policy_root.isValid() && object_class == CLASS_OU) {
|
||||
const QList<QModelIndex> parent_policy_list = target_console->search_items(policy_root, PolicyOURole_DN, parent_dn, {ItemType_PolicyOU});
|
||||
|
||||
if (!parent_policy_list.isEmpty()) {
|
||||
const QModelIndex parent_policy = parent_policy_list[0];
|
||||
const QModelIndex parent_policy = target_console->search_item(policy_root, PolicyOURole_DN, parent_dn, {ItemType_PolicyOU});
|
||||
|
||||
if (parent_policy.isValid()) {
|
||||
policy_ou_impl_add_objects_from_dns(target_console, ad_inner, {created_dn}, parent_policy);
|
||||
}
|
||||
}
|
||||
@ -1137,6 +1128,7 @@ void ObjectImpl::set_disabled(const bool disabled) {
|
||||
|
||||
for (const QString &dn : changed_objects) {
|
||||
const QList<QModelIndex> index_list = target_console->search_items(root_index, ObjectRole_DN, dn, {ItemType_Object});
|
||||
|
||||
for (const QModelIndex &index : index_list) {
|
||||
QStandardItem *item = target_console->get_item(index);
|
||||
item->setData(disabled, ObjectRole_AccountDisabled);
|
||||
@ -1221,18 +1213,10 @@ void console_object_move_and_rename(ConsoleWidget *console, ConsoleWidget *buddy
|
||||
// is that new object is duplicated.
|
||||
const QModelIndex object_root = get_object_tree_root(target_console);
|
||||
if (object_root.isValid()) {
|
||||
const QModelIndex new_parent_index = [=]() {
|
||||
const QList<QModelIndex> results = target_console->search_items(object_root, ObjectRole_DN, new_parent_dn, {ItemType_Object});
|
||||
const QModelIndex parent_object = target_console->search_item(object_root, ObjectRole_DN, new_parent_dn, {ItemType_Object});
|
||||
|
||||
if (results.size() == 1) {
|
||||
return results[0];
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}();
|
||||
|
||||
if (new_parent_index.isValid()) {
|
||||
object_impl_add_objects_to_console(target_console, object_map.values(), new_parent_index);
|
||||
if (parent_object.isValid()) {
|
||||
object_impl_add_objects_to_console(target_console, object_map.values(), parent_object);
|
||||
|
||||
console_object_delete_dn_list(target_console, old_dn_list, object_root, ItemType_Object, ObjectRole_DN);
|
||||
}
|
||||
@ -1324,19 +1308,13 @@ void console_object_move_and_rename(ConsoleWidget *console, ConsoleWidget *buddy
|
||||
// Apply changes to policy tree
|
||||
const QModelIndex policy_root = get_policy_tree_root(target_console);
|
||||
if (policy_root.isValid()) {
|
||||
const QModelIndex new_parent_index = [=]() {
|
||||
const QList<QModelIndex> results = target_console->search_items(policy_root, PolicyOURole_DN, new_parent_dn, {ItemType_PolicyOU});
|
||||
const QModelIndex new_parent_index = target_console->search_item(policy_root, PolicyOURole_DN, new_parent_dn, {ItemType_PolicyOU});
|
||||
|
||||
if (results.size() == 1) {
|
||||
return results[0];
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}();
|
||||
if (new_parent_index.isValid()) {
|
||||
policy_ou_impl_add_objects_to_console(target_console, object_map.values(), new_parent_index);
|
||||
|
||||
policy_ou_impl_add_objects_to_console(target_console, object_map.values(), new_parent_index);
|
||||
|
||||
console_object_delete_dn_list(target_console, old_dn_list, policy_root, ItemType_PolicyOU, PolicyOURole_DN);
|
||||
console_object_delete_dn_list(target_console, old_dn_list, policy_root, ItemType_PolicyOU, PolicyOURole_DN);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -91,11 +91,7 @@ void console_policy_tree_init(ConsoleWidget *console) {
|
||||
}
|
||||
|
||||
QModelIndex get_policy_tree_root(ConsoleWidget *console) {
|
||||
const QList<QModelIndex> index_list = console->search_items(QModelIndex(), {ItemType_PolicyRoot});
|
||||
const QModelIndex out = console->search_item(QModelIndex(), {ItemType_PolicyRoot});
|
||||
|
||||
if (!index_list.isEmpty()) {
|
||||
return index_list[0];
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -456,13 +456,9 @@ void console_query_tree_save(ConsoleWidget *console) {
|
||||
}
|
||||
|
||||
QModelIndex get_query_tree_root(ConsoleWidget *console) {
|
||||
const QList<QModelIndex> search_results = console->search_items(QModelIndex(), QueryItemRole_IsRoot, true, {ItemType_QueryFolder});
|
||||
const QModelIndex out = console->search_item(QModelIndex(), QueryItemRole_IsRoot, true, {ItemType_QueryFolder});
|
||||
|
||||
if (!search_results.isEmpty()) {
|
||||
return search_results[0];
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
QList<QString> QueryFolderImpl::column_labels() const {
|
||||
|
@ -428,6 +428,30 @@ QList<QModelIndex> ConsoleWidget::search_items(const QModelIndex &parent, const
|
||||
return out;
|
||||
}
|
||||
|
||||
QModelIndex ConsoleWidget::search_item(const QModelIndex &parent, int role, const QVariant &value, const QList<int> &type_list) const {
|
||||
const QList<QModelIndex> index_list = search_items(parent, role, value, type_list);
|
||||
|
||||
if (index_list.isEmpty()) {
|
||||
const QModelIndex out = index_list[0];
|
||||
|
||||
return out;
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex ConsoleWidget::search_item(const QModelIndex &parent, const QList<int> &type) const {
|
||||
const QList<QModelIndex> index_list = search_items(parent, type);
|
||||
|
||||
if (index_list.isEmpty()) {
|
||||
const QModelIndex out = index_list[0];
|
||||
|
||||
return out;
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex ConsoleWidget::get_current_scope_item() const {
|
||||
const QModelIndex index = d->scope_view->selectionModel()->currentIndex();
|
||||
|
||||
|
@ -141,6 +141,12 @@ public:
|
||||
QList<QModelIndex> search_items(const QModelIndex &parent, int role, const QVariant &value, const QList<int> &type = QList<int>()) const;
|
||||
QList<QModelIndex> search_items(const QModelIndex &parent, const QList<int> &type) const;
|
||||
|
||||
// Single index versions of search f-ns. Use when you
|
||||
// expect only one valid result or none. QModelIndex()
|
||||
// is returned if no items are found.
|
||||
QModelIndex search_item(const QModelIndex &parent, int role, const QVariant &value, const QList<int> &type = QList<int>()) const;
|
||||
QModelIndex search_item(const QModelIndex &parent, const QList<int> &type) const;
|
||||
|
||||
QModelIndex get_current_scope_item() const;
|
||||
int get_child_count(const QModelIndex &index) const;
|
||||
|
||||
|
@ -263,15 +263,13 @@ void PolicyOUResultsWidget::remove_link() {
|
||||
|
||||
// Also remove gpo from OU in console
|
||||
const QModelIndex policy_root = get_policy_tree_root(console);
|
||||
const QList<QModelIndex> ou_search_results = console->search_items(policy_root, PolicyOURole_DN, ou_dn, {ItemType_PolicyOU});
|
||||
if (!ou_search_results.isEmpty()) {
|
||||
const QModelIndex ou_index = ou_search_results[0];
|
||||
const QModelIndex ou_index = console->search_item(policy_root, PolicyOURole_DN, ou_dn, {ItemType_PolicyOU});
|
||||
|
||||
if (ou_index.isValid()) {
|
||||
for (const QString &gpo_dn : gpo_dn_list) {
|
||||
const QList<QModelIndex> gpo_search_results = console->search_items(ou_index, PolicyRole_DN, gpo_dn, {ItemType_Policy});
|
||||
if (!gpo_search_results.isEmpty()) {
|
||||
const QModelIndex gpo_index = gpo_search_results[0];
|
||||
const QModelIndex gpo_index = console->search_item(ou_index, PolicyRole_DN, gpo_dn, {ItemType_Policy});
|
||||
|
||||
if (!gpo_index.isValid()) {
|
||||
console->delete_item(gpo_index);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user