mirror of
https://github.com/altlinux/admc.git
synced 2024-10-27 10:55:05 +03:00
only apply expiry if changed
add datetime_to_string() rename datetime_to_string() to datetime_to_display_string()
This commit is contained in:
parent
f468e2422e
commit
1d46cdade0
@ -107,16 +107,22 @@ void AccountTab::apply() {
|
||||
apply_attribute_edits(edits, target(), this);
|
||||
|
||||
// TODO: process errors
|
||||
// NOTE: have to operate on raw string datetime values here because (never) value can't be expressed as QDateTime
|
||||
AdResult expiry_result(false);
|
||||
const bool expiry_never = checkbox_is_checked(expiry_never_check);
|
||||
QString new_expiry_value;
|
||||
if (expiry_never) {
|
||||
expiry_result = AdInterface::instance()->attribute_replace(target(), ATTRIBUTE_ACCOUNT_EXPIRES, AD_LARGEINTEGERTIME_NEVER_1);
|
||||
new_expiry_value = AD_LARGEINTEGERTIME_NEVER_1;
|
||||
} else {
|
||||
const QString new_expiry_date_string = expiry_display->text();
|
||||
const QDate new_expiry_date = QDate::fromString(new_expiry_date_string, DATE_FORMAT);
|
||||
const QDateTime new_expiry(new_expiry_date, END_OF_DAY);
|
||||
new_expiry_value = datetime_to_string(ATTRIBUTE_ACCOUNT_EXPIRES, new_expiry);
|
||||
}
|
||||
|
||||
expiry_result = AdInterface::instance()->attribute_datetime_replace(target(), ATTRIBUTE_ACCOUNT_EXPIRES, new_expiry);
|
||||
const bool expiry_changed = (new_expiry_value != original_expiry_value);
|
||||
if (expiry_changed) {
|
||||
const AdResult expiry_result = AdInterface::instance()->attribute_replace(target(), ATTRIBUTE_ACCOUNT_EXPIRES, new_expiry_value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +132,7 @@ void AccountTab::reload() {
|
||||
}
|
||||
|
||||
const QString expiry_raw = AdInterface::instance()->attribute_get(target(), ATTRIBUTE_ACCOUNT_EXPIRES);
|
||||
original_expiry_value = expiry_raw;
|
||||
const bool expiry_never = datetime_is_never(ATTRIBUTE_ACCOUNT_EXPIRES, expiry_raw);
|
||||
|
||||
// NOTE: need to block signals from checks so that their slots aren't called
|
||||
|
@ -52,6 +52,7 @@ private:
|
||||
QCheckBox *expiry_set_check;
|
||||
QLabel *expiry_display;
|
||||
QPushButton *expiry_edit_button;
|
||||
QString original_expiry_value;
|
||||
};
|
||||
|
||||
#endif /* ACCOUNT_TAB_H */
|
||||
|
@ -320,27 +320,7 @@ QDateTime AdInterface::attribute_datetime_get(const QString &dn, const QString &
|
||||
}
|
||||
|
||||
AdResult AdInterface::attribute_datetime_replace(const QString &dn, const QString &attribute, const QDateTime &datetime) {
|
||||
const DatetimeFormat format = get_attribute_time_format(attribute);
|
||||
|
||||
QString datetime_string;
|
||||
switch (format) {
|
||||
case DatetimeFormat_LargeInteger: {
|
||||
const QDateTime ntfs_epoch(QDate(1601, 1, 1));
|
||||
const qint64 millis = ntfs_epoch.msecsTo(datetime);
|
||||
const qint64 hundred_nanos = millis * MILLIS_TO_100_NANOS;
|
||||
|
||||
datetime_string = QString::number(hundred_nanos);
|
||||
|
||||
break;
|
||||
}
|
||||
case DatetimeFormat_ISO8601: {
|
||||
datetime_string = datetime.toString(ISO8601_FORMAT_STRING);
|
||||
|
||||
break;
|
||||
}
|
||||
case DatetimeFormat_None: return AdResult(false);
|
||||
}
|
||||
|
||||
const QString datetime_string = datetime_to_string(attribute, datetime);
|
||||
const AdResult result = attribute_replace(dn, attribute, datetime_string);
|
||||
|
||||
return result;
|
||||
@ -351,7 +331,7 @@ AdResult AdInterface::attribute_replace(const QString &dn, const QString &attrib
|
||||
QString old_value_string;
|
||||
if (attribute_is_datetime(attribute)) {
|
||||
old_value_string = attribute_get(dn, attribute);
|
||||
old_value_display_string = datetime_raw_to_string(attribute, old_value_string);
|
||||
old_value_display_string = datetime_raw_to_display_string(attribute, old_value_string);
|
||||
} else {
|
||||
old_value_string = attribute_get(dn, attribute);
|
||||
old_value_display_string = old_value_string;
|
||||
@ -380,7 +360,7 @@ AdResult AdInterface::attribute_replace(const QString &dn, const QString &attrib
|
||||
|
||||
QString new_value_string;
|
||||
if (attribute_is_datetime(attribute)) {
|
||||
new_value_string = datetime_raw_to_string(attribute, value);
|
||||
new_value_string = datetime_raw_to_display_string(attribute, value);
|
||||
} else {
|
||||
new_value_string = value;
|
||||
}
|
||||
@ -1199,7 +1179,31 @@ DatetimeFormat get_attribute_time_format(const QString &attribute) {
|
||||
return datetime_formats.value(attribute, DatetimeFormat_None);
|
||||
}
|
||||
|
||||
QString datetime_raw_to_string(const QString &attribute, const QString &raw_value) {
|
||||
QString datetime_to_string(const QString &attribute, const QDateTime &datetime) {
|
||||
const DatetimeFormat format = get_attribute_time_format(attribute);
|
||||
|
||||
switch (format) {
|
||||
case DatetimeFormat_LargeInteger: {
|
||||
const QDateTime ntfs_epoch(QDate(1601, 1, 1));
|
||||
const qint64 millis = ntfs_epoch.msecsTo(datetime);
|
||||
const qint64 hundred_nanos = millis * MILLIS_TO_100_NANOS;
|
||||
|
||||
return QString::number(hundred_nanos);
|
||||
|
||||
break;
|
||||
}
|
||||
case DatetimeFormat_ISO8601: {
|
||||
return datetime.toString(ISO8601_FORMAT_STRING);
|
||||
|
||||
break;
|
||||
}
|
||||
case DatetimeFormat_None: return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
QString datetime_raw_to_display_string(const QString &attribute, const QString &raw_value) {
|
||||
if (datetime_is_never(attribute, raw_value)) {
|
||||
return "(never)";
|
||||
}
|
||||
|
@ -248,7 +248,8 @@ QString get_account_option_description(const AccountOption &option);
|
||||
int get_account_option_bit(const AccountOption &option);
|
||||
bool attribute_is_datetime(const QString &attribute);
|
||||
bool datetime_is_never(const QString &attribute, const QString &value);
|
||||
QString datetime_raw_to_string(const QString &attribute, const QString &raw_value);
|
||||
QString datetime_to_string(const QString &attribute, const QDateTime &datetime);
|
||||
QString datetime_raw_to_display_string(const QString &attribute, const QString &raw_value);
|
||||
QDateTime datetime_raw_to_datetime(const QString &attribute, const QString &raw_value);
|
||||
QString group_scope_to_string(GroupScope scope);
|
||||
QString group_type_to_string(GroupType type);
|
||||
|
Loading…
Reference in New Issue
Block a user