1
0
mirror of https://github.com/altlinux/admc.git synced 2024-10-26 17:25:38 +03:00

add object tab

This commit is contained in:
Dmitry Degtyarev 2020-08-11 16:01:12 +04:00
parent d785d8d956
commit 1b941164a3
8 changed files with 151 additions and 6 deletions

View File

@ -71,6 +71,7 @@ set(ADMC_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/account_tab.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/general_tab.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/address_tab.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/object_tab.cpp
)
set(TS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/translations)

View File

@ -23,9 +23,6 @@
#include <QSet>
// TODO: not sure if AD datetime fromat is always this one, LDAP allows multiple alternatives: https://ldapwiki.com/wiki/DateTime
#define ISO8601_FORMAT_STRING "yyyyMMddhhmmss.zZ"
#define MILLIS_TO_100_NANOS 10000
#define AD_PWD_LAST_SET_EXPIRED "0"
@ -1046,8 +1043,9 @@ bool attribute_is_datetime(const QString &attribute) {
DatetimeFormat get_attribute_time_format(const QString &attribute) {
static const QHash<QString, DatetimeFormat> datetime_formats = {
{"accountExpires", DatetimeFormat_LargeInteger},
{"whenChanged", DatetimeFormat_ISO8601},
{ATTRIBUTE_ACCOUNT_EXPIRES, DatetimeFormat_LargeInteger},
{ATTRIBUTE_WHEN_CREATED, DatetimeFormat_ISO8601},
{ATTRIBUTE_WHEN_CHANGED, DatetimeFormat_ISO8601},
};
return datetime_formats.value(attribute, DatetimeFormat_None);

View File

@ -33,6 +33,9 @@
// is updated on object changes
// Emits various signals for AD operation successes/failures
// TODO: not sure if AD datetime fromat is always this one, LDAP allows multiple alternatives: https://ldapwiki.com/wiki/DateTime
#define ISO8601_FORMAT_STRING "yyyyMMddhhmmss.zZ"
#define ATTRIBUTE_USER_ACCOUNT_CONTROL "userAccountControl"
#define ATTRIBUTE_USER_PRINCIPAL_NAME "userPrincipalName"
#define ATTRIBUTE_LOCKOUT_TIME "lockoutTime"
@ -56,6 +59,14 @@
#define ATTRIBUTE_POSTAL_CODE "postalCode"
#define ATTRIBUTE_STATE "st"
#define ATTRIBUTE_STREET "streetAddress"
#define ATTRIBUTE_CN "cn"
#define ATTRIBUTE_DISTINGUISHED_NAME "distinguishedName"
#define ATTRIBUTE_OBJECT_CLASS "objectClass"
#define ATTRIBUTE_WHEN_CREATED "whenCreated"
#define ATTRIBUTE_WHEN_CHANGED "whenChanged"
#define ATTRIBUTE_USN_CHANGED "uSNChanged"
#define ATTRIBUTE_USN_CREATED "uSNCreated"
#define ATTRIBUTE_OBJECT_CATEGORY "objectCategory"
#define LOCKOUT_UNLOCKED_VALUE "0"

View File

@ -64,10 +64,37 @@ void DetailsTab::add_attribute_edit(const QString &attribute, const QString &lab
AdInterface::instance()->attribute_replace(target(), attribute, new_value);
}
});
reload_attribute_edit(edit, attribute);
}
void DetailsTab::add_attribute_display(const QString &attribute, const QString &label_text, QLayout *label_layout, QLayout *edit_layout) {
auto label = new QLabel(label_text, this);
auto edit = new QLineEdit(this);
edit->setReadOnly(true);
label_layout->addWidget(label);
edit_layout->addWidget(edit);
reload_attribute_edit(edit, attribute);
}
void DetailsTab::reload_attribute_edit(QLineEdit *edit, const QString &attribute) {
connect(
this, &DetailsTab::reloaded,
[this, edit, attribute]() {
const QString current_value = AdInterface::instance()->attribute_get(target(), attribute);
QString current_value;
if (attribute_is_datetime(attribute)) {
const QString datetime_raw = AdInterface::instance()->attribute_get(target(), attribute);
current_value = datetime_raw_to_string(attribute, datetime_raw);
} else if (attribute == ATTRIBUTE_OBJECT_CLASS) {
// TODO: not sure how to get the "primary" attribute, for now just getting the last one
const QList<QString> classes = AdInterface::instance()->attribute_get_multi(target(), attribute);
current_value = classes.last();
} else {
current_value = AdInterface::instance()->attribute_get(target(), attribute);
}
edit->setText(current_value);
});

View File

@ -25,6 +25,7 @@
class DetailsWidget;
class QLayout;
class QLineEdit;
class DetailsTab : public QWidget {
Q_OBJECT
@ -45,9 +46,12 @@ protected:
QString title;
void add_attribute_edit(const QString &attribute, const QString &label_text, QLayout *label_layout, QLayout *edit_layout);
void add_attribute_display(const QString &attribute, const QString &label_text, QLayout *label_layout, QLayout *edit_layout);
private:
DetailsWidget *details;
void reload_attribute_edit(QLineEdit *edit, const QString &attribute);
};
#endif /* DETAILS_TAB_H */

View File

@ -24,6 +24,7 @@
#include "account_tab.h"
#include "general_tab.h"
#include "address_tab.h"
#include "object_tab.h"
#include "ad_interface.h"
#include "settings.h"
#include "object_context_menu.h"
@ -43,6 +44,7 @@ DetailsWidget::DetailsWidget(ObjectContextMenu *object_context_menu, ContainersW
tabs = {
new GeneralTab(this),
new ObjectTab(this),
new AttributesTab(this),
new AccountTab(this),
new MembersTab(object_context_menu, this),

64
src/object_tab.cpp Normal file
View File

@ -0,0 +1,64 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020 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 "object_tab.h"
#include "ad_interface.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
ObjectTab::ObjectTab(DetailsWidget *details_arg)
: DetailsTab(details_arg)
{
title = tr("Object");
// TODO: don't know why, but if i just have hbox as top layout, the widgets are misaligned
const auto top_layout = new QVBoxLayout(this);
const auto attributes_layout = new QHBoxLayout();
top_layout->insertLayout(-1, attributes_layout);
const auto label_layout = new QVBoxLayout();
const auto edit_layout = new QVBoxLayout();
attributes_layout->insertLayout(-1, label_layout);
attributes_layout->insertLayout(-1, edit_layout);
auto make_line_edit =
[this, label_layout, edit_layout](const QString &attribute, const QString &label_text) {
add_attribute_display(attribute, label_text, label_layout, edit_layout);
};
// TODO: canonical name in ADUC replaces "CN=" with "/" making it look like a directory path
make_line_edit(ATTRIBUTE_DISTINGUISHED_NAME, tr("Canonical name:"));
make_line_edit(ATTRIBUTE_OBJECT_CLASS, tr("Object class:"));
make_line_edit(ATTRIBUTE_WHEN_CREATED, tr("Created:"));
make_line_edit(ATTRIBUTE_WHEN_CHANGED, tr("Changed:"));
make_line_edit(ATTRIBUTE_USN_CREATED, tr("USN created:"));
make_line_edit(ATTRIBUTE_USN_CHANGED, tr("USN changed:"));
}
void ObjectTab::reload() {
emit reloaded();
}
bool ObjectTab::accepts_target() const {
return !target().isEmpty();
}

38
src/object_tab.h Normal file
View File

@ -0,0 +1,38 @@
/*
* ADMC - AD Management Center
*
* Copyright (C) 2020 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/>.
*/
#ifndef OBJECT_TAB_H
#define OBJECT_TAB_H
#include "details_tab.h"
class DetailsWidget;
// Shows member objects of targeted group
class ObjectTab final : public DetailsTab {
Q_OBJECT
public:
ObjectTab(DetailsWidget *details_arg);
void reload();
bool accepts_target() const;
};
#endif /* OBJECT_TAB_H */