diff options
author | Andres Vieira <anvieiravazquez@gmail.com> | 2020-04-27 19:41:15 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-28 10:00:12 +0200 |
commit | 092e27563302de9dc8355d5fbabdcee0e8170aab (patch) | |
tree | 18381b1c6f9e7a6e1e3ce15590aecf1781a2a93e /Applications | |
parent | cb118111b66c74a665ede1bce0e9f30feb492acc (diff) | |
download | serenity-092e27563302de9dc8355d5fbabdcee0e8170aab.zip |
FileManager: Disable permission checkboxes if user is not owner of path
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/FileManager/PropertiesDialog.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Applications/FileManager/PropertiesDialog.cpp b/Applications/FileManager/PropertiesDialog.cpp index 10b8950914..f4d2f87d17 100644 --- a/Applications/FileManager/PropertiesDialog.cpp +++ b/Applications/FileManager/PropertiesDialog.cpp @@ -73,6 +73,7 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo m_icon->set_preferred_size(32, 32); m_name = file_path.basename(); + m_path = file_path.string(); m_name_box = file_container.add<GUI::TextBox>(); m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); @@ -155,7 +156,7 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo update(); } -PropertiesDialog::~PropertiesDialog() {} +PropertiesDialog::~PropertiesDialog() { } void PropertiesDialog::update() { @@ -226,17 +227,28 @@ void PropertiesDialog::make_permission_checkboxes(GUI::Widget& parent, Permissio auto& label = widget.add<GUI::Label>(label_string); label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + struct stat st; + if (lstat(m_path.characters(), &st)) { + perror("stat"); + return; + } + + auto can_edit_checkboxes = st.st_uid == getuid(); + auto& box_read = widget.add<GUI::CheckBox>("Read"); box_read.set_checked(mode & masks.read); box_read.on_checked = [&, masks](bool checked) { permission_changed(masks.read, checked); }; + box_read.set_enabled(can_edit_checkboxes); auto& box_write = widget.add<GUI::CheckBox>("Write"); box_write.set_checked(mode & masks.write); box_write.on_checked = [&, masks](bool checked) { permission_changed(masks.write, checked); }; + box_write.set_enabled(can_edit_checkboxes); auto& box_execute = widget.add<GUI::CheckBox>("Execute"); box_execute.set_checked(mode & masks.execute); box_execute.on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); }; + box_execute.set_enabled(can_edit_checkboxes); } void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent) |