1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-18 02:04:36 +03:00

Add "Clear all" button to security tab

Button allows to clear all permission selection
(except inherited permissions).
This commit is contained in:
Semyon Knyazev 2024-11-06 00:41:34 +04:00
parent 2a144009eb
commit fa5774bbc7
5 changed files with 66 additions and 2 deletions

View File

@ -203,6 +203,26 @@ void PermissionsWidget::update_permissions() {
ignore_item_changed_signal = false;
}
bool PermissionsWidget::there_are_selected_permissions() const {
for (int row = 0; row < rights_model->rowCount(); ++row) {
const QList<PermissionColumn> columns = {PermissionColumn_Allowed, PermissionColumn_Denied};
for (PermissionColumn col : columns) {
const QModelIndex index = rights_model->index(row, col);
if (!index.isValid()) {
continue;
}
QStandardItem *item = rights_model->itemFromIndex(index);
const bool checked = item->checkState() == Qt::Checked && item->isEnabled();
if (checked) {
return true;
}
}
}
return false;
}
void PermissionsWidget::make_model_rights_read_only() {
// NOTE: important to ignore this signal because
// it's slot reloads the rights model

View File

@ -76,6 +76,7 @@ public:
virtual void update_permissions(AppliedObjects applied_objs, const QString &appliable_child_class = QString());
// Updates permissions with current applied objects value
virtual void update_permissions();
bool there_are_selected_permissions() const;
signals:
void edited();

View File

@ -60,7 +60,13 @@ SecurityTab::SecurityTab(QList<AttributeEdit *> *edit_list, QWidget *parent)
permissions_widgets.append(ui->read_write_permissions_widget);
permissions_widgets.append(ui->delegation_widget);
for (PermissionsWidget *widget : permissions_widgets) {
connect(widget, &PermissionsWidget::edited, tab_edit, &SecurityTabEdit::edited);
connect(widget, &PermissionsWidget::edited,
[this, widget](){
tab_edit->edited();
if ((!ui->clear_all_button->isEnabled() && widget->there_are_selected_permissions())) {
ui->clear_all_button->setEnabled(true);
}
});
}
const QHash<QWidget*, PermissionsWidget*> tab_permission_wget_map = {
@ -87,9 +93,15 @@ SecurityTab::SecurityTab(QList<AttributeEdit *> *edit_list, QWidget *parent)
if (current_trustee.isEmpty()) {
return;
}
bool clear_enabled = false;
for (PermissionsWidget *widget : permissions_widgets) {
widget->set_current_trustee(current_trustee);
if (widget->there_are_selected_permissions()) {
clear_enabled = true;
}
}
ui->clear_all_button->setEnabled(clear_enabled);
});
connect(
@ -105,6 +117,9 @@ SecurityTab::SecurityTab(QList<AttributeEdit *> *edit_list, QWidget *parent)
connect(
ui->applied_objects_cmbBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SecurityTab::on_applied_objs_cmbbox);
connect(
ui->clear_all_button, &QAbstractButton::clicked,
this, &SecurityTab::on_clear_all);
}
void SecurityTab::load(AdInterface &ad, const AdObject &object) {
@ -277,6 +292,23 @@ void SecurityTab::on_applied_objs_cmbbox() {
}
}
void SecurityTab::on_clear_all() {
const QByteArray trustee = get_current_trustee();
if (trustee.isEmpty()) {
return;
}
// Do not reload sd to leave permission selection enabled for
// trustee removed from security descriptor.
security_descriptor_remove_trustee(sd, {trustee});
for (PermissionsWidget* perm_wget : permissions_widgets) {
perm_wget->update_permissions();
}
tab_edit->edited();
ui->clear_all_button->setDisabled(true);
}
void SecurityTabEdit::load(AdInterface &ad, const AdObject &object) {
security_tab->load(ad, object);
}

View File

@ -71,6 +71,7 @@ private:
QByteArray get_current_trustee() const;
void load_applied_objects_cmbbox(const QStringList &target_class_list);
void on_applied_objs_cmbbox();
void on_clear_all();
signals:
void current_trustee_changed(const QByteArray &current_trustee);

View File

@ -122,6 +122,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="clear_all_button">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Clear all</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -133,7 +143,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<property name="tabBarAutoHide">
<bool>false</bool>