id
int64
0
877k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
66
repo_stars
int64
94
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
11 values
repo_extraction_date
stringclasses
197 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
1,538,599
search_thread.cpp
altlinux_admc/src/admc/search_thread.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "search_thread.h" #include "adldap.h" #include "settings.h" #include "status.h" #include "utils.h" #include <QHash> SearchThread::SearchThread(const QString base_arg, const SearchScope scope_arg, const QString &filter_arg, const QList<QString> attributes_arg) { stop_flag = false; base = base_arg; scope = scope_arg; filter = filter_arg; attributes = attributes_arg; m_failed_to_connect = false; m_hit_object_display_limit = false; static int id_max = 0; id = id_max; id_max++; } void SearchThread::stop() { stop_flag = true; } void SearchThread::run() { AdInterface ad; if (!ad.is_connected()) { m_failed_to_connect = true; return; } AdCookie cookie; const int object_display_limit = settings_get_variant(SETTING_object_display_limit).toInt(); int total_results_count = 0; while (true) { QHash<QString, AdObject> results; const bool success = ad.search_paged(base, scope, filter, attributes, &results, &cookie); total_results_count += results.count(); if (total_results_count > object_display_limit) { m_hit_object_display_limit = true; break; } ad_messages = ad.messages(); emit results_ready(results); const bool search_interrupted = (!success || stop_flag); if (search_interrupted) { break; } if (!cookie.more_pages()) { break; } } } int SearchThread::get_id() const { return id; } bool SearchThread::failed_to_connect() const { return m_failed_to_connect; } bool SearchThread::hit_object_display_limit() const { return m_hit_object_display_limit; } QList<AdMessage> SearchThread::get_ad_messages() const { return ad_messages; } void search_thread_display_errors(SearchThread *thread, QWidget *parent) { if (thread->failed_to_connect()) { error_log({QCoreApplication::translate("object_impl.cpp", "Failed to connect to server while searching for objects.")}, parent); } else if (thread->hit_object_display_limit()) { error_log({QCoreApplication::translate("object_impl.cpp", "Could not load all objects. Increase object display limit in Filter Options or reduce number of objects by applying a filter. Filter Options is accessible from main window's menubar via the \"View\" menu.")}, parent); } }
3,190
C++
.cpp
87
31.954023
284
0.689409
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,600
globals.cpp
altlinux_admc/src/admc/globals.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "globals.h" #include "adldap.h" #include "settings.h" #include "status.h" #include "icon_manager/icon_manager.h" #include <QLocale> AdConfig *g_adconfig = new AdConfig(); Status *g_status = new Status(); IconManager *g_icon_manager = new IconManager(); void load_g_adconfig(AdInterface &ad) { const QLocale locale = settings_get_variant(SETTING_locale).toLocale(); g_adconfig->load(ad, locale); AdInterface::set_config(g_adconfig); }
1,235
C++
.cpp
33
35.333333
75
0.749164
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,601
rename_object_helper.cpp
altlinux_admc/src/admc/rename_object_helper.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "rename_object_helper.h" #include "adldap.h" #include "attribute_edits/attribute_edit.h" #include "globals.h" #include "status.h" #include "utils.h" #include <QDialog> #include <QLineEdit> void RenameObjectHelper::success_msg(const QString &old_name) { const QString message = QString(tr("Object %1 was renamed.")).arg(old_name); g_status->add_message(message, StatusType_Success); } void RenameObjectHelper::fail_msg(const QString &old_name) { const QString message = QString(tr("Failed to rename object %1")).arg(old_name); g_status->add_message(message, StatusType_Error); } RenameObjectHelper::RenameObjectHelper(AdInterface &ad, const QString &target_arg, QLineEdit *name_edit_arg, const QList<AttributeEdit *> &edits_arg, QDialog *parent_dialog_arg, QList<QLineEdit *> required, QDialogButtonBox *button_box) : QObject(parent_dialog_arg) { name_edit = name_edit_arg; edits = edits_arg; target = target_arg; parent_dialog = parent_dialog_arg; required_list = required; ok_button = nullptr; if (button_box != nullptr) { ok_button = button_box->button(QDialogButtonBox::Ok); } const QString name = dn_get_name(target); name_edit->setText(name); limit_edit(name_edit, ATTRIBUTE_CN); const AdObject object = ad.search_object(target); AttributeEdit::load(edits, ad, object); if (!required_list.isEmpty() && ok_button != nullptr) { for (QLineEdit *edit : required_list) { connect(edit, &QLineEdit::textChanged, this, &RenameObjectHelper::on_edited); } on_edited(); } } bool RenameObjectHelper::accept() const { AdInterface ad; if (ad_failed(ad, parent_dialog)) { return false; } const QString old_dn = target; const QString old_name = dn_get_name(target); const QString new_name = get_new_name(); const bool verify_name_success = verify_object_name(new_name, parent_dialog); if (!verify_name_success) { return false; } const bool verify_success = AttributeEdit::verify(edits, ad, target); if (!verify_success) { return false; } show_busy_indicator(); const QString new_dn = get_new_dn(); const bool rename_success = ad.object_rename(target, new_name); bool final_success = false; if (rename_success) { const bool apply_success = AttributeEdit::apply(edits, ad, new_dn); if (apply_success) { final_success = true; } } hide_busy_indicator(); g_status->display_ad_messages(ad, parent_dialog); if (final_success) { RenameObjectHelper::success_msg(old_name); } else { RenameObjectHelper::fail_msg(old_name); } return final_success; } QString RenameObjectHelper::get_new_name() const { const QString new_name = name_edit->text().trimmed(); return new_name; } QString RenameObjectHelper::get_new_dn() const { const QString new_name = get_new_name(); const QString new_dn = dn_rename(target, new_name); return new_dn; } void RenameObjectHelper::on_edited() { const bool all_required_filled = [this]() { QRegExp reg_exp_spaces("^\\s*$"); for (QLineEdit *edit : required_list) { if (edit->text().isEmpty() || edit->text().contains(reg_exp_spaces)) { return false; } } return true; }(); ok_button->setEnabled(all_required_filled); }
4,231
C++
.cpp
114
32.210526
236
0.682575
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,602
create_object_helper.cpp
altlinux_admc/src/admc/create_object_helper.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_object_helper.h" #include "adldap.h" #include "attribute_edits/attribute_edit.h" #include "globals.h" #include "status.h" #include "utils.h" #include <QDialog> #include <QDialogButtonBox> #include <QLineEdit> #include <QPushButton> // TODO: the logic of "enable/disable ok button // depending on whether all required edits contain // input" is duplicated in password dialog and maybe in // other places. Can create an abstraction for it to // reduce duplication. CreateObjectHelper::CreateObjectHelper(QLineEdit *name_edit_arg, QDialogButtonBox *button_box, const QList<AttributeEdit *> &edits_list, const QList<QLineEdit *> &required_list, const QString &object_class, const QString &parent_dn_arg, QDialog *parent_dialog_arg) : QObject(parent_dialog_arg) { parent_dialog = parent_dialog_arg; name_edit = name_edit_arg; m_edit_list = edits_list; m_required_list = required_list; m_object_class = object_class; parent_dn = parent_dn_arg; ok_button = button_box->button(QDialogButtonBox::Ok); limit_edit(name_edit, ATTRIBUTE_CN); for (QLineEdit *edit : m_required_list) { connect( edit, &QLineEdit::textChanged, this, &CreateObjectHelper::on_edited); } on_edited(); } bool CreateObjectHelper::accept() const { AdInterface ad; if (ad_failed(ad, parent_dialog)) { return false; } const QString name = get_created_name(); const QString dn = get_created_dn(); auto fail_msg = [name]() { const QString message = QString(tr("Failed to create object %1")).arg(name); g_status->add_message(message, StatusType_Error); }; const bool verify_name_success = verify_object_name(name, parent_dialog); if (!verify_name_success) { fail_msg(); return false; } // Verify edits const bool verify_success = AttributeEdit::verify(m_edit_list, ad, dn); if (!verify_success) { fail_msg(); return false; } bool final_success = true; const QHash<QString, QList<QString>> attr_map = [&]() { if (m_object_class == CLASS_SHARED_FOLDER) { // NOTE: for shared folders, UNC name must // be defined on creation because it's a // mandatory attribute return QHash<QString, QList<QString>>({ {ATTRIBUTE_OBJECT_CLASS, {m_object_class}}, {ATTRIBUTE_UNC_NAME, {"placeholder"}}, }); } else { return QHash<QString, QList<QString>>({ {ATTRIBUTE_OBJECT_CLASS, {m_object_class}}, }); } }(); const bool add_success = ad.object_add(dn, attr_map); final_success = (final_success && add_success); if (add_success) { const bool is_user_or_person = (m_object_class == CLASS_USER || m_object_class == CLASS_INET_ORG_PERSON); const bool is_computer = (m_object_class == CLASS_COMPUTER); if (is_user_or_person) { const int uac = [this, dn, &ad]() { const AdObject object = ad.search_object(dn, {ATTRIBUTE_USER_ACCOUNT_CONTROL}); const int out = object.get_int(ATTRIBUTE_USER_ACCOUNT_CONTROL); return out; }(); const int bit = UAC_PASSWD_NOTREQD; const int updated_uac = bitmask_set(uac, bit, false); final_success = (final_success && ad.attribute_replace_int(dn, ATTRIBUTE_USER_ACCOUNT_CONTROL, updated_uac, DoStatusMsg_No)); } else if (is_computer) { // NOTE: other attributes like primary // group and sam account type are // automatically changed by the server when // we set UAC to the correct value const int uac = (UAC_PASSWD_NOTREQD | UAC_WORKSTATION_TRUST_ACCOUNT); final_success = (final_success && ad.attribute_replace_int(dn, ATTRIBUTE_USER_ACCOUNT_CONTROL, uac)); } const bool apply_success = AttributeEdit::apply(m_edit_list, ad, dn); final_success = (final_success && apply_success); } if (!final_success && add_success) { ad.object_delete(dn); } g_status->display_ad_messages(ad, parent_dialog); if (final_success) { const QString message = QString(tr("Object %1 was created")).arg(name); g_status->add_message(message, StatusType_Success); } else { fail_msg(); } return final_success; } // Enable/disable create button if all required edits filled void CreateObjectHelper::on_edited() { const bool all_required_filled = [this]() { for (QLineEdit *edit : m_required_list) { if (edit->text().isEmpty()) { return false; } } return true; }(); ok_button->setEnabled(all_required_filled); } QString CreateObjectHelper::get_created_name() const { // NOTE: trim whitespaces because server will do it // anyway and we want a correct name const QString name = name_edit->text().trimmed(); return name; } QString CreateObjectHelper::get_created_dn() const { const QString name = get_created_name(); const QString dn = dn_from_name_and_parent(name, parent_dn, m_object_class); return dn; }
6,041
C++
.cpp
149
33.993289
264
0.65158
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,603
status.cpp
altlinux_admc/src/admc/status.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "status.h" #include "adldap.h" #include "error_log_dialog.h" #include "globals.h" #include "settings.h" #include <QCoreApplication> #include <QDateTime> #include <QDebug> #include <QDialog> #include <QDialogButtonBox> #include <QPlainTextEdit> #include <QStatusBar> #include <QTextEdit> #include <QVBoxLayout> #define MAX_MESSAGES_IN_LOG 200 void Status::init(QStatusBar *statusbar, QTextEdit *message_log) { m_status_bar = statusbar; m_message_log = message_log; } void Status::add_message(const QString &msg, const StatusType &type) { if (m_status_bar == nullptr || m_message_log == nullptr) { return; } m_status_bar->showMessage(msg); const QString timestamp = []() { const QDateTime current_datetime = QDateTime::currentDateTime(); return current_datetime.toString("hh:mm:ss"); }(); const QString timestamped_msg = QString("%1 %2").arg(timestamp, msg); const bool timestamps_ON = settings_get_variant(SETTING_timestamp_log).toBool(); const QColor color = [type]() { switch (type) { case StatusType_Success: return Qt::darkGreen; case StatusType_Error: return Qt::red; } return Qt::black; }(); const QColor original_color = m_message_log->textColor(); m_message_log->setTextColor(color); if (timestamps_ON) { m_message_log->append(timestamped_msg); } else { m_message_log->append(msg); } m_message_log->setTextColor(original_color); // Limit number of messages in log by deleting old ones // once over limit QTextCursor cursor = m_message_log->textCursor(); const int message_count = cursor.blockNumber(); if (message_count > MAX_MESSAGES_IN_LOG) { cursor.movePosition(QTextCursor::Start); cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, 0); cursor.select(QTextCursor::LineUnderCursor); cursor.removeSelectedText(); cursor.deleteChar(); } // Move cursor to newest message QTextCursor end_cursor = m_message_log->textCursor(); end_cursor.movePosition(QTextCursor::End); m_message_log->setTextCursor(end_cursor); } void Status::display_ad_messages(const QList<AdMessage> &messages, QWidget *parent) { log_messages(messages); ad_error_log(messages, parent); } void Status::display_ad_messages(const AdInterface &ad, QWidget *parent) { const QList<AdMessage> messages = ad.messages(); display_ad_messages(messages, parent); } void Status::log_messages(const QList<AdMessage> &messages) { if (m_status_bar == nullptr || m_message_log == nullptr) { return; } for (const AdMessage &message : messages) { const StatusType status_type = [message]() { switch (message.type()) { case AdMessageType_Success: return StatusType_Success; case AdMessageType_Error: return StatusType_Error; } return StatusType_Success; }(); add_message(message.text(), status_type); } } void Status::log_messages(const AdInterface &ad) { const QList<AdMessage> messages = ad.messages(); log_messages(messages); } void ad_error_log(const QList<AdMessage> &messages, QWidget *parent) { const QList<QString> error_list = [&]() { QList<QString> out; for (const auto &message : messages) { if (message.type() == AdMessageType_Error) { out.append(message.text()); } } return out; }(); error_log(error_list, parent); } void ad_error_log(const AdInterface &ad, QWidget *parent) { const QList<AdMessage> messages = ad.messages(); ad_error_log(messages, parent); } void error_log(const QList<QString> error_list, QWidget *parent) { if (error_list.isEmpty()) { return; } auto error_log_dialog = new ErrorLogDialog(parent); const QString errors_text = error_list.join("\n"); error_log_dialog->set_text(errors_text); error_log_dialog->open(); }
4,834
C++
.cpp
132
31.44697
85
0.681302
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,604
error_log_dialog.cpp
altlinux_admc/src/admc/error_log_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "error_log_dialog.h" #include "ui_error_log_dialog.h" #include "settings.h" ErrorLogDialog::ErrorLogDialog(QWidget *parent) : QDialog(parent) { ui = new Ui::ErrorLogDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); settings_setup_dialog_geometry(SETTING_error_log_dialog_geometry, this); } ErrorLogDialog::~ErrorLogDialog() { delete ui; } void ErrorLogDialog::set_text(const QString &text) { ui->text_edit->setPlainText(text); }
1,258
C++
.cpp
35
33.542857
76
0.749178
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,605
main_window_connection_error.cpp
altlinux_admc/src/admc/main_window_connection_error.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "main_window_connection_error.h" #include "ui_main_window_connection_error.h" #include "adldap.h" #include "connection_options_dialog.h" #include "globals.h" #include "main_window.h" #include "settings.h" #include "utils.h" MainWindowConnectionError::MainWindowConnectionError() : QMainWindow() { ui = new Ui::MainWindowConnectionError(); ui->setupUi(this); center_widget(this); connect( ui->retry_button, &QAbstractButton::clicked, this, &MainWindowConnectionError::on_retry_button); connect( ui->quit_button, &QAbstractButton::clicked, this, &MainWindowConnectionError::close); connect( ui->options_button, &QAbstractButton::clicked, this, &MainWindowConnectionError::open_connection_options); } MainWindowConnectionError::~MainWindowConnectionError() { delete ui; } void MainWindowConnectionError::on_retry_button() { AdInterface ad; if (ad_connected(ad, this)) { load_g_adconfig(ad); MainWindow *real_main_window = new MainWindow(ad, this); real_main_window->show(); QMainWindow::hide(); } } void MainWindowConnectionError::open_connection_options() { auto dialog = new ConnectionOptionsDialog(this); dialog->open(); }
2,045
C++
.cpp
58
31.551724
72
0.729757
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,606
about_dialog.cpp
altlinux_admc/src/admc/about_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "about_dialog.h" #include "ui_about_dialog.h" #include "config.h" AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent) { ui = new Ui::AboutDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); ui->version_label->setText(QString(tr("Version %1")).arg(ADMC_VERSION)); } AboutDialog::~AboutDialog() { delete ui; }
1,138
C++
.cpp
32
33.1875
76
0.739091
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
1,538,607
utils.cpp
altlinux_admc/src/admc/utils.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "utils.h" #include "adldap.h" #include "console_widget/console_widget.h" #include "globals.h" #include "settings.h" #include "status.h" #include <QAbstractItemModel> #include <QAbstractItemView> #include <QCheckBox> #include <QCursor> #include <QGuiApplication> #include <QHash> #include <QHeaderView> #include <QLineEdit> #include <QList> #include <QMap> #include <QMenu> #include <QMessageBox> #include <QModelIndex> #include <QPersistentModelIndex> #include <QPlainTextEdit> #include <QPoint> #include <QScreen> #include <QSortFilterProxyModel> #include <QStandardItem> #include <QStandardItemModel> #include <QTreeView> QMessageBox *message_box_generic(const QMessageBox::Icon icon, const QString &title, const QString &text, QWidget *parent); int get_range_upper(const QString &attribute); QList<QStandardItem *> make_item_row(const int count) { QList<QStandardItem *> row; for (int i = 0; i < count; i++) { const auto item = new QStandardItem(); row.append(item); } return row; } void set_horizontal_header_labels_from_map(QStandardItemModel *model, const QMap<int, QString> &labels_map) { for (int col = 0; col < model->columnCount(); col++) { const QString label = [=]() { if (labels_map.contains(col)) { return labels_map[col]; } else { return QString(); } }(); model->setHorizontalHeaderItem(col, new QStandardItem(label)); } } void set_line_edit_to_decimal_numbers_only(QLineEdit *edit) { edit->setValidator(new QRegExpValidator(QRegExp("[0-9]*"), edit)); } void enable_widget_on_selection(QWidget *widget, QAbstractItemView *view) { auto selection_model = view->selectionModel(); auto do_it = [widget, selection_model]() { const bool has_selection = selection_model->hasSelection(); widget->setEnabled(has_selection); }; QObject::connect( selection_model, &QItemSelectionModel::selectionChanged, do_it); do_it(); } void show_busy_indicator() { QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } void hide_busy_indicator() { QGuiApplication::restoreOverrideCursor(); } bool confirmation_dialog(const QString &text, QWidget *parent) { const bool confirm_actions = settings_get_variant(SETTING_confirm_actions).toBool(); if (!confirm_actions) { return true; } const QString title = QObject::tr("Confirm action"); const QMessageBox::StandardButton reply = QMessageBox::question(parent, title, text, QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { return true; } else { return false; } } void set_data_for_row(const QList<QStandardItem *> &row, const QVariant &data, const int role) { for (QStandardItem *item : row) { item->setData(data, role); } } bool ad_connected_base(const AdInterface &ad, QWidget *parent) { if (!ad.is_connected()) { ad_error_log(ad, parent); } return ad.is_connected(); } bool ad_connected(const AdInterface &ad, QWidget *parent) { return ad_connected_base(ad, parent); } bool ad_failed(const AdInterface &ad, QWidget *parent) { return !ad_connected_base(ad, parent); } QString get_classes_filter(const QList<QString> &class_list) { QList<QString> class_filters; for (const QString &object_class : class_list) { const QString class_filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_OBJECT_CLASS, object_class); class_filters.append(class_filter); } const QString out = filter_OR(class_filters); return out; } QString is_container_filter() { const QList<QString> accepted_classes = g_adconfig->get_filter_containers(); const QString out = get_classes_filter(accepted_classes); return out; } void limit_edit(QLineEdit *edit, const QString &attribute) { const int range_upper = get_range_upper(attribute); if (range_upper > 0) { edit->setMaxLength(range_upper); } } void limit_plain_text_edit(QPlainTextEdit *edit, const QString &attribute) { const int range_upper = get_range_upper(attribute); if (range_upper > 0) { QObject::connect( edit, &QPlainTextEdit::textChanged, edit, [edit, range_upper]() { const QString text = edit->toPlainText(); if (text.length() > range_upper) { edit->setPlainText(text.left(range_upper)); } }); } } QList<QPersistentModelIndex> persistent_index_list(const QList<QModelIndex> &indexes) { QList<QPersistentModelIndex> out; for (const QModelIndex &index : indexes) { out.append(QPersistentModelIndex(index)); } return out; } QList<QModelIndex> normal_index_list(const QList<QPersistentModelIndex> &indexes) { QList<QModelIndex> out; for (const QPersistentModelIndex &index : indexes) { out.append(QModelIndex(index)); } return out; } // Hide advanced view only" objects if advanced view setting // is off QString advanced_features_filter(const QString &filter) { const bool advanced_features_OFF = !settings_get_variant(SETTING_advanced_features).toBool(); if (advanced_features_OFF) { const QString advanced_features = filter_CONDITION(Condition_NotEquals, ATTRIBUTE_SHOW_IN_ADVANCED_VIEW_ONLY, LDAP_BOOL_TRUE); const QString out = filter_AND({filter, advanced_features}); return out; } else { return filter; } } // NOTE: configuration and schema objects are hidden so that // they don't show up in regular searches. Have to use // search_object() and manually add them to search results. void dev_mode_search_results(QHash<QString, AdObject> &results, AdInterface &ad, const QString &base) { const bool dev_mode = settings_get_variant(SETTING_feature_dev_mode).toBool(); if (!dev_mode) { return; } const QString domain_dn = g_adconfig->domain_dn(); const QString configuration_dn = g_adconfig->configuration_dn(); const QString schema_dn = g_adconfig->schema_dn(); if (base == domain_dn) { results[configuration_dn] = ad.search_object(configuration_dn); } else if (base == configuration_dn) { results[schema_dn] = ad.search_object(schema_dn); } } QMessageBox *message_box_generic(const QMessageBox::Icon icon, const QString &title, const QString &text, QWidget *parent) { auto message_box = new QMessageBox(parent); message_box->setAttribute(Qt::WA_DeleteOnClose); message_box->setStandardButtons(QMessageBox::Ok); message_box->setWindowTitle(title); message_box->setText(text); message_box->setIcon(icon); message_box->open(); return message_box; } QMessageBox *message_box_critical(QWidget *parent, const QString &title, const QString &text) { return message_box_generic(QMessageBox::Critical, title, text, parent); } QMessageBox *message_box_information(QWidget *parent, const QString &title, const QString &text) { return message_box_generic(QMessageBox::Information, title, text, parent); } QMessageBox *message_box_question(QWidget *parent, const QString &title, const QString &text) { return message_box_generic(QMessageBox::Question, title, text, parent); } QMessageBox *message_box_warning(QWidget *parent, const QString &title, const QString &text) { return message_box_generic(QMessageBox::Warning, title, text, parent); } QList<QString> index_list_to_dn_list(const QList<QModelIndex> &index_list, const int dn_role) { QList<QString> out; for (const QModelIndex &index : index_list) { const QString dn = index.data(dn_role).toString(); out.append(dn); } return out; } QList<QString> get_selected_dn_list(ConsoleWidget *console, const int type, const int dn_role) { const QList<QModelIndex> indexes = console->get_selected_items(type); const QList<QString> out = index_list_to_dn_list(indexes, dn_role); return out; } QString get_selected_target_dn(ConsoleWidget *console, const int type, const int dn_role) { const QList<QString> dn_list = get_selected_dn_list(console, type, dn_role); if (!dn_list.isEmpty()) { return dn_list[0]; } else { return QString(); } } void center_widget(QWidget *widget) { QScreen *primary_screen = QGuiApplication::primaryScreen(); if (primary_screen != nullptr) { widget->move(primary_screen->geometry().center() - widget->frameGeometry().center()); } } QString generate_new_name(const QList<QString> &existing_name_list, const QString &name_base) { const QString first = name_base; if (!existing_name_list.contains(first)) { return first; } int n = 2; auto get_name = [&]() { return QString("%1 (%2)").arg(name_base).arg(n); }; while (existing_name_list.contains(get_name())) { n++; // NOTE: new name caps out at 1000 as a reasonable // limit, not a bug if (n > 1000) { break; } } return get_name(); } QList<QString> variant_list_to_string_list(const QList<QVariant> &variant_list) { QList<QString> out; for (const QVariant &variant : variant_list) { const QString string = variant.toString(); out.append(string); } return out; } QList<QVariant> string_list_to_variant_list(const QList<QString> &string_list) { QList<QVariant> out; for (const QString &string : string_list) { const QVariant variant = QVariant(string); out.append(variant); } return out; } bool string_contains_bad_chars(const QString &string, const QString &bad_chars) { const QRegularExpression regexp = [&]() { const QString bad_chars_escaped = QRegularExpression::escape(bad_chars); const QString regexp_string = QString("[%1]").arg(bad_chars_escaped); const QRegularExpression out = QRegularExpression(regexp_string); return out; }(); const bool out = string.contains(regexp); return out; } bool verify_object_name(const QString &name, QWidget *parent) { const bool contains_bad_chars = [&]() { const bool some_bad_chars = string_contains_bad_chars(name, NAME_BAD_CHARS); const bool starts_with_space = name.startsWith(" "); const bool ends_with_space = name.endsWith(" "); const bool starts_with_question_mark = name.startsWith("?"); const bool out = (some_bad_chars || starts_with_space || ends_with_space || starts_with_question_mark); return out; }(); if (contains_bad_chars) { const QString error_text = QString(QCoreApplication::translate("utils.cpp", "Input field for Name contains one or more of the following illegal characters: # , + \" \\ < > ; = (leading space) (trailing space) (leading question mark)")); message_box_warning(parent, QCoreApplication::translate("utils.cpp", "Error"), error_text); return false; } return true; } void setup_lineedit_autofill(QLineEdit *src, QLineEdit *dest) { QObject::connect( src, &QLineEdit::textChanged, [src, dest]() { const QString src_input = src->text(); dest->setText(src_input); }); } void setup_full_name_autofill(QLineEdit *first_name_edit, QLineEdit *last_name_edit, QLineEdit *full_name_edit) { auto autofill_full_name = [=]() { const QString full_name_value = [=]() { const QString first_name = first_name_edit->text().trimmed(); const QString last_name = last_name_edit->text().trimmed(); const bool last_name_first = settings_get_variant(SETTING_last_name_before_first_name).toBool(); if (!first_name.isEmpty() && !last_name.isEmpty()) { if (last_name_first) { return last_name + " " + first_name; } else { return first_name + " " + last_name; } } else if (!first_name.isEmpty()) { return first_name; } else if (!last_name.isEmpty()) { return last_name; } else { return QString(); } }(); full_name_edit->setText(full_name_value); }; QObject::connect( first_name_edit, &QLineEdit::textChanged, first_name_edit, autofill_full_name); QObject::connect( last_name_edit, &QLineEdit::textChanged, last_name_edit, autofill_full_name); } int get_range_upper(const QString &attribute) { if (attribute == ATTRIBUTE_UPN_SUFFIXES) { // NOTE: schema doesn't define a max length for // "upn suffixes", but we do need a limit. Use // half of total max length of upn as a good // estimate. const int upn_suffix_max_length = [&]() { const int upn_max_length = g_adconfig->get_attribute_range_upper(ATTRIBUTE_USER_PRINCIPAL_NAME); const int out = upn_max_length / 2; return out; }(); return upn_suffix_max_length; } else { const int out = g_adconfig->get_attribute_range_upper(attribute); return out; } } void set_line_edit_to_hex_numbers_only(QLineEdit *edit) { edit->setValidator(new QRegExpValidator(QRegExp("[0-9a-f]*"), edit)); } void set_line_edit_to_time_span_format(QLineEdit *edit) { QRegExp time_span_reg_exp("([0-9]{1,4}:[0-2][0-3]:[0-5][0-9]:[0-5][0-9])|^\\(never\\)&|^\\(none\\)&"); edit->setValidator(new QRegExpValidator(time_span_reg_exp)); } QString gpo_status_from_int(int status) { switch (status) { case 0: return QObject::tr("Enabled"); case 1: return QObject::tr("User configuration disabled"); case 2: return QObject::tr("Computer configuration disabled"); case 3: return QObject::tr("Disabled"); default: return QObject::tr("Undefined GPO status"); } } QString current_dc_dns_host_name(AdInterface &ad) { const AdObject rootDSE = ad.search_object(""); const QString server_name = rootDSE.get_string(ATTRIBUTE_SERVER_NAME); const AdObject server = ad.search_object(server_name); const QString out = server.get_string(ATTRIBUTE_DNS_HOST_NAME); return out; }
15,049
C++
.cpp
382
33.819372
244
0.673004
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,608
find_widget.cpp
altlinux_admc/src/admc/find_widgets/find_widget.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "find_widget.h" #include "ui_find_widget.h" #include "adldap.h" #include "console_impls/find_object_impl.h" #include "console_impls/item_type.h" #include "console_impls/object_impl.h" #include "globals.h" #include "search_thread.h" #include "settings.h" #include "status.h" #include "utils.h" #include <QMenu> #include <QStandardItem> FindWidget::FindWidget(QWidget *parent) : QWidget(parent) { ui = new Ui::FindWidget(); ui->setupUi(this); action_view_icons = new QAction(tr("&Icons"), this); action_view_icons->setCheckable(true); action_view_list = new QAction(tr("&List"), this); action_view_list->setCheckable(true); action_view_detail = new QAction(tr("&Detail"), this); action_view_detail->setCheckable(true); action_customize_columns = new QAction(tr("&Customize Columns"), this); action_toggle_description_bar = new QAction(tr("&Description Bar"), this); action_toggle_description_bar->setCheckable(true); const ConsoleWidgetActions console_actions = [&]() { ConsoleWidgetActions out; out.view_icons = action_view_icons; out.view_list = action_view_list; out.view_detail = action_view_detail; out.toggle_description_bar = action_toggle_description_bar; out.customize_columns = action_customize_columns; // Use placeholders for unused actions out.navigate_up = new QAction(this); out.navigate_back = new QAction(this); out.navigate_forward = new QAction(this); out.refresh = new QAction(this); out.toggle_console_tree = new QAction(this); return out; }(); ui->console->set_actions(console_actions); object_impl = new ObjectImpl(ui->console); ui->console->register_impl(ItemType_Object, object_impl); object_impl->set_find_action_enabled(false); object_impl->set_refresh_action_enabled(false); auto find_object_impl = new FindObjectImpl(ui->console); ui->console->register_impl(ItemType_FindObject, find_object_impl); const QList<QStandardItem *> row = ui->console->add_scope_item(ItemType_FindObject, QModelIndex()); head_item = row[0]; head_item->setText(tr("Find results")); ui->console->set_scope_view_visible(false); const QModelIndex head_index = head_item->index(); ui->console->set_current_scope(head_index); connect( ui->find_button, &QPushButton::clicked, this, &FindWidget::find); connect( ui->clear_button, &QPushButton::clicked, this, &FindWidget::on_clear_button); // NOTE: need this for the case where dialog is closed // while a search is in progress. Without this busy // indicator stays on. connect( this, &QObject::destroyed, this, []() { hide_busy_indicator(); }); } FindWidget::~FindWidget() { delete ui; } void FindWidget::set_classes(const QList<QString> &class_list, const QList<QString> &selected_list) { ui->filter_widget->set_classes(class_list, selected_list); } void FindWidget::enable_filtering_all_classes() { ui->filter_widget->enable_filtering_all_classes(); } void FindWidget::set_default_base(const QString &default_base) { ui->select_base_widget->set_default_base(default_base); } void FindWidget::set_buddy_console(ConsoleWidget *buddy_console) { object_impl->set_buddy_console(buddy_console); } QVariant FindWidget::save_console_state() const { const QVariant state = ui->console->save_state(); return state; } void FindWidget::restore_console_state(const QVariant &state) { ui->console->restore_state(state); } void FindWidget::setup_action_menu(QMenu *menu) { ui->console->setup_menubar_action_menu(menu); } void FindWidget::setup_view_menu(QMenu *menu) { menu->addAction(action_view_icons); menu->addAction(action_view_list); menu->addAction(action_view_detail); menu->addSeparator(); menu->addAction(action_customize_columns); menu->addAction(action_toggle_description_bar); } void FindWidget::clear_results() { const QModelIndex head_index = head_item->index(); ui->console->delete_children(head_index); } void FindWidget::find() { // Prepare search args const QString filter = ui->filter_widget->get_filter(); const QString base = ui->select_base_widget->get_base(); const QList<QString> search_attributes = console_object_search_attributes(); auto find_thread = new SearchThread(base, SearchScope_All, filter, search_attributes); connect( find_thread, &SearchThread::results_ready, this, &FindWidget::handle_find_thread_results); connect( this, &QObject::destroyed, find_thread, &SearchThread::stop); connect( ui->stop_button, &QPushButton::clicked, find_thread, &SearchThread::stop); connect( find_thread, &SearchThread::finished, this, [this, find_thread]() { g_status->display_ad_messages(find_thread->get_ad_messages(), this); search_thread_display_errors(find_thread, this); ui->find_button->setEnabled(true); ui->clear_button->setEnabled(true); hide_busy_indicator(); find_thread->deleteLater(); }); show_busy_indicator(); // NOTE: disable find and clear buttons, do not want // those functions to be available while a search is in // progress ui->find_button->setEnabled(false); ui->clear_button->setEnabled(false); clear_results(); find_thread->start(); } void FindWidget::handle_find_thread_results(const QHash<QString, AdObject> &results) { const QModelIndex head_index = head_item->index(); for (const AdObject &object : results) { const QList<QStandardItem *> row = ui->console->add_results_item(ItemType_Object, head_index); console_object_load(row, object); } } QList<QString> FindWidget::get_selected_dns() const { const QList<QModelIndex> indexes = ui->console->get_selected_items(ItemType_Object); const QList<QString> out = index_list_to_dn_list(indexes, ObjectRole_DN); return out; } void FindWidget::on_clear_button() { ui->filter_widget->clear(); clear_results(); }
7,011
C++
.cpp
177
34.615819
103
0.695831
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,609
find_policy_dialog.cpp
altlinux_admc/src/admc/find_widgets/find_policy_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "find_policy_dialog.h" #include "find_policy_dialog_p.h" #include "ui_find_policy_dialog.h" #include "adldap.h" #include "console_impls/find_policy_impl.h" #include "console_impls/found_policy_impl.h" #include "console_impls/item_type.h" #include "globals.h" #include "search_thread.h" #include "settings.h" #include "status.h" #include "utils.h" #include <QAction> #include <QMenuBar> #include <QStandardItem> FindPolicyDialog::FindPolicyDialog(ConsoleWidget *buddy_console, QWidget *parent) : QDialog(parent) { ui = new Ui::FindPolicyDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto menubar = new QMenuBar(); layout()->setMenuBar(menubar); auto action_menu = menubar->addMenu(tr("&Action")); menubar->setContextMenuPolicy(Qt::PreventContextMenu); auto view_menu = menubar->addMenu(tr("&View")); ui->find_button->setDefault(true); // Fill search item combo const QList<SearchItem> search_item_list = { SearchItem_Name, SearchItem_GUID, }; for (const SearchItem &search_item : search_item_list) { const QString search_item_string = [&]() { switch (search_item) { case SearchItem_Name: return tr("Name"); case SearchItem_GUID: return tr("GUID"); } return QString(); }(); ui->search_item_combo->addItem(search_item_string, (int) search_item); } // Fill condition combo const QList<Condition> condition_list = { Condition_Contains, Condition_Equals, Condition_StartsWith, Condition_EndsWith, }; for (const Condition &condition : condition_list) { const QString condition_string = condition_to_display_string(condition); ui->condition_combo->addItem(condition_string, (int) condition); } // Setup console auto find_impl = new FindPolicyImpl(ui->console); ui->console->register_impl(ItemType_FindPolicy, find_impl); auto found_policy_impl = new FoundPolicyImpl(ui->console); ui->console->register_impl(ItemType_FoundPolicy, found_policy_impl); found_policy_impl->set_buddy_console(buddy_console); auto action_view_icons = new QAction(tr("&Icons"), this); action_view_icons->setCheckable(true); auto action_view_list = new QAction(tr("&List"), this); action_view_list->setCheckable(true); auto action_view_detail = new QAction(tr("&Detail"), this); action_view_detail->setCheckable(true); auto action_customize_columns = new QAction(tr("&Customize Columns"), this); auto action_toggle_description_bar = new QAction(tr("&Description Bar"), this); action_toggle_description_bar->setCheckable(true); const ConsoleWidgetActions console_actions = [&]() { ConsoleWidgetActions out; out.view_icons = action_view_icons; out.view_list = action_view_list; out.view_detail = action_view_detail; out.toggle_description_bar = action_toggle_description_bar; out.customize_columns = action_customize_columns; // Use placeholders for unused actions out.navigate_up = new QAction(this); out.navigate_back = new QAction(this); out.navigate_forward = new QAction(this); out.refresh = new QAction(this); out.toggle_console_tree = new QAction(this); return out; }(); ui->console->set_actions(console_actions); ui->console->setup_menubar_action_menu(action_menu); view_menu->addAction(action_view_icons); view_menu->addAction(action_view_list); view_menu->addAction(action_view_detail); view_menu->addSeparator(); view_menu->addAction(action_customize_columns); view_menu->addAction(action_toggle_description_bar); const QList<QStandardItem *> row = ui->console->add_scope_item(ItemType_FindPolicy, QModelIndex()); head_item = row[0]; head_item->setText(tr("Find results")); ui->console->set_scope_view_visible(false); const QModelIndex head_index = head_item->index(); ui->console->set_current_scope(head_index); settings_setup_dialog_geometry(SETTING_find_policy_dialog_geometry, this); const QVariant console_state = settings_get_variant(SETTING_find_policy_dialog_console_state); ui->console->restore_state(console_state); connect( ui->add_button, &QAbstractButton::clicked, this, &FindPolicyDialog::add_filter); connect( ui->find_button, &QAbstractButton::clicked, this, &FindPolicyDialog::find); connect( ui->clear_button, &QAbstractButton::clicked, this, &FindPolicyDialog::clear_results); } FindPolicyDialog::~FindPolicyDialog() { const QVariant console_state = ui->console->save_state(); settings_set_variant(SETTING_find_policy_dialog_console_state, console_state); delete ui; } void FindPolicyDialog::add_filter() { const QString filter = [&]() { const QString attribute = [&]() -> QString { const SearchItem search_item = (SearchItem) ui->search_item_combo->currentData().toInt(); switch (search_item) { case SearchItem_Name: return ATTRIBUTE_DISPLAY_NAME; case SearchItem_GUID: return ATTRIBUTE_CN; } return QString(); }(); const Condition condition = (Condition) ui->condition_combo->currentData().toInt(); const QString value = ui->value_edit->text(); const QString out = filter_CONDITION(condition, attribute, value); return out; }(); const QString filter_display = [&]() { const QString search_item_display = [&]() -> QString { const SearchItem search_item = (SearchItem) ui->search_item_combo->currentData().toInt(); switch (search_item) { case SearchItem_Name: return tr("Name"); case SearchItem_GUID: return tr("GUID"); } return QString(); }(); const QString condition_display = [&]() { const Condition condition = (Condition) ui->condition_combo->currentData().toInt(); const QString out = condition_to_display_string(condition); return out; }(); const QString value = ui->value_edit->text(); const QString out = QString("%1 %2: \"%3\"").arg(search_item_display, condition_display, value); return out; }(); auto item = new QListWidgetItem(); item->setText(filter_display); item->setData(Qt::UserRole, filter); ui->filter_list->addItem(item); ui->value_edit->clear(); } void FindPolicyDialog::find() { const QString base = g_adconfig->policies_dn(); const QString filter = [this]() { QList<QString> filter_string_list; for (int i = 0; i < ui->filter_list->count(); i++) { const QListWidgetItem *item = ui->filter_list->item(i); const QString this_filter = item->data(Qt::UserRole).toString(); filter_string_list.append(this_filter); } const QString out = filter_AND(filter_string_list); return out; }(); const QList<QString> search_attributes = QList<QString>(); auto search_thread = new SearchThread(base, SearchScope_Children, filter, search_attributes); connect( search_thread, &SearchThread::results_ready, this, &FindPolicyDialog::handle_search_thread_results); connect( this, &QObject::destroyed, search_thread, &SearchThread::stop); connect( ui->stop_button, &QPushButton::clicked, search_thread, &SearchThread::stop); connect( search_thread, &SearchThread::finished, this, [this, search_thread]() { g_status->display_ad_messages(search_thread->get_ad_messages(), this); search_thread_display_errors(search_thread, this); ui->find_button->setEnabled(true); ui->clear_button->setEnabled(true); hide_busy_indicator(); search_thread->deleteLater(); }); show_busy_indicator(); // NOTE: disable find and clear buttons, do not want // those functions to be available while a search is in // progress ui->find_button->setEnabled(false); ui->clear_button->setEnabled(false); clear_results(); search_thread->start(); } void FindPolicyDialog::handle_search_thread_results(const QHash<QString, AdObject> &results) { const QModelIndex head_index = head_item->index(); for (const AdObject &object : results.values()) { const QList<QStandardItem *> row = ui->console->add_results_item(ItemType_FoundPolicy, head_index); found_policy_impl_load(row, object); } } void FindPolicyDialog::clear_results() { const QModelIndex head_index = head_item->index(); ui->console->delete_children(head_index); }
9,663
C++
.cpp
226
36.026549
107
0.667627
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,610
find_object_dialog.cpp
altlinux_admc/src/admc/find_widgets/find_object_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "find_object_dialog.h" #include "ui_find_object_dialog.h" #include "ad_config.h" #include "ad_filter.h" #include "find_widget.h" #include "globals.h" #include "settings.h" #include <QMenuBar> FindObjectDialog::FindObjectDialog(ConsoleWidget *buddy_console, const QString &default_base, QWidget *parent) : QDialog(parent) { ui = new Ui::FindObjectDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto menubar = new QMenuBar(); layout()->setMenuBar(menubar); auto action_menu = menubar->addMenu(tr("&Action")); menubar->setContextMenuPolicy(Qt::PreventContextMenu); auto view_menu = menubar->addMenu(tr("&View")); const QList<QString> class_list = filter_classes; const QList<QString> selected_list = { CLASS_USER, CLASS_CONTACT, CLASS_GROUP, }; ui->find_widget->set_buddy_console(buddy_console); ui->find_widget->set_classes(class_list, selected_list); ui->find_widget->set_default_base(default_base); ui->find_widget->setup_action_menu(action_menu); ui->find_widget->setup_view_menu(view_menu); ui->find_widget->enable_filtering_all_classes(); settings_setup_dialog_geometry(SETTING_find_object_dialog_geometry, this); const QVariant console_state = settings_get_variant(SETTING_find_object_dialog_console_state); ui->find_widget->restore_console_state(console_state); } FindObjectDialog::~FindObjectDialog() { const QVariant console_state = ui->find_widget->save_console_state(); settings_set_variant(SETTING_find_object_dialog_console_state, console_state); delete ui; }
2,400
C++
.cpp
58
37.862069
110
0.734764
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,611
icon_manager.cpp
altlinux_admc/src/admc/icon_manager/icon_manager.cpp
#include "icon_manager.h" #include "ad_defines.h" #include "utils.h" #include "ad_utils.h" #include "ad_object.h" #include "settings.h" #include "globals.h" #include "status.h" #include <QPainter> #include <QPixmap> #include <QAction> #include <QDir> #include <QTextStream> #include <QDebug> IconManager::IconManager() { } void IconManager::init(QMap<QString, QAction *> category_action_map) { append_actions(category_action_map); // NOTE: use a list of possible icons because // default icon themes for different DE's don't // fully intersect category_to_icon_list = { {OBJECT_CATEGORY_DOMAIN_DNS, {"network-server"}}, {OBJECT_CATEGORY_CONTAINER, {"folder"}}, {OBJECT_CATEGORY_OU, {"folder-documents"}}, {OBJECT_CATEGORY_GROUP, {"system-users"}}, {OBJECT_CATEGORY_PERSON, {"avatar-default", "avatar-default-symbolic"}}, {OBJECT_CATEGORY_COMPUTER, {"computer"}}, {OBJECT_CATEGORY_GP_CONTAINER, {"preferences-other"}}, {OBJECT_CATEGORY_VOLUME, {"folder-templates"}}, {OBJECT_CATEGORY_SERVERS_CONTAINER, {"folder"}}, {OBJECT_CATEGORY_SITE, {"go-home"}}, // These categories are not AD object categories. They are used within ADMC context {ADMC_CATEGORY_QUERY_ITEM, {"document-send"}}, {ADMC_CATEGORY_QUERY_FOLDER, {"folder"}}, {ADMC_CATEGORY_ALL_POLICIES_FOLDER, {"folder"}}, {ADMC_CATEGORY_GP_OBJECTS, {"folder"}}, {ADMC_CATEGORY_FSMO_ROLE_CONTAINER, {"applications-system"}}, {ADMC_CATEGORY_FSMO_ROLE, {"emblem-system"}}, {ADMC_CATEGORY_DOMAIN_INFO_ITEM, {"network-workgroup"}}, // Icons for some system containers and objects {OBJECT_CATEGORY_BUILTIN, {"emblem-system", "emblem-system-symbolic"}}, {OBJECT_CATEGORY_LOST_AND_FOUND, {"emblem-system", "emblem-system-symbolic"}}, {OBJECT_CATEGORY_INFRASTRUCTURE_UPDATE, {"emblem-system", "emblem-system-symbolic"}}, {OBJECT_CATEGORY_MSDS_QUOTA_CONTAINER, {"emblem-system", "emblem-system-symbolic"}}, {OBJECT_CATEGORY_PSO, {"preferences-desktop-personal"}}, {OBJECT_CATEGORY_PSO_CONTAINER, {"preferences-desktop"}}, }; // Indicator icons indicator_map = { {inheritance_indicator, {"changes-prevent"}}, {enforced_indicator, {"stop"}}, {block_indicator, {"dialog-error"}}, {link_indicator, {"mail-forward"}}, {search_indicator, {"system-search"}}, {warning_indicator, {"dialog-warning"}} }; // NOTE: This is the icon used when no icon is // defined for some object category error_icon = "dialog-question"; QString custom_themes_path = settings_get_variant(SETTING_custom_icon_themes_path).toString(); if (custom_themes_path.isEmpty()) { custom_themes_path = "/usr/share/ad-integration-themes"; settings_set_variant(SETTING_custom_icon_themes_path, custom_themes_path); } QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << custom_themes_path); system_theme = QIcon::themeName(); const QString current_theme = settings_get_variant(SETTING_current_icon_theme).toString(); const bool theme_is_available = get_available_themes().contains(current_theme); if (theme_is_available) { set_theme(current_theme); } else { set_theme(system_theme); if (!current_theme.isEmpty()) { g_status->add_message(QObject::tr("Theme from settings not found. System theme is set."), StatusType_Error); } } } QIcon IconManager::overlay_scope_item_icon(const QIcon &clean_icon, const QIcon &overlay_icon, IconOverlayPosition position) const { QIcon overlapped_icon; //Icon looks not distorted with 16x16 size QPixmap original_pixmap = clean_icon.pixmap(32, 32); QPixmap overlay_pixmap = overlay_icon.pixmap(10, 10); QPainter painter(&original_pixmap); switch (position) { case IconOverlayPosition_BottomLeft: painter.drawPixmap(0, original_pixmap.height() - 8, overlay_pixmap); break; case IconOverlayPosition_TopLeft: painter.drawPixmap(0, 0, overlay_pixmap); break; case IconOverlayPosition_TopRight: painter.drawPixmap(original_pixmap.width() - 8, 0, overlay_pixmap); break; case IconOverlayPosition_BottomRight: painter.drawPixmap(original_pixmap.width() - 8, original_pixmap.height() - 8, overlay_pixmap); break; default: break; } overlapped_icon.addPixmap(original_pixmap); return overlapped_icon; } QIcon IconManager::overlay_scope_item_icon(const QIcon &clean_icon, const QIcon &overlay_icon, const QSize &clean_icon_size, const QSize &overlay_icon_size, const QPoint &pos) const { QIcon overlapped_icon; //Icon looks not distorted with 16x16 size QPixmap original_pixmap = clean_icon.pixmap(clean_icon_size.height(), clean_icon_size.width()); QPixmap overlay_pixmap = overlay_icon.pixmap(overlay_icon_size); QPainter painter(&original_pixmap); painter.drawPixmap(pos.x(), pos.y(), overlay_pixmap); overlapped_icon.addPixmap(original_pixmap); return overlapped_icon; } void IconManager::update_action_icons() { for (const QString &category : category_action_map.keys()) { category_action_map[category]->setIcon(get_object_icon(category)); } } void IconManager::update_icons_array() { type_index_icons_array[ItemIconType_Policy_Clean] = get_object_icon(OBJECT_CATEGORY_GP_CONTAINER); type_index_icons_array[ItemIconType_Policy_Link] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Policy_Clean], get_indicator_icon(link_indicator), QSize(16, 16), QSize(12, 12), QPoint(-2, 6)); type_index_icons_array[ItemIconType_Policy_Link_Disabled] = type_index_icons_array[ItemIconType_Policy_Link].pixmap(16, 16, QIcon::Disabled); type_index_icons_array[ItemIconType_Policy_Enforced] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Policy_Link], get_indicator_icon(enforced_indicator), QSize(16, 16), QSize(8, 8), QPoint(8, 8)); type_index_icons_array[ItemIconType_Policy_Enforced_Disabled] = type_index_icons_array[ItemIconType_Policy_Enforced].pixmap(16, 16, QIcon::Disabled); type_index_icons_array[ItemIconType_OU_Clean] = get_object_icon(OBJECT_CATEGORY_OU); type_index_icons_array[ItemIconType_OU_InheritanceBlocked] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_OU_Clean], get_indicator_icon(inheritance_indicator), QSize(16, 16), QSize(10, 10), QPoint(6, 6)); type_index_icons_array[ItemIconType_Domain_Clean] = get_object_icon(OBJECT_CATEGORY_DOMAIN_DNS); type_index_icons_array[ItemIconType_Domain_InheritanceBlocked] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Domain_Clean], get_indicator_icon(inheritance_indicator), QSize(16, 16), QSize(10, 10), QPoint(6, 6)); type_index_icons_array[ItemIconType_Person_Clean] = get_object_icon(OBJECT_CATEGORY_PERSON).pixmap(max_icon_size); type_index_icons_array[ItemIconType_Person_Blocked] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Person_Clean], get_indicator_icon(block_indicator), max_icon_size, QSize(max_icon_size.width()/2, max_icon_size.height()/2), QPoint(max_icon_size.width()/2, max_icon_size.width()/2)); type_index_icons_array[ItemIconType_Site_Clean] = get_object_icon(OBJECT_CATEGORY_SITE); type_index_icons_array[ItemIconType_Computer_Clean] = get_object_icon(OBJECT_CATEGORY_COMPUTER).pixmap(max_icon_size); type_index_icons_array[ItemIconType_Computer_Blocked] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Computer_Clean], get_indicator_icon(block_indicator), max_icon_size, QSize(max_icon_size.width()/2, max_icon_size.height()/2), QPoint(max_icon_size.width()/2, max_icon_size.width()/2)); type_index_icons_array[ItemIconType_Group_Clean] = get_object_icon(OBJECT_CATEGORY_GROUP).pixmap(max_icon_size); } const QIcon &IconManager::get_icon_for_type(ItemIconType icon_type) const { const QIcon &icon = type_index_icons_array[icon_type]; return icon; } QIcon IconManager::get_object_icon(const AdObject &object) const { const QString object_category = [&]() { const QString category_dn = object.get_string(ATTRIBUTE_OBJECT_CATEGORY); const QString out = dn_get_name(category_dn); return out; }(); const QIcon out = get_object_icon(object_category); return out; } QIcon IconManager::get_object_icon(const QString &object_category) const { const QString icon_name = [&]() -> QString { const QList<QString> fallback_icon_list = { fallback_icon_name, "emblem-system", "emblem-system-symbolic", "dialog-question", }; QList<QString> icon_name_list = category_to_icon_list.value(object_category, fallback_icon_list); icon_name_list.prepend(object_category); for (const QString &icon : icon_name_list) { if (QIcon::hasThemeIcon(icon)) { return icon; } } return error_icon; }(); const QIcon icon = QIcon::fromTheme(icon_name); return icon; } QIcon IconManager::get_indicator_icon(const QString &indicator_icon_name) const { if (indicator_icon_name.isEmpty()) { return QIcon::fromTheme(error_icon); } QList<QString> icon_name_list = indicator_map[indicator_icon_name]; icon_name_list.prepend(indicator_icon_name); icon_name_list.append(fallback_icon_name); QIcon icon; for (const QString &icon_name : icon_name_list) { if (QIcon::hasThemeIcon(icon_name)) { icon = QIcon::fromTheme(icon_name); return icon; } } icon = QIcon::fromTheme(error_icon); return icon; } void IconManager::set_theme(const QString &icons_theme) { if (theme == icons_theme && !icons_theme.isEmpty()) { return; } theme = icons_theme.isEmpty() ? QIcon::fallbackThemeName() : icons_theme; QIcon::setThemeName(icons_theme); settings_set_variant(SETTING_current_icon_theme, icons_theme); update_action_icons(); update_icons_array(); } void IconManager::append_actions(const QMap<QString, QAction *> &categorized_actions) { category_action_map.insert(categorized_actions); } QStringList IconManager::get_available_themes() { QStringList available_themes = {system_theme}; // Check existence and add themes from custom path const QDir custom_themes_dir = settings_get_variant(SETTING_custom_icon_themes_path).toString(); for (const QString &theme_dir : custom_themes_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { const QDir dir(custom_themes_dir.filePath(theme_dir)); if (dir.exists("index.theme")) { available_themes.append(theme_dir); } } return available_themes; } QString IconManager::get_localized_theme_name(const QLocale locale, const QString &theme) { // Map is used for concatenation "Name" string with corresponding // language string/regexp in [] brackets for localized name search const QMap<QLocale::Language, QString> language_string_map = { {QLocale::Russian, "[ru]"} }; const QLocale::Language language = locale.language(); const QString search_string = "Name="; const QString search_string_localized = language_string_map.contains(language) ? QString("Name%1=").arg(language_string_map[language]): QString(); const bool theme_is_system = theme == system_theme; const QDir theme_dir = theme_is_system ? QDir(system_icons_dir_path).filePath(theme) : QDir(settings_get_variant(SETTING_custom_icon_themes_path). toString()).filePath(theme); QFile index_theme_file(theme_dir.filePath("index.theme")); index_theme_file.open(QIODevice::ReadOnly); QString theme_name; QTextStream in(&index_theme_file); QString line; do { line = in.readLine(); if (line.contains(search_string, Qt::CaseSensitive)) { theme_name = line.remove(search_string); } if (!search_string_localized.isEmpty() && line.contains(search_string_localized, Qt::CaseSensitive)) { theme_name = line.remove(search_string_localized); break; } } while (!line.isNull()); index_theme_file.close(); if (theme_is_system) { theme_name += QObject::tr(" (System)"); } return theme_name; }
13,581
C++
.cpp
266
41.105263
181
0.638866
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,612
select_object_advanced_dialog.cpp
altlinux_admc/src/admc/select_dialogs/select_object_advanced_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "select_object_advanced_dialog.h" #include "ui_select_object_advanced_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" #include <QMenuBar> SelectObjectAdvancedDialog::SelectObjectAdvancedDialog(const QList<QString> classes, QWidget *parent) : QDialog(parent) { ui = new Ui::SelectObjectAdvancedDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto menubar = new QMenuBar(); layout()->setMenuBar(menubar); auto view_menu = menubar->addMenu(tr("&View")); ui->find_widget->set_classes(classes, classes); ui->find_widget->setup_view_menu(view_menu); const QVariant console_state = settings_get_variant(SETTING_select_object_advanced_dialog_console_state); ui->find_widget->restore_console_state(console_state); settings_setup_dialog_geometry(SETTING_select_object_advanced_dialog_geometry, this); } SelectObjectAdvancedDialog::~SelectObjectAdvancedDialog() { const QVariant console_state = ui->find_widget->save_console_state(); settings_set_variant(SETTING_select_object_advanced_dialog_console_state, console_state); delete ui; } QList<QString> SelectObjectAdvancedDialog::get_selected_dns() const { return ui->find_widget->get_selected_dns(); }
2,039
C++
.cpp
47
40.468085
109
0.758586
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,613
select_object_match_dialog.cpp
altlinux_admc/src/admc/select_dialogs/select_object_match_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "select_object_match_dialog.h" #include "ui_select_object_match_dialog.h" #include "console_impls/object_impl.h" #include "select_object_dialog.h" #include "settings.h" #include "utils.h" #include <QPushButton> #include <QStandardItemModel> SelectObjectMatchDialog::SelectObjectMatchDialog(const QHash<QString, AdObject> &search_results, QWidget *parent) : QDialog(parent) { ui = new Ui::SelectObjectMatchDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); model = new QStandardItemModel(this); model->setHorizontalHeaderLabels(SelectObjectDialog::header_labels()); ui->view->sortByColumn(0, Qt::AscendingOrder); ui->view->setModel(model); for (const AdObject &object : search_results) { add_select_object_to_model(model, object); } QPushButton *ok_button = ui->button_box->button(QDialogButtonBox::Ok); enable_widget_on_selection(ok_button, ui->view); settings_setup_dialog_geometry(SETTING_select_object_match_dialog_geometry, this); settings_restore_header_state(SETTING_select_object_match_header_state, ui->view->header()); } SelectObjectMatchDialog::~SelectObjectMatchDialog() { settings_save_header_state(SETTING_select_object_match_header_state, ui->view->header()); delete ui; } QList<QString> SelectObjectMatchDialog::get_selected() const { QList<QString> out; const QList<QModelIndex> selected_indexes = ui->view->selectionModel()->selectedRows(); for (const QModelIndex &index : selected_indexes) { const QString dn = index.data(ObjectRole_DN).toString(); out.append(dn); } return out; }
2,417
C++
.cpp
57
38.964912
113
0.746052
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,614
select_container_dialog.cpp
altlinux_admc/src/admc/select_dialogs/select_container_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "select_container_dialog.h" #include "ui_select_container_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" #include "status.h" #include "utils.h" #include "icon_manager/icon_manager.h" #include <QDialogButtonBox> #include <QHeaderView> #include <QPushButton> #include <QSortFilterProxyModel> #include <QStandardItemModel> #include <QTreeView> #include <QVBoxLayout> QStandardItem *make_container_node(const AdObject &object); SelectContainerDialog::SelectContainerDialog(AdInterface &ad, QWidget *parent) : QDialog(parent) { ui = new Ui::SelectContainerDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); ui->view->sortByColumn(0, Qt::AscendingOrder); model = new QStandardItemModel(this); proxy_model = new QSortFilterProxyModel(this); proxy_model->setSourceModel(model); proxy_model->setSortCaseSensitivity(Qt::CaseInsensitive); ui->view->setModel(proxy_model); // Hide all columns except name column QHeaderView *header = ui->view->header(); for (int i = 0; i < header->count(); i++) { header->setSectionHidden(i, true); } header->setSectionHidden(0, false); QPushButton *ok_button = ui->button_box->button(QDialogButtonBox::Ok); enable_widget_on_selection(ok_button, ui->view); // Load head object const QString head_dn = g_adconfig->domain_dn(); const AdObject head_object = ad.search_object(head_dn); QStandardItem *item = make_container_node(head_object); model->appendRow(item); // NOTE: geometry is shared with the subclass // MoveObjectDialog but that is intended. settings_setup_dialog_geometry(SETTING_select_container_dialog_geometry, this); connect( ui->view, &QTreeView::expanded, this, &SelectContainerDialog::on_item_expanded); } SelectContainerDialog::~SelectContainerDialog() { delete ui; } QString SelectContainerDialog::get_selected() const { const QModelIndex selected_index = ui->view->selectionModel()->currentIndex(); const QString dn = selected_index.data(ContainerRole_DN).toString(); return dn; } void SelectContainerDialog::fetch_node(const QModelIndex &proxy_index) { const QModelIndex index = proxy_model->mapToSource(proxy_index); AdInterface ad; if (ad_failed(ad, this)) { return; } show_busy_indicator(); model->removeRows(0, model->rowCount(index), index); const QString base = index.data(ContainerRole_DN).toString(); const SearchScope scope = SearchScope_Children; const QString filter = [=]() { QString out; out = is_container_filter(); out = advanced_features_filter(out); return out; }(); const QList<QString> attributes = QList<QString>(); QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); dev_mode_search_results(results, ad, base); QStandardItem *parent = model->itemFromIndex(index); for (const AdObject &object : results.values()) { auto item = make_container_node(object); parent->appendRow(item); } parent->setData(true, ContainerRole_Fetched); hide_busy_indicator(); } void SelectContainerDialog::on_item_expanded(const QModelIndex &index) { const bool fetched = index.data(ContainerRole_Fetched).toBool(); if (!fetched) { fetch_node(index); } } QStandardItem *make_container_node(const AdObject &object) { auto item = new QStandardItem(); item->setData(false, ContainerRole_Fetched); // NOTE: add fake child to new items, so that the child indicator is shown while they are childless until they are fetched item->appendRow(new QStandardItem()); const QString dn = object.get_dn(); item->setData(dn, ContainerRole_DN); const QString name = dn_get_name(dn); item->setText(name); const QIcon icon = g_icon_manager->get_object_icon(object); item->setIcon(icon); return item; }
4,742
C++
.cpp
120
35.275
126
0.721143
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,615
select_policy_dialog.cpp
altlinux_admc/src/admc/select_dialogs/select_policy_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "select_policy_dialog.h" #include "ui_select_policy_dialog.h" #include "adldap.h" #include "console_impls/policy_impl.h" #include "globals.h" #include "settings.h" #include "status.h" #include "utils.h" #include <QPushButton> #include <QStandardItemModel> SelectPolicyDialog::SelectPolicyDialog(AdInterface &ad, QWidget *parent) : QDialog(parent) { ui = new Ui::SelectPolicyDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); model = new QStandardItemModel(this); ui->view->setModel(model); ui->view->setHeaderHidden(true); QPushButton *ok_button = ui->button_box->button(QDialogButtonBox::Ok); enable_widget_on_selection(ok_button, ui->view); const QString base = g_adconfig->domain_dn(); const SearchScope scope = SearchScope_All; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_OBJECT_CLASS, CLASS_GP_CONTAINER); const QList<QString> attributes = QList<QString>(); const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); for (const AdObject &object : results.values()) { auto item = new QStandardItem(); model->appendRow(item); console_policy_load_item(item, object); } settings_setup_dialog_geometry(SETTING_select_policy_dialog_geometry, this); } SelectPolicyDialog::~SelectPolicyDialog() { delete ui; } QList<QString> SelectPolicyDialog::get_selected_dns() const { QList<QString> dns; const QList<QModelIndex> indexes = ui->view->selectionModel()->selectedRows(); for (const QModelIndex &index : indexes) { const QString dn = index.data(PolicyRole_DN).toString(); dns.append(dn); } return dns; }
2,492
C++
.cpp
63
35.968254
106
0.731758
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,616
select_object_dialog.cpp
altlinux_admc/src/admc/select_dialogs/select_object_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "select_object_dialog.h" #include "ui_select_object_dialog.h" #include "adldap.h" #include "console_impls/object_impl.h" #include "globals.h" #include "select_object_advanced_dialog.h" #include "select_object_match_dialog.h" #include "settings.h" #include "utils.h" #include <QStandardItemModel> enum SelectColumn { SelectColumn_Name, SelectColumn_Type, SelectColumn_Folder, SelectColumn_COUNT, }; SelectObjectDialog::SelectObjectDialog(const QList<QString> class_list_arg, const SelectObjectDialogMultiSelection multi_selection_arg, QWidget *parent) : QDialog(parent) { ui = new Ui::SelectObjectDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); class_list = class_list_arg; multi_selection = multi_selection_arg; const QList<QString> selected_list = class_list; ui->select_classes_widget->set_classes(class_list, selected_list); model = new QStandardItemModel(this); model->setHorizontalHeaderLabels(header_labels()); ui->view->setModel(model); enable_widget_on_selection(ui->remove_button, ui->view); settings_setup_dialog_geometry(SETTING_select_object_dialog_geometry, this); settings_restore_header_state(SETTING_select_object_header_state, ui->view->header()); connect( ui->add_button, &QPushButton::clicked, this, &SelectObjectDialog::on_add_button); connect( ui->remove_button, &QAbstractButton::clicked, this, &SelectObjectDialog::on_remove_button); connect( ui->advanced_button, &QPushButton::clicked, this, &SelectObjectDialog::open_advanced_dialog); } SelectObjectDialog::~SelectObjectDialog() { settings_save_header_state(SETTING_select_object_header_state, ui->view->header()); delete ui; } QList<QString> SelectObjectDialog::header_labels() { const QList<QString> out = { tr("Name"), tr("Type"), tr("Folder"), }; return out; } QList<QString> SelectObjectDialog::get_selected() const { QList<QString> out; for (int row = 0; row < model->rowCount(); row++) { const QModelIndex index = model->index(row, 0); const QString dn = index.data(ObjectRole_DN).toString(); out.append(dn); } return out; } QList<SelectedObjectData> SelectObjectDialog::get_selected_advanced() const { QList<SelectedObjectData> out; for (int row = 0; row < model->rowCount(); row++) { const QModelIndex index = model->index(row, 0); const QString dn = index.data(ObjectRole_DN).toString(); const QString category = index.data(ObjectRole_ObjectCategory).toString(); out.append({dn, category}); } return out; } void SelectObjectDialog::accept() { const QList<QString> selected = get_selected(); const bool selected_multiple_when_single_selection = (multi_selection == SelectObjectDialogMultiSelection_No && selected.size() > 1); if (selected_multiple_when_single_selection) { message_box_warning(this, tr("Error"), tr("This selection accepts only one object. Remove extra objects to proceed.")); } else if (selected.isEmpty()) { // TODO: replace with "ok" button turning off // if selection is empty. but the // "selected_multiple_when_single_selection" // should still be done via warning, otherwise // would be confusing message_box_warning(this, tr("Error"), tr("You must select at least one object.")); } else { QDialog::accept(); } } void SelectObjectDialog::on_add_button() { if (ui->name_edit->text().isEmpty()) { return; } AdInterface ad; if (ad_failed(ad, this)) { return; } const QString base = ui->select_base_widget->get_base(); const QString filter = [&]() { const QString entered_name = ui->name_edit->text(); const QString name_filter = filter_OR({ filter_CONDITION(Condition_StartsWith, ATTRIBUTE_NAME, entered_name), filter_CONDITION(Condition_StartsWith, ATTRIBUTE_CN, entered_name), filter_CONDITION(Condition_StartsWith, ATTRIBUTE_SAM_ACCOUNT_NAME, entered_name), filter_CONDITION(Condition_StartsWith, ATTRIBUTE_USER_PRINCIPAL_NAME, entered_name), }); const QString classes_filter = ui->select_classes_widget->get_filter(); const QString out = filter_AND({ name_filter, classes_filter, }); return out; }(); const QHash<QString, AdObject> search_results = ad.search(base, SearchScope_All, filter, console_object_search_attributes()); if (search_results.size() == 1) { const QString dn = search_results.keys()[0]; add_objects_to_list({dn}, ad); } else if (search_results.size() > 1) { // Open dialog where you can select one of the matches auto dialog = new SelectObjectMatchDialog(search_results, this); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { const QList<QString> selected_matches = dialog->get_selected(); add_objects_to_list(selected_matches); }); } else if (search_results.size() == 0) { // Warn about failing to find any matches message_box_warning(this, tr("Error"), tr("Failed to find any matches.")); } } void SelectObjectDialog::on_remove_button() { const QList<QPersistentModelIndex> selected = persistent_index_list(ui->view->selectionModel()->selectedRows()); for (const QPersistentModelIndex &index : selected) { model->removeRows(index.row(), 1); } } void SelectObjectDialog::open_advanced_dialog() { auto dialog = new SelectObjectAdvancedDialog(class_list, this); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { const QList<QString> selected = dialog->get_selected_dns(); add_objects_to_list(selected); }); } void SelectObjectDialog::add_objects_to_list(const QList<QString> &dn_list) { AdInterface ad; if (ad_failed(ad, this)) { return; } add_objects_to_list(dn_list, ad); } // Adds objects to the list of selected objects. If list // contains objects that are already in list, they won't be // added and a message box will open warning user about // that. // NOTE: this is slightly inefficient because we search for // objects again, when they already were searched for by // callers of this f-n, in other words we don't reuse search // results. For majority of cases this is fine. For rare // cases where user is selecting truly huge amounts of // objects, they can wait. The alternative of caching // objects everywhere adds too much complexity. void SelectObjectDialog::add_objects_to_list(const QList<QString> &dn_list, AdInterface &ad) { const QList<QString> current_selected_list = get_selected(); bool any_duplicates = false; for (const QString &dn : dn_list) { const bool is_duplicate = current_selected_list.contains(dn); if (is_duplicate) { any_duplicates = true; } else { const AdObject object = ad.search_object(dn); add_select_object_to_model(model, object); } } if (any_duplicates) { message_box_warning(this, tr("Error"), tr("Selected object is already in the list.")); } ui->name_edit->clear(); } void add_select_object_to_model(QStandardItemModel *model, const AdObject &object) { const QList<QStandardItem *> row = make_item_row(SelectColumn_COUNT); console_object_item_data_load(row[0], object); const QString dn = object.get_dn(); const QString name = dn_get_name(dn); const QString object_class = object.get_string(ATTRIBUTE_OBJECT_CLASS); const QString type = g_adconfig->get_class_display_name(object_class); const QString folder = dn_get_parent_canonical(dn); row[SelectColumn_Name]->setText(name); row[SelectColumn_Type]->setText(type); row[SelectColumn_Folder]->setText(folder); model->appendRow(row); }
8,924
C++
.cpp
216
35.564815
152
0.682586
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,617
properties_warning_dialog.cpp
altlinux_admc/src/admc/properties_widgets/properties_warning_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "properties_warning_dialog.h" #include "ui_properties_warning_dialog.h" #include <QPushButton> PropertiesWarningDialog::PropertiesWarningDialog(const PropertiesWarningType type, QWidget *parent) : QDialog(parent) { ui = new Ui::PropertiesWarningDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); const QString label_text = [&]() { switch (type) { case PropertiesWarningType_SwitchToAttributes: return tr("You're switching to attributes tab, while another tab has unapplied changes. Choose to apply or discard those changes."); case PropertiesWarningType_SwitchFromAttributes: return tr("You're switching from attributes tab, while it has unapplied changes. Choose to apply or discard those changes."); } return QString(); }(); ui->label->setText(label_text); auto apply_button = ui->button_box->button(QDialogButtonBox::Apply); auto discard_button = ui->button_box->button(QDialogButtonBox::Discard); connect( apply_button, &QPushButton::clicked, this, &PropertiesWarningDialog::on_apply_button); connect( discard_button, &QPushButton::clicked, this, &PropertiesWarningDialog::on_discard_button); } PropertiesWarningDialog::~PropertiesWarningDialog() { delete ui; } void PropertiesWarningDialog::on_apply_button() { emit applied(); QDialog::accept(); } void PropertiesWarningDialog::on_discard_button() { emit discarded(); QDialog::accept(); }
2,294
C++
.cpp
55
37.6
191
0.734951
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,618
properties_dialog.cpp
altlinux_admc/src/admc/properties_widgets/properties_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "properties_dialog.h" #include "ui_properties_dialog.h" #include "adldap.h" #include "console_impls/object_impl.h" #include "globals.h" #include "properties_warning_dialog.h" #include "security_sort_warning_dialog.h" #include "settings.h" #include "status.h" #include "tab_widget.h" #include "tabs/account_tab.h" #include "tabs/address_tab.h" #include "tabs/attributes_tab.h" #include "tabs/delegation_tab.h" #include "tabs/error_tab.h" #include "tabs/general_computer_tab.h" #include "tabs/general_group_tab.h" #include "tabs/general_other_tab.h" #include "tabs/general_ou_tab.h" #include "tabs/general_policy_tab.h" #include "tabs/general_shared_folder_tab.h" #include "tabs/general_user_tab.h" #include "tabs/group_policy_tab.h" #include "tabs/laps_tab.h" #include "tabs/managed_by_tab.h" #include "tabs/membership_tab.h" #include "tabs/object_tab.h" #include "tabs/organization_tab.h" #include "tabs/os_tab.h" #include "tabs/profile_tab.h" #include "tabs/security_tab.h" #include "tabs/telephones_tab.h" #include "utils.h" #include <QAbstractItemView> #include <QAction> #include <QDebug> #include <QLabel> #include <QPushButton> QHash<QString, PropertiesDialog *> PropertiesDialog::instances; PropertiesDialog *PropertiesDialog::open_for_target(AdInterface &ad, const QString &target, bool *dialog_is_new, ConsoleWidget *console) { if (target.isEmpty()) { return nullptr; } show_busy_indicator(); const bool dialog_already_open_for_this_target = PropertiesDialog::instances.contains(target); PropertiesDialog *dialog; if (dialog_already_open_for_this_target) { // Focus already open dialog dialog = PropertiesDialog::instances[target]; dialog->raise(); dialog->setFocus(); } else { // Make new dialog for this target dialog = new PropertiesDialog(ad, target, console); dialog->open(); } hide_busy_indicator(); if (dialog_is_new != nullptr) { *dialog_is_new = !dialog_already_open_for_this_target; } return dialog; } void PropertiesDialog::open_when_view_item_activated(QAbstractItemView *view, const int dn_role) { connect( view, &QAbstractItemView::doubleClicked, view, [view, dn_role](const QModelIndex &index) { AdInterface ad; if (ad_failed(ad, view)) { return; } const QString dn = index.data(dn_role).toString(); open_for_target(ad, dn); }); } PropertiesDialog::PropertiesDialog(AdInterface &ad, const QString &target_arg, ConsoleWidget *console) : QDialog() { ui = new Ui::PropertiesDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); target = target_arg; security_warning_was_rejected = false; security_tab = nullptr; ui->tab_widget->enable_auto_switch_tab(false); PropertiesDialog::instances[target] = this; apply_button = ui->button_box->button(QDialogButtonBox::Apply); reset_button = ui->button_box->button(QDialogButtonBox::Reset); auto cancel_button = ui->button_box->button(QDialogButtonBox::Cancel); const QString title = [&]() { const QString target_name = dn_get_name(target_arg); if (!target_name.isEmpty()) { return QString(tr("%1 Properties")).arg(target_name); } else { return tr("Properties"); } }(); setWindowTitle(title); const AdObject object = ad.search_object(target); const bool is_person = (object.is_class(CLASS_USER) || object.is_class(CLASS_INET_ORG_PERSON)); // // Create tabs // QWidget *general_tab = [&]() -> QWidget * { if (is_person || object.is_class(CLASS_CONTACT)) { return new GeneralUserTab(&edit_list, this); } else if (object.is_class(CLASS_GROUP)) { return new GeneralGroupTab(&edit_list, this); } else if (object.is_class(CLASS_OU)) { return new GeneralOUTab(&edit_list, this); } else if (object.is_class(CLASS_COMPUTER)) { return new GeneralComputerTab(&edit_list, this); } else if (object.is_class(CLASS_GP_CONTAINER)) { return new GeneralPolicyTab(&edit_list, this); } else if (object.is_class(CLASS_SHARED_FOLDER)) { return new GeneralSharedFolderTab(&edit_list, this); } else if (!object.is_empty()) { return new GeneralOtherTab(&edit_list, this); } else { return new ErrorTab(this); } }(); ui->tab_widget->add_tab(general_tab, tr("General")); const bool advanced_view_ON = settings_get_variant(SETTING_advanced_features).toBool(); if (advanced_view_ON && !object.is_empty()) { auto object_tab = new ObjectTab(&edit_list, this); attributes_tab = new AttributesTab(&edit_list, this); ui->tab_widget->add_tab(object_tab, tr("Object")); ui->tab_widget->add_tab(attributes_tab, tr("Attributes")); } else { attributes_tab = nullptr; } if (is_person || object.is_class(CLASS_CONTACT)) { auto address_tab = new AddressTab(&edit_list, this); auto organization_tab = new OrganizationTab(&edit_list, this); auto telephones_tab = new TelephonesTab(&edit_list, this); ui->tab_widget->add_tab(address_tab, tr("Address")); ui->tab_widget->add_tab(organization_tab, tr("Organization")); ui->tab_widget->add_tab(telephones_tab, tr("Telephones")); } if (is_person) { auto account_tab = new AccountTab(ad, &edit_list, this); ui->tab_widget->add_tab(account_tab, tr("Account")); const bool profile_tab_enabled = settings_get_variant(SETTING_feature_profile_tab).toBool(); if (profile_tab_enabled) { auto profile_tab = new ProfileTab(&edit_list, this); ui->tab_widget->add_tab(profile_tab, tr("Profile")); } } if (object.is_class(CLASS_GROUP)) { auto members_tab = new MembershipTab(&edit_list, MembershipTabType_Members, this); ui->tab_widget->add_tab(members_tab, tr("Members")); } if (is_person || object.is_class(CLASS_COMPUTER) || object.is_class(CLASS_CONTACT) || object.is_class(CLASS_GROUP)) { auto member_of_tab = new MembershipTab(&edit_list, MembershipTabType_MemberOf, this); ui->tab_widget->add_tab(member_of_tab, tr("Member of")); } if (is_person || object.is_class(CLASS_COMPUTER)) { auto delegation_tab = new DelegationTab(&edit_list, this); ui->tab_widget->add_tab(delegation_tab, tr("Delegation")); } if (object.is_class(CLASS_OU) || object.is_class(CLASS_COMPUTER) || object.is_class(CLASS_SHARED_FOLDER)) { auto managed_by_tab = new ManagedByTab(&edit_list, this); ui->tab_widget->add_tab(managed_by_tab, tr("Managed by")); } if (object.is_class(CLASS_OU) || object.is_class(CLASS_DOMAIN)) { auto group_policy_tab = new GroupPolicyTab(&edit_list, console, target, this); ui->tab_widget->add_tab(group_policy_tab, tr("Group policy")); } if (object.is_class(CLASS_COMPUTER)) { auto os_tab = new OSTab(&edit_list, this); ui->tab_widget->add_tab(os_tab, tr("Operating System")); const bool laps_enabled = [&]() { const QList<QString> attribute_list = object.attributes(); const bool out = (attribute_list.contains(ATTRIBUTE_LAPS_PASSWORD) && attribute_list.contains(ATTRIBUTE_LAPS_EXPIRATION)); return out; }(); if (laps_enabled) { auto laps_tab = new LAPSTab(&edit_list, this); ui->tab_widget->add_tab(laps_tab, tr("LAPS")); } } const bool need_security_tab = object.attributes().contains(ATTRIBUTE_SECURITY_DESCRIPTOR); if (need_security_tab && advanced_view_ON) { security_tab = new SecurityTab(&edit_list, this); ui->tab_widget->add_tab(security_tab, tr("Security")); } for (AttributeEdit *edit : edit_list) { connect( edit, &AttributeEdit::edited, [this, edit]() { const bool already_added = apply_list.contains(edit); if (!already_added) { apply_list.append(edit); } apply_button->setEnabled(true); reset_button->setEnabled(true); }); } reset_internal(ad, object); settings_setup_dialog_geometry(SETTING_properties_dialog_geometry, this); connect( apply_button, &QPushButton::clicked, this, &PropertiesDialog::apply); connect( reset_button, &QPushButton::clicked, this, &PropertiesDialog::reset); connect( cancel_button, &QPushButton::clicked, this, &PropertiesDialog::reject); connect( ui->tab_widget, &TabWidget::current_changed, this, &PropertiesDialog::on_current_tab_changed); } PropertiesDialog::~PropertiesDialog() { delete ui; } // NOTE: order here is important. Attributes warning // can apply/discard changes, while security warning // can add a modification to security tab. Therefore // attributes warning needs to go first so that it // won't discard security warning modification. void PropertiesDialog::on_current_tab_changed(const int prev, const int current) { QWidget *prev_tab = ui->tab_widget->get_tab(prev); QWidget *new_tab = ui->tab_widget->get_tab(current); const bool switching_to_or_from_attributes = (prev_tab == attributes_tab || new_tab == attributes_tab); const bool is_modified = !apply_list.isEmpty(); const bool need_attributes_warning = (switching_to_or_from_attributes && is_modified); if (!need_attributes_warning) { ui->tab_widget->set_current_tab(current); open_security_warning(); return; } const PropertiesWarningType warning_type = [&]() { if (new_tab == attributes_tab) { return PropertiesWarningType_SwitchToAttributes; } else { return PropertiesWarningType_SwitchFromAttributes; } }(); auto attributes_warning_dialog = new PropertiesWarningDialog(warning_type, this); attributes_warning_dialog->open(); connect( attributes_warning_dialog, &PropertiesWarningDialog::applied, this, [this, current]() { AdInterface ad; if (ad_failed(ad, this)) { return; } apply_internal(ad); // NOTE: have to reset for attributes tab and other tabs // to load updates const AdObject object = ad.search_object(target); reset_internal(ad, object); ui->tab_widget->set_current_tab(current); }); connect( attributes_warning_dialog, &PropertiesWarningDialog::discarded, [this, current]() { reset(); ui->tab_widget->set_current_tab(current); }); connect( attributes_warning_dialog, &PropertiesWarningDialog::rejected, [this, prev]() { ui->tab_widget->set_current_tab(prev); }); // Open security warning after attributes warning // is finished connect( attributes_warning_dialog, &QDialog::finished, this, &PropertiesDialog::open_security_warning); } void PropertiesDialog::open_security_warning() { const bool security_tab_exists = (security_tab != nullptr); if (!security_tab_exists) { return; } // NOTE: if security warning was rejected once, // then security tab is forever read only and we // don't show the warning again (for this dialog // instance). if (security_warning_was_rejected) { return; } const bool switched_to_security_tab = [&]() { const QWidget *current_tab = ui->tab_widget->get_current_tab(); const bool out = (current_tab == security_tab); return out; }(); if (!switched_to_security_tab) { return; } const bool order_is_correct = security_tab->verify_acl_order(); if (order_is_correct) { return; } auto security_warning_dialog = new SecuritySortWarningDialog(this); security_warning_dialog->open(); connect( security_warning_dialog, &QDialog::accepted, this, &PropertiesDialog::on_security_warning_accepted); connect( security_warning_dialog, &QDialog::rejected, this, &PropertiesDialog::on_security_warning_rejected); } void PropertiesDialog::on_security_warning_accepted() { security_tab->fix_acl_order(); } void PropertiesDialog::on_security_warning_rejected() { security_tab->set_read_only(); security_warning_was_rejected = true; } void PropertiesDialog::accept() { AdInterface ad; if (ad_failed(ad, this)) { return; } const bool success = apply_internal(ad); if (success) { QDialog::accept(); } } void PropertiesDialog::done(int r) { PropertiesDialog::instances.remove(target); QDialog::done(r); } void PropertiesDialog::apply() { AdInterface ad; if (ad_failed(ad, this)) { return; } const bool apply_success = apply_internal(ad); ad.clear_messages(); if (apply_success) { const AdObject object = ad.search_object(target); reset_internal(ad, object); } } void PropertiesDialog::reset() { AdInterface ad; if (ad_connected(ad, this)) { const AdObject object = ad.search_object(target); reset_internal(ad, object); } } bool PropertiesDialog::apply_internal(AdInterface &ad) { // NOTE: only verify and apply edits in the "apply // list", aka the edits that were edited const bool edits_verify_success = AttributeEdit::verify(apply_list, ad, target); if (!edits_verify_success) { return false; } show_busy_indicator(); bool total_apply_success = true; const bool edits_apply_success = AttributeEdit::apply(apply_list, ad, target); if (!edits_apply_success) { total_apply_success = false; } g_status->display_ad_messages(ad, this); if (total_apply_success) { apply_button->setEnabled(false); reset_button->setEnabled(false); } hide_busy_indicator(); emit applied(); return total_apply_success; } void PropertiesDialog::reset_internal(AdInterface &ad, const AdObject &object) { AttributeEdit::load(edit_list, ad, object); apply_button->setEnabled(false); reset_button->setEnabled(false); apply_list.clear(); g_status->display_ad_messages(ad, this); }
15,404
C++
.cpp
394
32.576142
138
0.654839
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,619
properties_multi_dialog.cpp
altlinux_admc/src/admc/properties_widgets/properties_multi_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "properties_multi_dialog.h" #include "ui_properties_multi_dialog.h" #include "adldap.h" #include "attribute_edits/attribute_edit.h" #include "globals.h" #include "multi_tabs/account_multi_tab.h" #include "multi_tabs/address_multi_tab.h" #include "multi_tabs/general_other_multi_tab.h" #include "multi_tabs/general_user_multi_tab.h" #include "multi_tabs/organization_multi_tab.h" #include "multi_tabs/profile_multi_tab.h" #include "settings.h" #include "status.h" #include "tab_widget.h" #include "utils.h" #include <QAction> #include <QCheckBox> #include <QDialogButtonBox> #include <QPushButton> PropertiesMultiDialog::PropertiesMultiDialog(AdInterface &ad, const QList<QString> &target_list_arg, const QList<QString> &class_list) : QDialog() { ui = new Ui::PropertiesMultiDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); target_list = target_list_arg; apply_button = ui->button_box->button(QDialogButtonBox::Apply); if (class_list == QList<QString>({CLASS_USER})) { auto general_user_tab = new GeneralUserMultiTab(&edit_list, &check_map, this); auto account_tab = new AccountMultiTab(ad, &edit_list, &check_map, this); auto address_tab = new AddressMultiTab(&edit_list, &check_map, this); auto profile_tab = new ProfileMultiTab(&edit_list, &check_map, this); auto organization_tab = new OrganizationMultiTab(&edit_list, &check_map, this); ui->tab_widget->add_tab(general_user_tab, tr("General")); ui->tab_widget->add_tab(account_tab, tr("Account")); ui->tab_widget->add_tab(address_tab, tr("Address")); ui->tab_widget->add_tab(profile_tab, tr("Profile")); ui->tab_widget->add_tab(organization_tab, tr("Organization")); } else { auto general_other_tab = new GeneralOtherMultiTab(&edit_list, &check_map, this); ui->tab_widget->add_tab(general_other_tab, tr("General")); } for (AttributeEdit *edit : check_map.keys()) { QCheckBox *apply_check = check_map[edit]; connect( apply_check, &QAbstractButton::toggled, this, &PropertiesMultiDialog::on_edited); connect( apply_check, &QAbstractButton::toggled, edit, [edit, apply_check]() { const bool enabled = apply_check->isChecked(); edit->set_enabled(enabled); }); } for (AttributeEdit *edit : edit_list) { edit->set_enabled(false); } settings_setup_dialog_geometry(SETTING_object_multi_dialog_geometry, this); connect( apply_button, &QPushButton::clicked, this, &PropertiesMultiDialog::apply); } PropertiesMultiDialog::~PropertiesMultiDialog() { delete ui; } void PropertiesMultiDialog::accept() { const bool success = apply(); if (success) { QDialog::accept(); } } bool PropertiesMultiDialog::apply() { AdInterface ad; if (ad_failed(ad, this)) { return false; } show_busy_indicator(); const bool apply_success = [&]() { bool out = true; for (AttributeEdit *edit : edit_list) { QCheckBox *apply_check = check_map[edit]; const bool need_to_apply = apply_check->isChecked(); if (need_to_apply) { const bool success = [&]() { bool success_out = true; for (const QString &target : target_list) { const bool this_success = edit->apply(ad, target); success_out = (success_out && this_success); } return success_out; }(); if (success) { apply_check->setChecked(false); } out = (out && success); } } return out; }(); g_status->display_ad_messages(ad, this); hide_busy_indicator(); emit applied(); return apply_success; } void PropertiesMultiDialog::on_edited() { apply_button->setEnabled(true); }
4,856
C++
.cpp
126
31.666667
134
0.643101
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,620
list_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/list_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/list_attribute_dialog.h" #include "attribute_dialogs/ui_list_attribute_dialog.h" #include "adldap.h" #include "attribute_dialogs/attribute_dialog.h" #include "attribute_dialogs/octet_attribute_dialog.h" #include "globals.h" #include "settings.h" #include "utils.h" ListAttributeDialog::ListAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent) { ui = new Ui::ListAttributeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); // Default value indiciating no max length max_length = 0; AttributeDialog::load_attribute_label(ui->attribute_label); ui->add_button->setVisible(!read_only); ui->remove_button->setVisible(!read_only); for (const QByteArray &value : value_list) { add_value(value); } settings_setup_dialog_geometry(SETTING_list_attribute_dialog_geometry, this); connect( ui->add_button, &QAbstractButton::clicked, this, &ListAttributeDialog::on_add_button); connect( ui->remove_button, &QAbstractButton::clicked, this, &ListAttributeDialog::on_remove_button); } ListAttributeDialog::~ListAttributeDialog() { delete ui; } void ListAttributeDialog::accept() { const bool contains_empty_values = [&]() { const bool is_bool = (g_adconfig->get_attribute_type(get_attribute()) == AttributeType_Boolean); if (is_bool) { return false; } const QList<QByteArray> value_list = get_value_list(); for (const QByteArray &value : value_list) { const QString value_string = QString(value); const bool value_is_all_spaces = (value.count(' ') == value.length()); const bool value_is_empty = value.isEmpty() || value_is_all_spaces; if (value_is_empty) { return true; } } return false; }(); if (contains_empty_values) { message_box_warning(this, tr("Error"), tr("One or more values are empty. Edit or remove them to proceed.")); } else { QDialog::accept(); } } void ListAttributeDialog::on_add_button() { const bool read_only = false; const bool single_valued = true; AttributeDialog *dialog = AttributeDialog::make(get_attribute(), QList<QByteArray>(), read_only, single_valued, this); if (dialog == nullptr) { return; } dialog->setWindowTitle(tr("Add Value")); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { const QList<QByteArray> new_values = dialog->get_value_list(); if (!new_values.isEmpty()) { const QByteArray value = new_values[0]; add_value(value); } }); } void ListAttributeDialog::on_remove_button() { const QList<QListWidgetItem *> selected = ui->list_widget->selectedItems(); for (const auto item : selected) { delete item; } } QList<QByteArray> ListAttributeDialog::get_value_list() const { QList<QByteArray> new_values; for (int i = 0; i < ui->list_widget->count(); i++) { const QListWidgetItem *item = ui->list_widget->item(i); const QString new_value_string = item->text(); const QByteArray new_value = string_to_bytes(new_value_string); new_values.append(new_value); } return new_values; } void ListAttributeDialog::set_value_max_length(const int max_length_arg) { max_length = max_length_arg; } void ListAttributeDialog::add_value(const QByteArray value) { const QString text = bytes_to_string(value); const QList<QListWidgetItem *> find_results = ui->list_widget->findItems(text, Qt::MatchExactly); const bool value_already_exists = !find_results.isEmpty(); if (!value_already_exists) { ui->list_widget->addItem(text); } } ListAttributeDialogType ListAttributeDialog::get_type() const { const AttributeType type = g_adconfig->get_attribute_type(get_attribute()); switch (type) { case AttributeType_Octet: return ListAttributeDialogType_Octet; case AttributeType_Sid: return ListAttributeDialogType_Octet; case AttributeType_UTCTime: return ListAttributeDialogType_Datetime; case AttributeType_GeneralizedTime: return ListAttributeDialogType_Datetime; default: break; } return ListAttributeDialogType_String; } QString ListAttributeDialog::bytes_to_string(const QByteArray bytes) const { const ListAttributeDialogType editor_type = get_type(); switch (editor_type) { case ListAttributeDialogType_String: return QString(bytes); case ListAttributeDialogType_Octet: return octet_bytes_to_string(bytes, OctetDisplayFormat_Hexadecimal); case ListAttributeDialogType_Datetime: return QString(bytes); } return QString(); } QByteArray ListAttributeDialog::string_to_bytes(const QString string) const { const ListAttributeDialogType editor_type = get_type(); switch (editor_type) { case ListAttributeDialogType_String: return string.toUtf8(); case ListAttributeDialogType_Octet: return octet_string_to_bytes(string, OctetDisplayFormat_Hexadecimal); case ListAttributeDialogType_Datetime: return string.toUtf8(); } return QByteArray(); }
6,186
C++
.cpp
150
35.506667
142
0.695964
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,621
attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/attribute_dialog.h" #include "ad_config.h" #include "ad_utils.h" #include "ad_display.h" #include "globals.h" #include "attribute_dialogs/bool_attribute_dialog.h" #include "attribute_dialogs/datetime_attribute_dialog.h" #include "attribute_dialogs/list_attribute_dialog.h" #include "attribute_dialogs/number_attribute_dialog.h" #include "attribute_dialogs/octet_attribute_dialog.h" #include "attribute_dialogs/string_attribute_dialog.h" #include "attribute_dialogs/number_attribute_dialog.h" #include "attribute_dialogs/hex_number_attribute_dialog.h" #include "attribute_dialogs/time_span_attribute_dialog.h" #include <QLabel> #include <QDebug> AttributeDialog *AttributeDialog::make(const QString &attribute, const QList<QByteArray> &value_list, const bool read_only, const bool single_valued, QWidget *parent) { // Single/multi valued logic is separated out of the // switch statement for better flow auto octet_attribute_dialog = [&]() -> AttributeDialog * { if (single_valued) { return new OctetAttributeDialog(value_list, attribute, read_only, parent); } else { return new ListAttributeDialog(value_list, attribute, read_only, parent); } }; auto string_attribute_dialog = [&]() -> AttributeDialog * { if (single_valued) { const bool attribute_is_number = g_adconfig->get_attribute_is_number(attribute); if (attribute_is_number) { if (attribute_value_is_hex_displayed(attribute)) return new HexNumberAttributeDialog(value_list, attribute, read_only, parent); else return new NumberAttributeDialog(value_list, attribute, read_only, parent); } else { return new StringAttributeDialog(value_list, attribute, read_only, parent); } } else { return new ListAttributeDialog(value_list, attribute, read_only, parent); } }; auto bool_attribute_dialog = [&]() -> AttributeDialog * { if (single_valued) { return new BoolAttributeDialog(value_list, attribute, read_only, parent); } else { return new ListAttributeDialog(value_list, attribute, read_only, parent); } }; auto datetime_attribute_dialog = [&]() -> AttributeDialog * { if (single_valued) { return new DatetimeAttributeDialog(value_list, attribute, read_only, parent); } else { return nullptr; } }; auto time_span_attribute_dialog = [&]() -> AttributeDialog * { if (single_valued) { return new TimeSpanAttributeDialog(value_list, attribute, read_only, parent); } else { return nullptr; } }; AttributeType type = g_adconfig->get_attribute_type(attribute); const LargeIntegerSubtype large_int_subtype = g_adconfig->get_attribute_large_integer_subtype(attribute); if (type == AttributeType_LargeInteger && large_int_subtype == LargeIntegerSubtype_Datetime) type = AttributeType_UTCTime; AttributeDialog *dialog = [&]() -> AttributeDialog * { if (type == AttributeType_LargeInteger && large_int_subtype == LargeIntegerSubtype_Timespan) { return time_span_attribute_dialog(); } switch (type) { case AttributeType_Octet: return octet_attribute_dialog(); case AttributeType_Sid: return octet_attribute_dialog(); case AttributeType_Boolean: return bool_attribute_dialog(); case AttributeType_Unicode: return string_attribute_dialog(); case AttributeType_StringCase: return string_attribute_dialog(); case AttributeType_DSDN: return string_attribute_dialog(); case AttributeType_IA5: return string_attribute_dialog(); case AttributeType_Teletex: return string_attribute_dialog(); case AttributeType_ObjectIdentifier: return string_attribute_dialog(); case AttributeType_Integer: return string_attribute_dialog(); case AttributeType_Enumeration: return string_attribute_dialog(); case AttributeType_LargeInteger: return string_attribute_dialog(); case AttributeType_UTCTime: return datetime_attribute_dialog(); case AttributeType_GeneralizedTime: return datetime_attribute_dialog(); case AttributeType_NTSecDesc: return octet_attribute_dialog(); case AttributeType_Numeric: return string_attribute_dialog(); case AttributeType_Printable: return string_attribute_dialog(); case AttributeType_DNString: return string_attribute_dialog(); // NOTE: putting these here as confirmed to be unsupported case AttributeType_ReplicaLink: return nullptr; case AttributeType_DNBinary: return nullptr; } return nullptr; }(); const QString title = [&]() { const QString title_action = [&]() { if (read_only) { return tr("View"); } else { return tr("Edit"); } }(); const QString title_attribute = attribute_type_display_string(type); if (single_valued) { return QString("%1 %2").arg(title_action, title_attribute); } else { return QString(tr("%1 Multi-Valued %2", "This is a dialog title for attribute editors. Example: \"Edit Multi-Valued String\"")).arg(title_action, title_attribute); } }(); if (dialog != nullptr) { dialog->setWindowTitle(title); } return dialog; } AttributeDialog::AttributeDialog(const QString &attribute, const bool read_only, QWidget *parent) : QDialog(parent) { m_attribute = attribute; m_read_only = read_only; } QString AttributeDialog::get_attribute() const { return m_attribute; } bool AttributeDialog::get_read_only() const { return m_read_only; } void AttributeDialog::load_attribute_label(QLabel *attribute_label) { const QString text = QString(tr("Attribute: %1")).arg(m_attribute); attribute_label->setText(text); }
6,941
C++
.cpp
149
39
175
0.674945
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,622
octet_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/octet_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/octet_attribute_dialog.h" #include "attribute_dialogs/ui_octet_attribute_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" #include "utils.h" #include <QFont> #include <QFontDatabase> #include <cstdint> #include <cstdlib> OctetDisplayFormat current_format(QComboBox *format_combo); int format_base(const OctetDisplayFormat format); char *itoa(int value, char *result, int base); OctetAttributeDialog::OctetAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent) { ui = new Ui::OctetAttributeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); prev_format = OctetDisplayFormat_Hexadecimal; const QFont fixed_font = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->edit->setFont(fixed_font); ui->edit->setReadOnly(read_only); const QByteArray value = value_list.value(0, QByteArray()); const QString value_string = octet_bytes_to_string(value, current_format(ui->format_combo)); ui->edit->setPlainText(value_string); settings_setup_dialog_geometry(SETTING_octet_attribute_dialog_geometry, this); connect( ui->format_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &OctetAttributeDialog::on_format_combo); } OctetAttributeDialog::~OctetAttributeDialog() { delete ui; } QList<QByteArray> OctetAttributeDialog::get_value_list() const { const QString text = ui->edit->toPlainText(); if (!text.isEmpty()) { const QByteArray bytes = octet_string_to_bytes(text, current_format(ui->format_combo)); return {bytes}; } else { return {}; } } void OctetAttributeDialog::accept() { const bool input_ok = check_input(current_format(ui->format_combo)); if (input_ok) { AttributeDialog::accept(); } } void OctetAttributeDialog::on_format_combo() { // Check that input is ok for previous format, otherwise // won't be able to convert it to new format const bool input_ok_for_prev_format = check_input(prev_format); if (input_ok_for_prev_format) { // Convert input in prev format back to bytes, then // convert bytes to input in new format // Ex: hex -> bytes -> octal const QString old_text = ui->edit->toPlainText(); const QByteArray bytes = octet_string_to_bytes(old_text, prev_format); const QString new_text = octet_bytes_to_string(bytes, current_format(ui->format_combo)); ui->edit->setPlainText(new_text); prev_format = current_format(ui->format_combo); } else { // Revert to previous format if input is invalid for // current format ui->format_combo->blockSignals(true); ui->format_combo->setCurrentIndex((int) prev_format); ui->format_combo->blockSignals(false); } } bool OctetAttributeDialog::check_input(const OctetDisplayFormat format) { const bool ok = [=]() { const QString text = ui->edit->toPlainText(); if (text.isEmpty()) { return true; } const QList<QString> text_split = text.split(" "); // Check that all elements of text (separated by // space) match the format for (const QString &element : text_split) { switch (format) { case OctetDisplayFormat_Hexadecimal: { const QRegExp rx("([0-9a-f]{2})"); if (!rx.exactMatch(element)) { return false; } break; } case OctetDisplayFormat_Binary: { const QRegExp rx("([0-1]{8})"); if (!rx.exactMatch(element)) { return false; } break; } case OctetDisplayFormat_Decimal: { const QRegExp rx("([0-9]{3})"); if (!rx.exactMatch(element)) { return false; } const int number = element.toInt(); if (0 > number || number > 255) { return false; } break; } case OctetDisplayFormat_Octal: { const QRegExp rx("([0-7]{3})"); if (!rx.exactMatch(element)) { return false; } // NOTE: technically forcing an octal // number into decimal here, but it // works out fine for range checking const int number = element.toInt(); if (0 > number || number > 377) { return false; } break; } } } return true; }(); if (!ok) { const QString title = tr("Error"); const QString text = [format]() { switch (format) { case OctetDisplayFormat_Hexadecimal: return tr("Input must be strings of 2 hexadecimal digits separated by spaces. Example: \"0a 00 b5 ff\""); case OctetDisplayFormat_Binary: return tr("Input must be strings of 8 binary digits separated by spaces. Example: \"01010010 01000010 01000010\""); case OctetDisplayFormat_Decimal: return tr("Input must be strings of 3 decimal digits (0-255) separated by spaces. Example: \"010 000 191\""); case OctetDisplayFormat_Octal: return tr("Input must be strings of 3 octal digits (0-377) separated by spaces.. Example: \"070 343 301\""); } return QString(); }(); message_box_warning(this, title, text); } return ok; } OctetDisplayFormat current_format(QComboBox *format_combo) { const int format_index = format_combo->currentIndex(); const OctetDisplayFormat format = (OctetDisplayFormat) (format_index); return format; } QString octet_bytes_to_string(const QByteArray bytes, const OctetDisplayFormat format) { QString out; for (int i = 0; i < bytes.size(); i++) { if (i > 0) { out += " "; } const char byte_char = bytes[i]; uint8_t byte = (uint8_t) byte_char; char buffer[100]; const int base = format_base(format); itoa((int) byte, buffer, base); const QString byte_string_unpadded(buffer); const int string_length = [format]() { switch (format) { case OctetDisplayFormat_Hexadecimal: return 2; case OctetDisplayFormat_Binary: return 8; case OctetDisplayFormat_Decimal: return 3; case OctetDisplayFormat_Octal: return 3; } return 0; }(); // "5" => "005" // "f" => "0f" const QString byte_string = byte_string_unpadded.rightJustified(string_length, '0'); out += byte_string; } return out; } QByteArray octet_string_to_bytes(const QString string, const OctetDisplayFormat format) { if (string.isEmpty()) { return QByteArray(); } const QList<QString> string_split = string.split(" "); QByteArray out; for (const QString &byte_string_padded : string_split) { // NOTE: remove padding because strtol doesn't understand it // "005" => "5" const QString byte_string = [byte_string_padded]() { QString byte = byte_string_padded; while (byte[0] == '0' && byte.size() > 0) { byte.remove(0, 1); } return byte; }(); const QByteArray byte_bytes = byte_string.toLocal8Bit(); const char *byte_cstr = byte_bytes.constData(); const int base = format_base(format); const long int byte_li = strtol(byte_cstr, NULL, base); const char byte = (char) byte_li; out.append(byte); } return out; } int format_base(const OctetDisplayFormat format) { switch (format) { case OctetDisplayFormat_Hexadecimal: return 16; case OctetDisplayFormat_Binary: return 2; case OctetDisplayFormat_Decimal: return 10; case OctetDisplayFormat_Octal: return 8; } return 0; } /** * C++ version 0.4 char* style "itoa": * Written by Luk√°s Chmela * Released under GPLv3. */ // NOTE: not included in base lib, so had to copypaste. Maybe find some other more popular implementation and use that (with appropriate license). Preferrably something that automatically pads the result (leading 0's). char *itoa(int value, char *result, int base) { // check that the base is valid if (base < 2 || base > 36) { *result = '\0'; return result; } char *ptr = result, *ptr1 = result, tmp_char; int tmp_value; do { tmp_value = value; value /= base; *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]; } while (value); // Apply negative sign if (tmp_value < 0) *ptr++ = '-'; *ptr-- = '\0'; while (ptr1 < ptr) { tmp_char = *ptr; *ptr-- = *ptr1; *ptr1++ = tmp_char; } return result; }
10,239
C++
.cpp
255
31.396078
218
0.607762
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,623
string_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/string_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/string_attribute_dialog.h" #include "attribute_dialogs/ui_string_attribute_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" #include "utils.h" StringAttributeDialog::StringAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent) { ui = new Ui::StringAttributeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); limit_plain_text_edit(ui->edit, attribute); ui->edit->setReadOnly(read_only); const QByteArray value = value_list.value(0, QByteArray()); const QString value_string = QString(value); ui->edit->setPlainText(value_string); settings_setup_dialog_geometry(SETTING_string_attribute_dialog_geometry, this); } StringAttributeDialog::~StringAttributeDialog() { delete ui; } QList<QByteArray> StringAttributeDialog::get_value_list() const { const QString new_value_string = ui->edit->toPlainText(); if (new_value_string.isEmpty()) { return {}; } else { const QByteArray new_value = new_value_string.toUtf8(); return {new_value}; } }
2,039
C++
.cpp
50
37.5
146
0.742539
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,624
time_span_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/time_span_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2023 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "time_span_attribute_dialog.h" #include "ui_time_span_attribute_dialog.h" #include "settings.h" #include "utils.h" #include "ad_display.cpp" #include "ad_defines.h" #include <QString> TimeSpanAttributeDialog::TimeSpanAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent), ui(new Ui::TimeSpanAttributeDialog) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); const QByteArray value = value_list.value(0, QByteArray()); set_line_edit_to_time_span_format(ui->time_span_edit); ui->time_span_edit->setReadOnly(read_only); ui->time_span_edit->setText(timespan_display_value(value)); settings_setup_dialog_geometry(SETTING_time_span_attribute_dialog_geometry, this); } TimeSpanAttributeDialog::~TimeSpanAttributeDialog() { delete ui; } QList<QByteArray> TimeSpanAttributeDialog::get_value_list() const { const QString new_value_string = ui->time_span_edit->text(); QByteArray value = QByteArray::number(0); if (new_value_string == "(none)") { return {value}; } if (new_value_string == "(never)") { value = QByteArray::number(LLONG_MIN); return {value}; } QStringList d_hh_mm_ss = new_value_string.split(':'); if (d_hh_mm_ss.size() != 4) { return {value}; } qint64 hundred_nanos = 100 * std::chrono::nanoseconds(-d_hh_mm_ss[0].toLongLong() * DAYS_TO_SECONDS + -d_hh_mm_ss[1].toLongLong() * HOURS_TO_SECONDS + -d_hh_mm_ss[2].toLongLong() * MINUTES_TO_SECONDS -d_hh_mm_ss[3].toLongLong()).count(); value = QByteArray::number(hundred_nanos); return {value}; }
2,675
C++
.cpp
64
35.640625
152
0.669492
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,625
datetime_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/datetime_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/datetime_attribute_dialog.h" #include "attribute_dialogs/ui_datetime_attribute_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" DatetimeAttributeDialog::DatetimeAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent) { ui = new Ui::DatetimeAttributeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); ui->edit->setReadOnly(read_only); const QByteArray value = value_list.value(0, QByteArray()); const QString value_string = QString(value); const QDateTime value_datetime = datetime_string_to_qdatetime(get_attribute(), value_string, g_adconfig); ui->edit->setDateTime(value_datetime); settings_setup_dialog_geometry(SETTING_datetime_attribute_dialog_geometry, this); } DatetimeAttributeDialog::~DatetimeAttributeDialog() { delete ui; } QList<QByteArray> DatetimeAttributeDialog::get_value_list() const { const QDateTime value_datetime = ui->edit->dateTime(); const QString value_string = datetime_qdatetime_to_string(get_attribute(), value_datetime, g_adconfig); const QByteArray value = value_string.toUtf8(); const QList<QByteArray> value_list = {value}; return value_list; }
2,162
C++
.cpp
47
43.021277
150
0.760932
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,626
number_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/number_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/number_attribute_dialog.h" #include "attribute_dialogs/ui_number_attribute_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" #include "utils.h" NumberAttributeDialog::NumberAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent) { ui = new Ui::NumberAttributeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); set_line_edit_to_decimal_numbers_only(ui->edit); limit_edit(ui->edit, attribute); ui->edit->setReadOnly(read_only); const QByteArray value = value_list.value(0, QByteArray()); const QString value_string = QString(value); ui->edit->setText(value_string); settings_setup_dialog_geometry(SETTING_number_attribute_dialog_geometry, this); } NumberAttributeDialog::~NumberAttributeDialog() { delete ui; } QList<QByteArray> NumberAttributeDialog::get_value_list() const { const QString new_value_string = ui->edit->text(); if (new_value_string.isEmpty()) { return {}; } else { const QByteArray new_value = new_value_string.toUtf8(); return {new_value}; } }
2,070
C++
.cpp
51
37.254902
146
0.739781
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,627
bool_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/bool_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/bool_attribute_dialog.h" #include "attribute_dialogs/ui_bool_attribute_dialog.h" #include "adldap.h" #include "globals.h" #include "settings.h" BoolAttributeDialog::BoolAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent) { ui = new Ui::BoolAttributeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); ui->true_button->setEnabled(!read_only); ui->false_button->setEnabled(!read_only); ui->unset_button->setEnabled(!read_only); if (value_list.isEmpty()) { ui->unset_button->setChecked(true); } else { const QByteArray value = value_list[0]; const QString value_string = QString(value); const bool value_bool = ad_string_to_bool(value_string); if (value_bool) { ui->true_button->setChecked(true); } else { ui->false_button->setChecked(true); } } settings_setup_dialog_geometry(SETTING_bool_attribute_dialog_geometry, this); } BoolAttributeDialog::~BoolAttributeDialog() { delete ui; } QList<QByteArray> BoolAttributeDialog::get_value_list() const { if (ui->unset_button->isChecked()) { return QList<QByteArray>(); } else if (ui->true_button->isChecked()) { const QByteArray value = QString(LDAP_BOOL_TRUE).toUtf8(); return {value}; } else if (ui->false_button->isChecked()) { const QByteArray value = QString(LDAP_BOOL_FALSE).toUtf8(); return {value}; } else { return QList<QByteArray>(); } }
2,486
C++
.cpp
63
34.888889
142
0.701493
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,628
hex_number_attribute_dialog.cpp
altlinux_admc/src/admc/attribute_dialogs/hex_number_attribute_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2023 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_dialogs/hex_number_attribute_dialog.h" #include "attribute_dialogs/ui_hex_number_attribute_dialog.h" #include "adldap.h" #include "globals.h" #include "utils.h" #include "settings.h" #include <QDebug> HexNumberAttributeDialog::HexNumberAttributeDialog(const QList<QByteArray> &value_list, const QString &attribute, const bool read_only, QWidget *parent) : AttributeDialog(attribute, read_only, parent), ui(new Ui::HexNumberAttributeDialog) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); AttributeDialog::load_attribute_label(ui->attribute_label); const QByteArray value = value_list.value(0, QByteArray()); set_line_edit_to_hex_numbers_only(ui->edit); ui->edit->setMaxLength(2 * sizeof(int)); ui->edit->setReadOnly(read_only); //quint32 conversion for unsigned hex representation QString value_text = QString::number((quint32)value.toInt(), 16); ui->edit->setText(value_text); settings_setup_dialog_geometry(SETTING_hex_number_attribute_dialog_geometry, this); } HexNumberAttributeDialog::~HexNumberAttributeDialog() { delete ui; } QList<QByteArray> HexNumberAttributeDialog::get_value_list() const { const QString new_value_string = ui->edit->text(); bool ok_toUInt; int int_value = (int)new_value_string.toUInt(&ok_toUInt, 16); if (new_value_string.isEmpty() || !ok_toUInt) { return {}; } else { const QByteArray new_value = QByteArray::number(int_value); return {new_value}; } }
2,245
C++
.cpp
53
39
152
0.738991
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,629
query_folder_impl.cpp
altlinux_admc/src/admc/console_impls/query_folder_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/query_folder_impl.h" #include "adldap.h" #include "console_impls/item_type.h" #include "console_impls/object_impl.h" #include "console_impls/query_item_impl.h" #include "console_widget/results_view.h" #include "create_dialogs/create_query_folder_dialog.h" #include "create_dialogs/create_query_item_dialog.h" #include "edit_query_widgets/edit_query_folder_dialog.h" #include "globals.h" #include "settings.h" #include "utils.h" #include "icon_manager/icon_manager.h" #include <QFileDialog> #include <QJsonDocument> #include <QMenu> #include <QStack> #include <QStandardItem> #include <QStandardPaths> #define QUERY_ROOT "QUERY_ROOT" void console_query_move(ConsoleWidget *console, const QList<QPersistentModelIndex> &index_list, const QModelIndex &new_parent_index, const bool delete_old_branch = true); QueryFolderImpl::QueryFolderImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { copied_is_cut = false; set_results_view(new ResultsView(console_arg)); auto create_query_folder_action = new QAction(tr("Query folder"), this); auto create_query_item_action = new QAction(tr("Query item"), this); auto new_menu = new QMenu(tr("New"), console_arg); new_action = new_menu->menuAction(); new_menu->addAction(create_query_folder_action); new_menu->addAction(create_query_item_action); edit_action = new QAction(tr("Edit"), this); import_action = new QAction(tr("&Import query..."), this); connect( create_query_folder_action, &QAction::triggered, this, &QueryFolderImpl::on_create_query_folder); connect( create_query_item_action, &QAction::triggered, this, &QueryFolderImpl::on_create_query_item); connect( edit_action, &QAction::triggered, this, &QueryFolderImpl::on_edit_query_folder); connect( import_action, &QAction::triggered, this, &QueryFolderImpl::on_import); } void QueryFolderImpl::on_create_query_folder() { auto dialog = new CreateQueryFolderDialog(console); const QModelIndex parent_index = console->get_selected_item(ItemType_QueryFolder); const QList<QString> sibling_name_list = get_sibling_name_list(parent_index, QModelIndex()); dialog->set_sibling_name_list(sibling_name_list); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, parent_index]() { const QString name = dialog->name(); const QString description = dialog->description(); console_query_folder_create(console, name, description, parent_index); console_query_tree_save(console); }); } void QueryFolderImpl::on_create_query_item() { const QModelIndex parent_index = console->get_selected_item(ItemType_QueryFolder); const QList<QString> sibling_name_list = get_sibling_name_list(parent_index, QModelIndex()); auto dialog = new CreateQueryItemDialog(sibling_name_list, console); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, parent_index]() { const QString name = dialog->name(); const QString description = dialog->description(); const QString filter = dialog->filter(); const QString base = dialog->base(); const QByteArray filter_state = dialog->filter_state(); const bool scope_is_children = dialog->scope_is_children(); console_query_item_create(console, name, description, filter, filter_state, base, scope_is_children, parent_index); console_query_tree_save(console); }); } void QueryFolderImpl::on_edit_query_folder() { auto dialog = new EditQueryFolderDialog(console); const QModelIndex index = console->get_selected_item(ItemType_QueryFolder); { const QString name = index.data(Qt::DisplayRole).toString(); const QString description = index.data(QueryItemRole_Description).toString(); const QModelIndex parent_index = index.parent(); const QList<QString> sibling_name_list = get_sibling_name_list(parent_index, index); dialog->set_data(sibling_name_list, name, description); } dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, index]() { const QString name = dialog->name(); const QString description = dialog->description(); const QList<QStandardItem *> row = console->get_row(index); console_query_folder_load(row, name, description); console_query_tree_save(console); }); } bool QueryFolderImpl::can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(dropped_list); UNUSED_ARG(target); UNUSED_ARG(target_type); const bool dropped_is_target = dropped_list.contains(target); if (dropped_is_target) { return false; } const bool dropped_are_query_item_or_folder = (dropped_type_list - QSet<int>({ItemType_QueryItem, ItemType_QueryFolder})).isEmpty(); return dropped_are_query_item_or_folder; } void QueryFolderImpl::drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(dropped_type_list); UNUSED_ARG(target_type); console_query_move(console, dropped_list, target); } QList<QAction *> QueryFolderImpl::get_all_custom_actions() const { QList<QAction *> out; out.append(new_action); out.append(edit_action); out.append(import_action); return out; } QSet<QAction *> QueryFolderImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); const bool is_root = [&]() { QStandardItem *item = console->get_item(index); const bool out = item->data(QueryItemRole_IsRoot).toBool(); return out; }(); QSet<QAction *> out; if (single_selection) { if (is_root) { out.insert(new_action); out.insert(import_action); } else { out.insert(new_action); out.insert(edit_action); out.insert(import_action); } } return out; } QSet<StandardAction> QueryFolderImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); const bool is_root = [&]() { QStandardItem *item = console->get_item(index); const bool out = item->data(QueryItemRole_IsRoot).toBool(); return out; }(); QSet<StandardAction> out; if (!is_root) { out.insert(StandardAction_Delete); } if (single_selection) { if (is_root) { out.insert(StandardAction_Paste); } else { out.insert(StandardAction_Cut); out.insert(StandardAction_Copy); out.insert(StandardAction_Paste); } } return out; } void QueryFolderImpl::delete_action(const QList<QModelIndex> &index_list) { query_action_delete(console, index_list); } void QueryFolderImpl::cut(const QList<QModelIndex> &index_list) { copied_list = persistent_index_list(index_list); copied_is_cut = true; } void QueryFolderImpl::copy(const QList<QModelIndex> &index_list) { copied_list = persistent_index_list(index_list); copied_is_cut = false; } void QueryFolderImpl::paste(const QList<QModelIndex> &index_list) { const QModelIndex parent_index = index_list[0]; const bool recursive_cut_and_paste = (copied_is_cut && copied_list.contains(parent_index)); if (recursive_cut_and_paste) { message_box_warning(console, tr("Error"), tr("Can't cut and paste query folder into itself.")); return; } const bool parent_is_same = [&]() { for (const QModelIndex &index : copied_list) { const QModelIndex this_parent = index.parent(); if (this_parent == parent_index) { return true; } } return false; }(); // TODO: this is a band-aid on top of name conflict // check inside move(), try to make this // centralized if possible // Prohibit copy+paste into same parent. // console_query_move() does check for name // conflicts but doesn't handle this edge case. if (!copied_is_cut && parent_is_same) { message_box_warning(console, tr("Error"), tr("There's already an item with this name.")); return; } const bool delete_old_branch = copied_is_cut; console_query_move(console, copied_list, parent_index, delete_old_branch); } void QueryFolderImpl::on_import() { const QModelIndex parent_index = console->get_selected_item(ItemType_QueryFolder); const QList<QString> path_list = [&]() { const QString caption = QCoreApplication::translate("query_item_impl.cpp", "Import Query"); const QString dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); const QString file_filter = QCoreApplication::translate("query_item_impl.cpp", "JSON (*.json)"); const QList<QString> out = QFileDialog::getOpenFileNames(console, caption, dir, file_filter); return out; }(); if (path_list.isEmpty()) { return; } for (const QString &file_path : path_list) { const QHash<QString, QVariant> data = [&]() { QFile file(file_path); file.open(QIODevice::ReadOnly); const QByteArray json_bytes = file.readAll(); const QJsonDocument json_document = QJsonDocument::fromJson(json_bytes); if (json_document.isNull()) { const QString error_text = QString(QCoreApplication::translate("query.cpp", "Query file is corrupted.")); message_box_warning(console, QCoreApplication::translate("query.cpp", "Error"), error_text); return QHash<QString, QVariant>(); } const QHash<QString, QVariant> out = json_document.toVariant().toHash(); return out; }(); console_query_item_load_hash(console, data, parent_index); } console_query_tree_save(console); } void console_query_tree_init(ConsoleWidget *console) { const QList<QStandardItem *> root_row = console->add_scope_item(ItemType_QueryFolder, console->domain_info_index()); auto root = root_row[0]; root->setText(QCoreApplication::translate("query", "Saved Queries")); root->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_QUERY_FOLDER)); root->setDragEnabled(false); root->setData(true, QueryItemRole_IsRoot); // Add rest of tree const QHash<QString, QVariant> folder_list = settings_get_variant(SETTING_query_folders).toHash(); const QHash<QString, QVariant> item_list = settings_get_variant(SETTING_query_items).toHash(); QStack<QPersistentModelIndex> folder_stack; folder_stack.append(root->index()); while (!folder_stack.isEmpty()) { const QPersistentModelIndex folder_index = folder_stack.pop(); const QList<QString> child_list = [&]() { const QString folder_path = console_query_folder_path(folder_index); const QHash<QString, QVariant> folder_data = folder_list[folder_path].toHash(); return folder_data["child_list"].toStringList(); }(); // Go through children and add them as folders or // query items for (const QString &path : child_list) { if (item_list.contains(path)) { // Query item const QHash<QString, QVariant> data = item_list[path].toHash(); console_query_item_load_hash(console, data, folder_index); } else if (folder_list.contains(path)) { // Query folder const QHash<QString, QVariant> data = folder_list[path].toHash(); const QString name = data["name"].toString(); const QString description = data["description"].toString(); const QPersistentModelIndex child_index = console_query_folder_create(console, name, description, folder_index); folder_stack.append(child_index); } } } } // Saves current state of queries tree to settings. Should // be called after every modication to queries tree void console_query_tree_save(ConsoleWidget *console) { const QModelIndex root = get_query_tree_root(console); if (!root.isValid()) { return; } QHash<QString, QVariant> folder_list; QHash<QString, QVariant> item_list; QStack<QModelIndex> stack; stack.append(root); const QAbstractItemModel *model = root.model(); while (!stack.isEmpty()) { const QModelIndex index = stack.pop(); // Add children to stack for (int i = 0; i < model->rowCount(index); i++) { const QModelIndex child = model->index(i, 0, index); stack.append(child); } const QString path = console_query_folder_path(index); const QString parent_path = console_query_folder_path(index.parent()); const ItemType type = (ItemType) console_item_get_type(index); const QList<QString> child_list = [&]() { QList<QString> out; for (int i = 0; i < model->rowCount(index); i++) { const QModelIndex child = model->index(i, 0, index); const QString child_path = console_query_folder_path(child); out.append(child_path); } return out; }(); if (type == ItemType_QueryFolder) { const bool is_root = !index.parent().isValid(); if (is_root) { QHash<QString, QVariant> data; data["child_list"] = QVariant(child_list); folder_list[path] = data; } else { const QString name = index.data(Qt::DisplayRole).toString(); const QString description = index.data(QueryItemRole_Description).toString(); QHash<QString, QVariant> data; data["name"] = name; data["description"] = description; data["child_list"] = QVariant(child_list); folder_list[path] = data; } } else if (type == ItemType_QueryItem) { const QHash<QString, QVariant> data = console_query_item_save_hash(index); item_list[path] = data; } } const QVariant folder_variant = QVariant(folder_list); const QVariant item_variant = QVariant(item_list); settings_set_variant(SETTING_query_folders, folder_variant); settings_set_variant(SETTING_query_items, item_variant); } QModelIndex get_query_tree_root(ConsoleWidget *console) { const QModelIndex out = console->search_item(console->domain_info_index(), QueryItemRole_IsRoot, true, {ItemType_QueryFolder}); return out; } QList<QString> QueryFolderImpl::column_labels() const { return { QCoreApplication::translate("query_folder.cpp", "Name"), QCoreApplication::translate("query_folder.cpp", "Description"), }; } QList<int> QueryFolderImpl::default_columns() const { return {QueryColumn_Name, QueryColumn_Description}; } // NOTE: use constant QUERY_ROOT for root because query root // item has different name depending on app language. The // end result is that path for root is equal to // "QUERY_ROOT", while all other paths start with // "QUERY_ROOT/a/b/c..." QString console_query_folder_path(const QModelIndex &index) { const bool is_query_root = !index.parent().isValid(); if (is_query_root) { return QString(QUERY_ROOT); } const QList<QString> path_split = [&index]() { QList<QString> out; QModelIndex current = index; while (current.isValid()) { const QString name = current.data(Qt::DisplayRole).toString(); out.prepend(name); current = current.parent(); } // NOTE: remove root out.removeAt(0); return out; }(); const QString path = [&path_split]() { QString out; for (int i = 0; i < path_split.size(); i++) { const QString part = path_split[i]; if (i == 0) { out += QString(QUERY_ROOT) + "/"; } else { out += "/"; } out += part; } return out; }(); return path; } QModelIndex console_query_folder_create(ConsoleWidget *console, const QString &name, const QString &description, const QModelIndex &parent) { const QList<QStandardItem *> row = console->add_scope_item(ItemType_QueryFolder, parent); console_query_folder_load(row, name, description); return row[0]->index(); } void console_query_folder_load(const QList<QStandardItem *> &row, const QString &name, const QString &description) { QStandardItem *main_item = row[0]; main_item->setData(description, QueryItemRole_Description); main_item->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_QUERY_FOLDER)); main_item->setData(false, QueryItemRole_IsRoot); row[QueryColumn_Name]->setText(name); row[QueryColumn_Description]->setText(description); } bool console_query_or_folder_name_is_good(const QString &name, const QList<QString> &sibling_names, QWidget *parent_widget) { if (name.isEmpty()) { const QString error_text = QString(QCoreApplication::translate("query.cpp", "Name may not be empty")); message_box_warning(parent_widget, QCoreApplication::translate("query.cpp", "Error"), error_text); return false; } const bool name_conflict = sibling_names.contains(name); const bool name_contains_slash = name.contains("/"); if (name_conflict) { const QString error_text = QString(QCoreApplication::translate("query.cpp", "There's already an item with this name.")); message_box_warning(parent_widget, QCoreApplication::translate("query.cpp", "Error"), error_text); } else if (name_contains_slash) { const QString error_text = QString(QCoreApplication::translate("query.cpp", "Names cannot contain \"/\".")); message_box_warning(parent_widget, QCoreApplication::translate("query.cpp", "Error"), error_text); } const bool name_is_good = (!name_conflict && !name_contains_slash); return name_is_good; } bool console_query_or_folder_name_is_good(const QString &name, const QModelIndex &parent_index, QWidget *parent_widget, const QModelIndex &current_index) { const QList<QString> sibling_names = get_sibling_name_list(parent_index, current_index); return console_query_or_folder_name_is_good(name, sibling_names, parent_widget); } void query_action_delete(ConsoleWidget *console, const QList<QModelIndex> &index_list) { const bool confirmed = confirmation_dialog(QCoreApplication::translate("query_folder_impl.cpp", "Are you sure you want to delete this item?"), console); if (!confirmed) { return; } const QList<QPersistentModelIndex> persistent_list = persistent_index_list(index_list); for (const QPersistentModelIndex &index : persistent_list) { console->delete_item(index); } console_query_tree_save(console); } void console_query_move(ConsoleWidget *console, const QList<QPersistentModelIndex> &index_list, const QModelIndex &new_parent_index, const bool delete_old_branch) { // Check for name conflict for (const QPersistentModelIndex &index : index_list) { const QString name = index.data(Qt::DisplayRole).toString(); if (!console_query_or_folder_name_is_good(name, new_parent_index, console, index)) { return; } } for (const QPersistentModelIndex &old_index : index_list) { // Create a copy of the tree branch at new location. Go // down the branch and replicate all of the children. // This map contains mapping between old parents of // indexes in branch and new parents. Filled out as the // branch is copied over to new location. QHash<QPersistentModelIndex, QPersistentModelIndex> new_parent_map; new_parent_map[old_index.parent()] = new_parent_index; QStack<QPersistentModelIndex> stack; QList<QPersistentModelIndex> created_list; stack.append(old_index); while (!stack.isEmpty()) { const QPersistentModelIndex index = stack.pop(); const QPersistentModelIndex new_parent = new_parent_map[index.parent()]; const ItemType type = (ItemType) console_item_get_type(index); if (type == ItemType_QueryItem) { const QString description = index.data(QueryItemRole_Description).toString(); const QString filter = index.data(QueryItemRole_Filter).toString(); const QByteArray filter_state = index.data(QueryItemRole_FilterState).toByteArray(); const QString base = index.data(QueryItemRole_Base).toString(); const QString name = index.data(Qt::DisplayRole).toString(); const bool scope_is_children = index.data(QueryItemRole_ScopeIsChildren).toBool(); const QModelIndex item_index = console_query_item_create(console, name, description, filter, filter_state, base, scope_is_children, new_parent); created_list.append(item_index); } else if (type == ItemType_QueryFolder) { const QString name = index.data(Qt::DisplayRole).toString(); const QString description = index.data(QueryItemRole_Description).toString(); const QModelIndex folder_index = console_query_folder_create(console, name, description, new_parent); created_list.append(folder_index); new_parent_map[index] = QPersistentModelIndex(folder_index); } QAbstractItemModel *index_model = (QAbstractItemModel *) index.model(); for (int row = 0; row < index_model->rowCount(index); row++) { const QModelIndex child = index_model->index(row, 0, index); // NOTE: don't add indexes that were // created during the move process, to // avoid infinite loop. This can happen // when copying and pasting a folder // into itself. const bool child_was_created = created_list.contains(QPersistentModelIndex(child)); if (!child_was_created) { stack.append(QPersistentModelIndex(child)); } } } // Delete branch at old location if (delete_old_branch) { console->delete_item(old_index); } } console_query_tree_save(console); } QList<QString> get_sibling_name_list(const QModelIndex &parent_index, const QModelIndex &index_to_omit) { QList<QString> out; const QAbstractItemModel *model = parent_index.model(); for (int row = 0; row < model->rowCount(parent_index); row++) { const QModelIndex sibling = model->index(row, 0, parent_index); const QString sibling_name = sibling.data(Qt::DisplayRole).toString(); const bool this_is_query_itself = (sibling == index_to_omit); if (this_is_query_itself) { continue; } out.append(sibling_name); } return out; }
24,342
C++
.cpp
520
38.975
178
0.659609
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,630
object_impl.cpp
altlinux_admc/src/admc/console_impls/object_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/object_impl.h" #include "adldap.h" #include "attribute_dialogs/list_attribute_dialog.h" #include "console_filter_dialog.h" #include "console_impls/find_object_impl.h" #include "console_impls/item_type.h" #include "console_impls/policy_ou_impl.h" #include "console_impls/policy_root_impl.h" #include "console_impls/query_folder_impl.h" #include "console_impls/query_item_impl.h" #include "console_widget/results_view.h" #include "create_dialogs/create_computer_dialog.h" #include "create_dialogs/create_contact_dialog.h" #include "create_dialogs/create_group_dialog.h" #include "create_dialogs/create_ou_dialog.h" #include "create_dialogs/create_shared_folder_dialog.h" #include "create_dialogs/create_user_dialog.h" #include "find_widgets/find_object_dialog.h" #include "globals.h" #include "password_dialog.h" #include "properties_widgets/properties_dialog.h" #include "properties_widgets/properties_multi_dialog.h" #include "rename_dialogs/rename_group_dialog.h" #include "rename_dialogs/rename_object_dialog.h" #include "rename_dialogs/rename_other_dialog.h" #include "rename_dialogs/rename_user_dialog.h" #include "search_thread.h" #include "select_dialogs/select_container_dialog.h" #include "select_dialogs/select_object_dialog.h" #include "settings.h" #include "status.h" #include "utils.h" #include "tabs/general_user_tab.h" #include "tabs/general_group_tab.h" #include "icon_manager/icon_manager.h" #include "create_dialogs/create_pso_dialog.h" #include "results_widgets/pso_results_widget/pso_results_widget.h" #include <QDebug> #include <QMenu> #include <QSet> #include <QStandardItemModel> #include <QStackedWidget> #include <QMessageBox> #include <algorithm> enum DropType { DropType_Move, DropType_AddToGroup, DropType_None }; DropType console_object_get_drop_type(const QModelIndex &dropped, const QModelIndex &target); QList<QString> get_selected_dn_list_object(ConsoleWidget *console); QString get_selected_target_dn_object(ConsoleWidget *console); void console_object_delete_dn_list(ConsoleWidget *console, const QList<QString> &dn_list, const QModelIndex &tree_root, const int type, const int dn_role); bool can_create_class_at_parent(const QString &create_class, const QString &parent_class); void console_object_move_and_rename(const QList<ConsoleWidget *> &console_list, AdInterface &ad, const QHash<QString, QString> &old_to_new_dn_map_arg, const QString &new_parent_dn); ObjectImpl::ObjectImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { console_list = { console, }; stacked_widget = new QStackedWidget(console_arg); set_results_view(new ResultsView(console_arg)); group_results_widget = new GeneralGroupTab(); user_results_widget = new GeneralUserTab(); pso_results_widget = new PSOResultsWidget(); stacked_widget->addWidget(group_results_widget); stacked_widget->addWidget(user_results_widget); stacked_widget->addWidget(pso_results_widget); stacked_widget->addWidget(view()); set_results_widget(stacked_widget); find_action_enabled = true; refresh_action_enabled = true; toolbar_create_user = nullptr; toolbar_create_group = nullptr; toolbar_create_ou = nullptr; object_filter = settings_get_variant(SETTING_object_filter).toString(); object_filter_enabled = settings_get_variant(SETTING_object_filter_enabled).toBool(); new_action_map[CLASS_USER] = new QAction(tr("User"), this); new_action_map[CLASS_COMPUTER] = new QAction(tr("Computer"), this); new_action_map[CLASS_OU] = new QAction(tr("OU"), this); new_action_map[CLASS_GROUP] = new QAction(tr("Group"), this); new_action_map[CLASS_SHARED_FOLDER] = new QAction(tr("Shared Folder"), this); new_action_map[CLASS_INET_ORG_PERSON] = new QAction(tr("inetOrgPerson"), this); new_action_map[CLASS_CONTACT] = new QAction(tr("Contact"), this); find_action = new QAction(tr("Find..."), this); move_action = new QAction(tr("Move..."), this); add_to_group_action = new QAction(tr("Add to group..."), this); enable_action = new QAction(tr("Enable"), this); disable_action = new QAction(tr("Disable"), this); reset_password_action = new QAction(tr("Reset password"), this); reset_account_action = new QAction(tr("Reset account"), this); edit_upn_suffixes_action = new QAction(tr("Edit UPN suffixes"), this); create_pso_action = new QAction(tr("Create password setting object"), this); auto new_menu = new QMenu(tr("New"), console_arg); new_action = new_menu->menuAction(); const QList<QString> new_action_keys_sorted = [&]() { QList<QString> out = new_action_map.keys(); std::sort(out.begin(), out.end()); return out; }(); for (const QString &key : new_action_keys_sorted) { QAction *action = new_action_map[key]; new_menu->addAction(action); } connect( new_action_map[CLASS_USER], &QAction::triggered, this, &ObjectImpl::on_new_user); connect( new_action_map[CLASS_COMPUTER], &QAction::triggered, this, &ObjectImpl::on_new_computer); connect( new_action_map[CLASS_OU], &QAction::triggered, this, &ObjectImpl::on_new_ou); connect( new_action_map[CLASS_GROUP], &QAction::triggered, this, &ObjectImpl::on_new_group); connect( new_action_map[CLASS_SHARED_FOLDER], &QAction::triggered, this, &ObjectImpl::on_new_shared_folder); connect( new_action_map[CLASS_INET_ORG_PERSON], &QAction::triggered, this, &ObjectImpl::on_new_inet_org_person); connect( new_action_map[CLASS_CONTACT], &QAction::triggered, this, &ObjectImpl::on_new_contact); connect( move_action, &QAction::triggered, this, &ObjectImpl::on_move); connect( add_to_group_action, &QAction::triggered, this, &ObjectImpl::on_add_to_group); connect( enable_action, &QAction::triggered, this, &ObjectImpl::on_enable); connect( disable_action, &QAction::triggered, this, &ObjectImpl::on_disable); connect( reset_password_action, &QAction::triggered, this, &ObjectImpl::on_reset_password); connect( reset_account_action, &QAction::triggered, this, &ObjectImpl::on_reset_account); connect( find_action, &QAction::triggered, this, &ObjectImpl::on_find); connect( edit_upn_suffixes_action, &QAction::triggered, this, &ObjectImpl::on_edit_upn_suffixes); connect( console, &ConsoleWidget::selection_changed, this, &ObjectImpl::update_toolbar_actions); connect( create_pso_action, &QAction::triggered, this, &ObjectImpl::on_create_pso); } void ObjectImpl::set_buddy_console(ConsoleWidget *buddy_console) { console_list = { console, buddy_console, }; } // Load children of this item in scope tree // and load results linked to this scope item void ObjectImpl::fetch(const QModelIndex &index) { const QString base = index.data(ObjectRole_DN).toString(); const SearchScope scope = SearchScope_Children; // // Search object's children // const QString filter = [=]() { QString out; // NOTE: OR user filter with containers filter so // that container objects are always shown, even if // they are filtered out by user filter if (object_filter_enabled) { out = filter_OR({is_container_filter(), out}); out = filter_OR({object_filter, out}); } out = advanced_features_filter(out); return out; }(); const QList<QString> attributes = console_object_search_attributes(); // NOTE: do an extra search before real search for // objects that should be visible in dev mode const bool dev_mode = settings_get_variant(SETTING_feature_dev_mode).toBool(); if (dev_mode) { AdInterface ad; if (ad_connected(ad, console)) { QHash<QString, AdObject> results; dev_mode_search_results(results, ad, base); object_impl_add_objects_to_console(console, results.values(), index); } } console_object_search(console, index, base, scope, filter, attributes); } bool ObjectImpl::can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(target_type); const bool dropped_are_all_objects = (dropped_type_list == QSet<int>({ItemType_Object})); if (dropped_are_all_objects) { if (dropped_list.size() == 1) { const QPersistentModelIndex dropped = dropped_list[0]; const DropType drop_type = console_object_get_drop_type(dropped, target); const bool can_drop = (drop_type != DropType_None); return can_drop; } else { // NOTE: always allow dropping when dragging // multiple objects. This way, whatever objects // can drop will be dropped and if others fail // to drop it's not a big deal. return true; } } else { return false; } } void ObjectImpl::drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(target_type); UNUSED_ARG(dropped_type_list); const QString target_dn = target.data(ObjectRole_DN).toString(); AdInterface ad; if (ad_failed(ad, console)) { return; } show_busy_indicator(); for (const QPersistentModelIndex &dropped : dropped_list) { const QString dropped_dn = dropped.data(ObjectRole_DN).toString(); const DropType drop_type = console_object_get_drop_type(dropped, target); switch (drop_type) { case DropType_Move: { const bool move_success = ad.object_move(dropped_dn, target_dn); if (move_success) { move(ad, QList<QString>({dropped_dn}), target_dn); } break; } case DropType_AddToGroup: { ad.group_add_member(target_dn, dropped_dn); break; } case DropType_None: { break; } } } hide_busy_indicator(); g_status->display_ad_messages(ad, console); } QString ObjectImpl::get_description(const QModelIndex &index) const { QString out; const QString object_count_text = console_object_count_string(console, index); out += object_count_text; if (object_filter_enabled) { out += tr(" [Filtering enabled]"); } return out; } void ObjectImpl::activate(const QModelIndex &index) { properties({index}); } QList<QAction *> ObjectImpl::get_all_custom_actions() const { QList<QAction *> out = { new_action, find_action, add_to_group_action, enable_action, disable_action, reset_password_action, reset_account_action, edit_upn_suffixes_action, move_action, create_pso_action, }; return out; } QSet<QAction *> ObjectImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { QSet<QAction *> out; const QString object_class = index.data(ObjectRole_ObjectClasses).toStringList().last(); const bool is_container = [=]() { const QList<QString> container_classes = g_adconfig->get_filter_containers(); return container_classes.contains(object_class); }(); const bool is_user = (object_class == CLASS_USER); const bool is_group = (object_class == CLASS_GROUP); const bool is_domain = (object_class == CLASS_DOMAIN); const bool is_computer = (object_class == CLASS_COMPUTER); const bool is_pso_container = (object_class == CLASS_PSO_CONTAINER); const bool account_disabled = index.data(ObjectRole_AccountDisabled).toBool(); if (single_selection) { // Single selection only if (is_container) { out.insert(new_action); if (find_action_enabled) { out.insert(find_action); } } if (is_user) { out.insert(reset_password_action); } if (is_user || is_computer) { if (account_disabled) { out.insert(enable_action); } else { out.insert(disable_action); } } if (is_computer) { out.insert(reset_account_action); } if (is_domain) { out.insert(edit_upn_suffixes_action); } if (is_pso_container) { out.insert(create_pso_action); } } else { // Multi selection only if (is_user) { out.insert(enable_action); out.insert(disable_action); } if (is_computer) { out.insert(reset_account_action); } } // Single OR multi selection if (is_user || is_group) { out.insert(add_to_group_action); } out.insert(move_action); // NOTE: have to manually call setVisible here // because "New" actions are contained inside "New" // sub-menu, so console widget can't manage them for (const QString &action_object_class : new_action_map.keys()) { QAction *action = new_action_map[action_object_class]; const bool is_visible = can_create_class_at_parent(action_object_class, object_class); action->setVisible(is_visible); } return out; } QSet<QAction *> ObjectImpl::get_disabled_custom_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(single_selection); QSet<QAction *> out; const QString object_class = index.data(ObjectRole_ObjectClasses).toStringList().last(); const bool cannot_move = index.data(ObjectRole_CannotMove).toBool(); if (cannot_move || object_class == CLASS_PSO) { out.insert(move_action); } return out; } QSet<StandardAction> ObjectImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { QSet<StandardAction> out; out.insert(StandardAction_Properties); // NOTE: only add refresh action if item was fetched, // this filters out all the objects like users that // should never get refresh action const bool can_refresh = console_item_get_was_fetched(index); if (can_refresh && single_selection && refresh_action_enabled) { out.insert(StandardAction_Refresh); } const bool can_rename = [&]() { const QList<QString> renamable_class_list = { CLASS_USER, CLASS_GROUP, CLASS_OU, }; const QString object_class = index.data(ObjectRole_ObjectClasses).toStringList().last(); const bool can_rename_out = (single_selection && renamable_class_list.contains(object_class)); return can_rename_out; }(); if (can_rename) { out.insert(StandardAction_Rename); } out.insert(StandardAction_Delete); return out; } QSet<StandardAction> ObjectImpl::get_disabled_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(single_selection); QSet<StandardAction> out; const bool cannot_rename = index.data(ObjectRole_CannotRename).toBool(); const bool cannot_delete = index.data(ObjectRole_CannotDelete).toBool(); if (cannot_rename) { out.insert(StandardAction_Rename); } if (cannot_delete) { out.insert(StandardAction_Delete); } return out; } void ObjectImpl::rename(const QList<QModelIndex> &index_list) { const QModelIndex index = index_list[0]; const QString object_class = index.data(ObjectRole_ObjectClasses).toStringList().last(); console_object_rename(console_list, index_list, ObjectRole_DN, object_class); } void console_object_rename(const QList<ConsoleWidget *> &console_list, const QList<QModelIndex> &index_list, const int dn_role, const QString &object_class) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } const QString old_dn = [&]() { if (!index_list.isEmpty()) { const QModelIndex index = index_list[0]; const QString out = index.data(dn_role).toString(); return out; } else { return QString(); } }(); RenameObjectDialog *dialog = [&]() -> RenameObjectDialog * { const bool is_user = (object_class == CLASS_USER); const bool is_group = (object_class == CLASS_GROUP); if (is_user) { return new RenameUserDialog(ad, old_dn, console_list[0]); } else if (is_group) { return new RenameGroupDialog(ad, old_dn, console_list[0]); } else { return new RenameOtherDialog(ad, old_dn, console_list[0]); } }(); dialog->open(); QObject::connect( dialog, &QDialog::accepted, console_list[0], [console_list, dialog, old_dn]() { AdInterface ad_inner; if (ad_failed(ad_inner, console_list[0])) { return; } const QString new_dn = dialog->get_new_dn(); const QString parent_dn = dn_get_parent(old_dn); console_object_move_and_rename(console_list, ad_inner, {{old_dn, new_dn}}, parent_dn); }); } void ObjectImpl::properties(const QList<QModelIndex> &index_list) { const QList<QString> class_list = [&]() { QSet<QString> out; for (const QModelIndex &index : index_list) { const QList<QString> this_class_list = index.data(ObjectRole_ObjectClasses).toStringList(); const QString main_class = this_class_list.last(); out.insert(main_class); } return QList<QString>(out.begin(), out.end()); }(); console_object_properties(console_list, index_list, ObjectRole_DN, class_list); } void console_object_properties(const QList<ConsoleWidget *> &console_list, const QList<QModelIndex> &index_list, const int dn_role, const QList<QString> &class_list) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } const QList<QString> dn_list = index_list_to_dn_list(index_list, dn_role); auto on_object_properties_applied = [console_list, dn_list]() { AdInterface ad2; if (ad_failed(ad2, console_list[0])) { return; } const QList<AdObject> object_list = [&]() { QList<AdObject> out; for (const QString &dn : dn_list) { const AdObject object = ad2.search_object(dn); // TODO: band-aid for the situations // where properties dialog interacts // with deleted objects. Bad stuff can // still happen if properties is opened // while object exists, then object is // deleted and properties is applied. // Remove this or improve it when you // tackle this issue head-on. if (object.is_empty()) { continue; } out.append(object); } return out; }(); auto apply_changes = [&ad2, &object_list](ConsoleWidget *target_console) { auto apply_changes_to_branch = [&](const QModelIndex &root_index, const int item_type, const int update_dn_role) { if (!root_index.isValid()) { return; } for (const AdObject &object : object_list) { const QString dn = object.get_dn(); const QModelIndex object_index = target_console->search_item(root_index, update_dn_role, dn, {item_type}); if (object_index.isValid()) { const QList<QStandardItem *> object_row = target_console->get_row(object_index); console_object_load(object_row, object); } } }; const QModelIndex object_root = get_object_tree_root(target_console); const QModelIndex query_root = get_query_tree_root(target_console); const QModelIndex policy_root = get_policy_tree_root(target_console); const QModelIndex find_object_root = get_find_object_root(target_console); apply_changes_to_branch(object_root, ItemType_Object, ObjectRole_DN); apply_changes_to_branch(query_root, ItemType_Object, ObjectRole_DN); apply_changes_to_branch(find_object_root, ItemType_Object, ObjectRole_DN); // Apply to policy branch if (policy_root.isValid()) { for (const AdObject &object : object_list) { const QString dn = object.get_dn(); const QModelIndex object_index = target_console->search_item(policy_root, PolicyOURole_DN, dn, {ItemType_PolicyOU}); if (object_index.isValid()) { const QList<QStandardItem *> object_row = target_console->get_row(object_index); policy_ou_impl_load_row(object_row, object); } } } }; for (ConsoleWidget *console : console_list) { apply_changes(console); } g_status->display_ad_messages(ad2, console_list[0]); }; if (dn_list.size() == 1) { const QString dn = dn_list[0]; bool dialog_is_new; PropertiesDialog *dialog = PropertiesDialog::open_for_target(ad, dn, &dialog_is_new, console_list[0]); if (dialog_is_new) { QObject::connect( dialog, &PropertiesDialog::applied, console_list[0], on_object_properties_applied); QObject::connect( dialog, &PropertiesDialog::applied, [console_list]() {console_list[0]->update_current_item_results_widget();}); } } else if (dn_list.size() > 1) { auto dialog = new PropertiesMultiDialog(ad, dn_list, class_list); dialog->open(); QObject::connect( dialog, &PropertiesMultiDialog::applied, console_list[0], on_object_properties_applied); } } void ObjectImpl::refresh(const QList<QModelIndex> &index_list) { if (index_list.size() != 1) { return; } const QModelIndex index = index_list[0]; console->delete_children(index); fetch(index); update_results_widget(index); } void ObjectImpl::delete_action(const QList<QModelIndex> &index_list) { console_object_delete(console_list, index_list, ObjectRole_DN); } void ObjectImpl::selected_as_scope(const QModelIndex &index) { AdInterface ad; if (ad_failed(ad, console)) { return; } const QString dn = index.data(ObjectRole_DN).toString(); const AdObject object = ad.search_object(dn); if (object.is_class(CLASS_GROUP)) { stacked_widget->setCurrentWidget(group_results_widget); group_results_widget->update(ad, object); } else if (object.is_class(CLASS_CONTACT) || object.is_class(CLASS_USER) || object.is_class(CLASS_INET_ORG_PERSON)) { stacked_widget->setCurrentWidget(user_results_widget); user_results_widget->update(ad, object); } else if (object.is_class(CLASS_PSO)) { stacked_widget->setCurrentWidget(pso_results_widget); pso_results_widget->update(object); } else { stacked_widget->setCurrentWidget(view()); } } void ObjectImpl::update_results_widget(const QModelIndex &index) const { const QStringList index_data_classes = index.data(ObjectRole_ObjectClasses).toStringList(); if (!(index_data_classes.contains(CLASS_GROUP) || index_data_classes.contains(CLASS_CONTACT) || index_data_classes.contains(CLASS_USER) || index_data_classes.contains(CLASS_INET_ORG_PERSON) || index_data_classes.contains(CLASS_PSO))) { return; } AdInterface ad; if (ad_failed(ad, console)) { return; } const QString dn = index.data(ObjectRole_DN).toString(); const AdObject object = ad.search_object(dn); if (object.is_class(CLASS_GROUP)) { group_results_widget->update(ad, object); return; } if (object.is_class(CLASS_CONTACT) || object.is_class(CLASS_USER) || object.is_class(CLASS_INET_ORG_PERSON)) { user_results_widget->update(ad, object); return; } if (object.is_class(CLASS_PSO)) { pso_results_widget->update(object); return; } } void console_object_delete(const QList<ConsoleWidget *> &console_list, const QList<QModelIndex> &index_list, const int dn_role) { const bool confirmed = console_object_deletion_dialog(console_list[0], index_list); if (!confirmed) { return; } AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } show_busy_indicator(); const QList<QString> deleted_list = [&]() { QList<QString> out; const QList<QString> target_list = index_list_to_dn_list(index_list, dn_role); for (const QString &target : target_list) { const bool success = ad.object_delete(target); if (success) { out.append(target); } } return out; }(); auto apply_changes = [&ad, &deleted_list](ConsoleWidget *target_console) { const QList<QModelIndex> root_list = { get_object_tree_root(target_console), get_query_tree_root(target_console), get_find_object_root(target_console), }; for (const QModelIndex &root : root_list) { if (root.isValid()) { console_object_delete_dn_list(target_console, deleted_list, root, ItemType_Object, ObjectRole_DN); } } const QModelIndex policy_root = get_policy_tree_root(target_console); if (policy_root.isValid()) { console_object_delete_dn_list(target_console, deleted_list, policy_root, ItemType_PolicyOU, PolicyOURole_DN); } }; for (ConsoleWidget *console : console_list) { apply_changes(console); } hide_busy_indicator(); g_status->display_ad_messages(ad, console_list[0]); } void ObjectImpl::set_find_action_enabled(const bool enabled) { find_action_enabled = enabled; } void ObjectImpl::set_refresh_action_enabled(const bool enabled) { refresh_action_enabled = enabled; } void ObjectImpl::set_toolbar_actions(QAction *toolbar_create_user_arg, QAction *toolbar_create_group_arg, QAction *toolbar_create_ou_arg) { toolbar_create_user = toolbar_create_user_arg; toolbar_create_group = toolbar_create_group_arg; toolbar_create_ou = toolbar_create_ou_arg; connect( toolbar_create_user, &QAction::triggered, this, &ObjectImpl::on_new_user); connect( toolbar_create_group, &QAction::triggered, this, &ObjectImpl::on_new_group); connect( toolbar_create_ou, &QAction::triggered, this, &ObjectImpl::on_new_ou); } QList<QString> ObjectImpl::column_labels() const { return object_impl_column_labels(); } QList<int> ObjectImpl::default_columns() const { return object_impl_default_columns(); } void ObjectImpl::refresh_tree() { const QModelIndex object_tree_root = get_object_tree_root(console); if (!object_tree_root.isValid()) { return; } show_busy_indicator(); console->refresh_scope(object_tree_root); hide_busy_indicator(); } void ObjectImpl::open_console_filter_dialog() { auto dialog = new ConsoleFilterDialog(console); const QVariant dialog_state = settings_get_variant(SETTING_console_filter_dialog_state); dialog->restore_state(dialog_state); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { object_filter = dialog->get_filter(); object_filter_enabled = dialog->get_filter_enabled(); settings_set_variant(SETTING_object_filter, object_filter); settings_set_variant(SETTING_object_filter_enabled, object_filter_enabled); settings_set_variant(SETTING_console_filter_dialog_state, dialog->save_state()); refresh_tree(); }); } void ObjectImpl::on_new_user() { new_object(CLASS_USER); } void ObjectImpl::on_new_computer() { new_object(CLASS_COMPUTER); } void ObjectImpl::on_new_ou() { new_object(CLASS_OU); } void ObjectImpl::on_new_group() { new_object(CLASS_GROUP); } void ObjectImpl::on_new_shared_folder() { new_object(CLASS_SHARED_FOLDER); } void ObjectImpl::on_new_inet_org_person() { new_object(CLASS_INET_ORG_PERSON); } void ObjectImpl::on_new_contact() { new_object(CLASS_CONTACT); } void ObjectImpl::on_create_pso() { new_object(CLASS_PSO); } void ObjectImpl::on_move() { AdInterface ad; if (ad_failed(ad, console)) { return; } auto dialog = new SelectContainerDialog(ad, console); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { AdInterface ad2; if (ad_failed(ad2, console)) { return; } const QList<QString> dn_list = get_selected_dn_list_object(console); show_busy_indicator(); const QString new_parent_dn = dialog->get_selected(); // First move in AD const QList<QString> moved_objects = [&]() { QList<QString> out; for (const QString &dn : dn_list) { const bool success = ad2.object_move(dn, new_parent_dn); if (success) { out.append(dn); } } return out; }(); g_status->display_ad_messages(ad2, nullptr); // Then move in console move(ad2, moved_objects, new_parent_dn); hide_busy_indicator(); }); } void ObjectImpl::on_enable() { set_disabled(false); } void ObjectImpl::on_disable() { set_disabled(true); } void ObjectImpl::on_add_to_group() { auto dialog = new SelectObjectDialog({CLASS_GROUP}, SelectObjectDialogMultiSelection_Yes, console); dialog->setWindowTitle(tr("Add to Group")); dialog->open(); connect( dialog, &SelectObjectDialog::accepted, this, [this, dialog]() { AdInterface ad; if (ad_failed(ad, console)) { return; } show_busy_indicator(); const QList<QString> target_list = get_selected_dn_list_object(console); const QList<QString> groups = dialog->get_selected(); for (const QString &target : target_list) { for (auto group : groups) { ad.group_add_member(group, target); } } hide_busy_indicator(); g_status->display_ad_messages(ad, console); }); } void ObjectImpl::on_find() { const QList<QString> dn_list = get_selected_dn_list_object(console); const QString dn = dn_list[0]; auto find_dialog = new FindObjectDialog(console, dn, console); find_dialog->open(); } void ObjectImpl::on_reset_password() { AdInterface ad; if (ad_failed(ad, console)) { return; } const QString dn = get_selected_target_dn_object(console); auto dialog = new PasswordDialog(ad, dn, console); dialog->open(); } void ObjectImpl::on_edit_upn_suffixes() { AdInterface ad; if (ad_failed(ad, console)) { return; } // Open attribute dialog for upn suffixes attribute of // partitions object const QString partitions_dn = g_adconfig->partitions_dn(); const AdObject partitions_object = ad.search_object(partitions_dn); const QList<QByteArray> current_values = partitions_object.get_values(ATTRIBUTE_UPN_SUFFIXES); g_status->display_ad_messages(ad, console); const QString attribute = ATTRIBUTE_UPN_SUFFIXES; const bool read_only = false; auto dialog = new ListAttributeDialog(current_values, attribute, read_only, console); dialog->setWindowTitle(tr("Edit UPN Suffixes")); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, partitions_dn]() { AdInterface ad_inner; if (ad_failed(ad_inner, console)) { return; } const QList<QByteArray> new_values = dialog->get_value_list(); ad_inner.attribute_replace_values(partitions_dn, ATTRIBUTE_UPN_SUFFIXES, new_values); g_status->display_ad_messages(ad_inner, console); }); } void ObjectImpl::on_reset_account() { const bool confirmed = confirmation_dialog(tr("Are you sure you want to reset this account?"), console); if (!confirmed) { return; } AdInterface ad; if (ad_failed(ad, console)) { return; } show_busy_indicator(); const QList<QString> target_list = get_selected_dn_list_object(console); for (const QString &target : target_list) { ad.computer_reset_account(target); } hide_busy_indicator(); g_status->display_ad_messages(ad, console); } void ObjectImpl::new_object(const QString &object_class) { const QString parent_dn = get_selected_target_dn_object(console); console_object_create({console}, object_class, parent_dn); } void console_object_create(const QList<ConsoleWidget *> &console_list, const QString &object_class, const QString &parent_dn) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } // NOTE: creating dialogs here instead of directly // in "on_new_x" slots looks backwards but it's // necessary to avoid even more code duplication // due to having to pass "ad" and "parent_dn" args // to dialog ctors CreateObjectDialog *dialog = [&]() -> CreateObjectDialog * { const bool is_user = (object_class == CLASS_USER); const bool is_group = (object_class == CLASS_GROUP); const bool is_computer = (object_class == CLASS_COMPUTER); const bool is_ou = (object_class == CLASS_OU); const bool is_shared_folder = (object_class == CLASS_SHARED_FOLDER); const bool is_inet_org_person = (object_class == CLASS_INET_ORG_PERSON); const bool is_contact = (object_class == CLASS_CONTACT); const bool is_pso = (object_class == CLASS_PSO); if (is_user) { return new CreateUserDialog(ad, parent_dn, CLASS_USER, console_list[0]); } else if (is_group) { return new CreateGroupDialog(parent_dn, console_list[0]); } else if (is_computer) { return new CreateComputerDialog(parent_dn, console_list[0]); } else if (is_ou) { return new CreateOUDialog(parent_dn, console_list[0]); } else if (is_shared_folder) { return new CreateSharedFolderDialog(parent_dn, console_list[0]); } else if (is_inet_org_person) { return new CreateUserDialog(ad, parent_dn, CLASS_INET_ORG_PERSON, console_list[0]); } else if (is_contact) { return new CreateContactDialog(parent_dn, console_list[0]); } else if (is_pso) { return new CreatePSODialog(parent_dn, console_list[0]); } else { return nullptr; } }(); if (dialog == nullptr) { return; } dialog->open(); QObject::connect( dialog, &QDialog::accepted, console_list[0], [console_list, dialog, parent_dn, object_class]() { AdInterface ad_inner; if (ad_failed(ad_inner, console_list[0])) { return; } show_busy_indicator(); const QString created_dn = dialog->get_created_dn(); // NOTE: we don't just use currently selected index as // parent to add new object onto, because you can create // an object in a query tree or find dialog. Therefore // need to search for index of parent object in domain // tree. auto apply_changes = [&](ConsoleWidget *target_console) { const QModelIndex object_root = get_object_tree_root(target_console); if (object_root.isValid()) { const QModelIndex parent_object = target_console->search_item(object_root, ObjectRole_DN, parent_dn, {ItemType_Object}); if (parent_object.isValid()) { object_impl_add_objects_to_console_from_dns(target_console, ad_inner, {created_dn}, parent_object); } } // NOTE: changes are not applied to // find tree because creation of // objects shouldn't affect find // results. If it does affect them by // creating a new object that fits // search criteria, then find dialog // can just be considered out of date // and should be updated // Apply changes to policy tree const QModelIndex policy_root = get_policy_tree_root(target_console); if (policy_root.isValid() && object_class == CLASS_OU) { 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); } } }; for (ConsoleWidget *console : console_list) { apply_changes(console); } hide_busy_indicator(); }); } void ObjectImpl::set_disabled(const bool disabled) { AdInterface ad; if (ad_failed(ad, console)) { return; } show_busy_indicator(); const QList<QString> changed_objects = [&]() { QList<QString> out; const QList<QString> dn_list = get_selected_dn_list_object(console); for (const QString &dn : dn_list) { const bool success = ad.user_set_account_option(dn, AccountOption_Disabled, disabled); if (success) { out.append(dn); } } return out; }(); auto apply_changes = [&changed_objects, &disabled](ConsoleWidget *target_console) { auto apply_changes_to_branch = [&](const QModelIndex &root_index) { if (!root_index.isValid()) { return; } 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); const QString category= dn_get_name(item->data(ObjectRole_ObjectCategory).toString()); QIcon icon; if (category == OBJECT_CATEGORY_PERSON) { icon = disabled ? g_icon_manager->get_icon_for_type(ItemIconType_Person_Blocked) : g_icon_manager->get_icon_for_type(ItemIconType_Person_Clean); } else if (category == OBJECT_CATEGORY_COMPUTER) { icon = disabled ? g_icon_manager->get_icon_for_type(ItemIconType_Computer_Blocked) : g_icon_manager->get_icon_for_type(ItemIconType_Computer_Clean); } item->setIcon(icon); } } }; const QModelIndex object_root = get_object_tree_root(target_console); const QModelIndex find_object_root = get_find_object_root(target_console); const QModelIndex query_root = get_query_tree_root(target_console); apply_changes_to_branch(object_root); apply_changes_to_branch(find_object_root); apply_changes_to_branch(query_root); }; for (ConsoleWidget *target_console : console_list) { apply_changes(target_console); } hide_busy_indicator(); g_status->display_ad_messages(ad, console); } void console_object_move_and_rename(const QList<ConsoleWidget *> &console_list, AdInterface &ad, const QHash<QString, QString> &old_to_new_dn_map_arg, const QString &new_parent_dn) { // NOTE: sometimes, some objects that are supposed // to be moved don't actually need to be. For // example, if an object were to be moved to an // object that is already it's current parent. If // we were to move them that would cause gui // glitches because that kind of move is not // considered in the update logic. Instead, we skip // these kinds of objects. const QHash<QString, QString> &old_to_new_dn_map = [&]() { QHash<QString, QString> out; for (const QString &old_dn : old_to_new_dn_map_arg.keys()) { const QString new_dn = old_to_new_dn_map_arg[old_dn]; const bool dn_changed = (new_dn != old_dn); if (dn_changed) { out[old_dn] = new_dn; } } return out; }(); const QList<QString> old_dn_list = old_to_new_dn_map.keys(); const QList<QString> new_dn_list = old_to_new_dn_map.values(); // NOTE: search for objects once here to reuse them // multiple times later const QHash<QString, AdObject> object_map = [&]() { QHash<QString, AdObject> out; for (const QString &dn : new_dn_list) { const AdObject object = ad.search_object(dn); out[dn] = object; } return out; }(); auto apply_changes = [&ad, &old_to_new_dn_map, &old_dn_list, &new_parent_dn, &object_map](ConsoleWidget *target_console) { // For object tree, we add items representing // updated objects and delete old items. In the case // of move, this moves the items to their new // parent. In the case of rename, this updates // item's information about the object by recreating // it. // NOTE: delete old item AFTER adding new item // because: If old item is deleted first, then it's // possible for new parent to get selected (if they // are next to each other in scope tree). Then what // happens is that due to new parent being selected, // it gets fetched and loads new object. End result // is that new object is duplicated. const QModelIndex object_root = get_object_tree_root(target_console); if (object_root.isValid()) { const QModelIndex parent_object = target_console->search_item(object_root, ObjectRole_DN, new_parent_dn, {ItemType_Object}); 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); } } // For query tree, we don't move items or recreate // items but instead update items. Move doesn't make // sense because query tree doesn't represent the // object tree. Note that changing name or DN of // objects may mean that the parent query may become // invalid. For example, if query searches for all // objects with names starting with "foo" and we // rename an object in that query so that it doesn't // start with "foo" anymore. Since it is too // complicated to determine match criteria on the // client, and refreshing the query is too wasteful, // we instead mark queries with modified objects as // "out of date". It is then up to the user to // refresh the query if needed. const QModelIndex query_root = get_query_tree_root(target_console); if (query_root.isValid()) { // Find indexes of modified objects in query // tree const QHash<QString, QModelIndex> index_map = [&]() { QHash<QString, QModelIndex> out; for (const QString &old_dn : old_dn_list) { const QList<QModelIndex> results = target_console->search_items(query_root, ObjectRole_DN, old_dn, {ItemType_Object}); for (const QModelIndex &index : results) { out[old_dn] = index; } } return out; }(); for (const QString &old_dn : index_map.keys()) { const QModelIndex index = index_map[old_dn]; // Mark parent query as "out of date". Icon // and tooltip will be restored after // refresh const QModelIndex query_index = index.parent(); QStandardItem *item = target_console->get_item(query_index); item->setIcon(g_icon_manager->get_indicator_icon(g_icon_manager->warning_indicator)); item->setToolTip(QCoreApplication::translate("ObjectImpl", "Query may be out of date")); // Update item row const QList<QStandardItem *> row = target_console->get_row(index); const QString new_dn = old_to_new_dn_map[old_dn]; const AdObject object = object_map[new_dn]; console_object_load(row, object); } } // TODO: decrease code duplication // For find tree, we only reload the rows to // update name, and attributes (DN for example) const QModelIndex find_object_root = get_query_tree_root(target_console); if (find_object_root.isValid()) { // Find indexes of modified objects in find // tree const QHash<QString, QModelIndex> index_map = [&]() { QHash<QString, QModelIndex> out; for (const QString &old_dn : old_dn_list) { const QList<QModelIndex> results = target_console->search_items(find_object_root, ObjectRole_DN, old_dn, {ItemType_Object}); for (const QModelIndex &index : results) { out[old_dn] = index; } } return out; }(); for (const QString &old_dn : index_map.keys()) { const QModelIndex index = index_map[old_dn]; // Update item row const QList<QStandardItem *> row = target_console->get_row(index); const QString new_dn = old_to_new_dn_map[old_dn]; const AdObject object = object_map[new_dn]; console_object_load(row, object); } } // Apply changes to policy tree const QModelIndex policy_root = get_policy_tree_root(target_console); if (policy_root.isValid()) { const QModelIndex new_parent_index = target_console->search_item(policy_root, PolicyOURole_DN, new_parent_dn, {ItemType_PolicyOU}); if (new_parent_index.isValid()) { 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); } } }; for (ConsoleWidget *console : console_list) { apply_changes(console); } } // NOTE: this is a helper f-n for move_and_rename() that // generates the new_dn_list for you, assuming that you just // want to move objects to new parent without renaming void ObjectImpl::move(AdInterface &ad, const QList<QString> &old_dn_list, const QString &new_parent_dn) { const QHash<QString, QString> old_to_new_dn_map = [&]() { QHash<QString, QString> out; for (const QString &old_dn : old_dn_list) { const QString new_dn = dn_move(old_dn, new_parent_dn); out[old_dn] = new_dn; } return out; }(); console_object_move_and_rename(console_list, ad, old_to_new_dn_map, new_parent_dn); } void ObjectImpl::update_toolbar_actions() { const QHash<QString, QAction *> toolbar_action_map = { {CLASS_USER, toolbar_create_user}, {CLASS_GROUP, toolbar_create_group}, {CLASS_OU, toolbar_create_ou}, }; // Disable all actions by default for (const QString &action_object_class : toolbar_action_map.keys()) { QAction *action = toolbar_action_map[action_object_class]; if (action == nullptr) { continue; } action->setEnabled(false); } // Then enable them depending on current selection const QList<QModelIndex> target_list = console->get_selected_items(ItemType_Object); const bool single_selection = (target_list.size() == 1); if (!single_selection) { return; } const QModelIndex target = target_list[0]; const QVariant target_data = target.data(ObjectRole_ObjectClasses); if (!target_data.canConvert<QStringList>() || target_data.toStringList().isEmpty()) { return; } const QString object_class = target_data.toStringList().last(); for (const QString &action_object_class : toolbar_action_map.keys()) { QAction *action = toolbar_action_map[action_object_class]; if (action == nullptr) { continue; } const bool is_enabled = can_create_class_at_parent(action_object_class, object_class); action->setEnabled(is_enabled); } } void object_impl_add_objects_to_console(ConsoleWidget *console, const QList<AdObject> &object_list, const QModelIndex &parent) { if (!parent.isValid()) { return; } // NOTE: don't add if parent wasn't fetched yet. If that // is the case then the object will be added naturally // when parent is fetched. const bool parent_was_fetched = console_item_get_was_fetched(parent); if (!parent_was_fetched) { return; } for (const AdObject &object : object_list) { if (object.is_empty()) continue; const bool should_be_in_scope = [&]() { // NOTE: "containers" referenced here don't mean // objects with "container" object class. // Instead it means all the objects that can // have children(some of which are not // "container" class). const bool is_container = [=]() { const QList<QString> filter_containers = g_adconfig->get_filter_containers(); const QString object_class = object.get_string(ATTRIBUTE_OBJECT_CLASS); return filter_containers.contains(object_class); }(); const bool show_non_containers_ON = settings_get_variant(SETTING_show_non_containers_in_console_tree).toBool(); return (is_container || show_non_containers_ON); }(); const QList<QStandardItem *> row = [&]() { if (should_be_in_scope) { return console->add_scope_item(ItemType_Object, parent); } else { return console->add_results_item(ItemType_Object, parent); } }(); console_object_load(row, object); } } // Helper f-n that searches for objects and then adds them void object_impl_add_objects_to_console_from_dns(ConsoleWidget *console, AdInterface &ad, const QList<QString> &dn_list, const QModelIndex &parent) { const QList<AdObject> object_list = [&]() { QList<AdObject> out; for (const QString &dn : dn_list) { const AdObject object = ad.search_object(dn); out.append(object); } return out; }(); object_impl_add_objects_to_console(console, object_list, parent); } void console_object_load(const QList<QStandardItem *> row, const AdObject &object) { // Load attribute columns for (int i = 0; i < g_adconfig->get_columns().count(); i++) { if (g_adconfig->get_columns().count() > row.size()) { break; } const QString attribute = g_adconfig->get_columns()[i]; if (!object.contains(attribute)) { continue; } const QString display_value = [attribute, object]() { if (attribute == ATTRIBUTE_OBJECT_CLASS) { const QString object_class = object.get_string(attribute); if (object_class == CLASS_GROUP) { const GroupScope scope = object.get_group_scope(); const QString scope_string = group_scope_string(scope); const GroupType type = object.get_group_type(); const QString type_string = group_type_string_adjective(type); return QString("%1 - %2").arg(type_string, scope_string); } else { return g_adconfig->get_class_display_name(object_class); } } else { const QByteArray value = object.get_value(attribute); return attribute_display_value(attribute, value, g_adconfig); } }(); row[i]->setText(display_value); } console_object_item_data_load(row[0], object); const bool cannot_move = object.get_system_flag(SystemFlagsBit_DomainCannotMove); for (auto item : row) { item->setDragEnabled(!cannot_move); } } void console_object_item_data_load(QStandardItem *item, const AdObject &object) { item->setData(object.get_dn(), ObjectRole_DN); const QList<QString> object_classes = object.get_strings(ATTRIBUTE_OBJECT_CLASS); item->setData(QVariant(object_classes), ObjectRole_ObjectClasses); const QString object_category = object.get_string(ATTRIBUTE_OBJECT_CATEGORY); item->setData(object_category, ObjectRole_ObjectCategory); const bool cannot_move = object.get_system_flag(SystemFlagsBit_DomainCannotMove); item->setData(cannot_move, ObjectRole_CannotMove); const bool cannot_rename = object.get_system_flag(SystemFlagsBit_DomainCannotRename); item->setData(cannot_rename, ObjectRole_CannotRename); const bool cannot_delete = object.get_system_flag(SystemFlagsBit_CannotDelete); item->setData(cannot_delete, ObjectRole_CannotDelete); const bool account_disabled = object.get_account_option(AccountOption_Disabled, g_adconfig); item->setData(account_disabled, ObjectRole_AccountDisabled); console_object_item_load_icon(item, account_disabled); } QList<QString> object_impl_column_labels() { QList<QString> out; for (const QString &attribute : g_adconfig->get_columns()) { const QString attribute_display_name = g_adconfig->get_column_display_name(attribute); out.append(attribute_display_name); } return out; } QList<int> object_impl_default_columns() { // By default show first 3 columns: name, class and // description return {0, 1, 2}; } QList<QString> console_object_search_attributes() { QList<QString> attributes; attributes += g_adconfig->get_columns(); // NOTE: needed for loading group type/scope into "type" // column attributes += ATTRIBUTE_GROUP_TYPE; // NOTE: system flags are needed to disable // delete/move/rename for objects that can't do those // actions attributes += ATTRIBUTE_SYSTEM_FLAGS; attributes += ATTRIBUTE_USER_ACCOUNT_CONTROL; // NOTE: needed to know which icon to use for object attributes += ATTRIBUTE_OBJECT_CATEGORY; // NOTE: for context menu block inheritance checkbox attributes += ATTRIBUTE_GPOPTIONS; // NOTE: needed to know gpo status attributes += ATTRIBUTE_FLAGS; return attributes; } // NOTE: it is possible for a search to start while a // previous one hasn't finished. For that reason, this f-n // contains multiple workarounds for issues caused by that // case. void console_object_search(ConsoleWidget *console, const QModelIndex &index, const QString &base, const SearchScope scope, const QString &filter, const QList<QString> &attributes) { auto search_id_matches = [](QStandardItem *item, SearchThread *thread) { const int id_from_item = item->data(MyConsoleRole_SearchThreadId).toInt(); const int thread_id = thread->get_id(); const bool match = (id_from_item == thread_id); return match; }; QStandardItem *item = console->get_item(index); // Set icon to indicate that item is in "search" state item->setIcon(g_icon_manager->get_indicator_icon(g_icon_manager->search_indicator)); // NOTE: need to set this role to disable actions during // fetch item->setData(true, ObjectRole_Fetching); item->setDragEnabled(false); auto search_thread = new SearchThread(base, scope, filter, attributes); // NOTE: change item's search thread, this will be used // later to handle situations where a thread is started // while another is running item->setData(search_thread->get_id(), MyConsoleRole_SearchThreadId); const QPersistentModelIndex persistent_index = index; // NOTE: need to pass console as receiver object to // connect() even though we're using lambda as a slot. // This is to be able to define queuedconnection type, // because there's no connect() version with no receiver // which has a connection type argument. QObject::connect( search_thread, &SearchThread::results_ready, console, [=](const QHash<QString, AdObject> &results) { // NOTE: fetched index might become invalid for // many reasons, parent getting moved, deleted, // item at the index itself might get modified. // Since this slot runs in the main thread, it's // not possible for any catastrophic conflict to // happen, so it's enough to just stop the // search. if (!persistent_index.isValid()) { search_thread->stop(); return; } QStandardItem *item_now = console->get_item(persistent_index); // NOTE: if another thread was started for this // item, abort this thread const bool thread_id_match = search_id_matches(item_now, search_thread); if (!thread_id_match) { search_thread->stop(); return; } object_impl_add_objects_to_console(console, results.values(), persistent_index); }, Qt::QueuedConnection); QObject::connect( search_thread, &SearchThread::finished, console, [=]() { if (!persistent_index.isValid()) { return; } g_status->display_ad_messages(search_thread->get_ad_messages(), console); search_thread_display_errors(search_thread, console); QStandardItem *item_now = console->get_item(persistent_index); // NOTE: if another thread was started for this // item, don't change item data. It will be // changed by that other thread. const bool thread_id_match = search_id_matches(item_now, search_thread); if (!thread_id_match) { return; } const bool is_disabled = item_now->data(ObjectRole_AccountDisabled).toBool(); console_object_item_load_icon(item_now, is_disabled); item_now->setData(false, ObjectRole_Fetching); item_now->setDragEnabled(true); search_thread->deleteLater(); }, Qt::QueuedConnection); search_thread->start(); } void console_object_tree_init(ConsoleWidget *console, AdInterface &ad) { const QList<QStandardItem *> row = console->add_scope_item(ItemType_Object, console->domain_info_index()); auto root = row[0]; const QString top_dn = g_adconfig->domain_dn(); const AdObject top_object = ad.search_object(top_dn); console_object_item_data_load(root, top_object); const QString domain = g_adconfig->domain().toLower(); root->setText(domain); } QModelIndex get_object_tree_root(ConsoleWidget *console) { const QString head_dn = g_adconfig->domain_dn(); const QModelIndex console_root = console->domain_info_index(); const QList<QModelIndex> search_results = console->search_items(console_root, ObjectRole_DN, head_dn, {ItemType_Object}); if (!search_results.isEmpty()) { // NOTE: domain object may also appear in queries, // so have to find the real head by finding the // index with no parent for (const QModelIndex &index : search_results) { const QModelIndex parent = index.parent(); if (parent == console->domain_info_index()) { return index; } } return QModelIndex(); } else { return QModelIndex(); } } QString console_object_count_string(ConsoleWidget *console, const QModelIndex &index) { const int count = console->get_child_count(index); const QString out = QCoreApplication::translate("object_impl", "%n object(s)", "", count); return out; } // Determine what kind of drop type is dropping this object // onto target. If drop type is none, then can't drop this // object on this target. DropType console_object_get_drop_type(const QModelIndex &dropped, const QModelIndex &target) { const bool dropped_is_target = [&]() { const QString dropped_dn = dropped.data(ObjectRole_DN).toString(); const QString target_dn = target.data(ObjectRole_DN).toString(); return (dropped_dn == target_dn); }(); const QList<QString> dropped_classes = dropped.data(ObjectRole_ObjectClasses).toStringList(); const QList<QString> target_classes = target.data(ObjectRole_ObjectClasses).toStringList(); const bool dropped_is_user = dropped_classes.contains(CLASS_USER); const bool dropped_is_group = dropped_classes.contains(CLASS_GROUP); const bool target_is_group = target_classes.contains(CLASS_GROUP); const bool target_is_fetching = target.data(ObjectRole_Fetching).toBool(); if (dropped_is_target || target_is_fetching) { return DropType_None; } else if (dropped_is_user && target_is_group) { return DropType_AddToGroup; } else if (dropped_is_group && target_is_group) { return DropType_AddToGroup; } else { const QList<QString> dropped_superiors = g_adconfig->get_possible_superiors(dropped_classes); const bool target_is_valid_superior = [&]() { for (const auto &object_class : dropped_superiors) { if (target_classes.contains(object_class)) { return true; } } return false; }(); if (target_is_valid_superior) { return DropType_Move; } else { return DropType_None; } } } QList<QString> get_selected_dn_list_object(ConsoleWidget *console) { return get_selected_dn_list(console, ItemType_Object, ObjectRole_DN); } QString get_selected_target_dn_object(ConsoleWidget *console) { return get_selected_target_dn(console, ItemType_Object, ObjectRole_DN); } void console_object_delete_dn_list(ConsoleWidget *console, const QList<QString> &dn_list, const QModelIndex &tree_root, const int type, const int dn_role) { for (const QString &dn : dn_list) { const QList<QModelIndex> index_list = console->search_items(tree_root, dn_role, dn, {type}); const QList<QPersistentModelIndex> persistent_list = persistent_index_list(index_list); for (const QPersistentModelIndex &index : persistent_list) { console->delete_item(index); } } } bool can_create_class_at_parent(const QString &create_class, const QString &parent_class) { // NOTE: to get full list of possible // superiors, need to use the all of the parent // classes too, not just the leaf class const QList<QString> action_object_class_list = g_adconfig->get_inherit_chain(create_class); const QList<QString> possible_superiors = g_adconfig->get_possible_superiors(QList<QString>(action_object_class_list)); const bool out = possible_superiors.contains(parent_class); return out; } void console_object_item_load_icon(QStandardItem *item, bool disabled) { const QString category = dn_get_name(item->data(ObjectRole_ObjectCategory).toString()); QIcon icon; if (item->data(ConsoleRole_Type).toInt() == ItemType_QueryItem) { icon = g_icon_manager->get_object_icon(ADMC_CATEGORY_QUERY_ITEM); item->setIcon(icon); return; } if (category == OBJECT_CATEGORY_PERSON) { icon = disabled ? g_icon_manager->get_icon_for_type(ItemIconType_Person_Blocked) : g_icon_manager->get_icon_for_type(ItemIconType_Person_Clean); item->setIcon(icon); return; } else if (category == OBJECT_CATEGORY_COMPUTER) { icon = disabled ? g_icon_manager->get_icon_for_type(ItemIconType_Computer_Blocked) : g_icon_manager->get_icon_for_type(ItemIconType_Computer_Clean); item->setIcon(icon); return; } else if (category == OBJECT_CATEGORY_GROUP) { icon = g_icon_manager->get_icon_for_type(ItemIconType_Group_Clean); item->setIcon(icon); return; } icon = g_icon_manager->get_object_icon(category); item->setIcon(icon); } bool console_object_deletion_dialog(ConsoleWidget *console, const QList<QModelIndex> &index_deleted_list) { QString main_message; if (index_deleted_list.size() == 1) { main_message = QCoreApplication::translate("ObjectImpl", "Are you sure you want to delete this object?"); } else { main_message = QCoreApplication::translate("ObjectImpl", "Are you sure you want to delete these objects?"); } QString contains_objects_message; int not_empty_containers_count = 0; for (QModelIndex index : index_deleted_list) { if (index.model()->hasChildren(index)) { ++not_empty_containers_count; } } if (not_empty_containers_count == 1 && index_deleted_list.size() == 1) { contains_objects_message = QCoreApplication::translate("ObjectImpl", " It contains other objects."); } else if (not_empty_containers_count >= 1) { contains_objects_message = QCoreApplication::translate("ObjectImpl", " Containers to be deleted contain other objects."); } const bool confirm_actions = settings_get_variant(SETTING_confirm_actions).toBool(); if (not_empty_containers_count > 0 || confirm_actions) { QMessageBox::StandardButton answer = QMessageBox::question(console, QObject::tr("Confirm action"), main_message + contains_objects_message); return answer == QMessageBox::Yes; } return true; }
68,455
C++
.cpp
1,565
35.2
182
0.632719
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,631
find_object_impl.cpp
altlinux_admc/src/admc/console_impls/find_object_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/find_object_impl.h" #include "adldap.h" #include "console_impls/object_impl.h" #include "console_widget/results_view.h" #include "item_type.h" #include <QModelIndex> #include <QStandardItem> FindObjectImpl::FindObjectImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { auto view = new ResultsView(console_arg); view->set_drag_drop_enabled(false); set_results_view(view); } QString FindObjectImpl::get_description(const QModelIndex &index) const { const QString object_count_text = console_object_count_string(console, index); return object_count_text; } QList<QString> FindObjectImpl::column_labels() const { return object_impl_column_labels(); } QList<int> FindObjectImpl::default_columns() const { return object_impl_default_columns(); } QModelIndex get_find_object_root(ConsoleWidget *console) { const QModelIndex out = console->search_item(QModelIndex(), {ItemType_FindObject}); return out; }
1,751
C++
.cpp
46
35.673913
87
0.761652
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,632
policy_ou_impl.cpp
altlinux_admc/src/admc/console_impls/policy_ou_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/policy_ou_impl.h" #include "adldap.h" #include "console_impls/all_policies_folder_impl.h" #include "console_impls/item_type.h" #include "console_impls/object_impl.h" #include "console_impls/policy_impl.h" #include "create_dialogs/create_policy_dialog.h" #include "find_widgets/find_policy_dialog.h" #include "globals.h" #include "gplink.h" #include "results_widgets/policy_ou_results_widget/policy_ou_results_widget.h" #include "select_dialogs/select_policy_dialog.h" #include "status.h" #include "utils.h" #include "icon_manager/icon_manager.h" #include "fsmo/fsmo_utils.h" #include <QDebug> #include <QMenu> #include <QStandardItem> #include <QMessageBox> bool index_is_domain(const QModelIndex &index) { const QString dn = index.data(PolicyOURole_DN).toString(); const QString domain_dn = g_adconfig->domain_dn(); const bool out = (dn == domain_dn); return out; } PolicyOUImpl::PolicyOUImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { policy_ou_results_widget = new PolicyOUResultsWidget(console_arg); set_results_widget(policy_ou_results_widget); create_ou_action = new QAction(tr("Create OU"), this); create_and_link_gpo_action = new QAction(tr("Create a GPO and link to this OU"), this); link_gpo_action = new QAction(tr("Link existing GPO"), this); find_gpo_action = new QAction(tr("Find GPO"), this); change_gp_options_action = new QAction(tr("Block inheritance"), this); change_gp_options_action->setCheckable(true); update_gp_options_check_state(); connect( create_ou_action, &QAction::triggered, this, &PolicyOUImpl::create_ou); connect( create_and_link_gpo_action, &QAction::triggered, this, &PolicyOUImpl::create_and_link_gpo); connect( link_gpo_action, &QAction::triggered, this, &PolicyOUImpl::link_gpo); connect( find_gpo_action, &QAction::triggered, this, &PolicyOUImpl::find_gpo); connect( change_gp_options_action, &QAction::triggered, this, &PolicyOUImpl::change_gp_options); } void PolicyOUImpl::selected_as_scope(const QModelIndex &index) { policy_ou_results_widget->update(index); } // TODO: perform searches in separate threads void PolicyOUImpl::fetch(const QModelIndex &index) { AdInterface ad; if (ad_failed(ad, console)) { return; } const QString dn = index.data(PolicyOURole_DN).toString(); // Add child OU's { const QString base = dn; const SearchScope scope = SearchScope_Children; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_OBJECT_CLASS, CLASS_OU); QList<QString> attributes = console_object_search_attributes(); const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); policy_ou_impl_add_objects_to_console(console, results.values(), index); } const bool is_domain = index_is_domain(index); // Add "All policies" folder if this is domain if (is_domain) { const QList<QStandardItem *> all_policies_row = console->add_scope_item(ItemType_AllPoliciesFolder, index); QStandardItem *all_policies_item = all_policies_row[0]; all_policies_item->setText(tr("All policies")); all_policies_item->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_ALL_POLICIES_FOLDER)); // Set sort index for "All policies" to 1 so it's always // at the bottom of the policy tree console->set_item_sort_index(all_policies_item->index(), 2); } // Add policies linked to this OU 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(); console->get_item(index)->setData(gplink_string, PolicyOURole_Gplink_String); policy_ou_impl_add_objects_from_dns(console, ad, gpo_list, index); policy_ou_results_widget->update_inheritance_widget(index); } bool PolicyOUImpl::can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(target); UNUSED_ARG(target_type); UNUSED_ARG(dropped_list); const bool dropped_are_policy = (dropped_type_list == QSet<int>({ItemType_Policy})); return dropped_are_policy; } void PolicyOUImpl::drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(target_type); UNUSED_ARG(dropped_type_list); const QString ou_dn = target.data(PolicyOURole_DN).toString(); const QList<QString> gpo_list = [&]() { QList<QString> out; for (const QPersistentModelIndex &index : dropped_list) { const QString gpo = index.data(PolicyRole_DN).toString(); out.append(gpo); } return out; }(); link_gpo_to_ou(target, ou_dn, gpo_list); // Need to refresh so that results widget is updated // because linking a gpo changes contents of results. const QModelIndex current_scope = console->get_current_scope_item(); console->refresh_scope(current_scope); } void PolicyOUImpl::refresh(const QList<QModelIndex> &index_list) { const QModelIndex index = index_list[0]; console->delete_children(index); fetch(index); policy_ou_results_widget->update(index); } void PolicyOUImpl::activate(const QModelIndex &index) { properties({index}); } QList<QAction *> PolicyOUImpl::get_all_custom_actions() const { QList<QAction *> out; update_gp_options_check_state(); out.append(create_ou_action); out.append(create_and_link_gpo_action); out.append(link_gpo_action); out.append(find_gpo_action); out.append(change_gp_options_action); return out; } QSet<QAction *> PolicyOUImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); QSet<QAction *> out; update_gp_options_check_state(); if (single_selection) { out.insert(create_ou_action); out.insert(create_and_link_gpo_action); out.insert(link_gpo_action); out.insert(change_gp_options_action); const bool is_domain = [&]() { const QString dn = index.data(PolicyOURole_DN).toString(); const QString domain_dn = g_adconfig->domain_dn(); const bool is_domain_out = (dn == domain_dn); return is_domain_out; }(); if (is_domain) { out.insert(find_gpo_action); } } return out; } QSet<StandardAction> PolicyOUImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); UNUSED_ARG(single_selection); QSet<StandardAction> out; out.insert(StandardAction_Properties); const bool can_refresh = console_item_get_was_fetched(index); if (can_refresh) { out.insert(StandardAction_Refresh); } const bool is_domain = index_is_domain(index); if (!is_domain) { out.insert(StandardAction_Rename); out.insert(StandardAction_Delete); } return out; } QList<QString> PolicyOUImpl::column_labels() const { return {tr("Name")}; } QList<int> PolicyOUImpl::default_columns() const { return {0}; } void PolicyOUImpl::create_ou() { const QString parent_dn = get_selected_target_dn(console, ItemType_PolicyOU, PolicyOURole_DN); console_object_create({console}, CLASS_OU, parent_dn); } void PolicyOUImpl::create_and_link_gpo() { AdInterface ad; if (ad_failed(ad, console)) { return; } const QList<QModelIndex> selected_list = console->get_selected_items(ItemType_PolicyOU); if (selected_list.isEmpty()) { return; } if (!current_dc_is_master_for_role(ad, FSMORole_PDCEmulation) && gpo_edit_without_PDC_disabled) { QMessageBox::StandardButton answer = QMessageBox::question(console, QObject::tr("Creation is not available"), QObject::tr("ADMC is connected to DC without the PDC-Emulator role - " "group policy creation is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { connect_to_PDC_emulator(ad, console); return; } else { return; } } const QModelIndex target_index = selected_list[0]; const QString target_dn = target_index.data(PolicyOURole_DN).toString(); auto dialog = new CreatePolicyDialog(ad, console); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, target_index, target_dn]() { AdInterface ad2; if (ad_failed(ad2, console)) { return; } const QString gpo_dn = dialog->get_created_dn(); link_gpo_to_ou(target_index, target_dn, {gpo_dn}); const QModelIndex current_scope = console->get_current_scope_item(); policy_ou_results_widget->update(current_scope); // Add policy to "all policies" folder const AdObject gpo_object = ad2.search_object(gpo_dn); const QModelIndex all_policies_index = get_all_policies_folder_index(console); all_policies_folder_impl_add_objects(console, {gpo_object}, all_policies_index); }); } void PolicyOUImpl::link_gpo() { AdInterface ad; if (ad_failed(ad, console)) { return; } auto dialog = new SelectPolicyDialog(ad, console); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { const QList<QModelIndex> selected_list = console->get_selected_items(ItemType_PolicyOU); const QModelIndex selected_index = selected_list[0]; const QString target_dn = get_selected_target_dn(console, ItemType_PolicyOU, PolicyOURole_DN); const QList<QString> gpo_list = dialog->get_selected_dns(); link_gpo_to_ou(selected_index, target_dn, gpo_list); }); } void PolicyOUImpl::properties(const QList<QModelIndex> &index_list) { console_object_properties({console}, index_list, PolicyOURole_DN, {CLASS_OU}); } void PolicyOUImpl::rename(const QList<QModelIndex> &index_list) { console_object_rename({console}, index_list, PolicyOURole_DN, CLASS_OU); } void PolicyOUImpl::delete_action(const QList<QModelIndex> &index_list) { console_object_delete({console}, index_list, PolicyOURole_DN); } void policy_ou_impl_add_objects_from_dns(ConsoleWidget *console, AdInterface &ad, const QList<QString> &dn_list, const QModelIndex &parent) { const QList<AdObject> object_list = [&]() { QList<AdObject> out; for (const QString &dn : dn_list) { const AdObject object = ad.search_object(dn); out.append(object); } return out; }(); policy_ou_impl_add_objects_to_console(console, object_list, parent); } void policy_ou_impl_add_objects_to_console(ConsoleWidget *console, const QList<AdObject> &object_list, const QModelIndex &parent) { if (!parent.isValid()) { return; } const bool parent_was_fetched = console_item_get_was_fetched(parent); if (!parent_was_fetched) { return; } for (const AdObject &object : object_list) { const bool is_ou = object.is_class(CLASS_OU); const bool is_gpc = object.is_class(CLASS_GP_CONTAINER); if (is_ou) { const QList<QStandardItem *> row = console->add_scope_item(ItemType_PolicyOU, parent); policy_ou_impl_load_row(row, object); console->set_item_sort_index(row[0]->index(), 1); } else if (is_gpc) { const QList<QStandardItem *> row = console->add_scope_item(ItemType_Policy, parent); console_policy_load(row, object); } } } void policy_ou_impl_load_row(const QList<QStandardItem *> row, const AdObject &object) { QStandardItem *item = row[0]; policy_ou_impl_load_item_data(item, object); const QString name = object.get_string(ATTRIBUTE_NAME); item->setText(name); } void PolicyOUImpl::link_gpo_to_ou(const QModelIndex &ou_index, const QString &ou_dn, const QList<QString> &gpo_list) { AdInterface ad; if (ad_failed(ad, console)) { return; } const Gplink original_gplink = [&]() { const AdObject target_object = ad.search_object(ou_dn); const QString gplink_string = target_object.get_string(ATTRIBUTE_GPLINK); const Gplink out = Gplink(gplink_string); return out; }(); const Gplink new_gplink = [&]() { Gplink out = original_gplink; for (const QString &gpo : gpo_list) { out.add(gpo); } return out; }(); const QString new_gplink_string = new_gplink.to_string(); bool success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, new_gplink_string); g_status->display_ad_messages(ad, console); if (!success) return; update_ou_item_gplink_data(new_gplink_string, ou_index, console); const QList<QString> added_gpo_list = [&]() { QList<QString> out; const QList<QString> new_gpo_list = new_gplink.get_gpo_list(); for (const QString &gpo : new_gpo_list) { const bool added = !original_gplink.contains(gpo); if (added) { out.append(gpo); } } return out; }(); policy_ou_impl_add_objects_from_dns(console, ad, added_gpo_list, ou_index); const QModelIndex current_scope = console->get_current_scope_item(); policy_ou_results_widget->update(current_scope); } void PolicyOUImpl::find_gpo() { auto dialog = new FindPolicyDialog(console, console); dialog->open(); } void PolicyOUImpl::change_gp_options() { AdInterface ad; if (ad_failed(ad, console)) { return; } QStandardItem *currentItem = console->get_item(console->get_current_scope_item()); const QString dn = currentItem->data(PolicyOURole_DN).toString(); bool checked = change_gp_options_action->isChecked(); bool res; QIcon icon_to_set; bool is_domain = index_is_domain(currentItem->index()); if (checked) { res = ad.attribute_replace_string(dn, ATTRIBUTE_GPOPTIONS, GPOPTIONS_BLOCK_INHERITANCE); icon_to_set = is_domain ? g_icon_manager->get_icon_for_type(ItemIconType_Domain_InheritanceBlocked) : g_icon_manager->get_icon_for_type(ItemIconType_OU_InheritanceBlocked); } else { res = ad.attribute_replace_string(dn, ATTRIBUTE_GPOPTIONS, GPOPTIONS_INHERIT); icon_to_set = is_domain ? g_icon_manager->get_icon_for_type(ItemIconType_Domain_Clean) : g_icon_manager->get_icon_for_type(ItemIconType_OU_Clean); } if (!res) { g_status->display_ad_messages(ad, console); change_gp_options_action->toggle(); return; } currentItem->setData(checked, PolicyOURole_Inheritance_Block); currentItem->setIcon(icon_to_set); policy_ou_results_widget->update_inheritance_widget(currentItem->index()); } void PolicyOUImpl::update_gp_options_check_state() const { QVariant checked = console->get_current_scope_item().data(PolicyOURole_Inheritance_Block); if (checked.isValid()) { change_gp_options_action->setEnabled(true); change_gp_options_action->setChecked(checked.toBool()); } else change_gp_options_action->setDisabled(true); } void policy_ou_impl_load_item_data(QStandardItem *item, const AdObject &object) { const QString dn = object.get_dn(); item->setData(dn, PolicyOURole_DN); if (object.get_string(ATTRIBUTE_GPOPTIONS) == GPOPTIONS_BLOCK_INHERITANCE) { if (index_is_domain(item->index())) item->setIcon(g_icon_manager->get_icon_for_type(ItemIconType_Domain_InheritanceBlocked)); else item->setIcon(g_icon_manager->get_icon_for_type(ItemIconType_OU_InheritanceBlocked)); } else { item->setIcon(g_icon_manager->get_object_icon(object)); } bool inheritance_is_blocked = object.get_int(ATTRIBUTE_GPOPTIONS); item->setData(inheritance_is_blocked, PolicyOURole_Inheritance_Block); } QModelIndex get_ou_child_policy_index(ConsoleWidget *console, const QModelIndex &ou_index, const QString &policy_dn) { QList<QModelIndex> found_policy_indexes = console->search_items(ou_index, PolicyRole_DN, policy_dn, {ItemType_Policy}); QModelIndex policy_index; for (QModelIndex index : found_policy_indexes) { if (index.parent().data(ConsoleRole_Type) == ItemType_PolicyOU && index.parent().data(PolicyOURole_DN) == ou_index.data(PolicyOURole_DN)) { policy_index = index; return policy_index; } } return policy_index; } void update_ou_item_gplink_data(const QString &gplink, const QModelIndex &ou_index, ConsoleWidget *console) { QStandardItem *ou_item = console->get_item(ou_index); ou_item->setData(gplink, PolicyOURole_Gplink_String); } QModelIndex search_gpo_ou_index(ConsoleWidget *console, const QString &ou_dn) { 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}); return ou_dn_item_index; }
18,827
C++
.cpp
436
36.002294
175
0.663675
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,633
all_policies_folder_impl.cpp
altlinux_admc/src/admc/console_impls/all_policies_folder_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/all_policies_folder_impl.h" #include "adldap.h" #include "console_impls/item_type.h" #include "console_impls/policy_impl.h" #include "console_impls/policy_root_impl.h" #include "console_widget/results_view.h" #include "create_dialogs/create_policy_dialog.h" #include "globals.h" #include "gplink.h" #include "status.h" #include "utils.h" #include "fsmo/fsmo_utils.h" #include <QAction> #include <QList> #include <QStandardItem> #include <QMessageBox> AllPoliciesFolderImpl::AllPoliciesFolderImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { set_results_view(new ResultsView(console_arg)); create_policy_action = new QAction(tr("Create policy"), this); connect( create_policy_action, &QAction::triggered, this, &AllPoliciesFolderImpl::create_policy); } void AllPoliciesFolderImpl::fetch(const QModelIndex &index) { AdInterface ad; if (ad_failed(ad, console)) { return; } const QString base = g_adconfig->policies_dn(); const SearchScope scope = SearchScope_All; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_OBJECT_CLASS, CLASS_GP_CONTAINER); const QList<QString> attributes = QList<QString>(); const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); all_policies_folder_impl_add_objects(console, results.values(), index); } void AllPoliciesFolderImpl::refresh(const QList<QModelIndex> &index_list) { const QModelIndex index = index_list[0]; console->delete_children(index); fetch(index); } QList<QAction *> AllPoliciesFolderImpl::get_all_custom_actions() const { QList<QAction *> out; out.append(create_policy_action); return out; } QSet<QAction *> AllPoliciesFolderImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); UNUSED_ARG(single_selection); QSet<QAction *> out; out.insert(create_policy_action); return out; } QSet<StandardAction> AllPoliciesFolderImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); UNUSED_ARG(single_selection); QSet<StandardAction> out; out.insert(StandardAction_Refresh); return out; } QList<QString> AllPoliciesFolderImpl::column_labels() const { return {tr("Name")}; } QList<int> AllPoliciesFolderImpl::default_columns() const { return {0}; } void AllPoliciesFolderImpl::create_policy() { AdInterface ad; if (ad_failed(ad, console)) { return; } const QList<QModelIndex> selected_list = console->get_selected_items(ItemType_AllPoliciesFolder); if (selected_list.isEmpty()) { return; } if (!current_dc_is_master_for_role(ad, FSMORole_PDCEmulation) && gpo_edit_without_PDC_disabled) { QMessageBox::StandardButton answer = QMessageBox::question(console, QObject::tr("Creation is not available"), QObject::tr("ADMC is connected to DC without the PDC-Emulator role - " "group policy creation is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { connect_to_PDC_emulator(ad, console); return; } else { return; } } const QModelIndex parent_index = selected_list[0]; auto dialog = new CreatePolicyDialog(ad, console); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, parent_index]() { AdInterface ad2; if (ad_failed(ad2, console)) { return; } const QString dn = dialog->get_created_dn(); const AdObject object = ad2.search_object(dn); all_policies_folder_impl_add_objects(console, {object}, parent_index); }); } QModelIndex get_all_policies_folder_index(ConsoleWidget *console) { const QModelIndex policy_tree_root = get_policy_tree_root(console); 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) { if (!parent.isValid()) { return; } const bool parent_was_fetched = console_item_get_was_fetched(parent); if (!parent_was_fetched) { return; } for (const AdObject &object : object_list) { const QList<QStandardItem *> row = console->add_scope_item(ItemType_Policy, parent); console_policy_load(row, object); } }
5,573
C++
.cpp
141
33.319149
137
0.682181
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,634
query_item_impl.cpp
altlinux_admc/src/admc/console_impls/query_item_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/query_item_impl.h" #include "adldap.h" #include "console_impls/item_type.h" #include "console_impls/object_impl.h" #include "console_impls/query_folder_impl.h" #include "console_widget/results_view.h" #include "create_dialogs/create_query_item_dialog.h" #include "edit_query_widgets/edit_query_item_dialog.h" #include "globals.h" #include "settings.h" #include "utils.h" #include "icon_manager/icon_manager.h" #include <QCoreApplication> #include <QFileDialog> #include <QJsonDocument> #include <QMenu> #include <QStack> #include <QStandardItem> #include <QStandardPaths> #define QUERY_ROOT "QUERY_ROOT" const QString query_item_icon = "emblem-system"; QueryItemImpl::QueryItemImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { query_folder_impl = nullptr; set_results_view(new ResultsView(console_arg)); edit_action = new QAction(tr("Edit..."), this); export_action = new QAction(tr("Export query..."), this); connect( edit_action, &QAction::triggered, this, &QueryItemImpl::on_edit_query_item); connect( export_action, &QAction::triggered, this, &QueryItemImpl::on_export); } void QueryItemImpl::set_query_folder_impl(QueryFolderImpl *impl) { query_folder_impl = impl; } void QueryItemImpl::fetch(const QModelIndex &index) { // NOTE: reset icon and tooltip in case query is in the // "out of date" state QStandardItem *item = console->get_item(index); item->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_QUERY_ITEM)); item->setToolTip(""); const QString filter = index.data(QueryItemRole_Filter).toString(); const QString base = index.data(QueryItemRole_Base).toString(); const QList<QString> search_attributes = console_object_search_attributes(); const SearchScope scope = [&]() { const bool scope_is_children = index.data(QueryItemRole_ScopeIsChildren).toBool(); if (scope_is_children) { return SearchScope_Children; } else { return SearchScope_All; } }(); console_object_search(console, index, base, scope, filter, search_attributes); } QString QueryItemImpl::get_description(const QModelIndex &index) const { const QString object_count_text = console_object_count_string(console, index); return object_count_text; } QList<QAction *> QueryItemImpl::get_all_custom_actions() const { QList<QAction *> out; out.append(edit_action); out.append(export_action); return out; } QSet<QAction *> QueryItemImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); QSet<QAction *> out; if (single_selection) { out.insert(edit_action); out.insert(export_action); } return out; } QSet<StandardAction> QueryItemImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { QSet<StandardAction> out; out.insert(StandardAction_Delete); if (single_selection) { out.insert(StandardAction_Cut); out.insert(StandardAction_Copy); } const bool can_refresh = console_item_get_was_fetched(index); if (can_refresh && single_selection) { out.insert(StandardAction_Refresh); } return out; } void QueryItemImpl::refresh(const QList<QModelIndex> &index_list) { const QModelIndex index = index_list[0]; console->delete_children(index); fetch(index); } void QueryItemImpl::delete_action(const QList<QModelIndex> &index_list) { query_action_delete(console, index_list); } void QueryItemImpl::cut(const QList<QModelIndex> &index_list) { if (query_folder_impl != nullptr) { query_folder_impl->cut(index_list); } } void QueryItemImpl::copy(const QList<QModelIndex> &index_list) { if (query_folder_impl != nullptr) { query_folder_impl->copy(index_list); } } QList<QString> QueryItemImpl::column_labels() const { return object_impl_column_labels(); } QList<int> QueryItemImpl::default_columns() const { return object_impl_default_columns(); } void QueryItemImpl::on_export() { const QModelIndex index = console->get_selected_item(ItemType_QueryItem); const QString file_path = [&]() { const QString query_name = index.data(Qt::DisplayRole).toString(); const QString caption = QCoreApplication::translate("query_item_impl.cpp", "Export Query"); const QString suggested_file = QString("%1/%2.json").arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), query_name); const QString filter = QCoreApplication::translate("query_item_impl.cpp", "JSON (*.json)"); const QString out = QFileDialog::getSaveFileName(console, caption, suggested_file, filter); return out; }(); if (file_path.isEmpty()) { return; } const QHash<QString, QVariant> data = console_query_item_save_hash(index); const QByteArray json_bytes = QJsonDocument::fromVariant(data).toJson(); QFile file(file_path); file.open(QIODevice::WriteOnly); file.write(json_bytes); } void console_query_item_load(const QList<QStandardItem *> row, const QString &name, const QString &description, const QString &filter, const QByteArray &filter_state, const QString &base, const bool scope_is_children) { QStandardItem *main_item = row[0]; main_item->setData(description, QueryItemRole_Description); main_item->setData(filter, QueryItemRole_Filter); main_item->setData(filter_state, QueryItemRole_FilterState); main_item->setData(base, QueryItemRole_Base); main_item->setData(scope_is_children, QueryItemRole_ScopeIsChildren); main_item->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_QUERY_ITEM)); row[QueryColumn_Name]->setText(name); row[QueryColumn_Description]->setText(description); } QModelIndex console_query_item_create(ConsoleWidget *console, const QString &name, const QString &description, const QString &filter, const QByteArray &filter_state, const QString &base, const bool scope_is_children, const QModelIndex &parent) { const QList<QStandardItem *> row = console->add_scope_item(ItemType_QueryItem, parent); console_query_item_load(row, name, description, filter, filter_state, base, scope_is_children); return row[0]->index(); } QHash<QString, QVariant> console_query_item_save_hash(const QModelIndex &index) { const QString name = index.data(Qt::DisplayRole).toString(); const QString description = index.data(QueryItemRole_Description).toString(); const QString base = index.data(QueryItemRole_Base).toString(); const QString filter = index.data(QueryItemRole_Filter).toString(); const QByteArray filter_state = index.data(QueryItemRole_FilterState).toByteArray(); const bool scope_is_children = index.data(QueryItemRole_ScopeIsChildren).toBool(); QHash<QString, QVariant> data; data["name"] = name; data["description"] = description; data["base"] = base; data["filter"] = filter; data["filter_state"] = filter_state.toHex(); data["scope_is_children"] = scope_is_children; return data; } void console_query_item_load_hash(ConsoleWidget *console, const QHash<QString, QVariant> &data, const QModelIndex &parent_index) { if (data.isEmpty()) { return; } const QString name = data["name"].toString(); const QString description = data["description"].toString(); const QString base = data["base"].toString(); const bool scope_is_children = data["scope_is_children"].toBool(); const QString filter = data["filter"].toString(); const QByteArray filter_state = QByteArray::fromHex(data["filter_state"].toString().toLocal8Bit()); if (!console_query_or_folder_name_is_good(name, parent_index, console, QModelIndex())) { return; } console_query_item_create(console, name, description, filter, filter_state, base, scope_is_children, parent_index); } void QueryItemImpl::on_edit_query_item() { const QModelIndex index = console->get_selected_item(ItemType_QueryItem); const QModelIndex parent_index = index.parent(); const QList<QString> sibling_name_list = get_sibling_name_list(parent_index, index); auto dialog = new EditQueryItemDialog(sibling_name_list, console); { QString name; QString description; bool scope_is_children; QByteArray filter_state; QString filter; get_query_item_data(index, &name, &description, &scope_is_children, &filter_state, &filter); dialog->set_data(name, description, scope_is_children, filter_state, filter); } dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog, index]() { const QString name = dialog->name(); const QString description = dialog->description(); const QString filter = dialog->filter(); const QString base = dialog->base(); const QByteArray filter_state = dialog->filter_state(); const bool scope_is_children = dialog->scope_is_children(); const QList<QStandardItem *> row = console->get_row(index); console_query_item_load(row, name, description, filter, filter_state, base, scope_is_children); console_query_tree_save(console); console->refresh_scope(index); }); } void get_query_item_data(const QModelIndex &index, QString *name, QString *description, bool *scope_is_children, QByteArray *filter_state, QString *filter) { *name = index.data(Qt::DisplayRole).toString(); *description = index.data(QueryItemRole_Description).toString(); *scope_is_children = index.data(QueryItemRole_ScopeIsChildren).toBool(); *filter_state = index.data(QueryItemRole_FilterState).toByteArray(); *filter = index.data(QueryItemRole_Filter).toString(); }
10,665
C++
.cpp
235
40.408511
245
0.71474
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,635
domain_info_impl.cpp
altlinux_admc/src/admc/console_impls/domain_info_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2023 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "domain_info_impl.h" #include "console_widget/console_widget.h" #include "results_widgets/domain_info_results_widget/domain_info_results_widget.h" #include "console_impls/object_impl.h" #include "console_impls/policy_root_impl.h" #include "console_impls/query_folder_impl.h" #include "ad_interface.h" #include "item_type.h" #include "connection_options_dialog.h" #include "fsmo/fsmo_dialog.h" #include "utils.h" #include "status.h" #include "globals.h" #include "icon_manager/icon_manager.h" #include <QSet> #include <QAction> #include <QModelIndex> #include <QStandardItem> #include <QIcon> DomainInfoImpl::DomainInfoImpl(ConsoleWidget *console_arg): ConsoleImpl(console_arg) { domain_info_results_widget = new DomainInfoResultsWidget(console_arg); set_results_widget(domain_info_results_widget); edit_fsmo_action = new QAction(tr("Edit FSMO roles"), this); connection_options_action = new QAction(tr("Open connection options"), this); connect(edit_fsmo_action, &QAction::triggered, this, &DomainInfoImpl::open_fsmo_dialog); connect(connection_options_action, &QAction::triggered, this, &DomainInfoImpl::open_connection_options); } void DomainInfoImpl::selected_as_scope(const QModelIndex &index) { Q_UNUSED(index) domain_info_results_widget->update(); } void DomainInfoImpl::refresh(const QList<QModelIndex> &index_list) { Q_UNUSED(index_list) AdInterface ad; load_domain_info_item(ad); domain_info_results_widget->update(); console->clear_scope_tree(); console->set_current_scope(console->domain_info_index()); if (ad.is_connected()) { console_object_tree_init(console, ad); console_policy_tree_init(console); console_query_tree_init(console); } console->expand_item(console->domain_info_index()); } QList<QAction *> DomainInfoImpl::get_all_custom_actions() const { return {edit_fsmo_action, connection_options_action}; } QSet<QAction *> DomainInfoImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { Q_UNUSED(index) Q_UNUSED(single_selection) return {edit_fsmo_action, connection_options_action}; } QSet<StandardAction> DomainInfoImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { Q_UNUSED(index) Q_UNUSED(single_selection) return {StandardAction_Refresh}; } QList<QString> DomainInfoImpl::column_labels() const { return {tr("Name")}; } void DomainInfoImpl::load_domain_info_item(const AdInterface &ad) { QString dc = tr("Host not found"); if (ad.is_connected()) { dc = ad.get_dc(); } QStandardItem *domain_info_item = console->get_item(console->domain_info_index()); domain_info_item->setText(tr("Active directory managment center [") + dc + ']'); domain_info_item->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_DOMAIN_INFO_ITEM)); } void DomainInfoImpl::open_fsmo_dialog() { AdInterface ad; if (!ad.is_connected()) { return; } auto dialog = new FSMODialog(ad, console); dialog->open(); connect(dialog, &FSMODialog::master_changed, domain_info_results_widget, &DomainInfoResultsWidget::update_fsmo_roles); } void DomainInfoImpl::open_connection_options() { auto dialog = new ConnectionOptionsDialog(console); dialog->open(); connect(dialog, &ConnectionOptionsDialog::host_changed, [this](const QString &host) { show_busy_indicator(); console->refresh_scope(console->domain_info_index()); hide_busy_indicator(); g_status->add_message(tr("Connected to host ") + host, StatusType_Success); }); }
4,386
C++
.cpp
108
36.981481
122
0.731392
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,636
policy_root_impl.cpp
altlinux_admc/src/admc/console_impls/policy_root_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/policy_root_impl.h" #include "adldap.h" #include "console_impls/all_policies_folder_impl.h" #include "console_impls/item_type.h" #include "console_impls/policy_ou_impl.h" #include "console_widget/results_view.h" #include "globals.h" #include "gplink.h" #include "status.h" #include "utils.h" #include "icon_manager/icon_manager.h" #include <QList> #include <QStandardItem> PolicyRootImpl::PolicyRootImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { set_results_view(new ResultsView(console_arg)); } void PolicyRootImpl::fetch(const QModelIndex &index) { AdInterface ad; if (ad_failed(ad, console)) { return; } // Add domain object const QList<QStandardItem *> domain_row = console->add_scope_item(ItemType_PolicyOU, index); QStandardItem *domain_item = domain_row[0]; const QString domain_dn = g_adconfig->domain_dn(); const AdObject domain_object = ad.search_object(domain_dn); policy_ou_impl_load_item_data(domain_item, domain_object); const QString domain_name = g_adconfig->domain().toLower(); domain_item->setText(domain_name); } void PolicyRootImpl::refresh(const QList<QModelIndex> &index_list) { const QModelIndex index = index_list[0]; console->delete_children(index); fetch(index); } QSet<StandardAction> PolicyRootImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); UNUSED_ARG(single_selection); QSet<StandardAction> out; out.insert(StandardAction_Refresh); return out; } QList<QString> PolicyRootImpl::column_labels() const { return {tr("Name")}; } QList<int> PolicyRootImpl::default_columns() const { return {0}; } void console_policy_tree_init(ConsoleWidget *console) { const QList<QStandardItem *> head_row = console->add_scope_item(ItemType_PolicyRoot, console->domain_info_index()); auto policy_tree_head = head_row[0]; policy_tree_head->setText(QCoreApplication::translate("policy_root_impl", "Group Policy Objects")); policy_tree_head->setDragEnabled(false); policy_tree_head->setIcon(g_icon_manager->get_object_icon(ADMC_CATEGORY_GP_OBJECTS)); } QModelIndex get_policy_tree_root(ConsoleWidget *console) { const QModelIndex out = console->search_item(console->domain_info_index(), {ItemType_PolicyRoot}); return out; }
3,148
C++
.cpp
79
36.810127
120
0.745902
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,637
found_policy_impl.cpp
altlinux_admc/src/admc/console_impls/found_policy_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/found_policy_impl.h" #include "adldap.h" #include "console_impls/find_policy_impl.h" #include "console_impls/item_type.h" #include "console_impls/policy_impl.h" #include "utils.h" #include "globals.h" #include "icon_manager/icon_manager.h" #include <QAction> #include <QStandardItem> FoundPolicyImpl::FoundPolicyImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { console_list = { console, }; add_link_action = new QAction(tr("Add link..."), this); edit_action = new QAction(tr("Edit..."), this); connect( add_link_action, &QAction::triggered, this, &FoundPolicyImpl::on_add_link); connect( edit_action, &QAction::triggered, this, &FoundPolicyImpl::on_edit); } void FoundPolicyImpl::set_buddy_console(ConsoleWidget *buddy_console) { console_list = { console, buddy_console, }; } QList<QAction *> FoundPolicyImpl::get_all_custom_actions() const { return { add_link_action, edit_action, }; } QSet<QAction *> FoundPolicyImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); QSet<QAction *> out; if (single_selection) { out.insert(add_link_action); out.insert(edit_action); } return out; } QSet<StandardAction> FoundPolicyImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); QSet<StandardAction> out; out.insert(StandardAction_Delete); if (single_selection) { out.insert(StandardAction_Rename); out.insert(StandardAction_Properties); } return out; } void FoundPolicyImpl::rename(const QList<QModelIndex> &index_list) { UNUSED_ARG(index_list); PolicyResultsWidget *policy_results = nullptr; console_policy_rename(console_list, policy_results, ItemType_FoundPolicy, FoundPolicyRole_DN); } void FoundPolicyImpl::delete_action(const QList<QModelIndex> &index_list) { UNUSED_ARG(index_list); PolicyResultsWidget *policy_results = nullptr; console_policy_delete(console_list, policy_results, ItemType_FoundPolicy, FoundPolicyRole_DN); } void FoundPolicyImpl::properties(const QList<QModelIndex> &index_list) { UNUSED_ARG(index_list); PolicyResultsWidget *policy_results = nullptr; console_policy_properties(console_list, policy_results, ItemType_FoundPolicy, FoundPolicyRole_DN); } void FoundPolicyImpl::on_add_link() { PolicyResultsWidget *policy_results = nullptr; console_policy_add_link(console_list, policy_results, ItemType_FoundPolicy, FoundPolicyRole_DN); } void FoundPolicyImpl::on_edit() { console_policy_edit(console, ItemType_FoundPolicy, FoundPolicyRole_DN); } void found_policy_impl_load(const QList<QStandardItem *> &row, const AdObject &object) { QStandardItem *main_item = row[0]; const QIcon icon = g_icon_manager->get_object_icon(object); main_item->setIcon(icon); main_item->setData(object.get_dn(), FoundPolicyRole_DN); const QString display_name = object.get_string(ATTRIBUTE_DISPLAY_NAME); row[FindPolicyColumn_Name]->setText(display_name); const QString cn = object.get_string(ATTRIBUTE_CN); row[FindPolicyColumn_GUID]->setText(cn); }
4,064
C++
.cpp
106
34.358491
121
0.733452
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,638
find_policy_impl.cpp
altlinux_admc/src/admc/console_impls/find_policy_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/find_policy_impl.h" #include "adldap.h" #include "console_impls/object_impl.h" #include "console_widget/results_view.h" #include "item_type.h" #include "utils.h" #include <QModelIndex> #include <QStandardItem> FindPolicyImpl::FindPolicyImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { auto view = new ResultsView(console_arg); view->set_drag_drop_enabled(false); set_results_view(view); } QString FindPolicyImpl::get_description(const QModelIndex &index) const { const QString object_count_text = console_object_count_string(console, index); return object_count_text; } QList<QString> FindPolicyImpl::column_labels() const { const QList<QString> out = { tr("Name"), tr("GUID"), }; return out; } QList<int> FindPolicyImpl::default_columns() const { const QList<int> out = { FindPolicyColumn_Name, FindPolicyColumn_GUID, }; return out; } QModelIndex get_find_policy_root(ConsoleWidget *console) { const QModelIndex out = console->search_item(QModelIndex(), {ItemType_FindPolicy}); return out; }
1,900
C++
.cpp
55
31.472727
87
0.737589
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,639
policy_impl.cpp
altlinux_admc/src/admc/console_impls/policy_impl.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "console_impls/policy_impl.h" #include "adldap.h" #include "console_impls/find_policy_impl.h" #include "console_impls/found_policy_impl.h" #include "console_impls/item_type.h" #include "console_impls/policy_impl.h" #include "console_impls/policy_ou_impl.h" #include "console_impls/policy_root_impl.h" #include "globals.h" #include "results_widgets/policy_results_widget.h" #include "properties_widgets/properties_dialog.h" #include "rename_dialogs/rename_policy_dialog.h" #include "select_dialogs/select_object_dialog.h" #include "status.h" #include "utils.h" #include "icon_manager/icon_manager.h" #include "fsmo/fsmo_utils.h" #include <QAction> #include <QDebug> #include <QMessageBox> #include <QStandardItem> void policy_add_links(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const QList<QString> &policy_list, const QList<QString> &ou_list); void console_policy_update_policy_results(ConsoleWidget *console, PolicyResultsWidget *policy_results); void console_policy_remove_link(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role, const QString &ou_dn); PolicyImpl::PolicyImpl(ConsoleWidget *console_arg) : ConsoleImpl(console_arg) { policy_results = new PolicyResultsWidget(console_arg); set_results_widget(policy_results); add_link_action = new QAction(tr("Add link..."), this); edit_action = new QAction(tr("Edit..."), this); enforce_action = new QAction(tr("Enforced"), this); enforce_action->setCheckable(true); enforce_action->setData(GplinkOption_Enforced); disable_action = new QAction(tr("Disabled"), this); disable_action->setCheckable(true); disable_action->setData(GplinkOption_Disabled); update_gplink_option_check_actions(); connect( add_link_action, &QAction::triggered, this, &PolicyImpl::on_add_link); connect( edit_action, &QAction::triggered, this, &PolicyImpl::on_edit); connect( policy_results, &PolicyResultsWidget::ou_gplink_changed, this, &PolicyImpl::on_ou_gplink_changed); connect( enforce_action, &QAction::triggered, [this](){on_change_gplink_option_action(enforce_action);}); connect( disable_action, &QAction::triggered, [this](){on_change_gplink_option_action(disable_action);}); } bool PolicyImpl::can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(target); UNUSED_ARG(target_type); UNUSED_ARG(dropped_list); const bool dropped_are_policy_ou = (dropped_type_list == QSet<int>({ItemType_PolicyOU})); return dropped_are_policy_ou; } void PolicyImpl::drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type) { UNUSED_ARG(target_type); UNUSED_ARG(dropped_type_list); const QString policy_dn = target.data(PolicyRole_DN).toString(); const QList<QString> policy_list = {policy_dn}; const QList<QModelIndex> dropped_list_normal = normal_index_list(dropped_list); const QList<QString> ou_list = index_list_to_dn_list(dropped_list_normal, PolicyOURole_DN); policy_add_links({console}, policy_results, policy_list, ou_list); } void PolicyImpl::selected_as_scope(const QModelIndex &index) { AdInterface ad; if (ad_failed(ad, console)) { return; } // When selecting a policy, check it's permissions to // make sure that they permissions of GPT and GPC match. // If they don't, offer to update GPT permissions. const QString selected_gpo = index.data(PolicyRole_DN).toString(); bool ok = true; const bool perms_ok = ad.gpo_check_perms(selected_gpo, &ok); if (!perms_ok && ok) { const QString title = tr("Incorrect permissions detected"); const QString text = tr("Permissions for this policy's GPT don't match the permissions for it's GPC object. Would you like to update GPT permissions?"); auto sync_warning_dialog = new QMessageBox(console); sync_warning_dialog->setAttribute(Qt::WA_DeleteOnClose); sync_warning_dialog->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); sync_warning_dialog->setWindowTitle(title); sync_warning_dialog->setText(text); sync_warning_dialog->setIcon(QMessageBox::Warning); connect( sync_warning_dialog, &QDialog::accepted, console, [this, selected_gpo]() { AdInterface ad_inner; if (ad_failed(ad_inner, console)) { return; } ad_inner.gpo_sync_perms(selected_gpo); g_status->display_ad_messages(ad_inner, console); }); } g_status->log_messages(ad); policy_results->update(selected_gpo); } QList<QAction *> PolicyImpl::get_all_custom_actions() const { return { enforce_action, disable_action, add_link_action, edit_action, }; } QSet<QAction *> PolicyImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { QSet<QAction *> out; if (single_selection) { out.insert(add_link_action); out.insert(edit_action); if (index.parent().data(ConsoleRole_Type).toInt() == ItemType_PolicyOU) { update_gplink_option_check_actions(); out.insert(enforce_action); out.insert(disable_action); } } return out; } QSet<StandardAction> PolicyImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { UNUSED_ARG(index); QSet<StandardAction> out; out.insert(StandardAction_Delete); if (single_selection) { out.insert(StandardAction_Rename); out.insert(StandardAction_Refresh); out.insert(StandardAction_Properties); } return out; } void PolicyImpl::rename(const QList<QModelIndex> &index_list) { UNUSED_ARG(index_list); console_policy_rename({console}, policy_results, ItemType_Policy, PolicyRole_DN); } void PolicyImpl::delete_action(const QList<QModelIndex> &index_list) { const QModelIndex parent_index = index_list[0].parent(); const ItemType parent_type = (ItemType) console_item_get_type(parent_index); const bool parent_is_ou = (parent_type == ItemType_PolicyOU); if (parent_is_ou) { const QString ou_dn = parent_index.data(PolicyOURole_DN).toString(); console_policy_remove_link({console}, policy_results, ItemType_Policy, PolicyRole_DN, ou_dn); } else { console_policy_delete({console}, policy_results, ItemType_Policy, PolicyRole_DN); } } void PolicyImpl::refresh(const QList<QModelIndex> &index_list) { const QModelIndex index = index_list[0]; policy_results->update(index); } void PolicyImpl::properties(const QList<QModelIndex> &index_list) { UNUSED_ARG(index_list); console_policy_properties({console}, policy_results, ItemType_Policy, PolicyRole_DN); } void PolicyImpl::on_add_link() { console_policy_add_link({console}, policy_results, ItemType_Policy, PolicyRole_DN); } void PolicyImpl::on_edit() { console_policy_edit(console, ItemType_Policy, PolicyRole_DN); } void PolicyImpl::on_ou_gplink_changed(const QString &ou_dn, const Gplink &gplink, const QString &policy_dn, GplinkOption option) { QModelIndex ou_item_index = search_gpo_ou_index(console, ou_dn); if (!ou_item_index.isValid()) return; QModelIndex target_policy_index = get_ou_child_policy_index(console, ou_item_index, policy_dn); if (!target_policy_index.isValid()) return; update_ou_item_gplink_data(gplink.to_string(), ou_item_index, console); // Case of link deletion if (!gplink.contains(policy_dn)) { console->delete_item(target_policy_index); return; } // Case of option change if (option != GplinkOption_NoOption) { set_policy_item_icon(target_policy_index, gplink.get_option(policy_dn, option), option); } } void PolicyImpl::on_change_gplink_option_action(QAction *action) { AdInterface ad; if (ad_failed(ad, console)) { return; } GplinkOption option = (GplinkOption)action->data().toInt(); const QModelIndex policy_index = console->get_current_scope_item(); const QString gpo_dn = policy_index.data(PolicyRole_DN).toString(); const QModelIndex ou_index = policy_index.parent(); const QString ou_dn = ou_index.data(PolicyOURole_DN).toString(); bool checked = action->isChecked(); const QString gplink_string = ou_index.data(PolicyOURole_Gplink_String).toString(); Gplink gplink = Gplink(gplink_string); gplink.set_option(gpo_dn, option, checked); const QString updated_gplink_string = gplink.to_string(); bool success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, updated_gplink_string); if (success) { update_ou_item_gplink_data(updated_gplink_string, ou_index, console); set_policy_item_icon(policy_index, checked, option); policy_results->update(gpo_dn); } else { action->toggle(); } g_status->display_ad_messages(ad, console); } void PolicyImpl::update_gplink_option_check_actions() const { const QModelIndex policy_index = console->get_current_scope_item(); if (policy_index.parent().data(ConsoleRole_Type).toInt() != ItemType_PolicyOU) return; QStandardItem *item = console->get_item(policy_index); enforce_action->setChecked(policy_is_enforced(item)); disable_action->setChecked(policy_is_disabled(item)); } 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).toInt() != 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 set_policy_link_icon(QStandardItem *policy_item, bool is_enforced, bool is_disabled) { if (is_enforced) { if (!is_disabled) policy_item->setIcon(g_icon_manager->get_icon_for_type(ItemIconType_Policy_Enforced)); else policy_item->setIcon(g_icon_manager->get_icon_for_type(ItemIconType_Policy_Enforced_Disabled)); } else { if (!is_disabled) policy_item->setIcon(g_icon_manager->get_icon_for_type(ItemIconType_Policy_Link)); else policy_item->setIcon(g_icon_manager->get_icon_for_type(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_link_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_link_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) { 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_link_icon(main_item, is_enforced, is_disabled); } else { main_item->setIcon(g_icon_manager->get_object_icon(object)); } const QString display_name = object.get_string(ATTRIBUTE_DISPLAY_NAME); main_item->setText(display_name); const QString gpo_status = gpo_status_from_int(object.get_int(ATTRIBUTE_FLAGS)); main_item->setData(gpo_status, PolicyRole_GPO_Status); } 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); } void console_policy_rename(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } const QString dn = get_selected_target_dn(console_list[0], item_type, dn_role); auto dialog = new RenamePolicyDialog(ad, dn, console_list[0]); dialog->open(); QObject::connect( dialog, &QDialog::accepted, console_list[0], [console_list, policy_results, dn]() { AdInterface ad_inner; if (ad_failed(ad_inner, console_list[0])) { return; } const AdObject object = ad_inner.search_object(dn); // NOTE: ok to not update dn after rename // because policy rename doesn't change dn, since "policy name" is displayName auto apply_changes = [&dn, &object, policy_results](ConsoleWidget *target_console) { const QModelIndex policy_root = get_policy_tree_root(target_console); // NOTE: there can be duplicate items for // one policy because policy may be // displayed under multiple OU's if (policy_root.isValid()) { const QList<QModelIndex> index_list = target_console->search_items(policy_root, PolicyRole_DN, dn, {ItemType_Policy}); for (const QModelIndex &index : index_list) { const QList<QStandardItem *> row = target_console->get_row(index); console_policy_load(row, object); } } const QModelIndex find_policy_root = get_find_policy_root(target_console); if (find_policy_root.isValid()) { const QModelIndex index = target_console->search_item(find_policy_root, FoundPolicyRole_DN, dn, {ItemType_FoundPolicy}); if (index.isValid()) { const QList<QStandardItem *> row = target_console->get_row(index); console_policy_load(row, object); } } console_policy_update_policy_results(target_console, policy_results); }; for (ConsoleWidget *target_console : console_list) { apply_changes(target_console); } }); } void console_policy_add_link(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role) { auto dialog = new SelectObjectDialog({CLASS_OU}, SelectObjectDialogMultiSelection_Yes, console_list[0]); dialog->setWindowTitle(QCoreApplication::translate("PolicyImpl", "Add Link")); dialog->open(); QObject::connect( dialog, &SelectObjectDialog::accepted, console_list[0], [console_list, policy_results, dialog, item_type, dn_role]() { const QList<QString> gpo_list = get_selected_dn_list(console_list[0], item_type, dn_role); const QList<QString> ou_list = dialog->get_selected(); policy_add_links(console_list, policy_results, gpo_list, ou_list); }); } void console_policy_remove_link(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role, const QString &ou_dn) { const QList<QString> dn_list = get_selected_dn_list(console_list[0], item_type, dn_role); const QString confirmation_text = QCoreApplication::translate("PolicyImpl", "Are you sure you want to unlink this policy from the OU? Note that the actual policy object won't be deleted."); const bool confirmed = confirmation_dialog(confirmation_text, console_list[0]); if (!confirmed) { return; } AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } show_busy_indicator(); const QString gplink_new_string = [&]() { Gplink gplink = [&]() { const AdObject parent_object = ad.search_object(ou_dn); const QString gplink_old_string = parent_object.get_string(ATTRIBUTE_GPLINK); const Gplink out = Gplink(gplink_old_string); return out; }(); for (const QString &dn : dn_list) { gplink.remove(dn); } const QString out = gplink.to_string(); return out; }(); const bool replace_success = ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink_new_string); if (replace_success) { auto apply_changes = [&ou_dn, &dn_list, &gplink_new_string, policy_results](ConsoleWidget *target_console) { const QModelIndex policy_root = get_policy_tree_root(target_console); // NOTE: there can be duplicate items for // one policy because policy may be // displayed under multiple OU's if (policy_root.isValid()) { const QModelIndex ou_index = target_console->search_item(policy_root, PolicyOURole_DN, ou_dn, {ItemType_PolicyOU}); if (ou_index.isValid()) { update_ou_item_gplink_data(gplink_new_string, ou_index, target_console); for (const QString &dn : dn_list) { const QModelIndex gpo_index = get_ou_child_policy_index(target_console, ou_index, dn); target_console->delete_item(gpo_index); } } } console_policy_update_policy_results(target_console, policy_results); }; for (ConsoleWidget *target_console : console_list) { apply_changes(target_console); } } hide_busy_indicator(); g_status->display_ad_messages(ad, console_list[0]); } void console_policy_delete(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } if (!current_dc_is_master_for_role(ad, FSMORole_PDCEmulation) && gpo_edit_without_PDC_disabled) { QMessageBox::StandardButton answer = QMessageBox::question(console_list[0], QObject::tr("Deletion is not available"), QObject::tr("ADMC is connected to DC without the PDC-Emulator role - " "group policy deletion is prohibited by the setting. " "Connect to PDC-Emulator?")); if (answer == QMessageBox::Yes) { connect_to_PDC_emulator(ad, console_list[0]); return; } else { return; } } const QList<QString> dn_list = get_selected_dn_list(console_list[0], item_type, dn_role); const QString confirmation_text = QCoreApplication::translate("PolicyImpl", "Are you sure you want to delete this policy and all of it's links?"); const bool confirmed = confirmation_dialog(confirmation_text, console_list[0]); QStringList not_deleted_dn_list; if (!confirmed) { return; } show_busy_indicator(); const QList<QString> deleted_list = [&]() { QList<QString> out; for (const QString &dn : dn_list) { bool deleted_object = false; ad.gpo_delete(dn, &deleted_object); // NOTE: object may get deleted successfuly but // deleting GPT fails which makes gpo_delete() fail // as a whole, but we still want to remove gpo from // the console in that case if (deleted_object) { out.append(dn); } else { not_deleted_dn_list.append(dn); } } return out; }(); auto apply_changes = [&deleted_list, policy_results](ConsoleWidget *target_console) { const QModelIndex policy_root = get_policy_tree_root(target_console); // NOTE: there can be duplicate items for // one policy because policy may be // displayed under multiple OU's if (policy_root.isValid()) { for (const QString &dn : deleted_list) { const QList<QModelIndex> index_list = target_console->search_items(policy_root, PolicyRole_DN, dn, {ItemType_Policy}); const QList<QPersistentModelIndex> persistent_list = persistent_index_list(index_list); for (const QPersistentModelIndex &index : persistent_list) { target_console->delete_item(index); } } } const QModelIndex find_policy_root = get_find_policy_root(target_console); if (find_policy_root.isValid()) { for (const QString &dn : deleted_list) { const QList<QModelIndex> index_list = target_console->search_items(find_policy_root, FoundPolicyRole_DN, dn, {ItemType_FoundPolicy}); const QList<QPersistentModelIndex> persistent_list = persistent_index_list(index_list); for (const QPersistentModelIndex &index : persistent_list) { target_console->delete_item(index); } } } console_policy_update_policy_results(target_console, policy_results); }; for (ConsoleWidget *target_console : console_list) { apply_changes(target_console); } hide_busy_indicator(); g_status->log_messages(ad); if (!not_deleted_dn_list.isEmpty()) { QString message; if (not_deleted_dn_list.size() == 1) { message = PolicyImpl::tr("Failed to delete group policy"); AdObject not_deleted_object = ad.search_object(not_deleted_dn_list.first()); if (!not_deleted_object.is_empty() && not_deleted_object.get_bool("isCriticalSystemObject")) message += PolicyImpl::tr(": this is a critical policy"); } else { message = PolicyImpl::tr("Failed to delete the following group policies: \n"); for (QString not_deleted_dn : not_deleted_dn_list) { AdObject not_deleted_object = ad.search_object(not_deleted_dn); message += '\n' + not_deleted_object.get_string("displayName"); if (not_deleted_object.get_bool("isCriticalSystemObject")) message += PolicyImpl::tr(" (critical policy)"); } } QMessageBox::warning(console_list[0], "", message); } } void console_policy_properties(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const int item_type, const int dn_role) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } const QString dn = get_selected_target_dn(console_list[0], item_type, dn_role); bool dialog_is_new; PropertiesDialog *dialog = PropertiesDialog::open_for_target(ad, dn, &dialog_is_new); auto on_propeties_applied = [console_list, policy_results, dn]() { AdInterface ad_inner; if (ad_failed(ad_inner, console_list[0])) { return; } const AdObject object = ad_inner.search_object(dn); auto apply_changes = [policy_results, &dn, &object](ConsoleWidget *target_console) { const QModelIndex policy_root = get_policy_tree_root(target_console); if (policy_root.isValid()) { const QList<QModelIndex> index_list = target_console->search_items(policy_root, PolicyRole_DN, dn, {ItemType_Policy}); for (const QModelIndex &index : index_list) { const QList<QStandardItem *> row = target_console->get_row(index); console_policy_load(row, object); } const QModelIndex find_policy_root = get_find_policy_root(target_console); if (find_policy_root.isValid()) { const QModelIndex index = target_console->search_item(find_policy_root, FoundPolicyRole_DN, dn, {ItemType_FoundPolicy}); if (index.isValid()) { const QList<QStandardItem *> row = target_console->get_row(index); console_policy_load(row, object); } } } console_policy_update_policy_results(target_console, policy_results); }; for (ConsoleWidget *target_console : console_list) { apply_changes(target_console); } }; if (dialog_is_new) { QObject::connect( dialog, &PropertiesDialog::applied, console_list[0], on_propeties_applied); } } void policy_add_links(const QList<ConsoleWidget *> &console_list, PolicyResultsWidget *policy_results, const QList<QString> &policy_list, const QList<QString> &ou_list) { AdInterface ad; if (ad_failed(ad, console_list[0])) { return; } show_busy_indicator(); for (const QString &ou_dn : ou_list) { const QString base = ou_dn; const SearchScope scope = SearchScope_Object; const QString filter = QString(); const QList<QString> attributes = {ATTRIBUTE_GPLINK}; const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); const AdObject ou_object = results[ou_dn]; const QString gplink_string = ou_object.get_string(ATTRIBUTE_GPLINK); Gplink gplink = Gplink(gplink_string); for (const QString &policy : policy_list) { gplink.add(policy); } ad.attribute_replace_string(ou_dn, ATTRIBUTE_GPLINK, gplink.to_string()); } // TODO: serch for all policy objects once, then add // them to OU's const QList<AdObject> gpo_object_list = [&]() { const QString base = g_adconfig->policies_dn(); const SearchScope scope = SearchScope_Children; const QString filter = filter_dn_list(policy_list); const QList<QString> attributes = QList<QString>(); const QHash<QString, AdObject> search_results = ad.search(base, scope, filter, attributes); const QList<AdObject> out = search_results.values(); return out; }(); // NOTE: ok to not update dn after rename // because policy rename doesn't change dn, // since "policy name" is displayName auto apply_changes = [&ou_list, &gpo_object_list](ConsoleWidget *target_console) { const QModelIndex policy_root = get_policy_tree_root(target_console); if (policy_root.isValid()) { for (const QString &ou_dn : ou_list) { const QModelIndex ou_index = target_console->search_item(policy_root, PolicyOURole_DN, ou_dn, {ItemType_PolicyOU}); if (!ou_index.isValid()) { continue; } const bool ou_was_fetched = console_item_get_was_fetched(ou_index); if (!ou_was_fetched) { continue; } policy_ou_impl_add_objects_to_console(target_console, gpo_object_list, ou_index); target_console->refresh_scope(ou_index); } } }; for (ConsoleWidget *target_console : console_list) { apply_changes(target_console); } console_policy_update_policy_results(console_list[0], policy_results); hide_busy_indicator(); g_status->display_ad_messages(ad, console_list[0]); } // Update policy results widget if it's currently displayed void console_policy_update_policy_results(ConsoleWidget *console, PolicyResultsWidget *policy_results) { if (policy_results == nullptr) { return; } // NOTE: we always use Policy item type because that is // the only type which uses PolicyResultsWidget const QString results_gpo = policy_results->get_current_gpo(); const QString scope_gpo = get_selected_target_dn(console, ItemType_Policy, PolicyRole_DN); const bool results_is_shown = (results_gpo == scope_gpo); if (results_is_shown) { policy_results->update(results_gpo); } } bool policy_is_enforced(QStandardItem *policy_item) { bool is_enforced = false; const QString gplink_string = policy_item->parent()->data(PolicyOURole_Gplink_String).toString(); const Gplink gplink = Gplink(gplink_string); is_enforced = gplink.enforced_gpo_dn_list().contains(policy_item->data(PolicyRole_DN).toString()); return is_enforced; } bool policy_is_disabled(QStandardItem *policy_item) { bool is_disabled = false; const QString gplink_string = policy_item->parent()->data(PolicyOURole_Gplink_String).toString(); const Gplink gplink = Gplink(gplink_string); is_disabled = gplink.disabled_gpo_dn_list().contains(policy_item->data(PolicyRole_DN).toString()); return is_disabled; }
32,595
C++
.cpp
685
38.986861
193
0.647967
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,640
filter_dialog.cpp
altlinux_admc/src/admc/filter_widget/filter_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_dialog.h" #include "ui_filter_dialog.h" #include "adldap.h" #include "filter_widget/filter_widget.h" #include "settings.h" #include <QVariant> FilterDialog::FilterDialog(const QList<QString> &class_list, const QList<QString> &selected_list, QWidget *parent) : QDialog(parent) { ui = new Ui::FilterDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); ui->filter_widget->set_classes(class_list, selected_list); settings_setup_dialog_geometry(SETTING_filter_dialog_geometry, this); } FilterDialog::~FilterDialog() { delete ui; } QVariant FilterDialog::save_state() const { return ui->filter_widget->save_state(); } void FilterDialog::restore_state(const QVariant &state) { ui->filter_widget->restore_state(state); } void FilterDialog::enable_filtering_all_classes() { ui->filter_widget->enable_filtering_all_classes(); } QString FilterDialog::get_filter() const { return ui->filter_widget->get_filter(); }
1,758
C++
.cpp
48
34.166667
114
0.748528
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,641
filter_widget_simple_tab.cpp
altlinux_admc/src/admc/filter_widget/filter_widget_simple_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/filter_widget_simple_tab.h" #include "filter_widget/ui_filter_widget_simple_tab.h" #include "adldap.h" FilterWidgetSimpleTab::FilterWidgetSimpleTab() : FilterWidgetTab() { ui = new Ui::FilterWidgetSimpleTab(); ui->setupUi(this); } FilterWidgetSimpleTab::~FilterWidgetSimpleTab() { delete ui; } void FilterWidgetSimpleTab::set_classes(const QList<QString> &class_list, const QList<QString> &selected_list) { ui->select_classes_widget->set_classes(class_list, selected_list); } void FilterWidgetSimpleTab::enable_filtering_all_classes() { ui->select_classes_widget->enable_filtering_all_classes(); } QString FilterWidgetSimpleTab::get_filter() const { const QString name_filter = [this]() { const QString name = ui->name_edit->text(); if (!name.isEmpty()) { return filter_CONDITION(Condition_Contains, ATTRIBUTE_NAME, name); } else { return QString(); } }(); const QString classes_filter = ui->select_classes_widget->get_filter(); return filter_AND({name_filter, classes_filter}); } void FilterWidgetSimpleTab::clear() { ui->name_edit->clear(); } QVariant FilterWidgetSimpleTab::save_state() const { QHash<QString, QVariant> state; state["select_classes_widget"] = ui->select_classes_widget->save_state(); state["name"] = ui->name_edit->text(); return QVariant(state); } void FilterWidgetSimpleTab::restore_state(const QVariant &state_variant) { const QHash<QString, QVariant> state = state_variant.toHash(); ui->select_classes_widget->restore_state(state["select_classes_widget"]); ui->name_edit->setText(state["name"].toString()); }
2,471
C++
.cpp
62
36.306452
112
0.726703
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,642
filter_widget_normal_tab.cpp
altlinux_admc/src/admc/filter_widget/filter_widget_normal_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/filter_widget_normal_tab.h" #include "filter_widget/ui_filter_widget_normal_tab.h" #include "adldap.h" #include "globals.h" #include <algorithm> FilterWidgetNormalTab::FilterWidgetNormalTab() : FilterWidgetTab() { ui = new Ui::FilterWidgetNormalTab(); ui->setupUi(this); connect( ui->attribute_class_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidgetNormalTab::update_attributes_combo); connect( ui->attribute_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidgetNormalTab::update_conditions_combo); connect( ui->condition_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidgetNormalTab::update_value_edit); connect( ui->remove_button, &QAbstractButton::clicked, this, &FilterWidgetNormalTab::remove_filter); connect( ui->add_button, &QAbstractButton::clicked, this, &FilterWidgetNormalTab::add_filter); connect( ui->clear_button, &QAbstractButton::clicked, this, &FilterWidgetNormalTab::clear_filters); } FilterWidgetNormalTab::~FilterWidgetNormalTab() { delete ui; } void FilterWidgetNormalTab::set_classes(const QList<QString> &class_list, const QList<QString> &selected_list) { for (const QString &object_class : filter_classes) { const QString display = g_adconfig->get_class_display_name(object_class); ui->attribute_class_combo->addItem(display, object_class); } ui->select_classes_widget->set_classes(class_list, selected_list); } void FilterWidgetNormalTab::enable_filtering_all_classes() { ui->select_classes_widget->enable_filtering_all_classes(); } QString FilterWidgetNormalTab::get_filter() const { const QString attribute_filter = [this]() { QList<QString> filters; for (int i = 0; i < ui->filter_list->count(); i++) { const QListWidgetItem *item = ui->filter_list->item(i); const QString filter = item->data(Qt::UserRole).toString(); filters.append(filter); } return filter_AND(filters); }(); const QString class_filter = ui->select_classes_widget->get_filter(); const bool classes = !class_filter.isEmpty(); const bool attributes = !attribute_filter.isEmpty(); if (classes && attributes) { return filter_AND({class_filter, attribute_filter}); } else if (!classes && attributes) { return attribute_filter; } else if (classes && !attributes) { return class_filter; } else { return QString(); } } void FilterWidgetNormalTab::clear() { ui->attribute_class_combo->setCurrentIndex(0); ui->value_edit->clear(); clear_filters(); } void FilterWidgetNormalTab::add_filter() { const QString filter = [&]() { const QString attribute = ui->attribute_combo->itemData(ui->attribute_combo->currentIndex()).toString(); const Condition condition = (Condition) ui->condition_combo->itemData(ui->condition_combo->currentIndex()).toInt(); const QString value = ui->value_edit->text(); const QString filter_display_string = [this, condition, value]() { const QString attribute_display = ui->attribute_combo->itemText(ui->attribute_combo->currentIndex()); const QString condition_string = condition_to_display_string(condition); const bool set_unset_condition = (condition == Condition_Set || condition == Condition_Unset); if (set_unset_condition) { return QString("%1 %2").arg(attribute_display, condition_string); } else { return QString("%1 %2: \"%3\"").arg(attribute_display, condition_string, value); } }(); return filter_CONDITION(condition, attribute, value); }(); const QString filter_display = [&]() { const QString attribute = ui->attribute_combo->itemData(ui->attribute_combo->currentIndex()).toString(); const Condition condition = (Condition) ui->condition_combo->itemData(ui->condition_combo->currentIndex()).toInt(); const QString value = ui->value_edit->text(); const QString attribute_display = ui->attribute_combo->itemText(ui->attribute_combo->currentIndex()); const QString condition_string = condition_to_display_string(condition); const bool set_unset_condition = (condition == Condition_Set || condition == Condition_Unset); if (set_unset_condition) { return QString("%1 %2").arg(attribute_display, condition_string); } else { return QString("%1 %2: \"%3\"").arg(attribute_display, condition_string, value); } }(); auto item = new QListWidgetItem(); item->setText(filter_display); item->setData(Qt::UserRole, filter); ui->filter_list->addItem(item); ui->value_edit->clear(); } void FilterWidgetNormalTab::remove_filter() { const QList<QListWidgetItem *> selected_items = ui->filter_list->selectedItems(); for (auto item : selected_items) { delete item; } } void FilterWidgetNormalTab::clear_filters() { ui->filter_list->clear(); } QVariant FilterWidgetNormalTab::save_state() const { QHash<QString, QVariant> state; state["select_classes_widget"] = ui->select_classes_widget->save_state(); QList<QString> filter_display_list; QList<QString> filter_value_list; for (int i = 0; i < ui->filter_list->count(); i++) { const QListWidgetItem *item = ui->filter_list->item(i); const QString filter_display = item->data(Qt::DisplayRole).toString(); const QString filter_value = item->data(Qt::UserRole).toString(); filter_display_list.append(filter_display); filter_value_list.append(filter_value); } state["filter_display_list"] = QVariant(filter_display_list); state["filter_value_list"] = QVariant(filter_value_list); return QVariant(state); } void FilterWidgetNormalTab::restore_state(const QVariant &state_variant) { const QHash<QString, QVariant> state = state_variant.toHash(); ui->select_classes_widget->restore_state(state["select_classes_widget"]); const QList<QString> filter_display_list = state["filter_display_list"].toStringList(); const QList<QString> filter_value_list = state["filter_value_list"].toStringList(); ui->filter_list->clear(); for (int i = 0; i < filter_display_list.size(); i++) { const QString filter_display = filter_display_list[i]; const QString filter_value = filter_value_list[i]; auto item = new QListWidgetItem(); item->setText(filter_display); item->setData(Qt::UserRole, filter_value); ui->filter_list->addItem(item); } } // Attributes combo contents depend on what attribute class is selected void FilterWidgetNormalTab::update_attributes_combo() { ui->attribute_combo->clear(); const QString object_class = [this]() { const int index = ui->attribute_class_combo->currentIndex(); const QVariant item_data = ui->attribute_class_combo->itemData(index); return item_data.toString(); }(); const QList<QString> attributes = g_adconfig->get_find_attributes(object_class); const QList<QString> display_attributes = [&]() { QList<QString> out; for (const QString &attribute : attributes) { const QString display_name = g_adconfig->get_attribute_display_name(attribute, object_class); out.append(display_name); } std::sort(out.begin(), out.end()); return out; }(); // NOTE: need backwards mapping from display name to attribute for insertion const QHash<QString, QString> display_to_attribute = [&]() { QHash<QString, QString> out; for (const QString &attribute : attributes) { const QString display_name = g_adconfig->get_attribute_display_name(attribute, object_class); out[display_name] = attribute; } return out; }(); // Insert attributes into combobox in the sorted order of display attributes for (const auto &display_attribute : display_attributes) { const QString attribute = display_to_attribute[display_attribute]; ui->attribute_combo->addItem(display_attribute, attribute); } } // Conditions combo contents depend on what attribute is selected void FilterWidgetNormalTab::update_conditions_combo() { const QList<Condition> conditions = [this]() -> QList<Condition> { const AttributeType attribute_type = [this]() { const int index = ui->attribute_combo->currentIndex(); const QVariant item_data = ui->attribute_combo->itemData(index); const QString attribute = item_data.toString(); return g_adconfig->get_attribute_type(attribute); }(); // NOTE: extra conditions don't work on DSDN type // attributes, so don't include them in the combobox // in that case if (attribute_type == AttributeType_DSDN) { return { Condition_Equals, Condition_NotEquals, Condition_Set, Condition_Unset, }; } else { return { Condition_StartsWith, Condition_EndsWith, Condition_Equals, Condition_NotEquals, Condition_Set, Condition_Unset, }; } }(); ui->condition_combo->clear(); for (const auto condition : conditions) { const QString condition_string = condition_to_display_string(condition); ui->condition_combo->addItem(condition_string, (int) condition); } } // Value edit is turned off for set/unset conditions void FilterWidgetNormalTab::update_value_edit() { const Condition condition = (Condition) ui->condition_combo->itemData(ui->condition_combo->currentIndex()).toInt(); const bool disable_value_edit = (condition == Condition_Set || condition == Condition_Unset); ui->value_edit->setDisabled(disable_value_edit); if (disable_value_edit) { ui->value_edit->clear(); } }
11,013
C++
.cpp
242
38.541322
123
0.669374
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,643
filter_widget_advanced_tab.cpp
altlinux_admc/src/admc/filter_widget/filter_widget_advanced_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/filter_widget_advanced_tab.h" #include "filter_widget/ui_filter_widget_advanced_tab.h" FilterWidgetAdvancedTab::FilterWidgetAdvancedTab() : FilterWidgetTab() { ui = new Ui::FilterWidgetAdvancedTab(); ui->setupUi(this); } FilterWidgetAdvancedTab::~FilterWidgetAdvancedTab() { delete ui; } QString FilterWidgetAdvancedTab::get_filter() const { const QString filter = ui->ldap_filter_edit->toPlainText(); return filter; } void FilterWidgetAdvancedTab::clear() { ui->ldap_filter_edit->clear(); } QVariant FilterWidgetAdvancedTab::save_state() const { const QString filter = ui->ldap_filter_edit->toPlainText(); return QVariant(filter); } void FilterWidgetAdvancedTab::restore_state(const QVariant &state_variant) { const QString filter = state_variant.toString(); ui->ldap_filter_edit->setPlainText(filter); }
1,653
C++
.cpp
44
35.045455
76
0.759375
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,644
select_base_widget.cpp
altlinux_admc/src/admc/filter_widget/select_base_widget.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/select_base_widget.h" #include "filter_widget/ui_select_base_widget.h" #include "adldap.h" #include "globals.h" #include "select_dialogs/select_container_dialog.h" #include "utils.h" SelectBaseWidget::SelectBaseWidget(QWidget *parent) : QWidget(parent) { ui = new Ui::SelectBaseWidget(); ui->setupUi(this); const QString domain_dn = g_adconfig->domain_dn(); const QString domain_name = dn_get_name(domain_dn); ui->combo->addItem(domain_name, domain_dn); connect( ui->browse_button, &QAbstractButton::clicked, this, &SelectBaseWidget::open_browse_dialog); } SelectBaseWidget::~SelectBaseWidget() { delete ui; } void SelectBaseWidget::set_default_base(const QString &default_base) { const QString name = dn_get_name(default_base); ui->combo->addItem(name, default_base); // Select default base in combo const int last_index = ui->combo->count() - 1; ui->combo->setCurrentIndex(last_index); } QString SelectBaseWidget::get_base() const { const int index = ui->combo->currentIndex(); const QVariant item_data = ui->combo->itemData(index); return item_data.toString(); } void SelectBaseWidget::open_browse_dialog() { AdInterface ad; if (ad_failed(ad, this)) { return; } auto browse_dialog = new SelectContainerDialog(ad, this); browse_dialog->open(); connect( browse_dialog, &QDialog::accepted, this, [this, browse_dialog]() { const QString selected = browse_dialog->get_selected(); const QString name = dn_get_name(selected); const int added_base_index = ui->combo->findText(name); const bool base_already_added = (added_base_index != -1); if (base_already_added) { ui->combo->setCurrentIndex(added_base_index); } else { ui->combo->addItem(name, selected); // Select newly added search base in combobox const int new_base_index = ui->combo->count() - 1; ui->combo->setCurrentIndex(new_base_index); } }); } QVariant SelectBaseWidget::save_state() const { const QString base = ui->combo->currentData().toString(); return QVariant(base); } void SelectBaseWidget::restore_state(const QVariant &state_variant) { const QString base = state_variant.toString(); const QString base_name = dn_get_name(base); ui->combo->clear(); ui->combo->addItem(base_name, base); }
3,298
C++
.cpp
86
33.116279
72
0.681904
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,645
class_filter_widget.cpp
altlinux_admc/src/admc/filter_widget/class_filter_widget.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/class_filter_widget.h" #include "filter_widget/ui_class_filter_widget.h" #include "adldap.h" #include "globals.h" #include "utils.h" #include <QCheckBox> ClassFilterWidget::ClassFilterWidget(QWidget *parent) : QWidget(parent) { ui = new Ui::ClassFilterWidget(); ui->setupUi(this); connect( ui->select_all_button, &QPushButton::clicked, this, &ClassFilterWidget::select_all); connect( ui->clear_selection_button, &QPushButton::clicked, this, &ClassFilterWidget::clear_selection); } ClassFilterWidget::~ClassFilterWidget() { delete ui; } void ClassFilterWidget::set_classes(const QList<QString> &class_list_arg, const QList<QString> &selected_list) { class_list = class_list_arg; for (const QString &object_class : class_list) { const QString class_string = g_adconfig->get_class_display_name(object_class); auto checkbox = new QCheckBox(class_string); checkbox_map[object_class] = checkbox; const bool is_selected = selected_list.contains(object_class); checkbox->setChecked(is_selected); ui->classes_layout->addWidget(checkbox); connect( checkbox, &QCheckBox::toggled, this, &ClassFilterWidget::changed); } } QString ClassFilterWidget::get_filter() const { const QList<QString> selected_list = [&] { QList<QString> out; // NOTE: important iterate over class list // because iterating over map keys causes // undefined order, which breaks tests and // creates other problems for (const QString &object_class : class_list) { QCheckBox *checkbox = checkbox_map[object_class]; if (checkbox->isChecked()) { out.append(object_class); } } return out; }(); const QString filter = get_classes_filter(selected_list); return filter; } QList<QString> ClassFilterWidget::get_selected_classes() const { QList<QString> out; for (const QString &object_class : class_list) { const QCheckBox *check = checkbox_map[object_class]; if (check->isChecked()) { out.append(object_class); } } return out; } void ClassFilterWidget::select_all() { for (QCheckBox *checkbox : checkbox_map.values()) { checkbox->setChecked(true); } } void ClassFilterWidget::clear_selection() { for (QCheckBox *checkbox : checkbox_map.values()) { checkbox->setChecked(false); } } QVariant ClassFilterWidget::save_state() const { QHash<QString, QVariant> state; // NOTE: important iterate over class list // because iterating over map keys causes // undefined order, which breaks tests and // creates other problems for (const QString &object_class : class_list) { QCheckBox *checkbox = checkbox_map[object_class]; const bool checked = checkbox->isChecked(); state[object_class] = QVariant(checked); } return QVariant(state); } void ClassFilterWidget::restore_state(const QVariant &state_variant) { const QHash<QString, QVariant> state = state_variant.toHash(); for (const QString &object_class : class_list) { const bool checked = [&]() { if (state.contains(object_class)) { const bool out = state[object_class].toBool(); return out; } else { return false; } }(); QCheckBox *checkbox = checkbox_map[object_class]; checkbox->setChecked(checked); } }
4,376
C++
.cpp
119
30.781513
112
0.671006
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,646
class_filter_dialog.cpp
altlinux_admc/src/admc/filter_widget/class_filter_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/class_filter_dialog.h" #include "filter_widget/ui_class_filter_dialog.h" #include "settings.h" #include <QPushButton> // NOTE: "all" checkbox functionality is messy due to // reuse and composition. It is what it is. ClassFilterDialog::ClassFilterDialog(const QList<QString> &class_list, const QList<QString> &selected_list, const bool filtering_all_classes_is_enabled, const bool all_is_checked, QWidget *parent) : QDialog(parent) { ui = new Ui::ClassFilterDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); ui->class_filter_widget->set_classes(class_list, selected_list); original_state = ui->class_filter_widget->save_state(); ui->all_checkbox->setVisible(filtering_all_classes_is_enabled); if (filtering_all_classes_is_enabled) { ui->all_checkbox->setChecked(all_is_checked); } connect( ui->button_box->button(QDialogButtonBox::Reset), &QPushButton::clicked, this, &ClassFilterDialog::reset); connect( ui->all_checkbox, &QCheckBox::toggled, this, &ClassFilterDialog::on_all_checkbox); connect( ui->all_checkbox, &QCheckBox::toggled, this, &ClassFilterDialog::on_input_changed); connect( ui->class_filter_widget, &ClassFilterWidget::changed, this, &ClassFilterDialog::on_input_changed); on_all_checkbox(); on_input_changed(); settings_setup_dialog_geometry(SETTING_class_filter_dialog_geometry, this); } ClassFilterDialog::~ClassFilterDialog() { delete ui; } QString ClassFilterDialog::get_filter() const { return ui->class_filter_widget->get_filter(); } QList<QString> ClassFilterDialog::get_selected_classes() const { return ui->class_filter_widget->get_selected_classes(); } bool ClassFilterDialog::get_all_is_checked() const { return ui->all_checkbox->isChecked(); } void ClassFilterDialog::reset() { ui->all_checkbox->setChecked(false); ui->class_filter_widget->restore_state(original_state); } void ClassFilterDialog::on_input_changed() { const bool input_is_valid = [&]() { const bool all_is_selected = ui->all_checkbox->isChecked(); const QList<QString> selected_classes = get_selected_classes(); const bool any_specific_class_selected = !selected_classes.isEmpty(); const bool out = (all_is_selected || any_specific_class_selected); return out; }(); QPushButton *ok_button = ui->button_box->button(QDialogButtonBox::Ok); ok_button->setEnabled(input_is_valid); } // Disable checkboxes for specific classes when "All" // checkbox is checked. void ClassFilterDialog::on_all_checkbox() { const bool all_is_checked = ui->all_checkbox->isChecked(); ui->class_filter_widget->setDisabled(all_is_checked); }
3,563
C++
.cpp
85
37.870588
196
0.723749
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,647
select_classes_widget.cpp
altlinux_admc/src/admc/filter_widget/select_classes_widget.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/select_classes_widget.h" #include "filter_widget/ui_select_classes_widget.h" #include "adldap.h" #include "filter_widget/class_filter_dialog.h" #include "globals.h" #include "utils.h" SelectClassesWidget::SelectClassesWidget(QWidget *parent) : QWidget(parent) { ui = new Ui::SelectClassesWidget(); ui->setupUi(this); filtering_all_classes_is_enabled = false; m_all_is_checked = false; connect( ui->select_button, &QAbstractButton::clicked, this, &SelectClassesWidget::open_dialog); } SelectClassesWidget::~SelectClassesWidget() { delete ui; } void SelectClassesWidget::set_classes(const QList<QString> &class_list_arg, const QList<QString> &selected_list_arg) { class_list = class_list_arg; m_selected_list = selected_list_arg; update_class_display(); } void SelectClassesWidget::enable_filtering_all_classes() { filtering_all_classes_is_enabled = true; } QString SelectClassesWidget::get_filter() const { if (m_all_is_checked) { return QString(); } else { const QString out = get_classes_filter(m_selected_list); return out; } } QVariant SelectClassesWidget::save_state() const { QHash<QString, QVariant> state; const QList<QVariant> selected_list_variant = string_list_to_variant_list(m_selected_list); state["selected_list"] = selected_list_variant; state["m_all_is_checked"] = m_all_is_checked; return state; } void SelectClassesWidget::restore_state(const QVariant &state_variant) { QHash<QString, QVariant> state = state_variant.toHash(); const QList<QVariant> saved_selected_list_variant = state["selected_list"].toList(); const QList<QString> saved_selected_list = variant_list_to_string_list(saved_selected_list_variant); m_selected_list = saved_selected_list; m_all_is_checked = state["m_all_is_checked"].toBool(); update_class_display(); } void SelectClassesWidget::open_dialog() { auto dialog = new ClassFilterDialog(class_list, m_selected_list, filtering_all_classes_is_enabled, m_all_is_checked, this); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { const QList<QString> new_selected_list = dialog->get_selected_classes(); m_selected_list = new_selected_list; m_all_is_checked = dialog->get_all_is_checked(); update_class_display(); }); } // Use current state to generate class display string void SelectClassesWidget::update_class_display() { // Convert class list to list of class display strings, // then sort it and finally join by comma's const QString display_string = [&]() { if (m_all_is_checked) { return tr("All"); } else { QList<QString> class_display_list; for (const QString &object_class : m_selected_list) { const QString class_display = g_adconfig->get_class_display_name(object_class); class_display_list.append(class_display); } std::sort(class_display_list.begin(), class_display_list.end()); const QString joined = class_display_list.join(", "); return joined; } }(); ui->classes_display->setText(display_string); // NOTE: set cursor to start because by default, // changing text causes line edit to scroll to the end ui->classes_display->setCursorPosition(0); }
4,256
C++
.cpp
105
35.266667
127
0.694492
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,648
filter_widget.cpp
altlinux_admc/src/admc/filter_widget/filter_widget.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "filter_widget/filter_widget.h" #include "filter_widget/ui_filter_widget.h" #include "filter_widget/filter_widget_advanced_tab.h" #include "filter_widget/filter_widget_normal_tab.h" #include "filter_widget/filter_widget_simple_tab.h" #include <QDebug> FilterWidget::FilterWidget(QWidget *parent) : QWidget(parent) { ui = new Ui::FilterWidget(); ui->setupUi(this); } FilterWidget::~FilterWidget() { delete ui; } void FilterWidget::set_classes(const QList<QString> &class_list, const QList<QString> &selected_list) { ui->simple_tab->set_classes(class_list, selected_list); ui->normal_tab->set_classes(class_list, selected_list); } void FilterWidget::enable_filtering_all_classes() { ui->simple_tab->enable_filtering_all_classes(); ui->normal_tab->enable_filtering_all_classes(); } QString FilterWidget::get_filter() const { const FilterWidgetTab *current_tab = dynamic_cast<FilterWidgetTab *>(ui->tab_widget->currentWidget()); if (current_tab) { return current_tab->get_filter(); } else { qDebug() << "Inserted a non FilterWidgetTab into FilterWidget"; return QString(); } } QVariant FilterWidget::save_state() const { QHash<QString, QVariant> state; state["current_tab_index"] = ui->tab_widget->currentIndex(); state["simple_state"] = ui->simple_tab->save_state(); state["normal_state"] = ui->normal_tab->save_state(); state["advanced_state"] = ui->advanced_tab->save_state(); return QVariant(state); } void FilterWidget::restore_state(const QVariant &state_variant) { const QHash<QString, QVariant> state = state_variant.toHash(); ui->tab_widget->setCurrentIndex(state["current_tab_index"].toInt()); ui->simple_tab->restore_state(state["simple_state"]); ui->normal_tab->restore_state(state["normal_state"]); ui->advanced_tab->restore_state(state["advanced_state"]); } void FilterWidget::clear() { ui->simple_tab->clear(); ui->normal_tab->clear(); ui->advanced_tab->clear(); }
2,798
C++
.cpp
70
36.728571
106
0.72171
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,649
edit_query_item_dialog.cpp
altlinux_admc/src/admc/edit_query_widgets/edit_query_item_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "edit_query_item_dialog.h" #include "ui_edit_query_item_dialog.h" #include "console_impls/query_folder_impl.h" #include "settings.h" EditQueryItemDialog::EditQueryItemDialog(const QList<QString> &sibling_name_list_arg, QWidget *parent) : QDialog(parent) { ui = new Ui::EditQueryItemDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); sibling_name_list = sibling_name_list_arg; settings_setup_dialog_geometry(SETTING_edit_query_item_dialog_geometry, this); } EditQueryItemDialog::~EditQueryItemDialog() { delete ui; } void EditQueryItemDialog::set_data(const QString &name, const QString &description, const bool scope_is_children, const QByteArray &filter_state, const QString &filter) { return ui->edit_query_item_widget->set_data(name, description, scope_is_children, filter_state, filter); } QString EditQueryItemDialog::name() const { return ui->edit_query_item_widget->name(); } QString EditQueryItemDialog::description() const { return ui->edit_query_item_widget->description(); } QString EditQueryItemDialog::filter() const { return ui->edit_query_item_widget->filter(); } QString EditQueryItemDialog::base() const { return ui->edit_query_item_widget->base(); } bool EditQueryItemDialog::scope_is_children() const { return ui->edit_query_item_widget->scope_is_children(); } QByteArray EditQueryItemDialog::filter_state() const { return ui->edit_query_item_widget->filter_state(); } void EditQueryItemDialog::accept() { const QString name = ui->edit_query_item_widget->name(); const bool name_is_valid = console_query_or_folder_name_is_good(name, sibling_name_list, this); if (name_is_valid) { QDialog::accept(); } }
2,511
C++
.cpp
62
37.725806
170
0.749692
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,650
edit_query_item_widget.cpp
altlinux_admc/src/admc/edit_query_widgets/edit_query_item_widget.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "edit_query_item_widget.h" #include "ui_edit_query_item_widget.h" #include "ad_filter.h" #include "filter_widget/filter_dialog.h" EditQueryItemWidget::EditQueryItemWidget(QWidget *parent) : QWidget(parent) { ui = new Ui::EditQueryItemWidget(); ui->setupUi(this); connect( ui->edit_filter_button, &QPushButton::clicked, this, &EditQueryItemWidget::open_filter_dialog); } EditQueryItemWidget::~EditQueryItemWidget() { delete ui; } QString EditQueryItemWidget::name() const { return ui->name_edit->text().trimmed(); } QString EditQueryItemWidget::description() const { return ui->description_edit->text(); } QString EditQueryItemWidget::filter() const { return ui->filter_display->toPlainText(); } QString EditQueryItemWidget::base() const { return ui->select_base_widget->get_base(); } bool EditQueryItemWidget::scope_is_children() const { return !ui->scope_checkbox->isChecked(); } QByteArray EditQueryItemWidget::filter_state() const { QHash<QString, QVariant> state; state["select_base_widget"] = ui->select_base_widget->save_state(); state["filter_dialog_state"] = filter_dialog_state; state["filter"] = filter(); QByteArray out; QDataStream state_stream(&out, QIODevice::WriteOnly); state_stream << state; return out; } void EditQueryItemWidget::set_data(const QString &name, const QString &description, const bool scope_is_children, const QByteArray &filter_state, const QString &filter) { QDataStream filter_state_stream(filter_state); QHash<QString, QVariant> state; filter_state_stream >> state; ui->select_base_widget->restore_state(state["select_base_widget"]); filter_dialog_state = state["filter_dialog_state"]; ui->filter_display->setPlainText(filter); ui->name_edit->setText(name); ui->description_edit->setText(description); ui->scope_checkbox->setChecked(!scope_is_children); } void EditQueryItemWidget::open_filter_dialog() { auto dialog = new FilterDialog(filter_classes, filter_classes, this); dialog->enable_filtering_all_classes(); dialog->restore_state(filter_dialog_state); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { filter_dialog_state = dialog->save_state(); const QString new_filter = dialog->get_filter(); ui->filter_display->setPlainText(new_filter); }); }
3,233
C++
.cpp
84
34.52381
170
0.721689
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,651
edit_query_folder_dialog.cpp
altlinux_admc/src/admc/edit_query_widgets/edit_query_folder_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "edit_query_folder_dialog.h" #include "ui_edit_query_folder_dialog.h" #include "console_impls/query_folder_impl.h" #include "settings.h" EditQueryFolderDialog::EditQueryFolderDialog(QWidget *parent) : QDialog(parent) { ui = new Ui::EditQueryFolderDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); settings_setup_dialog_geometry(SETTING_edit_query_folder_dialog_geometry, this); } EditQueryFolderDialog::~EditQueryFolderDialog() { delete ui; } QString EditQueryFolderDialog::name() const { return ui->name_edit->text(); } QString EditQueryFolderDialog::description() const { return ui->description_edit->text(); } void EditQueryFolderDialog::set_data(const QList<QString> &sibling_name_list_arg, const QString &name, const QString &description) { sibling_name_list = sibling_name_list_arg; ui->name_edit->setText(name); ui->description_edit->setText(description); } void EditQueryFolderDialog::accept() { const QString name = ui->name_edit->text().trimmed(); const bool name_is_valid = console_query_or_folder_name_is_good(name, sibling_name_list, this); if (name_is_valid) { QDialog::accept(); } }
1,972
C++
.cpp
51
35.823529
132
0.746464
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,652
create_computer_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_computer_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_computer_dialog.h" #include "ui_create_computer_dialog.h" #include "adldap.h" #include "attribute_edits/computer_sam_name_edit.h" #include "attribute_edits/upn_edit.h" #include "create_object_helper.h" #include "settings.h" #include "utils.h" CreateComputerDialog::CreateComputerDialog(const QString &parent_dn, QWidget *parent) : CreateObjectDialog(parent) { ui = new Ui::CreateComputerDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); // NOTE: some obscure missing features: // "Assign this computer account as a pre-Windows 2000 computer". Is this needed? // "The following user or group may join this computer to a domain". Tried to figure out how this is implemented and couldn't see any easy ways via attributes, so probably something to do with setting ACL'S. // "This is a managed computer" checkbox and an edit for guid/uuid which I assume modifies objectGUID? auto sam_name_edit = new ComputerSamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this); const QList<AttributeEdit *> edit_list = { sam_name_edit, }; const QList<QLineEdit *> required_list = { ui->name_edit, ui->sam_name_edit, }; // Autofill name -> sam account name connect( ui->name_edit, &QLineEdit::textChanged, this, &CreateComputerDialog::autofill_sam_name); helper = new CreateObjectHelper(ui->name_edit, ui->button_box, edit_list, required_list, CLASS_COMPUTER, parent_dn, this); settings_setup_dialog_geometry(SETTING_create_computer_dialog_geometry, this); } CreateComputerDialog::~CreateComputerDialog() { delete ui; } void CreateComputerDialog::accept() { const bool accepted = helper->accept(); if (accepted) { QDialog::accept(); } } QString CreateComputerDialog::get_created_dn() const { return helper->get_created_dn(); } // NOTE: can't use setup_lineedit_autofill() because // need to make input uppercase void CreateComputerDialog::autofill_sam_name() { const QString name_input = ui->name_edit->text(); ui->sam_name_edit->setText(name_input.toUpper()); }
2,913
C++
.cpp
69
38.695652
211
0.730905
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,653
create_group_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_group_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_group_dialog.h" #include "ui_create_group_dialog.h" #include "adldap.h" #include "attribute_edits/group_scope_edit.h" #include "attribute_edits/group_type_edit.h" #include "attribute_edits/sam_name_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/upn_edit.h" #include "create_object_helper.h" #include "settings.h" #include "utils.h" CreateGroupDialog::CreateGroupDialog(const QString &parent_dn, QWidget *parent) : CreateObjectDialog(parent) { ui = new Ui::CreateGroupDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this); auto scope_edit = new GroupScopeEdit(ui->scope_combo, this); auto type_edit = new GroupTypeEdit(ui->type_combo, this); const QList<AttributeEdit *> edit_list = { sam_name_edit, scope_edit, type_edit, }; const QList<QLineEdit *> required_edits = { ui->sam_name_edit, }; helper = new CreateObjectHelper(ui->name_edit, ui->button_box, edit_list, required_edits, CLASS_GROUP, parent_dn, this); settings_setup_dialog_geometry(SETTING_create_group_dialog_geometry, this); // name -> sam account name connect( ui->name_edit, &QLineEdit::textChanged, this, &CreateGroupDialog::autofill_sam_name); } CreateGroupDialog::~CreateGroupDialog() { delete ui; } void CreateGroupDialog::accept() { const bool accepted = helper->accept(); if (accepted) { QDialog::accept(); } } QString CreateGroupDialog::get_created_dn() const { return helper->get_created_dn(); } void CreateGroupDialog::autofill_sam_name() { const QString name_input = ui->name_edit->text(); ui->sam_name_edit->setText(name_input); }
2,580
C++
.cpp
69
33.884058
124
0.721554
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,654
create_query_item_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_query_item_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_query_item_dialog.h" #include "ui_create_query_item_dialog.h" #include "console_impls/query_folder_impl.h" #include "settings.h" CreateQueryItemDialog::CreateQueryItemDialog(const QList<QString> &sibling_name_list_arg, QWidget *parent) : QDialog(parent) { ui = new Ui::CreateQueryItemDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); sibling_name_list = sibling_name_list_arg; settings_setup_dialog_geometry(SETTING_create_query_item_dialog_geometry, this); } CreateQueryItemDialog::~CreateQueryItemDialog() { delete ui; } QString CreateQueryItemDialog::name() const { return ui->edit_query_widget->name(); } QString CreateQueryItemDialog::description() const { return ui->edit_query_widget->description(); } QString CreateQueryItemDialog::filter() const { return ui->edit_query_widget->filter(); } QString CreateQueryItemDialog::base() const { return ui->edit_query_widget->base(); } bool CreateQueryItemDialog::scope_is_children() const { return ui->edit_query_widget->scope_is_children(); } QByteArray CreateQueryItemDialog::filter_state() const { return ui->edit_query_widget->filter_state(); } void CreateQueryItemDialog::accept() { const QString name = ui->edit_query_widget->name(); const bool name_is_valid = console_query_or_folder_name_is_good(name, sibling_name_list, this); if (name_is_valid) { QDialog::accept(); } }
2,223
C++
.cpp
59
34.898305
106
0.748255
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,655
create_query_folder_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_query_folder_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_query_folder_dialog.h" #include "ui_create_query_folder_dialog.h" #include "console_impls/query_folder_impl.h" #include "settings.h" #include "utils.h" CreateQueryFolderDialog::CreateQueryFolderDialog(QWidget *parent) : QDialog(parent) { ui = new Ui::CreateQueryFolderDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); settings_setup_dialog_geometry(SETTING_create_query_folder_dialog_geometry, this); } CreateQueryFolderDialog::~CreateQueryFolderDialog() { delete ui; } QString CreateQueryFolderDialog::name() const { return ui->name_edit->text().trimmed(); } QString CreateQueryFolderDialog::description() const { return ui->description_edit->text().trimmed(); } void CreateQueryFolderDialog::set_sibling_name_list(const QList<QString> &list) { sibling_name_list = list; const QString default_name = [&]() { const QString out = generate_new_name(sibling_name_list, tr("New Folder")); return out; }(); ui->name_edit->setText(default_name); } void CreateQueryFolderDialog::accept() { const QString name = ui->name_edit->text().trimmed(); const bool name_is_valid = console_query_or_folder_name_is_good(name, sibling_name_list, this); if (name_is_valid) { QDialog::accept(); } }
2,081
C++
.cpp
55
34.727273
99
0.735586
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,656
create_shared_folder_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_shared_folder_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_shared_folder_dialog.h" #include "ui_create_shared_folder_dialog.h" #include "adldap.h" #include "attribute_edits/protect_deletion_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/upn_edit.h" #include "create_object_helper.h" #include "settings.h" #include "utils.h" CreateSharedFolderDialog::CreateSharedFolderDialog(const QString &parent_dn, QWidget *parent) : CreateObjectDialog(parent) { ui = new Ui::CreateSharedFolderDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto path_edit = new StringEdit(ui->path_edit, ATTRIBUTE_UNC_NAME, this); const QList<AttributeEdit *> edit_list = { path_edit, }; const QList<QLineEdit *> required_list = { ui->name_edit, ui->path_edit, }; helper = new CreateObjectHelper(ui->name_edit, ui->button_box, edit_list, required_list, CLASS_SHARED_FOLDER, parent_dn, this); settings_setup_dialog_geometry(SETTING_create_shared_folder_dialog_geometry, this); } CreateSharedFolderDialog::~CreateSharedFolderDialog() { delete ui; } void CreateSharedFolderDialog::accept() { const bool accepted = helper->accept(); if (accepted) { QDialog::accept(); } } QString CreateSharedFolderDialog::get_created_dn() const { return helper->get_created_dn(); }
2,115
C++
.cpp
56
34.571429
131
0.738025
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,657
create_user_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_user_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_user_dialog.h" #include "ui_create_user_dialog.h" #include "adldap.h" #include "attribute_edits/account_option_edit.h" #include "attribute_edits/password_edit.h" #include "attribute_edits/sam_name_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/upn_edit.h" #include "create_object_helper.h" #include "settings.h" #include "utils.h" CreateUserDialog::CreateUserDialog(AdInterface &ad, const QString &parent_dn, const QString &user_class, QWidget *parent) : CreateObjectDialog(parent) { ui = new Ui::CreateUserDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto first_name_edit = new StringEdit(ui->first_name_edit, ATTRIBUTE_FIRST_NAME, this); auto last_name_edit = new StringEdit(ui->last_name_edit, ATTRIBUTE_LAST_NAME, this); auto initials_edit = new StringEdit(ui->initials_edit, ATTRIBUTE_INITIALS, this); auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this); auto password_edit = new PasswordEdit(ui->password_main_edit, ui->password_confirm_edit, ui->show_password_check, this); auto upn_edit = new UpnEdit(ui->upn_prefix_edit, ui->upn_suffix_edit, this); upn_edit->init_suffixes(ad); const QHash<AccountOption, QCheckBox *> check_map = { {AccountOption_PasswordExpired, ui->must_change_pass_check}, {AccountOption_CantChangePassword, ui->cant_change_pass_check}, {AccountOption_DontExpirePassword, ui->dont_expire_pass_check}, {AccountOption_Disabled, ui->disabled_check}, }; QList<AttributeEdit *> option_edit_list; for (const AccountOption &option : check_map.keys()) { QCheckBox *check = check_map[option]; auto edit = new AccountOptionEdit(check, option, this); option_edit_list.append(edit); } account_option_setup_conflicts(check_map); setup_full_name_autofill(ui->first_name_edit, ui->last_name_edit, ui->name_edit); setup_lineedit_autofill(ui->upn_prefix_edit, ui->sam_name_edit); const QList<QLineEdit *> required_list = { ui->name_edit, ui->first_name_edit, ui->sam_name_edit, }; const QList<AttributeEdit *> edit_list = [&]() { QList<AttributeEdit *> out; out = { first_name_edit, last_name_edit, initials_edit, sam_name_edit, password_edit, upn_edit, }; out.append(option_edit_list); return out; }(); helper = new CreateObjectHelper(ui->name_edit, ui->button_box, edit_list, required_list, user_class, parent_dn, this); if (user_class != CLASS_USER) { setWindowTitle(QString(tr("Create %1")).arg(user_class)); } settings_setup_dialog_geometry(SETTING_create_user_dialog_geometry, this); } CreateUserDialog::~CreateUserDialog() { delete ui; } void CreateUserDialog::accept() { const bool accepted = helper->accept(); if (accepted) { QDialog::accept(); } } QString CreateUserDialog::get_created_dn() const { return helper->get_created_dn(); }
3,888
C++
.cpp
93
36.774194
124
0.697347
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,658
create_ou_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_ou_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_ou_dialog.h" #include "ui_create_ou_dialog.h" #include "adldap.h" #include "attribute_edits/protect_deletion_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/upn_edit.h" #include "create_object_helper.h" #include "settings.h" #include "utils.h" CreateOUDialog::CreateOUDialog(const QString &parent_dn, QWidget *parent) : CreateObjectDialog(parent) { ui = new Ui::CreateOUDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto deletion_edit = new ProtectDeletionEdit(ui->deletion_check, this); const QList<AttributeEdit *> edit_list = { deletion_edit, }; const QList<QLineEdit *> required_list = { ui->name_edit, }; helper = new CreateObjectHelper(ui->name_edit, ui->button_box, edit_list, required_list, CLASS_OU, parent_dn, this); settings_setup_dialog_geometry(SETTING_create_ou_dialog_geometry, this); } CreateOUDialog::~CreateOUDialog() { delete ui; } void CreateOUDialog::accept() { const bool accepted = helper->accept(); if (accepted) { QDialog::accept(); } } QString CreateOUDialog::get_created_dn() const { return helper->get_created_dn(); }
1,980
C++
.cpp
55
32.909091
120
0.730126
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,659
create_policy_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_policy_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_policy_dialog.h" #include "ui_create_policy_dialog.h" #include "adldap.h" #include "console_impls/policy_impl.h" #include "console_widget/console_widget.h" #include "globals.h" #include "settings.h" #include "status.h" #include "utils.h" #include <QPushButton> CreatePolicyDialog::CreatePolicyDialog(AdInterface &ad, QWidget *parent) : QDialog(parent) { ui = new Ui::CreatePolicyDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); const QString default_name = [&]() { const QList<QString> existing_name_list = [&]() { const QString base = g_adconfig->domain_dn(); const SearchScope scope = SearchScope_All; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_OBJECT_CLASS, CLASS_GP_CONTAINER); const QList<QString> attributes = {ATTRIBUTE_DISPLAY_NAME}; const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); QList<QString> out; for (const AdObject &object : results.values()) { const QString name = object.get_string(ATTRIBUTE_DISPLAY_NAME); out.append(name); } return out; }(); const QString out = generate_new_name(existing_name_list, tr("New Group Policy Object")); connect(ui->name_edit, &QLineEdit::textChanged, this, &CreatePolicyDialog::on_edited); on_edited(); return out; }(); ui->name_edit->setText(default_name); ui->name_edit->selectAll(); limit_edit(ui->name_edit, ATTRIBUTE_DISPLAY_NAME); settings_setup_dialog_geometry(SETTING_create_policy_dialog_geometry, this); } CreatePolicyDialog::~CreatePolicyDialog() { delete ui; } QString CreatePolicyDialog::get_created_dn() const { return created_dn; } void CreatePolicyDialog::accept() { AdInterface ad; if (ad_failed(ad, this)) { return; } show_busy_indicator(); const QString name = ui->name_edit->text().trimmed(); // NOTE: since this is *display name*, not just name, // have to manually check for conflict. Server wouldn't // catch this. const bool name_conflict = [&]() { const QString base = g_adconfig->domain_dn(); const SearchScope scope = SearchScope_All; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_DISPLAY_NAME, name); const QList<QString> attributes = QList<QString>(); const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); return !results.isEmpty(); }(); if (name_conflict) { message_box_warning(this, tr("Error"), tr("Group Policy Object with this name already exists.")); return; } const bool success = ad.gpo_add(name, created_dn); hide_busy_indicator(); g_status->display_ad_messages(ad, this); if (success) { QDialog::accept(); } } void CreatePolicyDialog::on_edited() { QRegExp reg_exp_spaces("^\\s*$"); if (ui->name_edit->text().isEmpty() || ui->name_edit->text().contains(reg_exp_spaces)) { ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } else { ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } }
4,061
C++
.cpp
101
34.673267
114
0.677518
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,660
create_contact_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_contact_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_contact_dialog.h" #include "ui_create_contact_dialog.h" #include "adldap.h" #include "attribute_edits/string_edit.h" #include "create_object_helper.h" #include "settings.h" #include "utils.h" CreateContactDialog::CreateContactDialog(const QString &parent_dn, QWidget *parent) : CreateObjectDialog(parent) { ui = new Ui::CreateContactDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); auto first_name_edit = new StringEdit(ui->first_name_edit, ATTRIBUTE_FIRST_NAME, this); auto last_name_edit = new StringEdit(ui->last_name_edit, ATTRIBUTE_LAST_NAME, this); auto initials_edit = new StringEdit(ui->initials_edit, ATTRIBUTE_INITIALS, this); auto display_name_edit = new StringEdit(ui->display_name_edit, ATTRIBUTE_DISPLAY_NAME, this); const QList<AttributeEdit *> edit_list = { first_name_edit, last_name_edit, initials_edit, display_name_edit, }; const QList<QLineEdit *> required_list = { ui->first_name_edit, ui->last_name_edit, ui->full_name_edit, ui->display_name_edit, }; setup_full_name_autofill(ui->first_name_edit, ui->last_name_edit, ui->full_name_edit); helper = new CreateObjectHelper(ui->full_name_edit, ui->button_box, edit_list, required_list, CLASS_CONTACT, parent_dn, this); settings_setup_dialog_geometry(SETTING_create_contact_dialog_geometry, this); } CreateContactDialog::~CreateContactDialog() { delete ui; } void CreateContactDialog::accept() { const bool accepted = helper->accept(); if (accepted) { QDialog::accept(); } } QString CreateContactDialog::get_created_dn() const { return helper->get_created_dn(); }
2,501
C++
.cpp
63
35.84127
130
0.721947
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,661
create_pso_dialog.cpp
altlinux_admc/src/admc/create_dialogs/create_pso_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2024 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "create_pso_dialog.h" #include "ui_create_pso_dialog.h" #include "ad_interface.h" #include "utils.h" #include "ad_utils.h" #include "status.h" #include "globals.h" #include "attribute_edits/protect_deletion_edit.h" #include <QPushButton> #include <QLineEdit> CreatePSODialog::CreatePSODialog(const QString &parent_dn_arg, QWidget *parent) : CreateObjectDialog(parent), ui(new Ui::CreatePSODialog), parent_dn(parent_dn_arg) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); deletion_edit = new ProtectDeletionEdit(ui->protect_deletion_checkbox, this); connect(ui->pso_edit_widget->name_line_edit(), &QLineEdit::textEdited, [this](const QString &text) { ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty()); }); } CreatePSODialog::~CreatePSODialog() { delete ui; } void CreatePSODialog::accept() { const QString name = ui->pso_edit_widget->name_line_edit()->text().trimmed(); bool name_verified = verify_object_name(name, this); if (!name_verified) { return; } AdInterface ad; if (ad_failed(ad, this)) { return; } if (ui->pso_edit_widget->settings_are_default()) { message_box_warning(this, "", tr("At least one password setting (except precedence) should not be default")); return; } QHash<QString, QList<QString>> pso_string_settings = ui->pso_edit_widget->pso_settings_string_values(); QHash<QString, QList<QString>> attrs_map = { {ATTRIBUTE_OBJECT_CLASS, {CLASS_PSO}}, }; for (const QString attribute : pso_string_settings.keys()) { attrs_map[attribute] = pso_string_settings[attribute]; } const QString dn = get_created_dn(); const bool add_success = ad.object_add(dn, attrs_map); g_status->display_ad_messages(ad, this); if (!add_success) { g_status->add_message(tr("Failed to create password settings object %1").arg(name), StatusType_Error); return; } deletion_edit->apply(ad, dn); g_status->add_message(tr("Password settings object %1 has been successfully created.").arg(name), StatusType_Success); QDialog::accept(); } QString CreatePSODialog::get_created_dn() const { const QString name = ui->pso_edit_widget->name_line_edit()->text().trimmed(); const QString dn = dn_from_name_and_parent(name, parent_dn, CLASS_PSO); return dn; }
3,146
C++
.cpp
80
35.125
122
0.700689
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,662
os_tab.cpp
altlinux_admc/src/admc/tabs/os_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/os_tab.h" #include "tabs/ui_os_tab.h" #include "adldap.h" #include "attribute_edits/string_edit.h" OSTab::OSTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::OSTab(); ui->setupUi(this); auto os_edit = new StringEdit(ui->os_edit, ATTRIBUTE_OS, this); auto version_edit = new StringEdit(ui->version_edit, ATTRIBUTE_OS_VERSION, this); auto pack_edit = new StringEdit(ui->pack_edit, ATTRIBUTE_OS_SERVICE_PACK, this); edit_list->append({ os_edit, version_edit, pack_edit, }); } OSTab::~OSTab() { delete ui; }
1,394
C++
.cpp
39
32.692308
85
0.715345
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,663
general_other_tab.cpp
altlinux_admc/src/admc/tabs/general_other_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_other_tab.h" #include "tabs/ui_general_other_tab.h" #include "adldap.h" #include "attribute_edits/general_name_edit.h" #include "attribute_edits/string_edit.h" GeneralOtherTab::GeneralOtherTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralOtherTab(); ui->setupUi(this); auto name_edit = new GeneralNameEdit(ui->name_label, this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); edit_list->append({ name_edit, description_edit, }); } GeneralOtherTab::~GeneralOtherTab() { delete ui; }
1,420
C++
.cpp
38
34.578947
94
0.739826
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,664
error_tab.cpp
altlinux_admc/src/admc/tabs/error_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/error_tab.h" #include "tabs/ui_error_tab.h" ErrorTab::ErrorTab(QWidget *parent) : QWidget(parent) { ui = new Ui::ErrorTab(); ui->setupUi(this); } ErrorTab::~ErrorTab() { delete ui; }
987
C++
.cpp
29
31.896552
72
0.73822
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,665
profile_tab.cpp
altlinux_admc/src/admc/tabs/profile_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/profile_tab.h" #include "tabs/ui_profile_tab.h" #include "adldap.h" #include "attribute_edits/string_edit.h" ProfileTab::ProfileTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::ProfileTab(); ui->setupUi(this); auto profile_path_edit = new StringEdit(ui->profile_path_edit, ATTRIBUTE_PROFILE_PATH, this); auto script_path_edit = new StringEdit(ui->script_path_edit, ATTRIBUTE_SCRIPT_PATH, this); auto home_dir_edit = new StringEdit(ui->home_dir_edit, ATTRIBUTE_HOME_DIRECTORY, this); edit_list->append({ profile_path_edit, script_path_edit, home_dir_edit, }); } ProfileTab::~ProfileTab() { delete ui; }
1,493
C++
.cpp
39
35.230769
97
0.728591
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,666
general_policy_tab.cpp
altlinux_admc/src/admc/tabs/general_policy_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_policy_tab.h" #include "tabs/ui_general_policy_tab.h" #include "adldap.h" #include "attribute_edits/datetime_edit.h" #include "attribute_edits/general_name_edit.h" #include "utils.h" #include <QDebug> // NOTE: missing "comment" and "owner" field, BUT not sure // about their inclusion. They straddle the boundary between // admc/gpui. On windows they are displayed/editable in both // GPM(admc equivalent) and GPME(gpui equivalent). Comment // is stored somewhere on sysvol. Owner, not sure, might be // in security descriptor? GeneralPolicyTab::GeneralPolicyTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralPolicyTab(); ui->setupUi(this); auto name_edit = new GeneralNameEdit(ui->name_label, this); auto created_edit = new DateTimeEdit(ui->created_edit, ATTRIBUTE_WHEN_CREATED, this); auto modified_edit = new DateTimeEdit(ui->modified_edit, ATTRIBUTE_WHEN_CHANGED, this); auto tab_edit = new GeneralPolicyTabEdit(ui, this); edit_list->append({ name_edit, created_edit, modified_edit, tab_edit, }); } GeneralPolicyTab::~GeneralPolicyTab() { delete ui; } GeneralPolicyTabEdit::GeneralPolicyTabEdit(Ui::GeneralPolicyTab *ui_arg, QObject *parent) : AttributeEdit(parent) { ui = ui_arg; } void GeneralPolicyTabEdit::load(AdInterface &ad, const AdObject &object) { // Load version strings const int ad_version = object.get_int(ATTRIBUTE_VERSION_NUMBER); int sysvol_version = 0; const bool get_sysvol_version_success = ad.gpo_get_sysvol_version(object, &sysvol_version); auto get_machine_version = [](const int version_number) { const int out = version_number & 0x0000FFFF; return out; }; auto get_user_version = [](const int version_number) { int out = version_number & 0xFFFF0000; out = out >> 16; return out; }; const int ad_user = get_user_version(ad_version); const int sysvol_user = get_user_version(sysvol_version); const int ad_machine = get_machine_version(ad_version); const int sysvol_machine = get_machine_version(sysvol_version); // If we fail to load version from sysvol, show // "unknown" instead of number const QString unknown_string = tr("unknown"); const QString sysvol_user_string = [&]() { if (get_sysvol_version_success) { return QString::number(sysvol_user); } else { return unknown_string; } }(); const QString sysvol_machine_string = [&]() { if (get_sysvol_version_success) { return QString::number(sysvol_machine); } else { return unknown_string; } }(); const QString user_version_string = QString("%1 (AD), %2 (sysvol)").arg(ad_user).arg(sysvol_user_string); const QString machine_version_string = QString("%1 (AD), %2 (sysvol)").arg(ad_machine).arg(sysvol_machine_string); ui->computer_version_label->setText(machine_version_string); ui->user_version_label->setText(user_version_string); const QString id = object.get_string(ATTRIBUTE_CN); ui->unique_id_label->setText(id); }
3,974
C++
.cpp
96
36.760417
118
0.700908
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,667
account_tab.cpp
altlinux_admc/src/admc/tabs/account_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/account_tab.h" #include "tabs/ui_account_tab.h" #include "attribute_edits/account_option_edit.h" #include "attribute_edits/expiry_edit.h" #include "attribute_edits/logon_computers_edit.h" #include "attribute_edits/logon_hours_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/unlock_edit.h" #include "attribute_edits/upn_edit.h" #include "settings.h" // NOTE: the "can't change password" checkbox does not // affect the permission in the security tab, even though // they control the same thing. And vice versa. Too // complicated to implement so this is a WONTFIX. AccountTab::AccountTab(AdInterface &ad, QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::AccountTab(); ui->setupUi(this); auto upn_edit = new UpnEdit(ui->upn_prefix_edit, ui->upn_suffix_edit, this); upn_edit->init_suffixes(ad); auto unlock_edit = new UnlockEdit(ui->unlock_check, this); auto expiry_widget_edit = new ExpiryEdit(ui->expiry_widget, this); auto logon_hours_edit = new LogonHoursEdit(ui->logon_hours_button, this); auto logon_computers_edit = new LogonComputersEdit(ui->logon_computers_button, this); const QHash<AccountOption, QCheckBox *> check_map = { {AccountOption_Disabled, ui->disabled_check}, {AccountOption_CantChangePassword, ui->cant_change_pass_check}, {AccountOption_PasswordExpired, ui->pass_expired_check}, {AccountOption_DontExpirePassword, ui->dont_expire_pass_check}, {AccountOption_AllowReversibleEncryption, ui->reversible_encrypt_check}, {AccountOption_SmartcardRequired, ui->smartcard_check}, {AccountOption_CantDelegate, ui->cant_delegate_check}, {AccountOption_UseDesKey, ui->des_key_check}, {AccountOption_DontRequirePreauth, ui->require_preauth_check}, }; for (const AccountOption &option : check_map.keys()) { QCheckBox *check = check_map[option]; auto edit = new AccountOptionEdit(check, option, this); edit_list->append(edit); } account_option_setup_conflicts(check_map); edit_list->append({ upn_edit, unlock_edit, expiry_widget_edit, logon_hours_edit, logon_computers_edit, }); const bool logon_computers_enabled = settings_get_variant(SETTING_feature_logon_computers).toBool(); if (!logon_computers_enabled) { ui->logon_computers_button->hide(); } } AccountTab::~AccountTab() { delete ui; }
3,284
C++
.cpp
75
39.44
104
0.722778
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,668
laps_tab.cpp
altlinux_admc/src/admc/tabs/laps_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/laps_tab.h" #include "tabs/ui_laps_tab.h" #include "adldap.h" #include "attribute_edits/laps_expiry_edit.h" #include "attribute_edits/string_edit.h" LAPSTab::LAPSTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::LAPSTab(); ui->setupUi(this); auto pass_edit = new StringEdit(ui->pass_lineedit, ATTRIBUTE_LAPS_PASSWORD, this); auto laps_edit = new LAPSExpiryEdit(ui->expiry_datetimeedit, ui->reset_expiry_button, this); edit_list->append({ pass_edit, laps_edit, }); } LAPSTab::~LAPSTab() { delete ui; }
1,379
C++
.cpp
38
33.5
96
0.72809
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,669
delegation_tab.cpp
altlinux_admc/src/admc/tabs/delegation_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/delegation_tab.h" #include "tabs/ui_delegation_tab.h" #include "adldap.h" #include "attribute_edits/delegation_edit.h" DelegationTab::DelegationTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::DelegationTab(); ui->setupUi(this); auto tab_edit = new DelegationEdit(ui->off_button, ui->on_button, this); edit_list->append({ tab_edit, }); } DelegationTab::~DelegationTab() { delete ui; }
1,252
C++
.cpp
35
33.171429
80
0.73493
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,670
security_tab.cpp
altlinux_admc/src/admc/tabs/security_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/security_tab.h" #include "tabs/ui_security_tab.h" #include "ad_security.h" #include "adldap.h" #include "globals.h" #include "select_dialogs/select_object_dialog.h" #include "select_well_known_trustee_dialog.h" #include "settings.h" #include "utils.h" #include "samba/ndr_security.h" #include <QDebug> #include <QLabel> #include <QPersistentModelIndex> #include <QSortFilterProxyModel> #include <QStandardItemModel> #include <QTreeView> #include <QVBoxLayout> struct security_descriptor; enum TrusteeItemRole { TrusteeItemRole_Sid = Qt::UserRole, }; enum EditAction { EditAction_None, EditAction_Add, EditAction_Remove, }; enum RightsItemRole { RightsItemRole_AccessMask = Qt::UserRole, RightsItemRole_ObjectType, RightsItemRole_ObjectTypeName, }; class RightsSortModel final : public QSortFilterProxyModel { public: using QSortFilterProxyModel::QSortFilterProxyModel; bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override { const QString name_left = source_left.data(Qt::DisplayRole).toString(); const QString name_right = source_right.data(Qt::DisplayRole).toString(); const QString object_type_name_left = source_left.data(RightsItemRole_ObjectTypeName).toString(); const QString object_type_name_right = source_right.data(RightsItemRole_ObjectTypeName).toString(); const QByteArray object_type_left = source_left.data(RightsItemRole_ObjectType).toByteArray(); const QByteArray object_type_right = source_right.data(RightsItemRole_ObjectType).toByteArray(); const uint32_t access_mask_left = source_left.data(RightsItemRole_AccessMask).toUInt(); const uint32_t access_mask_right = source_right.data(RightsItemRole_AccessMask).toUInt(); const bool is_common_left = object_type_left.isEmpty(); const bool is_common_right = object_type_right.isEmpty(); const bool is_control_left = (access_mask_left == SEC_ADS_CONTROL_ACCESS); const bool is_control_right = (access_mask_right == SEC_ADS_CONTROL_ACCESS); const bool is_read_left = (access_mask_left == SEC_ADS_READ_PROP); const bool is_read_right = (access_mask_right == SEC_ADS_READ_PROP); // Generic are before non-generic if (is_common_left != is_common_right) { return is_common_left; } // Generic among generic are in pre-defined order if (is_common_left && is_common_right) { const int common_index_left = common_rights_list.indexOf(access_mask_left); const int common_index_right = common_rights_list.indexOf(access_mask_right); return (common_index_left < common_index_right); } // Control rights are before read/write rights if (is_control_left != is_control_right) { return is_control_left; } // Control rights are sorted by name if (is_control_left && is_control_right) { return name_left < name_right; } // Read/write rights are sorted by name if (object_type_left != object_type_right) { return object_type_name_left < object_type_name_right; } // Read rights are before write rights if (is_read_left != is_read_right) { return is_read_left; } return name_left < name_right; } }; SecurityTab::SecurityTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::SecurityTab(); ui->setupUi(this); tab_edit = new SecurityTabEdit(ui, this); edit_list->append({ tab_edit, }); } void SecurityTab::fix_acl_order() { tab_edit->fix_acl_order(); } void SecurityTab::set_read_only() { tab_edit->set_read_only(); } bool SecurityTab::verify_acl_order() const { return tab_edit->verify_acl_order(); } SecurityTabEdit::SecurityTabEdit(Ui::SecurityTab *ui_arg, QObject *parent) : AttributeEdit(parent) { ui = ui_arg; sd = nullptr; ignore_item_changed_signal = false; read_only = false; trustee_model = new QStandardItemModel(0, 1, this); ui->trustee_view->setModel(trustee_model); rights_model = new QStandardItemModel(0, AceColumn_COUNT, this); set_horizontal_header_labels_from_map(rights_model, { {AceColumn_Name, tr("Name")}, {AceColumn_Allowed, tr("Allowed")}, {AceColumn_Denied, tr("Denied")}, }); rights_sort_model = new RightsSortModel(this); rights_sort_model->setSourceModel(rights_model); ui->rights_view->setModel(rights_sort_model); ui->rights_view->setColumnWidth(AceColumn_Name, 400); settings_restore_header_state(SETTING_security_tab_header_state, ui->rights_view->header()); connect( ui->trustee_view->selectionModel(), &QItemSelectionModel::currentChanged, this, &SecurityTabEdit::load_rights_model); connect( rights_model, &QStandardItemModel::itemChanged, this, &SecurityTabEdit::on_item_changed); connect( ui->add_trustee_button, &QAbstractButton::clicked, this, &SecurityTabEdit::on_add_trustee_button); connect( ui->add_well_known_trustee_button, &QAbstractButton::clicked, this, &SecurityTabEdit::on_add_well_known_trustee); connect( ui->remove_trustee_button, &QAbstractButton::clicked, this, &SecurityTabEdit::on_remove_trustee_button); } SecurityTabEdit::~SecurityTabEdit() { if (sd != nullptr) { security_descriptor_free(sd); } } void SecurityTabEdit::fix_acl_order() { security_descriptor_sort_dacl(sd); emit edited(); } void SecurityTabEdit::set_read_only() { ui->add_trustee_button->setEnabled(false); ui->add_well_known_trustee_button->setEnabled(false); ui->remove_trustee_button->setEnabled(false); make_rights_model_read_only(); read_only = true; } bool SecurityTabEdit::verify_acl_order() const { const bool out = security_descriptor_verify_acl_order(sd); return out; } SecurityTab::~SecurityTab() { settings_save_header_state(SETTING_security_tab_header_state, ui->rights_view->header()); delete ui; } // Load sd data into trustee model and rights model // NOTE: load_rights_model() is not explicitly called // here but it is called implicitly because // setCurrentIndex() emits currentChanged() signal // which calls load_rights_model() void SecurityTabEdit::load_current_sd(AdInterface &ad) { // Save previous selected trustee before reloading // trustee model. This is for the case where we // need to restore selection later. const QByteArray previous_selected_trustee = [&]() { const QList<QModelIndex> selected_list = ui->trustee_view->selectionModel()->selectedRows(); if (!selected_list.isEmpty()) { const QModelIndex selected = selected_list[0]; const QByteArray out = selected.data(TrusteeItemRole_Sid).toByteArray(); return out; } else { return QByteArray(); } }(); // Load trustee model trustee_model->removeRows(0, trustee_model->rowCount()); const QList<QByteArray> trustee_list = security_descriptor_get_trustee_list(sd); add_trustees(trustee_list, ad); // Select a trustee // // Note that trustee view must always have a // selection so that rights view displays // something. We also restore const QModelIndex selected_trustee = [&]() { const QModelIndex first_index = trustee_model->index(0, 0); // Restore previously selected trustee const QList<QModelIndex> match_list = trustee_model->match(first_index, TrusteeItemRole_Sid, previous_selected_trustee, -1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive)); if (!match_list.isEmpty()) { return match_list[0]; } else { return first_index; } }(); ui->trustee_view->selectionModel()->setCurrentIndex(selected_trustee, QItemSelectionModel::Current | QItemSelectionModel::ClearAndSelect); } void SecurityTabEdit::load(AdInterface &ad, const AdObject &object) { security_descriptor_free(sd); sd = object.get_security_descriptor(); target_class_list = object.get_strings(ATTRIBUTE_OBJECT_CLASS); // Create items in rights model. These will not // change until target object changes. Only the // state of items changes during editing. const QList<SecurityRight> right_list = ad_security_get_right_list_for_class(g_adconfig, target_class_list); rights_model->removeRows(0, rights_model->rowCount()); const QLocale::Language language = []() { const QLocale saved_locale = settings_get_variant(SETTING_locale).toLocale(); const QLocale::Language out = saved_locale.language(); return out; }(); for (const SecurityRight &right : right_list) { const QList<QStandardItem *> row = make_item_row(AceColumn_COUNT); // TODO: for russian, probably do "read/write // property - [property name]" to avoid having // to do suffixes properties const QString right_name = ad_security_get_right_name(g_adconfig, right.access_mask, right.object_type, language); const QString object_type_name = g_adconfig->get_right_name(right.object_type, language); row[AceColumn_Name]->setText(right_name); row[AceColumn_Allowed]->setCheckable(true); row[AceColumn_Denied]->setCheckable(true); row[0]->setData(right.access_mask, RightsItemRole_AccessMask); row[0]->setData(right.object_type, RightsItemRole_ObjectType); row[0]->setData(object_type_name, RightsItemRole_ObjectTypeName); rights_model->appendRow(row); } // NOTE: because rights model is dynamically filled // when trustee switches, we have to make rights // model read only again after it's reloaded if (read_only) { make_rights_model_read_only(); } rights_sort_model->sort(0); load_current_sd(ad); is_policy = object.is_class(CLASS_GP_CONTAINER); } // Load rights model based on current sd and current // trustee void SecurityTabEdit::load_rights_model() { const QModelIndex current_index = ui->trustee_view->currentIndex(); if (!current_index.isValid()) { return; } // NOTE: this flag is turned on so that // on_item_changed() slot doesn't react to us // changing state of items ignore_item_changed_signal = true; const QByteArray trustee = get_current_trustee(); for (int row = 0; row < rights_model->rowCount(); row++) { const SecurityRightState state = [&]() { QStandardItem *item = rights_model->item(row, 0); const uint32_t access_mask = item->data(RightsItemRole_AccessMask).toUInt(); const QByteArray object_type = item->data(RightsItemRole_ObjectType).toByteArray(); const SecurityRightState out = security_descriptor_get_right(sd, trustee, access_mask, object_type); return out; }(); const QHash<SecurityRightStateType, QStandardItem *> item_map = { {SecurityRightStateType_Allow, rights_model->item(row, AceColumn_Allowed)}, {SecurityRightStateType_Deny, rights_model->item(row, AceColumn_Denied)}, }; for (int type_i = 0; type_i < SecurityRightStateType_COUNT; type_i++) { const SecurityRightStateType type = (SecurityRightStateType) type_i; QStandardItem *item = item_map[type]; const bool object_state = state.get(SecurityRightStateInherited_No, type); const bool inherited_state = state.get(SecurityRightStateInherited_Yes, type); // Checkboxes become disabled if they // contain only inherited state. Note that // if there's both inherited and object // state for same right, checkbox is // enabled so that user can remove object // state. const bool disabled = (inherited_state && !object_state); item->setEnabled(!disabled); const Qt::CheckState check_state = [&]() { if (object_state || inherited_state) { return Qt::Checked; } else { return Qt::Unchecked; } }(); item->setCheckState(check_state); } } // NOTE: need to make read only again because // during load, items are enabled/disabled based on // their inheritance state if (read_only) { make_rights_model_read_only(); } ignore_item_changed_signal = false; } void SecurityTabEdit::make_rights_model_read_only() { // NOTE: important to ignore this signal because // it's slot reloads the rights model ignore_item_changed_signal = true; for (int row = 0; row < rights_model->rowCount(); row++) { const QList<int> col_list = { AceColumn_Allowed, AceColumn_Denied, }; for (const int col : col_list) { QStandardItem *item = rights_model->item(row, col); item->setEnabled(false); } } ignore_item_changed_signal = false; } void SecurityTabEdit::on_item_changed(QStandardItem *item) { // NOTE: in some cases we need to ignore this signal if (ignore_item_changed_signal) { return; } const AceColumn column = (AceColumn) item->column(); const bool incorrect_column = (column != AceColumn_Allowed && column != AceColumn_Denied); if (incorrect_column) { return; } QStandardItem *main_item = rights_model->item(item->row(), 0); const bool checked = (item->checkState() == Qt::Checked); const QByteArray trustee = get_current_trustee(); const uint32_t access_mask = main_item->data(RightsItemRole_AccessMask).toUInt(); const QByteArray object_type = main_item->data(RightsItemRole_ObjectType).toByteArray(); const bool allow = (column == AceColumn_Allowed); if (checked) { security_descriptor_add_right(sd, g_adconfig, target_class_list, trustee, access_mask, object_type, allow); } else { security_descriptor_remove_right(sd, g_adconfig, target_class_list, trustee, access_mask, object_type, allow); } load_rights_model(); emit edited(); } bool SecurityTabEdit::verify(AdInterface &ad, const QString &target) const { UNUSED_ARG(target); if (is_policy) { // To apply security tab for policies we need user // to have admin rights to be able to sync perms of // GPT const bool have_sufficient_rights = ad.logged_in_as_domain_admin(); return have_sufficient_rights; } else { return true; } } bool SecurityTabEdit::apply(AdInterface &ad, const QString &target) const { bool total_success = true; total_success = (total_success && ad_security_replace_security_descriptor(ad, target, sd)); if (is_policy) { total_success = (total_success && ad.gpo_sync_perms(target)); } return total_success; } void SecurityTabEdit::on_add_trustee_button() { auto dialog = new SelectObjectDialog({CLASS_USER, CLASS_GROUP}, SelectObjectDialogMultiSelection_Yes, ui->trustee_view); dialog->setWindowTitle(tr("Add Trustee")); dialog->open(); connect( dialog, &SelectObjectDialog::accepted, this, [this, dialog]() { AdInterface ad; if (ad_failed(ad, ui->trustee_view)) { return; } // Get sid's of selected objects const QList<QByteArray> sid_list = [&, dialog]() { QList<QByteArray> out; const QList<QString> selected_list = dialog->get_selected(); for (const QString &dn : selected_list) { const AdObject object = ad.search_object(dn, {ATTRIBUTE_OBJECT_SID}); const QByteArray sid = object.get_value(ATTRIBUTE_OBJECT_SID); out.append(sid); } return out; }(); add_trustees(sid_list, ad); }); } void SecurityTabEdit::on_remove_trustee_button() { AdInterface ad; if (ad_failed(ad, ui->remove_trustee_button)) { return; } const QList<QByteArray> removed_trustee_list = [&]() { QList<QByteArray> out; QItemSelectionModel *selection_model = ui->trustee_view->selectionModel(); const QList<QPersistentModelIndex> selected_list = persistent_index_list(selection_model->selectedRows()); for (const QPersistentModelIndex &index : selected_list) { const QByteArray sid = index.data(TrusteeItemRole_Sid).toByteArray(); out.append(sid); } return out; }(); // Remove from sd security_descriptor_remove_trustee(sd, removed_trustee_list); // Reload sd // // NOTE: we do this instead of removing selected // indexes because not all trustee's are guaranteed // to have been removed load_current_sd(ad); const bool removed_any = !removed_trustee_list.isEmpty(); if (removed_any) { emit edited(); } } void SecurityTabEdit::add_trustees(const QList<QByteArray> &sid_list, AdInterface &ad) { const QList<QString> current_sid_string_list = [&]() { QList<QString> out; for (int row = 0; row < trustee_model->rowCount(); row++) { QStandardItem *item = trustee_model->item(row, 0); const QByteArray sid = item->data(TrusteeItemRole_Sid).toByteArray(); const QString sid_string = object_sid_display_value(sid); out.append(sid_string); } return out; }(); bool added_anything = false; bool failed_to_add_because_already_exists = false; for (const QByteArray &sid : sid_list) { const QString sid_string = object_sid_display_value(sid); const bool trustee_already_in_list = (current_sid_string_list.contains(sid_string)); if (trustee_already_in_list) { failed_to_add_because_already_exists = true; continue; } auto item = new QStandardItem(); const QString name = ad_security_get_trustee_name(ad, sid); item->setText(name); item->setData(sid, TrusteeItemRole_Sid); trustee_model->appendRow(item); added_anything = true; } ui->trustee_view->sortByColumn(0, Qt::AscendingOrder); if (added_anything) { emit edited(); } if (failed_to_add_because_already_exists) { message_box_warning(ui->trustee_view, tr("Error"), tr("Failed to add some trustee's because they are already in the list.")); } } void SecurityTabEdit::on_add_well_known_trustee() { auto dialog = new SelectWellKnownTrusteeDialog(ui->trustee_view); dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { AdInterface ad; if (ad_failed(ad, ui->trustee_view)) { return; } const QList<QByteArray> trustee_list = dialog->get_selected(); add_trustees(trustee_list, ad); }); } QByteArray SecurityTabEdit::get_current_trustee() const { const QModelIndex current_index = ui->trustee_view->currentIndex(); QStandardItem *current_item = trustee_model->itemFromIndex(current_index); const QByteArray out = current_item->data(TrusteeItemRole_Sid).toByteArray(); return out; }
20,370
C++
.cpp
479
35.484342
187
0.663984
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,671
general_group_tab.cpp
altlinux_admc/src/admc/tabs/general_group_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_group_tab.h" #include "tabs/ui_general_group_tab.h" #include "adldap.h" #include "attribute_edits/general_name_edit.h" #include "attribute_edits/group_scope_edit.h" #include "attribute_edits/group_type_edit.h" #include "attribute_edits/sam_name_edit.h" #include "attribute_edits/string_edit.h" GeneralGroupTab::GeneralGroupTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralGroupTab(); ui->setupUi(this); edit_list->append(create_edits()); } GeneralGroupTab::GeneralGroupTab(QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralGroupTab(); ui->setupUi(this); m_edit_list.append(create_edits()); ui->name_label->setVisible(false); ui->description_edit->setReadOnly(true); ui->email_edit->setReadOnly(true); ui->notes_edit->setReadOnly(true); ui->sam_name_edit->setReadOnly(true); ui->scope_combo->setEditable(false); ui->type_combo->setEditable(false); } GeneralGroupTab::~GeneralGroupTab() { delete ui; } void GeneralGroupTab::update(AdInterface &ad, const AdObject &object) { AttributeEdit::load(m_edit_list, ad, object); } QList<AttributeEdit *> GeneralGroupTab::create_edits() { auto name_edit = new GeneralNameEdit(ui->name_label, this); auto sam_name_edit = new SamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); auto email_edit = new StringEdit(ui->email_edit, ATTRIBUTE_MAIL, this); auto notes_edit = new StringEdit(ui->notes_edit, ATTRIBUTE_INFO, this); auto scope_edit = new GroupScopeEdit(ui->scope_combo, this); auto type_edit = new GroupTypeEdit(ui->type_combo, this); QList<AttributeEdit *> edits_out = { name_edit, sam_name_edit, description_edit, email_edit, notes_edit, scope_edit, type_edit, }; return edits_out; }
2,754
C++
.cpp
71
35.112676
94
0.72216
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,672
object_tab.cpp
altlinux_admc/src/admc/tabs/object_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/object_tab.h" #include "tabs/ui_object_tab.h" #include "adldap.h" #include "attribute_edits/datetime_edit.h" #include "attribute_edits/dn_edit.h" #include "attribute_edits/gpoptions_edit.h" #include "attribute_edits/protect_deletion_edit.h" #include "attribute_edits/string_edit.h" #include <QFormLayout> ObjectTab::ObjectTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::ObjectTab(); ui->setupUi(this); auto dn_edit = new DNEdit(ui->dn_edit, this); auto class_edit = new StringEdit(ui->class_edit, ATTRIBUTE_OBJECT_CLASS, this); auto when_created_edit = new DateTimeEdit(ui->created_edit, ATTRIBUTE_WHEN_CREATED, this); auto when_changed_edit = new DateTimeEdit(ui->changed_edit, ATTRIBUTE_WHEN_CHANGED, this); auto usn_created_edit = new StringEdit(ui->usn_created_edit, ATTRIBUTE_USN_CREATED, this); auto usn_changed_edit = new StringEdit(ui->usn_changed_edit, ATTRIBUTE_USN_CHANGED, this); auto deletion_edit = new ProtectDeletionEdit(ui->deletion_check, this); edit_list->append({ dn_edit, class_edit, when_created_edit, when_changed_edit, usn_created_edit, usn_changed_edit, deletion_edit, }); } ObjectTab::~ObjectTab() { delete ui; }
2,083
C++
.cpp
52
36.519231
94
0.727363
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,673
general_ou_tab.cpp
altlinux_admc/src/admc/tabs/general_ou_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_ou_tab.h" #include "tabs/ui_general_ou_tab.h" #include "adldap.h" #include "attribute_edits/country_edit.h" #include "attribute_edits/general_name_edit.h" #include "attribute_edits/string_edit.h" GeneralOUTab::GeneralOUTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralOUTab(); ui->setupUi(this); auto name_edit = new GeneralNameEdit(ui->name_label, this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); auto street_edit = new StringEdit(ui->street_edit, ATTRIBUTE_STREET_OU, this); auto city_edit = new StringEdit(ui->city_edit, ATTRIBUTE_CITY, this); auto state_edit = new StringEdit(ui->state_edit, ATTRIBUTE_STATE, this); auto postal_code_edit = new StringEdit(ui->postal_code_edit, ATTRIBUTE_POSTAL_CODE, this); auto country_edit = new CountryEdit(ui->country_combo, this); edit_list->append({ name_edit, description_edit, street_edit, city_edit, state_edit, postal_code_edit, country_edit, }); } GeneralOUTab::~GeneralOUTab() { delete ui; }
1,945
C++
.cpp
49
36.061224
94
0.723134
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,674
attributes_tab.cpp
altlinux_admc/src/admc/tabs/attributes_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/attributes_tab.h" #include "tabs/ui_attributes_tab.h" #include "adldap.h" #include "attribute_dialogs/attribute_dialog.h" #include "globals.h" #include "settings.h" #include "tabs/attributes_tab_filter_menu.h" #include "tabs/attributes_tab_proxy.h" #include "utils.h" #include <QAction> #include <QDebug> #include <QHeaderView> #include <QMenu> #include <QStandardItemModel> QString attribute_type_display_string(const AttributeType type); AttributesTab::AttributesTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::AttributesTab(); ui->setupUi(this); auto tab_edit = new AttributesTabEdit(ui->view, ui->filter_button, ui->edit_button, ui->view_button, ui->load_optional_attrs_button, this); ui->view->setUniformRowHeights(true); edit_list->append({ tab_edit, }); } AttributesTabEdit::AttributesTabEdit(QTreeView *view_arg, QPushButton *filter_button_arg, QPushButton *edit_button_arg, QPushButton *view_button_arg, QPushButton *load_optional_attrs_button_arg, QObject *parent) : AttributeEdit(parent) { view = view_arg; filter_button = filter_button_arg; edit_button = edit_button_arg; view_button = view_button_arg; load_optional_attrs_button = load_optional_attrs_button_arg; model = new QStandardItemModel(0, AttributesColumn_COUNT, this); set_horizontal_header_labels_from_map(model, { {AttributesColumn_Name, tr("Name")}, {AttributesColumn_Value, tr("Value")}, {AttributesColumn_Type, tr("Type")}, }); auto filter_menu = new AttributesTabFilterMenu(view); proxy = new AttributesTabProxy(filter_menu, this); proxy->setSourceModel(model); view->setModel(proxy); filter_button->setMenu(filter_menu); enable_widget_on_selection(edit_button, view); settings_restore_header_state(SETTING_attributes_tab_header_state, view->header()); const QHash<QString, QVariant> state = settings_get_variant(SETTING_attributes_tab_header_state).toHash(); // This is the default sort, overriden by saved // sort when state is restored view->sortByColumn(AttributesColumn_Name, Qt::AscendingOrder); view->header()->restoreState(state["header"].toByteArray()); QItemSelectionModel *selection_model = view->selectionModel(); bool load_optional_is_set = settings_get_variant(SETTING_load_optional_attribute_values).toBool(); load_optional_attrs_button->setVisible(!load_optional_is_set); connect( selection_model, &QItemSelectionModel::selectionChanged, this, &AttributesTabEdit::update_edit_and_view_buttons); update_edit_and_view_buttons(); connect( view, &QAbstractItemView::doubleClicked, this, &AttributesTabEdit::on_double_click); connect( edit_button, &QAbstractButton::clicked, this, &AttributesTabEdit::edit_attribute); connect( view_button, &QAbstractButton::clicked, this, &AttributesTabEdit::view_attribute); connect( filter_menu, &AttributesTabFilterMenu::filter_changed, proxy, &AttributesTabProxy::invalidate); connect( load_optional_attrs_button, &QAbstractButton::clicked, this, &AttributesTabEdit::on_load_optional); } AttributesTab::~AttributesTab() { settings_set_variant(SETTING_attributes_tab_header_state, ui->view->header()->saveState()); delete ui; } QList<QStandardItem *> AttributesTabEdit::get_selected_row() const { const QItemSelectionModel *selection_model = view->selectionModel(); const QList<QModelIndex> selecteds = selection_model->selectedRows(); if (selecteds.isEmpty()) { return QList<QStandardItem *>(); } const QModelIndex proxy_index = selecteds[0]; const QModelIndex index = proxy->mapToSource(proxy_index); const QList<QStandardItem *> row = [this, index]() { QList<QStandardItem *> out; for (int col = 0; col < AttributesColumn_COUNT; col++) { const QModelIndex item_index = index.siblingAtColumn(col); QStandardItem *item = model->itemFromIndex(item_index); out.append(item); } return out; }(); return row; } void AttributesTabEdit::update_edit_and_view_buttons() { const QList<QStandardItem *> selected_row = get_selected_row(); const bool no_selection = selected_row.isEmpty(); if (no_selection) { edit_button->setVisible(true); edit_button->setEnabled(false); view_button->setVisible(false); view_button->setEnabled(false); } else { const QString attribute = selected_row[AttributesColumn_Name]->text(); const bool read_only = g_adconfig->get_attribute_is_system_only(attribute); if (read_only) { edit_button->setVisible(false); edit_button->setEnabled(false); view_button->setVisible(true); view_button->setEnabled(true); } else { edit_button->setVisible(true); edit_button->setEnabled(true); view_button->setVisible(false); view_button->setEnabled(false); } } } void AttributesTabEdit::on_double_click() { const QList<QStandardItem *> selected_row = get_selected_row(); const QString attribute = selected_row[AttributesColumn_Name]->text(); const bool read_only = g_adconfig->get_attribute_is_system_only(attribute); if (read_only) { view_attribute(); } else { edit_attribute(); } } void AttributesTabEdit::view_attribute() { const bool read_only = true; AttributeDialog *dialog = get_attribute_dialog(read_only); if (dialog == nullptr) { return; } dialog->open(); } void AttributesTabEdit::on_load_optional() { show_busy_indicator(); AdInterface ad; if (!ad.is_connected()) { hide_busy_indicator(); return; } load_optional_attribute_values(ad); current = original; reload_model(); hide_busy_indicator(); } void AttributesTabEdit::load_optional_attribute_values(AdInterface &ad) { // Chunks number is minimal query number (manually tested) to load objects // without errors. This value can be corrected after. const int attr_list_chunks_number = 5; int chunk_length = not_specified_optional_attributes.size()/attr_list_chunks_number; QSet<QString> optional_set_attrs; for (int from = 0; from < not_specified_optional_attributes.size(); from += chunk_length) { if (not_specified_optional_attributes.size() - from < chunk_length) { chunk_length = not_specified_optional_attributes.size() - from; } const QList<QString> attr_list_chunk = not_specified_optional_attributes.mid(from, chunk_length); const AdObject optional_attrs_object = ad.search_object(object_dn, attr_list_chunk); for (const QString &attribute : attr_list_chunk) { QList<QByteArray> values = optional_attrs_object.get_values(attribute); original[attribute] = values; if (!values.isEmpty()) { optional_set_attrs << attribute; } } } proxy->update_set_attributes(optional_set_attrs); } void AttributesTabEdit::edit_attribute() { const bool read_only = false; AttributeDialog *dialog = get_attribute_dialog(read_only); if (dialog == nullptr) { return; } dialog->open(); connect( dialog, &QDialog::accepted, this, [this, dialog]() { const QList<QStandardItem *> row = get_selected_row(); if (row.isEmpty()) { return; } const QList<QByteArray> new_value_list = dialog->get_value_list(); const QString attribute = dialog->get_attribute(); current[attribute] = new_value_list; load_row(row, attribute, new_value_list); // TODO: fix emit edited(); }); } void AttributesTabEdit::load(AdInterface &ad, const AdObject &object) { UNUSED_ARG(ad); original.clear(); object_dn = object.get_dn(); for (auto attribute : object.attributes()) { original[attribute] = object.get_values(attribute); } const QList<QString> object_classes = object.get_strings(ATTRIBUTE_OBJECT_CLASS); const QList<QString> optional_attributes = g_adconfig->get_optional_attributes(object_classes); for (const QString &attribute : optional_attributes) { if (!original.contains(attribute)) { not_specified_optional_attributes << attribute; } } proxy->load(object); bool load_optional = settings_get_variant(SETTING_load_optional_attribute_values).toBool(); if (load_optional) { load_optional_attribute_values(ad); } else { for (const QString &attribute : not_specified_optional_attributes) { if (!original.contains(attribute)) { original[attribute] = QList<QByteArray>(); } } } reload_model(); current = original; } bool AttributesTabEdit::apply(AdInterface &ad, const QString &target) const { bool total_success = true; for (const QString &attribute : current.keys()) { const QList<QByteArray> current_values = current[attribute]; const QList<QByteArray> original_values = original[attribute]; if (current_values != original_values) { const bool success = ad.attribute_replace_values(target, attribute, current_values); if (!success) { total_success = false; } } } return total_success; } void AttributesTabEdit::load_row(const QList<QStandardItem *> &row, const QString &attribute, const QList<QByteArray> &values) { const QString display_values = attribute_display_values(attribute, values, g_adconfig); const AttributeType type = g_adconfig->get_attribute_type(attribute); const QString type_display = attribute_type_display_string(type); row[AttributesColumn_Name]->setText(attribute); row[AttributesColumn_Value]->setText(display_values); row[AttributesColumn_Type]->setText(type_display); } // Return an appropriate attribute dialog for currently // selected attribute row. AttributeDialog *AttributesTabEdit::get_attribute_dialog(const bool read_only) { const QList<QStandardItem *> row = get_selected_row(); if (row.isEmpty()) { return nullptr; } const QString attribute = row[AttributesColumn_Name]->text(); const QList<QByteArray> value_list = current[attribute]; const bool single_valued = g_adconfig->get_attribute_is_single_valued(attribute); AttributeDialog *dialog = AttributeDialog::make(attribute, value_list, read_only, single_valued, view); return dialog; } void AttributesTabEdit::reload_model() { model->removeRows(0, model->rowCount()); for (auto attribute : original.keys()) { const QList<QStandardItem *> row = make_item_row(AttributesColumn_COUNT); const QList<QByteArray> values = original[attribute]; model->appendRow(row); load_row(row, attribute, values); } }
12,066
C++
.cpp
289
35.16955
154
0.678745
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,675
select_well_known_trustee_dialog.cpp
altlinux_admc/src/admc/tabs/select_well_known_trustee_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "select_well_known_trustee_dialog.h" #include "ui_select_well_known_trustee_dialog.h" #include "ad_security.h" #include "ad_utils.h" #include "settings.h" #include "utils.h" #include <QPushButton> SelectWellKnownTrusteeDialog::SelectWellKnownTrusteeDialog(QWidget *parent) : QDialog(parent) { ui = new Ui::SelectWellKnownTrusteeDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); for (const QString &sid_string : well_known_sid_list) { auto item = new QListWidgetItem(); const QByteArray sid_bytes = sid_string_to_bytes(sid_string); item->setData(Qt::UserRole, sid_bytes); const QString name = ad_security_get_well_known_trustee_name(sid_bytes); item->setText(name); ui->list->addItem(item); } QPushButton *ok_button = ui->button_box->button(QDialogButtonBox::Ok); enable_widget_on_selection(ok_button, ui->list); settings_setup_dialog_geometry(SETTING_select_well_known_trustee_dialog_geometry, this); } SelectWellKnownTrusteeDialog::~SelectWellKnownTrusteeDialog() { delete ui; } QList<QByteArray> SelectWellKnownTrusteeDialog::get_selected() const { QList<QByteArray> out; const QList<QListWidgetItem *> selected = ui->list->selectedItems(); for (QListWidgetItem *item : selected) { const QByteArray sid = item->data(Qt::UserRole).toByteArray(); out.append(sid); } return out; }
2,213
C++
.cpp
55
36.454545
92
0.732618
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,676
general_user_tab.cpp
altlinux_admc/src/admc/tabs/general_user_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_user_tab.h" #include "tabs/ui_general_user_tab.h" #include "adldap.h" #include "attribute_edits/general_name_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/string_other_edit.h" GeneralUserTab::GeneralUserTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralUserTab(); ui->setupUi(this); edit_list->append(create_edits()); } GeneralUserTab::GeneralUserTab(QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralUserTab(); ui->setupUi(this); m_edit_list = create_edits(); ui->name_label->setVisible(false); ui->description_edit->setReadOnly(true); ui->first_name_edit->setReadOnly(true); ui->last_name_edit->setReadOnly(true); ui->display_name_edit->setReadOnly(true); ui->initials_edit->setReadOnly(true); ui->email_edit->setReadOnly(true); ui->office_edit->setReadOnly(true); ui->web_page_edit->setReadOnly(true); ui->telephone_edit->setReadOnly(true); ui->web_page_button->setVisible(false); ui->telephone_button->setVisible(false); } void GeneralUserTab::update(AdInterface &ad, const AdObject &object) { AttributeEdit::load(m_edit_list, ad, object); } GeneralUserTab::~GeneralUserTab() { delete ui; } QList<AttributeEdit *> GeneralUserTab::create_edits() { auto name_edit = new GeneralNameEdit(ui->name_label, this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); auto first_name_edit = new StringEdit(ui->first_name_edit, ATTRIBUTE_FIRST_NAME, this); auto last_name_edit = new StringEdit(ui->last_name_edit, ATTRIBUTE_LAST_NAME, this); auto display_name_edit = new StringEdit(ui->display_name_edit, ATTRIBUTE_DISPLAY_NAME, this); auto initials_edit = new StringEdit(ui->initials_edit, ATTRIBUTE_INITIALS, this); auto mail_edit = new StringEdit(ui->email_edit, ATTRIBUTE_MAIL, this); auto office_edit = new StringEdit(ui->office_edit, ATTRIBUTE_OFFICE, this); auto telephone_edit = new StringOtherEdit(ui->telephone_edit, ui->telephone_button, ATTRIBUTE_TELEPHONE_NUMBER, ATTRIBUTE_TELEPHONE_NUMBER_OTHER, this); auto web_page_edit = new StringOtherEdit(ui->web_page_edit, ui->web_page_button, ATTRIBUTE_WWW_HOMEPAGE, ATTRIBUTE_WWW_HOMEPAGE_OTHER, this); QList<AttributeEdit *> edits_out = { name_edit, description_edit, first_name_edit, last_name_edit, display_name_edit, initials_edit, mail_edit, office_edit, telephone_edit, web_page_edit, }; return edits_out; }
3,408
C++
.cpp
80
38.5625
156
0.723379
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,677
attributes_tab_proxy.cpp
altlinux_admc/src/admc/tabs/attributes_tab_proxy.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/attributes_tab_proxy.h" #include "adldap.h" #include "attribute_dialogs/bool_attribute_dialog.h" #include "attribute_dialogs/datetime_attribute_dialog.h" #include "attribute_dialogs/list_attribute_dialog.h" #include "attribute_dialogs/octet_attribute_dialog.h" #include "attribute_dialogs/string_attribute_dialog.h" #include "globals.h" #include "settings.h" #include "tabs/attributes_tab.h" #include "tabs/attributes_tab_filter_menu.h" #include "utils.h" #include <QAction> #include <QDebug> #include <QHeaderView> #include <QMenu> #include <QStandardItemModel> QString attribute_type_display_string(const AttributeType type); AttributesTabProxy::AttributesTabProxy(AttributesTabFilterMenu *filter_menu_arg, QObject *parent) : QSortFilterProxyModel(parent) { filter_menu = filter_menu_arg; } void AttributesTabProxy::load(const AdObject &object) { const QList<QString> object_classes = object.get_strings(ATTRIBUTE_OBJECT_CLASS); const QList<QString> mandatory_attributes_list = g_adconfig->get_mandatory_attributes(object_classes); mandatory_attributes = QSet<QString>(mandatory_attributes_list.begin(), mandatory_attributes_list.end()); const QList<QString> optional_attributes_list = g_adconfig->get_optional_attributes(object_classes); optional_attributes = QSet<QString>(optional_attributes_list.begin(), optional_attributes_list.end()); const QList<QString> attributes_list = object.attributes(); set_attributes = QSet<QString>(attributes_list.begin(), attributes_list.end()); } void AttributesTabProxy::update_set_attributes(QSet<QString> attributes) { set_attributes += attributes; } bool AttributesTabProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { auto source = sourceModel(); const QString attribute = source->index(source_row, AttributesColumn_Name, source_parent).data().toString(); const bool system_only = g_adconfig->get_attribute_is_system_only(attribute); const bool unset = !set_attributes.contains(attribute); const bool mandatory = mandatory_attributes.contains(attribute); const bool optional = optional_attributes.contains(attribute); if (!filter_menu->filter_is_enabled(AttributeFilter_Unset) && unset) { return false; } if (!filter_menu->filter_is_enabled(AttributeFilter_Mandatory) && mandatory) { return false; } if (!filter_menu->filter_is_enabled(AttributeFilter_Optional) && optional) { return false; } if (filter_menu->filter_is_enabled(AttributeFilter_ReadOnly) && system_only) { const bool constructed = g_adconfig->get_attribute_is_constructed(attribute); const bool backlink = g_adconfig->get_attribute_is_backlink(attribute); if (!filter_menu->filter_is_enabled(AttributeFilter_SystemOnly) && !constructed && !backlink) { return false; } if (!filter_menu->filter_is_enabled(AttributeFilter_Constructed) && constructed) { return false; } if (!filter_menu->filter_is_enabled(AttributeFilter_Backlink) && backlink) { return false; } } if (!filter_menu->filter_is_enabled(AttributeFilter_ReadOnly) && system_only) { return false; } return true; }
4,060
C++
.cpp
87
42.505747
112
0.742662
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,678
managed_by_tab.cpp
altlinux_admc/src/admc/tabs/managed_by_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/managed_by_tab.h" #include "tabs/ui_managed_by_tab.h" #include "adldap.h" #include "attribute_edits/country_edit.h" #include "attribute_edits/group_scope_edit.h" #include "attribute_edits/group_type_edit.h" #include "attribute_edits/manager_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/string_other_edit.h" #include "utils.h" // NOTE: store manager's edits in separate list because they // don't apply to the target of properties. ManagedByTab::ManagedByTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::ManagedByTab(); ui->setupUi(this); auto tab_edit = new ManagedByTabEdit(ui, this); edit_list->append({ tab_edit, }); } ManagedByTabEdit::ManagedByTabEdit(Ui::ManagedByTab *ui_arg, QObject *parent) : AttributeEdit(parent) { ui = ui_arg; manager_edit = new ManagerEdit(ui->manager_widget, ATTRIBUTE_MANAGED_BY, this); auto office_edit = new StringEdit(ui->office_edit, ATTRIBUTE_OFFICE, this); auto street_edit = new StringEdit(ui->street_edit, ATTRIBUTE_STREET, this); auto city_edit = new StringEdit(ui->city_edit, ATTRIBUTE_CITY, this); auto state_edit = new StringEdit(ui->state_edit, ATTRIBUTE_STATE, this); auto country_edit = new CountryEdit(ui->country_combo, this); auto telephone_edit = new StringOtherEdit(ui->telephone_edit, ui->telephone_button, ATTRIBUTE_TELEPHONE_NUMBER, ATTRIBUTE_TELEPHONE_NUMBER_OTHER, this); auto fax_edit = new StringOtherEdit(ui->fax_edit, ui->fax_button, ATTRIBUTE_FAX_NUMBER, ATTRIBUTE_OTHER_FAX_NUMBER, this); manager_edits = { office_edit, street_edit, city_edit, state_edit, country_edit, telephone_edit, fax_edit, }; telephone_edit->set_read_only(true); fax_edit->set_read_only(true); connect( manager_edit, &ManagerEdit::edited, this, &ManagedByTabEdit::on_manager_edited); } ManagedByTab::~ManagedByTab() { delete ui; } void ManagedByTabEdit::on_manager_edited() { AdInterface ad; if (ad_failed(ad, ui->manager_widget)) { return; } load_manager_edits(ad); emit edited(); } void ManagedByTabEdit::load(AdInterface &ad, const AdObject &object) { manager_edit->load(ad, object); // NOTE: load AFTER loading manager! because manager // edits use current value of manager edit load_manager_edits(ad); } bool ManagedByTabEdit::apply(AdInterface &ad, const QString &dn) const { const bool success = manager_edit->apply(ad, dn); return success; } void ManagedByTabEdit::load_manager_edits(AdInterface &ad) { const QString manager = manager_edit->get_manager(); if (!manager.isEmpty()) { const AdObject manager_object = ad.search_object(manager); AttributeEdit::load(manager_edits, ad, manager_object); } else { AdObject empty_object; AttributeEdit::load(manager_edits, ad, empty_object); } }
3,774
C++
.cpp
97
34.793814
156
0.71585
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,679
membership_tab.cpp
altlinux_admc/src/admc/tabs/membership_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/membership_tab.h" #include "tabs/ui_membership_tab.h" #include "adldap.h" #include "globals.h" #include "properties_widgets/properties_dialog.h" #include "select_dialogs/select_object_dialog.h" #include "settings.h" #include "utils.h" #include <QDebug> #include <QStandardItemModel> // Store members in a set // Generate model from current members list // Add new members via select dialog // Remove through context menu or select+remove button enum MembersColumn { MembersColumn_Name, MembersColumn_Parent, MembersColumn_COUNT, }; enum MembersRole { MembersRole_DN = Qt::UserRole + 1, MembersRole_Primary = Qt::UserRole + 2, }; MembershipTab::MembershipTab(QList<AttributeEdit *> *edit_list, const MembershipTabType &type, QWidget *parent) : QWidget(parent) { ui = new Ui::MembershipTab(); ui->setupUi(this); auto tab_edit = new MembershipTabEdit(ui->view, ui->primary_button, ui->add_button, ui->remove_button, ui->properties_button, ui->primary_group_label, type, this); edit_list->append({ tab_edit, }); } MembershipTabEdit::MembershipTabEdit(QTreeView *view_arg, QPushButton *primary_button_arg, QPushButton *add_button_arg, QPushButton *remove_button_arg, QPushButton *properties_button_arg, QLabel *primary_group_label_arg, const MembershipTabType &type_arg, QObject *parent) : AttributeEdit(parent) { view = view_arg; primary_button = primary_button_arg; add_button = add_button_arg; remove_button = remove_button_arg; properties_button = properties_button_arg; primary_group_label = primary_group_label_arg; type = type_arg; model = new QStandardItemModel(0, MembersColumn_COUNT, this); set_horizontal_header_labels_from_map(model, { {MembersColumn_Name, tr("Name")}, {MembersColumn_Parent, tr("Folder")}, }); view->setModel(model); // Primary group widgets are visible only in Member of version if (type == MembershipTabType_Members) { primary_button->hide(); primary_group_label->hide(); } settings_restore_header_state(SETTING_membership_tab_header_state, view->header()); enable_widget_on_selection(remove_button, view); enable_widget_on_selection(properties_button, view); const QItemSelectionModel *selection_model = view->selectionModel(); connect( selection_model, &QItemSelectionModel::selectionChanged, this, &MembershipTabEdit::enable_primary_button_on_valid_selection); enable_primary_button_on_valid_selection(); connect( remove_button, &QAbstractButton::clicked, this, &MembershipTabEdit::on_remove_button); connect( add_button, &QAbstractButton::clicked, this, &MembershipTabEdit::on_add_button); connect( properties_button, &QAbstractButton::clicked, this, &MembershipTabEdit::on_properties_button); connect( primary_button, &QAbstractButton::clicked, this, &MembershipTabEdit::on_primary_button); PropertiesDialog::open_when_view_item_activated(view, MembersRole_DN); } MembershipTab::~MembershipTab() { settings_save_header_state(SETTING_membership_tab_header_state, ui->view->header()); delete ui; } void MembershipTabEdit::load(AdInterface &ad, const AdObject &object) { const QList<QString> values = object.get_strings(get_membership_attribute()); original_values = QSet<QString>(values.begin(), values.end()); current_values = original_values; // Add primary groups or primary members original_primary_values.clear(); switch (type) { case MembershipTabType_Members: { // Get users who have this group as primary group const QByteArray group_sid = object.get_value(ATTRIBUTE_OBJECT_SID); const QString group_rid = extract_rid_from_sid(group_sid, g_adconfig); const QString base = g_adconfig->domain_dn(); const SearchScope scope = SearchScope_All; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_PRIMARY_GROUP_ID, group_rid); const QList<QString> attributes = QList<QString>(); const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); for (const QString &user : results.keys()) { original_primary_values.insert(user); } break; } case MembershipTabType_MemberOf: { // Get primary group's dn // Need to first construct group sid from ATTRIBUTE_PRIMARY_GROUP_ID // and then search for object with that sid to get dn // Construct group sid from group rid + user sid // user sid = "S-foo-bar-baz-abc" // group rid = "xyz" // group sid = "S-foo-bar-baz-xyz" const QString group_rid = object.get_string(ATTRIBUTE_PRIMARY_GROUP_ID); const QByteArray user_sid = object.get_value(ATTRIBUTE_OBJECT_SID); const QString user_sid_string = attribute_display_value(ATTRIBUTE_OBJECT_SID, user_sid, g_adconfig); const int cut_index = user_sid_string.lastIndexOf("-") + 1; const QString group_sid = user_sid_string.left(cut_index) + group_rid; const QString base = g_adconfig->domain_dn(); const SearchScope scope = SearchScope_All; const QString filter = filter_CONDITION(Condition_Equals, ATTRIBUTE_OBJECT_SID, group_sid); const QList<QString> attributes = QList<QString>(); const QHash<QString, AdObject> results = ad.search(base, scope, filter, attributes); if (!results.isEmpty()) { const QString group_dn = results.values()[0].get_dn(); original_primary_values.insert(group_dn); } break; } } current_primary_values = original_primary_values; reload_model(); } bool MembershipTabEdit::apply(AdInterface &ad, const QString &target) const { bool total_success = true; // NOTE: logic is kinda duplicated but switching on behavior within iterations would be very confusing switch (type) { case MembershipTabType_Members: { const QString group = target; for (auto user : original_values) { const bool removed = !current_values.contains(user); if (removed) { const bool success = ad.group_remove_member(group, user); if (!success) { total_success = false; } } } for (auto user : current_values) { const bool added = !original_values.contains(user); if (added) { const bool success = ad.group_add_member(group, user); if (!success) { total_success = false; } } } break; } case MembershipTabType_MemberOf: { const QString user = target; // NOTE: must change primary group before // remove/add operations otherwise there will be // conflicts // Change primary group if (current_primary_values != original_primary_values) { const QString original_primary_group = original_primary_values.values()[0]; const QString group_dn = current_primary_values.values()[0]; const bool success = ad.user_set_primary_group(group_dn, target); if (!success) { total_success = false; } } // When setting primary groups, the server // performs some membership modifications on // it's end. Therefore, don't need to do // anything with groups that were or are primary. auto group_is_or_was_primary = [this](const QString &group) { return original_primary_values.contains(group) || current_primary_values.contains(group); }; // Remove user from groups that were removed for (auto group : original_values) { if (group_is_or_was_primary(group)) { continue; } const bool removed = !current_values.contains(group); if (removed) { const bool success = ad.group_remove_member(group, user); if (!success) { total_success = false; } } } // Add user to groups that were added for (auto group : current_values) { if (group_is_or_was_primary(group)) { continue; } const bool added = !original_values.contains(group); if (added) { const bool success = ad.group_add_member(group, user); if (!success) { total_success = false; } } } break; } } return total_success; } void MembershipTabEdit::on_add_button() { const QList<QString> classes = [this]() -> QList<QString> { switch (type) { case MembershipTabType_Members: return { CLASS_USER, CLASS_GROUP, CLASS_CONTACT, CLASS_COMPUTER, }; case MembershipTabType_MemberOf: return {CLASS_GROUP}; } return QList<QString>(); }(); auto dialog = new SelectObjectDialog(classes, SelectObjectDialogMultiSelection_Yes, view); const QString title = [&]() { switch (type) { case MembershipTabType_Members: return tr("Add Member"); case MembershipTabType_MemberOf: return tr("Add to Group"); } return QString(); }(); dialog->setWindowTitle(title); dialog->open(); connect( dialog, &SelectObjectDialog::accepted, this, [this, dialog]() { const QList<QString> selected = dialog->get_selected(); add_values(selected); }); } void MembershipTabEdit::on_remove_button() { const QItemSelectionModel *selection_model = view->selectionModel(); const QList<QModelIndex> selected = selection_model->selectedRows(); QList<QString> removed_values; for (auto index : selected) { const QString dn = index.data(MembersRole_DN).toString(); removed_values.append(dn); } const bool any_selected_are_primary = [this, removed_values]() { for (const QString &dn : removed_values) { if (current_primary_values.contains(dn)) { return true; } } return false; }(); if (any_selected_are_primary) { const QString error_text = [this]() { switch (type) { case MembershipTabType_Members: return tr("Can't remove because this group is a primary group to selected user."); case MembershipTabType_MemberOf: return tr("Can't remove because selected group is a primary group to this user."); } return QString(); }(); message_box_warning(view, tr("Error"), error_text); } else { remove_values(removed_values); } } void MembershipTabEdit::on_primary_button() { // Make selected group primary const QItemSelectionModel *selection_model = view->selectionModel(); const QList<QModelIndex> selecteds = selection_model->selectedRows(); const QModelIndex selected = selecteds[0]; const QString group_dn = selected.data(MembersRole_DN).toString(); // Old primary group becomes normal current_values.unite(current_primary_values); // New primary group stops being normal current_values.remove(group_dn); // and becomes primary current_primary_values = {group_dn}; reload_model(); emit edited(); } void MembershipTabEdit::on_properties_button() { AdInterface ad; if (ad_failed(ad, view)) { return; } const QModelIndex current = view->selectionModel()->currentIndex(); const QString dn = current.data(MembersRole_DN).toString(); PropertiesDialog::open_for_target(ad, dn); } void MembershipTabEdit::enable_primary_button_on_valid_selection() { if (primary_button == nullptr) { return; } const QItemSelectionModel *selection_model = view->selectionModel(); const QList<QModelIndex> selecteds = selection_model->selectedRows(); // Enable "set primary group" button if // 1) there's a selection // 2) the selected group is NOT primary already const QSet<QString> selected_dns = [selecteds]() { QSet<QString> out; for (const QModelIndex selected : selecteds) { const QString dn = selected.data(MembersRole_DN).toString(); out.insert(dn); } return out; }(); if (selected_dns.size() == 1) { const QString dn = selected_dns.values()[0]; const bool is_primary = current_primary_values.contains(dn); primary_button->setEnabled(!is_primary); } else { primary_button->setEnabled(false); } } void MembershipTabEdit::reload_model() { // Load primary group name into label if (type == MembershipTabType_MemberOf) { const QString primary_group_label_text = [this]() { QString out = tr("Primary group: "); if (!current_primary_values.isEmpty()) { const QString primary_group_dn = current_primary_values.values()[0]; const QString primary_group_name = dn_get_name(primary_group_dn); out += primary_group_name; } return out; }(); primary_group_label->setText(primary_group_label_text); } model->removeRows(0, model->rowCount()); const QSet<QString> all_values = current_values + current_primary_values; for (auto dn : all_values) { const QString name = dn_get_name(dn); const QString parent = dn_get_parent_canonical(dn); const QList<QStandardItem *> row = make_item_row(MembersColumn_COUNT); row[MembersColumn_Name]->setText(name); row[MembersColumn_Parent]->setText(parent); set_data_for_row(row, dn, MembersRole_DN); model->appendRow(row); } model->sort(MembersColumn_Name); } void MembershipTabEdit::add_values(QList<QString> values) { for (auto value : values) { current_values.insert(value); } reload_model(); emit edited(); } void MembershipTabEdit::remove_values(QList<QString> values) { for (auto value : values) { current_values.remove(value); } reload_model(); emit edited(); } QString MembershipTabEdit::get_membership_attribute() { switch (type) { case MembershipTabType_Members: return ATTRIBUTE_MEMBER; case MembershipTabType_MemberOf: return ATTRIBUTE_MEMBER_OF; } return ""; }
15,942
C++
.cpp
382
32.908377
272
0.628806
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,680
attributes_tab_filter_menu.cpp
altlinux_admc/src/admc/tabs/attributes_tab_filter_menu.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/attributes_tab_filter_menu.h" #include "adldap.h" #include "attribute_dialogs/bool_attribute_dialog.h" #include "attribute_dialogs/datetime_attribute_dialog.h" #include "attribute_dialogs/list_attribute_dialog.h" #include "attribute_dialogs/octet_attribute_dialog.h" #include "attribute_dialogs/string_attribute_dialog.h" #include "globals.h" #include "settings.h" #include "utils.h" #include <QAction> #include <QDebug> #include <QHeaderView> #include <QMenu> #include <QStandardItemModel> AttributesTabFilterMenu::AttributesTabFilterMenu(QWidget *parent) : QMenu(parent) { const QList<QVariant> state = settings_get_variant(SETTING_attributes_tab_filter_state).toList(); auto add_filter_action = [&](const QString text, const AttributeFilter filter) { QAction *action = addAction(text); action->setText(text); action->setObjectName(QString::number(filter)); action->setCheckable(true); const bool is_checked = [&]() { if (filter < state.size()) { return state[filter].toBool(); } else { return true; } }(); action->setChecked(is_checked); action_map.insert(filter, action); connect( action, &QAction::toggled, this, &AttributesTabFilterMenu::filter_changed); }; add_filter_action(tr("Unset"), AttributeFilter_Unset); add_filter_action(tr("Read-only"), AttributeFilter_ReadOnly); addSeparator(); add_filter_action(tr("Mandatory"), AttributeFilter_Mandatory); add_filter_action(tr("Optional"), AttributeFilter_Optional); addSeparator(); add_filter_action(tr("System-only"), AttributeFilter_SystemOnly); add_filter_action(tr("Constructed"), AttributeFilter_Constructed); add_filter_action(tr("Backlink"), AttributeFilter_Backlink); connect( action_map[AttributeFilter_ReadOnly], &QAction::toggled, this, &AttributesTabFilterMenu::on_read_only_changed); on_read_only_changed(); } AttributesTabFilterMenu::~AttributesTabFilterMenu() { const QList<QVariant> state = [&]() { QList<QVariant> out; for (int fitler_i = 0; fitler_i < AttributeFilter_COUNT; fitler_i++) { const AttributeFilter filter = (AttributeFilter) fitler_i; const QAction *action = action_map[filter]; const QVariant filter_state = QVariant(action->isChecked()); out.append(filter_state); } return out; }(); settings_set_variant(SETTING_attributes_tab_filter_state, state); } void AttributesTabFilterMenu::on_read_only_changed() { const bool read_only_is_enabled = action_map[AttributeFilter_ReadOnly]->isChecked(); const QList<AttributeFilter> read_only_sub_filters = { AttributeFilter_SystemOnly, AttributeFilter_Constructed, AttributeFilter_Backlink, }; for (const AttributeFilter &filter : read_only_sub_filters) { action_map[filter]->setEnabled(read_only_is_enabled); // Turning off read only turns off the sub read only // filters. Note that turning ON read only doesn't do // the opposite. if (!read_only_is_enabled) { action_map[filter]->setChecked(false); } } } bool AttributesTabFilterMenu::filter_is_enabled(const AttributeFilter filter) const { return action_map[filter]->isChecked(); }
4,211
C++
.cpp
102
35.598039
101
0.698409
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,681
address_tab.cpp
altlinux_admc/src/admc/tabs/address_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/address_tab.h" #include "tabs/ui_address_tab.h" #include "adldap.h" #include "attribute_edits/country_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/string_large_edit.h" AddressTab::AddressTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::AddressTab(); ui->setupUi(this); auto street_edit = new StringLargeEdit(ui->street_edit, ATTRIBUTE_STREET, this); auto po_box_edit = new StringEdit(ui->po_box_edit, ATTRIBUTE_PO_BOX, this); auto city_edit = new StringEdit(ui->city_edit, ATTRIBUTE_CITY, this); auto state_edit = new StringEdit(ui->state_edit, ATTRIBUTE_STATE, this); auto postal_code_edit = new StringEdit(ui->postal_code_edit, ATTRIBUTE_POSTAL_CODE, this); auto country_edit = new CountryEdit(ui->country_combo, this); edit_list->append({ street_edit, po_box_edit, city_edit, state_edit, street_edit, postal_code_edit, country_edit, }); } AddressTab::~AddressTab() { delete ui; }
1,850
C++
.cpp
48
34.916667
94
0.717949
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,682
general_shared_folder_tab.cpp
altlinux_admc/src/admc/tabs/general_shared_folder_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_shared_folder_tab.h" #include "tabs/ui_general_shared_folder_tab.h" #include "adldap.h" #include "attribute_edits/general_name_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/string_list_edit.h" GeneralSharedFolderTab::GeneralSharedFolderTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralSharedFolderTab(); ui->setupUi(this); auto name_edit = new GeneralNameEdit(ui->name_label, this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); auto keywords_edit = new StringListEdit(ui->keywords_button, ATTRIBUTE_KEYWORDS, this); edit_list->append({ name_edit, description_edit, keywords_edit, }); } GeneralSharedFolderTab::~GeneralSharedFolderTab() { delete ui; }
1,632
C++
.cpp
41
36.853659
98
0.747634
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,683
group_policy_tab.cpp
altlinux_admc/src/admc/tabs/group_policy_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/group_policy_tab.h" #include "tabs/ui_group_policy_tab.h" #include "adldap.h" #include "attribute_edits/gpoptions_edit.h" #include "globals.h" #include "select_dialogs/select_policy_dialog.h" #include "settings.h" #include "utils.h" #include "console_widget/console_widget.h" #include "results_widgets/policy_ou_results_widget/policy_ou_results_widget.h" #include "results_widgets/policy_ou_results_widget/inherited_policies_widget.h" #include "console_impls/item_type.h" #include "console_impls/policy_ou_impl.h" #include <QFormLayout> #include <QMenu> #include <QPushButton> #include <QStandardItemModel> #include <QCheckBox> GroupPolicyTab::GroupPolicyTab(QList<AttributeEdit *> *edit_list, ConsoleWidget *console_widget, const QString &ou_dn, QWidget *parent) : QWidget(parent), console(console_widget) { ui = new Ui::GroupPolicyTab(); ui->setupUi(this); inheritance_widget = new InheritedPoliciesWidget(console, this); gpo_options_check = new QCheckBox(tr("Block policy inheritance"), this); auto options_edit = new GpoptionsEdit(gpo_options_check, this); ui->verticalLayout->addWidget(inheritance_widget); ui->verticalLayout->addWidget(gpo_options_check); edit_list->append({options_edit}); target_ou_index = search_gpo_ou_index(console, ou_dn); if (console && target_ou_index.isValid()) { inheritance_widget->update(target_ou_index); connect(gpo_options_check, &QCheckBox::toggled, [this](bool toggled) { inheritance_widget->hide_not_enforced_inherited_links(toggled); }); connect(options_edit, &GpoptionsEdit::gp_options_changed, [this](bool inheritance_blocked) { console->get_item(target_ou_index)->setData(inheritance_blocked, PolicyOURole_Inheritance_Block); inheritance_widget->update(target_ou_index); PolicyOUResultsWidget *result_ou_widget = dynamic_cast<PolicyOUResultsWidget*>(console->get_result_widget_for_index(target_ou_index)); if (result_ou_widget) result_ou_widget->update_inheritance_widget(target_ou_index); }); } } GroupPolicyTab::~GroupPolicyTab() { delete ui; }
2,923
C++
.cpp
64
41.5
146
0.734271
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,684
telephones_tab.cpp
altlinux_admc/src/admc/tabs/telephones_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/telephones_tab.h" #include "tabs/ui_telephones_tab.h" #include "adldap.h" #include "attribute_edits/string_large_edit.h" #include "attribute_edits/string_other_edit.h" TelephonesTab::TelephonesTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::TelephonesTab(); ui->setupUi(this); auto home_phone_edit = new StringOtherEdit(ui->home_phone_edit, ui->home_phone_button, ATTRIBUTE_HOME_PHONE, ATTRIBUTE_OTHER_HOME_PHONE, this); auto pager_edit = new StringOtherEdit(ui->pager_edit, ui->pager_button, ATTRIBUTE_PAGER, ATTRIBUTE_OTHER_PAGER, this); auto mobile_edit = new StringOtherEdit(ui->mobile_edit, ui->mobile_button, ATTRIBUTE_MOBILE, ATTRIBUTE_OTHER_MOBILE, this); auto fax_edit = new StringOtherEdit(ui->fax_edit, ui->fax_button, ATTRIBUTE_FAX_NUMBER, ATTRIBUTE_OTHER_FAX_NUMBER, this); auto ip_phone_edit = new StringOtherEdit(ui->ip_phone_edit, ui->ip_phone_button, ATTRIBUTE_IP_PHONE, ATTRIBUTE_OTHER_IP_PHONE, this); auto notes_edit = new StringLargeEdit(ui->notes_edit, ATTRIBUTE_INFO, this); edit_list->append({ home_phone_edit, pager_edit, mobile_edit, fax_edit, ip_phone_edit, notes_edit, }); } TelephonesTab::~TelephonesTab() { delete ui; }
2,079
C++
.cpp
46
41.652174
147
0.731984
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,685
organization_tab.cpp
altlinux_admc/src/admc/tabs/organization_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/organization_tab.h" #include "tabs/ui_organization_tab.h" #include "adldap.h" #include "attribute_edits/manager_edit.h" #include "attribute_edits/string_edit.h" #include "globals.h" #include "properties_widgets/properties_dialog.h" #include "settings.h" #include "utils.h" #include <QStandardItemModel> enum ReportsColumn { ReportsColumn_Name, ReportsColumn_Folder, ReportsColumn_COUNT, }; enum ReportsRole { ReportsRole_DN = Qt::UserRole + 1, }; OrganizationTab::OrganizationTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::OrganizationTab(); ui->setupUi(this); auto title_edit = new StringEdit(ui->job_title_edit, ATTRIBUTE_TITLE, this); auto department_edit = new StringEdit(ui->department_edit, ATTRIBUTE_DEPARTMENT, this); auto company_edit = new StringEdit(ui->company_edit, ATTRIBUTE_COMPANY, this); auto manager_edit = new ManagerEdit(ui->manager_widget, ATTRIBUTE_MANAGER, this); auto tab_edit = new OrganizationTabEdit(ui, this); edit_list->append({ title_edit, department_edit, company_edit, manager_edit, tab_edit, }); } OrganizationTabEdit::OrganizationTabEdit(Ui::OrganizationTab *ui_arg, QObject *parent) : AttributeEdit(parent) { ui = ui_arg; reports_model = new QStandardItemModel(0, ReportsColumn_COUNT, this); set_horizontal_header_labels_from_map(reports_model, { {ReportsColumn_Name, tr("Name")}, {ReportsColumn_Folder, tr("Folder")}, }); ui->reports_view->setModel(reports_model); PropertiesDialog::open_when_view_item_activated(ui->reports_view, ReportsRole_DN); settings_restore_header_state(SETTING_organization_tab_header_state, ui->reports_view->header()); } OrganizationTab::~OrganizationTab() { settings_save_header_state(SETTING_organization_tab_header_state, ui->reports_view->header()); delete ui; } void OrganizationTabEdit::load(AdInterface &ad, const AdObject &object) { UNUSED_ARG(ad); const QList<QString> reports = object.get_strings(ATTRIBUTE_DIRECT_REPORTS); reports_model->removeRows(0, reports_model->rowCount()); for (auto dn : reports) { const QString name = dn_get_name(dn); const QString parent = dn_get_parent_canonical(dn); const QList<QStandardItem *> row = make_item_row(ReportsColumn_COUNT); row[ReportsColumn_Name]->setText(name); row[ReportsColumn_Folder]->setText(parent); set_data_for_row(row, dn, ReportsRole_DN); reports_model->appendRow(row); } }
3,397
C++
.cpp
85
35.658824
101
0.721496
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,686
general_computer_tab.cpp
altlinux_admc/src/admc/tabs/general_computer_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "tabs/general_computer_tab.h" #include "tabs/ui_general_computer_tab.h" #include "adldap.h" #include "attribute_edits/computer_sam_name_edit.h" #include "attribute_edits/general_name_edit.h" #include "attribute_edits/string_edit.h" GeneralComputerTab::GeneralComputerTab(QList<AttributeEdit *> *edit_list, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralComputerTab(); ui->setupUi(this); auto name_edit = new GeneralNameEdit(ui->name_label, this); auto sam_name_edit = new ComputerSamNameEdit(ui->sam_name_edit, ui->sam_name_domain_edit, this); auto dns_edit = new StringEdit(ui->dns_host_name_edit, ATTRIBUTE_DNS_HOST_NAME, this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); auto location_edit = new StringEdit(ui->location_edit, ATTRIBUTE_LOCATION, this); sam_name_edit->set_enabled(false); dns_edit->set_enabled(false); edit_list->append({ name_edit, sam_name_edit, dns_edit, description_edit, location_edit, }); } GeneralComputerTab::~GeneralComputerTab() { delete ui; }
1,909
C++
.cpp
47
37.212766
100
0.733154
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,687
organization_multi_tab.cpp
altlinux_admc/src/admc/multi_tabs/organization_multi_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multi_tabs/organization_multi_tab.h" #include "multi_tabs/ui_organization_multi_tab.h" #include "ad_defines.h" #include "attribute_edits/manager_edit.h" #include "attribute_edits/string_edit.h" OrganizationMultiTab::OrganizationMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent) : QWidget(parent) { ui = new Ui::OrganizationMultiTab(); ui->setupUi(this); auto title_edit = new StringEdit(ui->title_edit, ATTRIBUTE_TITLE, this); auto department_edit = new StringEdit(ui->department_edit, ATTRIBUTE_DEPARTMENT, this); auto company_edit = new StringEdit(ui->company_edit, ATTRIBUTE_COMPANY, this); auto manager_edit = new ManagerEdit(ui->manager_edit, ATTRIBUTE_MANAGER, this); edit_list->append({ title_edit, department_edit, company_edit, manager_edit, }); check_map->insert(title_edit, ui->title_check); check_map->insert(department_edit, ui->department_check); check_map->insert(company_edit, ui->company_check); check_map->insert(manager_edit, ui->manager_check); } OrganizationMultiTab::~OrganizationMultiTab() { delete ui; }
1,962
C++
.cpp
46
39.282609
142
0.737035
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,688
account_multi_tab.cpp
altlinux_admc/src/admc/multi_tabs/account_multi_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multi_tabs/account_multi_tab.h" #include "multi_tabs/ui_account_multi_tab.h" #include "adldap.h" #include "attribute_edits/account_option_multi_edit.h" #include "attribute_edits/expiry_edit.h" #include "attribute_edits/string_edit.h" #include "attribute_edits/upn_multi_edit.h" #include <QHash> AccountMultiTab::AccountMultiTab(AdInterface &ad, QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent) : QWidget(parent) { ui = new Ui::AccountMultiTab(); ui->setupUi(this); auto upn_edit = new UpnMultiEdit(ui->upn_edit, ad, this); const QHash<AccountOption, QCheckBox *> option_to_check_map = { {AccountOption_Disabled, ui->option_disabled}, {AccountOption_PasswordExpired, ui->option_pass_expired}, {AccountOption_DontExpirePassword, ui->option_dont_expire_pass}, {AccountOption_UseDesKey, ui->option_use_des_key}, {AccountOption_SmartcardRequired, ui->option_smartcard}, {AccountOption_CantDelegate, ui->option_cant_delegate}, {AccountOption_DontRequirePreauth, ui->option_dont_require_kerb}, }; auto options_edit = new AccountOptionMultiEdit(option_to_check_map, this); auto expiry_edit = new ExpiryEdit(ui->expiry_edit, this); edit_list->append({ upn_edit, options_edit, expiry_edit, }); check_map->insert(upn_edit, ui->upn_check); check_map->insert(options_edit, ui->options_check); check_map->insert(expiry_edit, ui->expiry_check); } AccountMultiTab::~AccountMultiTab() { delete ui; }
2,358
C++
.cpp
55
39
149
0.727233
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,689
general_user_multi_tab.cpp
altlinux_admc/src/admc/multi_tabs/general_user_multi_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multi_tabs/general_user_multi_tab.h" #include "multi_tabs/ui_general_user_multi_tab.h" #include "ad_defines.h" #include "attribute_edits/string_edit.h" #include <QHash> GeneralUserMultiTab::GeneralUserMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralUserMultiTab(); ui->setupUi(this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); auto office_edit = new StringEdit(ui->office_edit, ATTRIBUTE_OFFICE, this); auto mobile_edit = new StringEdit(ui->mobile_edit, ATTRIBUTE_MOBILE, this); auto fax_edit = new StringEdit(ui->fax_edit, ATTRIBUTE_FAX_NUMBER, this); auto homepage_edit = new StringEdit(ui->web_edit, ATTRIBUTE_WWW_HOMEPAGE, this); auto mail_edit = new StringEdit(ui->email_edit, ATTRIBUTE_MAIL, this); edit_list->append({ description_edit, office_edit, mobile_edit, fax_edit, homepage_edit, mail_edit, }); check_map->insert(description_edit, ui->description_check); check_map->insert(office_edit, ui->office_check); check_map->insert(mobile_edit, ui->mobile_check); check_map->insert(fax_edit, ui->fax_check); check_map->insert(homepage_edit, ui->web_check); check_map->insert(mail_edit, ui->email_check); } GeneralUserMultiTab::~GeneralUserMultiTab() { delete ui; }
2,227
C++
.cpp
52
39.096154
140
0.724965
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,690
profile_multi_tab.cpp
altlinux_admc/src/admc/multi_tabs/profile_multi_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multi_tabs/profile_multi_tab.h" #include "ui_profile_multi_tab.h" #include "ad_defines.h" #include "attribute_edits/string_edit.h" #include <QHash> ProfileMultiTab::ProfileMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent) : QWidget(parent) { ui = new Ui::ProfileMultiTab(); ui->setupUi(this); auto profile_edit = new StringEdit(ui->profile_edit, ATTRIBUTE_PROFILE_PATH, this); auto script_edit = new StringEdit(ui->script_edit, ATTRIBUTE_SCRIPT_PATH, this); auto home_edit = new StringEdit(ui->home_edit, ATTRIBUTE_HOME_DIRECTORY, this); edit_list->append({ profile_edit, script_edit, home_edit, }); check_map->insert(profile_edit, ui->profile_check); check_map->insert(script_edit, ui->script_check); check_map->insert(home_edit, ui->home_check); } ProfileMultiTab::~ProfileMultiTab() { delete ui; }
1,720
C++
.cpp
43
36.813953
132
0.729179
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,691
general_other_multi_tab.cpp
altlinux_admc/src/admc/multi_tabs/general_other_multi_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multi_tabs/general_other_multi_tab.h" #include "multi_tabs/ui_general_other_multi_tab.h" #include "ad_defines.h" #include "attribute_edits/string_edit.h" #include <QHash> GeneralOtherMultiTab::GeneralOtherMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent) : QWidget(parent) { ui = new Ui::GeneralOtherMultiTab(); ui->setupUi(this); auto description_edit = new StringEdit(ui->description_edit, ATTRIBUTE_DESCRIPTION, this); edit_list->append({ description_edit, }); check_map->insert(description_edit, ui->description_check); }
1,408
C++
.cpp
34
38.735294
142
0.747623
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,692
address_multi_tab.cpp
altlinux_admc/src/admc/multi_tabs/address_multi_tab.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multi_tabs/address_multi_tab.h" #include "ui_address_multi_tab.h" #include "ad_defines.h" #include "attribute_edits/country_edit.h" #include "attribute_edits/string_edit.h" #include <QHash> AddressMultiTab::AddressMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent) : QWidget(parent) { ui = new Ui::AddressMultiTab(); ui->setupUi(this); auto po_edit = new StringEdit(ui->po_edit, ATTRIBUTE_PO_BOX, this); auto city_edit = new StringEdit(ui->city_edit, ATTRIBUTE_CITY, this); auto state_edit = new StringEdit(ui->state_edit, ATTRIBUTE_STATE, this); auto postal_edit = new StringEdit(ui->postal_edit, ATTRIBUTE_POSTAL_CODE, this); auto country_edit = new CountryEdit(ui->country_combo, this); edit_list->append({ po_edit, city_edit, state_edit, postal_edit, country_edit, }); check_map->insert(po_edit, ui->po_check); check_map->insert(city_edit, ui->city_check); check_map->insert(state_edit, ui->state_check); check_map->insert(postal_edit, ui->postal_check); check_map->insert(country_edit, ui->country_check); } AddressMultiTab::~AddressMultiTab() { delete ui; }
2,014
C++
.cpp
50
36.76
132
0.718814
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,693
unlock_edit.cpp
altlinux_admc/src/admc/attribute_edits/unlock_edit.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_edits/unlock_edit.h" #include "adldap.h" #include "utils.h" #include <QCheckBox> UnlockEdit::UnlockEdit(QCheckBox *check_arg, QObject *parent) : AttributeEdit(parent) { check = check_arg; connect( check, &QCheckBox::stateChanged, this, &AttributeEdit::edited); } QString UnlockEdit::label_text() { return tr("Unlock account"); } void UnlockEdit::load(AdInterface &ad, const AdObject &object) { UNUSED_ARG(ad); UNUSED_ARG(object); check->setChecked(false); } bool UnlockEdit::apply(AdInterface &ad, const QString &dn) const { if (check->isChecked()) { const bool result = ad.user_unlock(dn); check->setChecked(false); return result; } else { return true; } }
1,547
C++
.cpp
47
29.510638
72
0.716588
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,694
upn_multi_edit.cpp
altlinux_admc/src/admc/attribute_edits/upn_multi_edit.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_edits/upn_multi_edit.h" #include "adldap.h" #include "attribute_edits/upn_suffix_combo.h" #include "globals.h" #include <QComboBox> UpnMultiEdit::UpnMultiEdit(QComboBox *upn_suffix_combo_arg, AdInterface &ad, QObject *parent) : AttributeEdit(parent) { upn_suffix_combo = upn_suffix_combo_arg; upn_suffix_combo_init(upn_suffix_combo, ad); } bool UpnMultiEdit::apply(AdInterface &ad, const QString &target) const { const QString new_value = [&]() { const AdObject current_object = ad.search_object(target); const QString current_prefix = current_object.get_upn_prefix(); const QString new_suffix = upn_suffix_combo->currentText(); return QString("%1@%2").arg(current_prefix, new_suffix); }(); return ad.attribute_replace_string(target, ATTRIBUTE_USER_PRINCIPAL_NAME, new_value); } void UpnMultiEdit::set_enabled(const bool enabled) { upn_suffix_combo->setEnabled(enabled); }
1,731
C++
.cpp
41
39.219512
93
0.740785
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,695
logon_hours_dialog.cpp
altlinux_admc/src/admc/attribute_edits/logon_hours_dialog.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_edits/logon_hours_dialog.h" #include "attribute_edits/ui_logon_hours_dialog.h" #include "ad_utils.h" #include "settings.h" #include <QDateTime> #include <QStandardItemModel> #include <QTimeZone> QList<bool> shift_list(const QList<bool> &list, const int shift_amount); LogonHoursDialog::LogonHoursDialog(const QByteArray &value, QWidget *parent) : QDialog(parent) { ui = new Ui::LogonHoursDialog(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); model = new QStandardItemModel(DAYS_IN_WEEK, HOURS_IN_DAY, this); model->setVerticalHeaderLabels({ tr("Sunday"), tr("Monday"), tr("Tuesday"), tr("Wednesday"), tr("Thursday"), tr("Friday"), tr("Saturday"), }); const QList<QString> horizontalheader_labels = []() { QList<QString> out; for (int i = 0; i < HOURS_IN_DAY; i++) { const QString label = QString::number(i); out.append(label); } return out; }(); model->setHorizontalHeaderLabels(horizontalheader_labels); ui->view->setModel(model); ui->view->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); ui->view->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); for (int col = 0; col < model->columnCount(); col++) { ui->view->setColumnWidth(col, 5); } ui->local_time_button->setChecked(true); is_local_time = true; load(value); settings_setup_dialog_geometry(SETTING_logon_hours_dialog_geometry, this); const QString allowed_style_sheet = [&]() { const QPalette palette = ui->view->palette(); const QColor color = palette.highlight().color(); const QString out = QString("background-color: rgb(%1, %2, %3);").arg(QString::number(color.red()), QString::number(color.green()), QString::number(color.blue())); return out; }(); ui->legend_allowed->setStyleSheet(allowed_style_sheet); const QString denied_style_sheet = [&]() { const QPalette palette = ui->view->palette(); const QColor color = palette.base().color(); const QString out = QString("background-color: rgb(%1, %2, %3);").arg(QString::number(color.red()), QString::number(color.green()), QString::number(color.blue())); return out; }(); ui->legend_denied->setStyleSheet(denied_style_sheet); connect( ui->local_time_button, &QRadioButton::toggled, this, &LogonHoursDialog::on_local_time_button_toggled); } LogonHoursDialog::~LogonHoursDialog() { delete ui; } void LogonHoursDialog::load(const QByteArray &value) { ui->view->clearSelection(); original_value = value; const QList<QList<bool>> bools = logon_hours_to_bools(value, get_offset()); for (int day = 0; day < DAYS_IN_WEEK; day++) { for (int h = 0; h < HOURS_IN_DAY; h++) { const bool selected = bools[day][h]; if (selected) { const int row = day; const int column = h; const QModelIndex index = model->index(row, column); ui->view->selectionModel()->select(index, QItemSelectionModel::Select); } } } } QByteArray LogonHoursDialog::get() const { const QList<QList<bool>> bools = [&]() { QList<QList<bool>> out = logon_hours_to_bools(QByteArray(LOGON_HOURS_SIZE, '\0')); const QList<QModelIndex> selected = ui->view->selectionModel()->selectedIndexes(); for (const QModelIndex &index : selected) { const int day = index.row(); const int h = index.column(); out[day][h] = true; } return out; }(); const QList<QList<bool>> original_bools = logon_hours_to_bools(original_value); // NOTE: input has to always be equal to output. // Therefore, for the case where original value was // unset, we need this special logic so that input // doesn't change to a non-empty bytearray. if (bools == original_bools) { return original_value; } else { const QByteArray out = logon_hours_to_bytes(bools, get_offset()); return out; } } // Get current value, change time state and reload value void LogonHoursDialog::on_local_time_button_toggled(bool checked) { const QByteArray current_value = get(); // NOTE: important to change state after get() call so // current_value is in correct format is_local_time = checked; load(current_value); } int get_current_utc_offset() { const QDateTime current_datetime = QDateTime::currentDateTime(); const int offset_s = QTimeZone::systemTimeZone().offsetFromUtc(current_datetime); const int offset_h = offset_s / 60 / 60; return offset_h; } int LogonHoursDialog::get_offset() const { if (is_local_time) { return get_current_utc_offset(); } else { return 0; } } QList<QList<bool>> logon_hours_to_bools(const QByteArray &byte_list_arg, const int time_offset) { // NOTE: value may be empty or malformed. In that // case treat both as values that "allow all logon // times" (all bits set). This also handles the // case where value is unset and we need to treat // it as "allow all logon times". const QByteArray byte_list = [&]() { if (byte_list_arg.size() == LOGON_HOURS_SIZE) { return byte_list_arg; } else { return QByteArray(LOGON_HOURS_SIZE, (char) 0xFF); } }(); // Convet byte array to list of bools const QList<bool> joined = [&]() { QList<bool> out; for (const char byte : byte_list) { for (int bit_i = 0; bit_i < 8; bit_i++) { const int bit = (0x01 << bit_i); const bool is_set = bitmask_is_set((int) byte, bit); out.append(is_set); } } out = shift_list(out, time_offset); return out; }(); // Split the list into sublists for each day const QList<QList<bool>> out = [&]() { QList<QList<bool>> out_the; for (int i = 0; i < joined.size(); i += HOURS_IN_DAY) { const QList<bool> day_list = joined.mid(i, HOURS_IN_DAY); out_the.append(day_list); } return out_the; }(); return out; } QByteArray logon_hours_to_bytes(const QList<QList<bool>> bool_list, const int time_offset) { const QList<bool> joined = [&]() { QList<bool> out; for (const QList<bool> &sublist : bool_list) { out += sublist; } out = shift_list(out, -time_offset); return out; }(); const QByteArray out = [&]() { QByteArray bytes; for (int i = 0; i * 8 < joined.size(); i++) { const QList<bool> byte_list = joined.mid(i * 8, 8); int byte = 0; for (int bit_i = 0; bit_i < 8; bit_i++) { const int bit = (0x01 << bit_i); byte = bitmask_set(byte, bit, byte_list[bit_i]); } bytes.append(byte); } return bytes; }(); return out; } QList<bool> shift_list(const QList<bool> &list, const int shift_amount) { if (abs(shift_amount) > list.size()) { return list; } QList<bool> out; for (int i = 0; i < list.size(); i++) { const int shifted_i = [&]() { int out_i = i - shift_amount; if (out_i < 0) { out_i += list.size(); } else if (out_i >= list.size()) { out_i -= list.size(); } return out_i; }(); out.append(list[shifted_i]); } return out; }
8,474
C++
.cpp
222
31.117117
171
0.611043
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,696
group_scope_edit.cpp
altlinux_admc/src/admc/attribute_edits/group_scope_edit.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_edits/group_scope_edit.h" #include "adldap.h" #include "utils.h" #include <QComboBox> #include <QFormLayout> GroupScopeEdit::GroupScopeEdit(QComboBox *combo_arg, QObject *parent) : AttributeEdit(parent) { combo = combo_arg; for (int i = 0; i < GroupScope_COUNT; i++) { const GroupScope type = (GroupScope) i; const QString type_string = group_scope_string(type); combo->addItem(type_string, (int) type); } connect( combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AttributeEdit::edited); } void GroupScopeEdit::load(AdInterface &ad, const AdObject &object) { UNUSED_ARG(ad); const GroupScope scope = object.get_group_scope(); combo->setCurrentIndex((int) scope); const bool is_critical_system_object = object.get_bool(ATTRIBUTE_IS_CRITICAL_SYSTEM_OBJECT); if (is_critical_system_object) { combo->setDisabled(true); } } bool GroupScopeEdit::apply(AdInterface &ad, const QString &dn) const { const GroupScope new_value = (GroupScope) combo->currentData().toInt(); const bool success = ad.group_set_scope(dn, new_value); return success; }
1,962
C++
.cpp
50
35.6
96
0.723393
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,697
string_edit.cpp
altlinux_admc/src/admc/attribute_edits/string_edit.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_edits/string_edit.h" #include "adldap.h" #include "globals.h" #include "utils.h" #include <QLineEdit> StringEdit::StringEdit(QLineEdit *edit_arg, const QString &attribute_arg, QObject *parent) : AttributeEdit(parent) { attribute = attribute_arg; edit = edit_arg; if (g_adconfig->get_attribute_is_number(attribute)) { set_line_edit_to_decimal_numbers_only(edit); } limit_edit(edit, attribute); connect( edit, &QLineEdit::textChanged, this, &AttributeEdit::edited); } void StringEdit::load(AdInterface &ad, const AdObject &object) { UNUSED_ARG(ad); const QString value = object.get_string(attribute); edit->setText(value); } bool StringEdit::apply(AdInterface &ad, const QString &dn) const { const QString new_value = edit->text().trimmed(); const bool success = ad.attribute_replace_string(dn, attribute, new_value); return success; } void StringEdit::set_enabled(const bool enabled) { edit->setEnabled(enabled); }
1,796
C++
.cpp
49
33.489796
90
0.732565
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,698
computer_sam_name_edit.cpp
altlinux_admc/src/admc/attribute_edits/computer_sam_name_edit.cpp
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attribute_edits/computer_sam_name_edit.h" #include "adldap.h" #include "attribute_edits/sam_name_edit.h" #include "globals.h" #include "utils.h" #include <QLineEdit> #include <QRegularExpression> ComputerSamNameEdit::ComputerSamNameEdit(QLineEdit *edit_arg, QLineEdit *domain_edit, QObject *parent) : AttributeEdit(parent) { edit = edit_arg; edit->setMaxLength(SAM_NAME_COMPUTER_MAX_LENGTH); const QString domain_text = []() { const QString domain = g_adconfig->domain(); const QString domain_name = domain.split(".")[0]; const QString out = domain_name + "\\"; return out; }(); domain_edit->setText(domain_text); connect( edit, &QLineEdit::textChanged, this, &AttributeEdit::edited); } void ComputerSamNameEdit::load(AdInterface &ad, const AdObject &object) { UNUSED_ARG(ad); // NOTE: display value without the '$' at the end const QString value = [&]() { QString out = object.get_string(ATTRIBUTE_SAM_ACCOUNT_NAME); if (out.endsWith('$')) { out.chop(1); } return out; }(); edit->setText(value); } // NOTE: requirements are from here // https://social.technet.microsoft.com/wiki/contents/articles/11216.active-directory-requirements-for-creating-objects.aspx#Note_Regarding_the_quot_quot_Character_in_sAMAccountName bool ComputerSamNameEdit::verify(AdInterface &ad, const QString &dn) const { UNUSED_ARG(ad); UNUSED_ARG(dn); const bool out = sam_name_edit_verify(edit); return out; } bool ComputerSamNameEdit::apply(AdInterface &ad, const QString &dn) const { const QString name = edit->text().trimmed(); const QString new_value = QString("%1$").arg(name); const bool success = ad.attribute_replace_string(dn, ATTRIBUTE_SAM_ACCOUNT_NAME, new_value); return success; } void ComputerSamNameEdit::set_enabled(const bool enabled) { edit->setEnabled(enabled); }
2,733
C++
.cpp
70
35.057143
181
0.71407
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false