Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the displaying of optional attributes #432

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adldap/ad_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ AttributeType AdConfig::get_attribute_type(const QString &attribute) const {

const QString attribute_syntax = schema.get_string(ATTRIBUTE_ATTRIBUTE_SYNTAX);
const QString om_syntax = schema.get_string(ATTRIBUTE_OM_SYNTAX);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove that empty change please

if (type_map.contains(attribute_syntax) && type_map[attribute_syntax].contains(om_syntax)) {
return type_map[attribute_syntax][om_syntax];
} else {
Expand All @@ -576,6 +575,7 @@ LargeIntegerSubtype AdConfig::get_attribute_large_integer_subtype(const QString
ATTRIBUTE_LOCKOUT_TIME,
ATTRIBUTE_BAD_PWD_TIME,
ATTRIBUTE_CREATION_TIME,
ATTRIBUTE_MSDS_USER_PASSWORD_EXPIRY_TIME_COMPUTED,
};
static const QList<QString> timespans = {
ATTRIBUTE_MAX_PWD_AGE,
Expand Down
2 changes: 2 additions & 0 deletions src/adldap/ad_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ enum SystemFlagsBit {
#define ATTRIBUTE_OBJECT_VERSION "objectVersion"
#define ATTRIBUTE_SERVER_REFERENCE "serverReference"
#define ATTRIBUTE_SERVER_REFERENCE_BL "serverReferenceBL"
#define ATTRIBUTE_MSDS_USER_PASSWORD_EXPIRY_TIME_COMPUTED "msDS-UserPasswordExpiryTimeComputed"
#define ATTRIBUTE_MSDS_USER_ACCOUNT_CONTROL_COMPUTED "msDS-User-Account-Control-Computed"


#define CLASS_GROUP "group"
Expand Down
3 changes: 1 addition & 2 deletions src/adldap/ad_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ QString attribute_display_value(const QString &attribute, const QByteArray &valu
return samaccounttype_to_display_value(value);
} else if (attribute == ATTRIBUTE_PRIMARY_GROUP_ID) {
return primarygrouptype_to_display_value(value);
} else if (attribute == ATTRIBUTE_GROUP_TYPE || attribute == ATTRIBUTE_SYSTEM_FLAGS) {
} else if (attribute == ATTRIBUTE_GROUP_TYPE || attribute == ATTRIBUTE_SYSTEM_FLAGS || attribute == ATTRIBUTE_MSDS_USER_ACCOUNT_CONTROL_COMPUTED) {
return attribute_hex_displayed_value(attribute, value);
} else if (attribute == ATTRIBUTE_MS_DS_SUPPORTED_ETYPES) {
return msds_supported_etypes_to_display_value(value);
Expand All @@ -73,7 +73,6 @@ QString attribute_display_value(const QString &attribute, const QByteArray &valu
}
case AttributeType_LargeInteger: {
const LargeIntegerSubtype subtype = adconfig->get_attribute_large_integer_subtype(attribute);

switch (subtype) {
case LargeIntegerSubtype_Datetime: return large_integer_datetime_display_value(attribute, value, adconfig);
case LargeIntegerSubtype_Timespan: return timespan_display_value(value);
Expand Down
32 changes: 26 additions & 6 deletions src/admc/tabs/attributes_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <QHeaderView>
#include <QMenu>
#include <QStandardItemModel>
#include <QMouseEvent>
#include <QClipboard>

QString attribute_type_display_string(const AttributeType type);

Expand Down Expand Up @@ -90,14 +92,16 @@ AttributesTabEdit::AttributesTabEdit(QTreeView *view_arg, QPushButton *filter_bu

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);
optional_attrs_values_is_loaded = settings_get_variant(SETTING_load_optional_attribute_values).toBool();
load_optional_attrs_button->setVisible(!optional_attrs_values_is_loaded);

connect(
selection_model, &QItemSelectionModel::selectionChanged,
this, &AttributesTabEdit::update_edit_and_view_buttons);
update_edit_and_view_buttons();

view->installEventFilter(this);

connect(
view, &QAbstractItemView::doubleClicked,
this, &AttributesTabEdit::on_double_click);
Expand Down Expand Up @@ -147,7 +151,6 @@ QList<QStandardItem *> AttributesTabEdit::get_selected_row() const {

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);
Expand Down Expand Up @@ -175,6 +178,24 @@ void AttributesTabEdit::update_edit_and_view_buttons() {
}
}

void AttributesTabEdit::copy_action(){
const QList<QStandardItem *> selected_row = get_selected_row();
QApplication::clipboard()->setText(selected_row[AttributesColumn_Value]->text());
}

bool AttributesTabEdit::eventFilter(QObject *watched, QEvent *event){
if (watched == view && event->type() == 82){
QMenu menu;
QAction* saveAction = menu.addAction("Копировать");
connect(
saveAction, &QAction::triggered,
this, &AttributesTabEdit::copy_action);
menu.exec(QCursor::pos());
return true;
}
return QObject::eventFilter(watched, event);
}

void AttributesTabEdit::on_double_click() {
const QList<QStandardItem *> selected_row = get_selected_row();
const QString attribute = selected_row[AttributesColumn_Name]->text();
Expand Down Expand Up @@ -235,7 +256,7 @@ void AttributesTabEdit::load_optional_attribute_values(AdInterface &ad) {
}
}
}

optional_attrs_values_is_loaded = true;
proxy->update_set_attributes(optional_set_attrs);
}

Expand Down Expand Up @@ -290,8 +311,7 @@ void AttributesTabEdit::load(AdInterface &ad, const AdObject &object) {

proxy->load(object);

bool load_optional = settings_get_variant(SETTING_load_optional_attribute_values).toBool();
if (load_optional) {
if (optional_attrs_values_is_loaded) {
load_optional_attribute_values(ad);
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/admc/tabs/attributes_tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ class AttributesTabEdit final : public AttributeEdit {
QHash<QString, QList<QByteArray>> current;
QList<QString> not_specified_optional_attributes;
QString object_dn;
bool optional_attrs_values_is_loaded;

void update_edit_and_view_buttons();
void on_double_click();
void edit_attribute();
void view_attribute();
void on_load_optional();
bool eventFilter(QObject *watched, QEvent *event);
void copy_action();
void load_optional_attribute_values(AdInterface &ad);
void load_row(const QList<QStandardItem *> &row, const QString &attribute, const QList<QByteArray> &values);
QList<QStandardItem *> get_selected_row() const;
Expand Down