Merge lp:~jeremywootten/pantheon-files/fix-context-menu-when-admin into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten on 2016-12-03
Status: Merged
Approved by: Daniel Fore on 2017-06-13
Approved revision: 2211
Merged at revision: 2579
Proposed branch: lp:~jeremywootten/pantheon-files/fix-context-menu-when-admin
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 233 lines (+56/-39)
5 files modified
libcore/PluginManager.vala (+15/-12)
libwidgets/Chrome/BreadcrumbIconList.vala (+7/-7)
src/Application.vala (+1/-1)
src/View/AbstractDirectoryView.vala (+26/-18)
src/View/Sidebar.vala (+7/-1)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-context-menu-when-admin
Reviewer Review Type Date Requested Status
Adam Bieńkowski code 2016-12-03 Approve on 2017-06-10
Review via email: mp+312415@code.launchpad.net

Commit message

Do not show certain unusable options when running as admin and cures some terminal warnings

Description of the change

This branch does not show certain unusable options when running as admin and cures some terminal warnings.

TO TEST:
After installing and killing existing Files processes, run "New Window as Administrator" from plank or "pantheon-files-pkexec" from the command line. Compared to trunk there are fewer context menu options, the trash and network are unavailable and there are fewer terminal warnings.

To post a comment you must log in.
Jeremy Wootten (jeremywootten) wrote :

Whether or not the program is run with pkexec or (gk)sudo, the network options in the sidebar do not work in trunk and are suppressed in this branch.

Adam Bieńkowski (donadigo) wrote :

Two comments. I can confirm that there are less warnings in the output and that there are no network options.

review: Needs Fixing (code / testing)
2209. By Jeremy Wootten on 2017-06-04

Merge trunk to r2571

2210. By Jeremy Wootten on 2017-06-05

Merge trunk to r2572 and resolve conflicts

Jeremy Wootten (jeremywootten) wrote :

Fixed conflicts with trunk r2572.

2211. By Jeremy Wootten on 2017-06-05

Fix indentation in PluginManager

Jeremy Wootten (jeremywootten) wrote :

Fixed indentation fault in PluginManager.

The comment "/* Add Entire Network BUILTIN */" is reproduced in the replacement code.

Adam Bieńkowski (donadigo) wrote :

Code looks good to me now. Thanks.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libcore/PluginManager.vala'
2--- libcore/PluginManager.vala 2017-02-10 19:35:18 +0000
3+++ libcore/PluginManager.vala 2017-06-05 15:22:19 +0000
4@@ -28,6 +28,7 @@
5 Gee.List<string> names;
6 bool in_available = false;
7 bool update_queued = false;
8+ bool is_admin = false;
9
10 [Version (deprecated = true, deprecated_since = "0.2", replacement = "Marlin.PluginManager.menuitem_references")]
11 public GLib.List<Gtk.Widget>? menus; /* this doesn't manage GObject references properly */
12@@ -36,24 +37,26 @@
13
14 private string[] plugin_dirs;
15
16- public PluginManager (string plugin_dir) {
17+ public PluginManager (string plugin_dir, uint user_id) {
18+ is_admin = (user_id == 0);
19 plugin_hash = new Gee.HashMap<string,Plugins.Base> ();
20 names = new Gee.ArrayList<string> ();
21-
22 menuitem_references = new Gee.LinkedList<Gtk.Widget> ();
23-
24 plugin_dirs = new string[0];
25- plugin_dirs += Path.build_filename (plugin_dir, "core");
26- plugin_dirs += plugin_dir;
27-
28- load_plugins ();
29-
30- /* Monitor plugin dirs */
31- foreach (string path in plugin_dirs)
32- set_directory_monitor (path);
33+
34+ if (!is_admin) {
35+ plugin_dirs += Path.build_filename (plugin_dir, "core");
36+ plugin_dirs += plugin_dir;
37+
38+ load_plugins ();
39+
40+ /* Monitor plugin dirs */
41+ foreach (string path in plugin_dirs)
42+ set_directory_monitor (path);
43+ }
44 }
45
46- public void load_plugins () {
47+ private void load_plugins () {
48 load_modules_from_dir (plugin_dirs[0]);
49 in_available = true;
50 load_modules_from_dir (plugin_dirs[1]);
51
52=== modified file 'libwidgets/Chrome/BreadcrumbIconList.vala'
53--- libwidgets/Chrome/BreadcrumbIconList.vala 2017-02-17 17:07:08 +0000
54+++ libwidgets/Chrome/BreadcrumbIconList.vala 2017-06-05 15:22:19 +0000
55@@ -53,9 +53,9 @@
56
57
58 /* music */
59- string dir;
60+ string? dir;
61 dir = Environment.get_user_special_dir (UserDirectory.MUSIC);
62- if (dir.contains (Path.DIR_SEPARATOR_S)) {
63+ if (dir != null && dir.contains (Path.DIR_SEPARATOR_S)) {
64 BreadcrumbIconInfo icon = {dir, Marlin.ICON_FOLDER_MUSIC_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), false, Filename.display_basename (dir)};
65 icon.exploded[0] = Path.DIR_SEPARATOR_S;
66 add_icon (icon);
67@@ -63,7 +63,7 @@
68
69 /* image */
70 dir = Environment.get_user_special_dir (UserDirectory.PICTURES);
71- if (dir.contains (Path.DIR_SEPARATOR_S)) {
72+ if (dir != null && dir.contains (Path.DIR_SEPARATOR_S)) {
73 BreadcrumbIconInfo icon = {dir, Marlin.ICON_FOLDER_PICTURES_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), false, Filename.display_basename (dir)};
74 icon.exploded[0] = Path.DIR_SEPARATOR_S;
75 add_icon (icon);
76@@ -71,7 +71,7 @@
77
78 /* movie */
79 dir = Environment.get_user_special_dir (UserDirectory.VIDEOS);
80- if (dir.contains (Path.DIR_SEPARATOR_S)) {
81+ if (dir != null && dir.contains (Path.DIR_SEPARATOR_S)) {
82 BreadcrumbIconInfo icon = {dir, Marlin.ICON_FOLDER_VIDEOS_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), false, Filename.display_basename (dir)};
83 icon.exploded[0] = Path.DIR_SEPARATOR_S;
84 add_icon (icon);
85@@ -79,7 +79,7 @@
86
87 /* downloads */
88 dir = Environment.get_user_special_dir (UserDirectory.DOWNLOAD);
89- if (dir.contains (Path.DIR_SEPARATOR_S)) {
90+ if (dir != null && dir.contains (Path.DIR_SEPARATOR_S)) {
91 BreadcrumbIconInfo icon = {dir, Marlin.ICON_FOLDER_DOWNLOADS_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), false, Filename.display_basename (dir)};
92 icon.exploded[0] = Path.DIR_SEPARATOR_S;
93 add_icon (icon);
94@@ -87,7 +87,7 @@
95
96 /* documents */
97 dir = Environment.get_user_special_dir (UserDirectory.DOCUMENTS);
98- if (dir.contains (Path.DIR_SEPARATOR_S)) {
99+ if (dir != null && dir.contains (Path.DIR_SEPARATOR_S)) {
100 BreadcrumbIconInfo icon = {dir, Marlin.ICON_FOLDER_DOCUMENTS_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), false, Filename.display_basename (dir)};
101 icon.exploded[0] = Path.DIR_SEPARATOR_S;
102 add_icon (icon);
103@@ -95,7 +95,7 @@
104
105 /* templates */
106 dir = Environment.get_user_special_dir (UserDirectory.TEMPLATES);
107- if (dir.contains (Path.DIR_SEPARATOR_S)) {
108+ if (dir != null && dir.contains (Path.DIR_SEPARATOR_S)) {
109 BreadcrumbIconInfo icon = {dir, Marlin.ICON_FOLDER_TEMPLATES_SYMBOLIC, false, null, null, dir.split (Path.DIR_SEPARATOR_S), false, Filename.display_basename (dir)};
110 icon.exploded[0] = Path.DIR_SEPARATOR_S;
111 add_icon (icon);
112
113=== modified file 'src/Application.vala'
114--- src/Application.vala 2017-06-04 11:12:44 +0000
115+++ src/Application.vala 2017-06-05 15:22:19 +0000
116@@ -98,7 +98,7 @@
117 this.clipboard = Marlin.ClipboardManager.get_for_display ();
118 this.recent = new Gtk.RecentManager ();
119
120- plugins = new Marlin.PluginManager (Config.PLUGIN_DIR);
121+ plugins = new Marlin.PluginManager (Config.PLUGIN_DIR, (uint)(Posix.getuid ()));
122
123 /**TODO** move the volume manager here? */
124 /**TODO** gio: This should be using the UNMOUNTED feature of GFileMonitor instead */
125
126=== modified file 'src/View/AbstractDirectoryView.vala'
127--- src/View/AbstractDirectoryView.vala 2017-05-24 10:16:45 +0000
128+++ src/View/AbstractDirectoryView.vala 2017-06-05 15:22:19 +0000
129@@ -269,7 +269,13 @@
130 private bool in_network_root = false;
131 protected bool is_writable = false;
132 protected bool is_loading;
133- protected bool show_remote_thumbnails {get; set; default = false;}
134+ protected bool helpers_shown;
135+ protected bool show_remote_thumbnails {get; set; default = false;}
136+ protected bool is_admin {
137+ get {
138+ return (uint)Posix.getuid () == 0;
139+ }
140+ }
141
142 private Gtk.Widget view;
143 private unowned Marlin.ClipboardManager clipboard;
144@@ -1073,7 +1079,7 @@
145 }
146
147 private void on_selection_action_trash (GLib.SimpleAction action, GLib.Variant? param) {
148- trash_or_delete_selected_files (false);
149+ trash_or_delete_selected_files (is_admin);
150 }
151
152 private void on_selection_action_delete (GLib.SimpleAction action, GLib.Variant? param) {
153@@ -1909,7 +1915,7 @@
154
155 menu.append_section (null, clipboard_menu);
156
157- if (slot.directory.has_trash_dirs) {
158+ if (slot.directory.has_trash_dirs && !is_admin) {
159 menu.append_section (null, builder.get_object ("trash") as GLib.MenuModel);
160 } else {
161 menu.append_section (null, builder.get_object ("delete") as GLib.MenuModel);
162@@ -2679,9 +2685,9 @@
163 _("You do not have permission to change this location"),
164 window as Gtk.Window);
165 break;
166- } else if (no_mods) {
167- /* If already in trash, permanently delete the file */
168- trash_or_delete_selected_files (in_trash);
169+ } else if (no_mods || is_admin) {
170+ /* If already in trash or running as root, permanently delete the file */
171+ trash_or_delete_selected_files (in_trash || is_admin);
172 return true;
173 } else if (only_shift_pressed) {
174 trash_or_delete_selected_files (true);
175@@ -3432,18 +3438,20 @@
176 dir.file.sort_column_id = sort_column_id;
177 dir.file.sort_order = sort_order;
178
179- dir.location.set_attributes_async.begin (info,
180- GLib.FileQueryInfoFlags.NONE,
181- GLib.Priority.DEFAULT,
182- null,
183- (obj, res) => {
184- try {
185- GLib.FileInfo inf;
186- dir.location.set_attributes_async.end (res, out inf);
187- } catch (GLib.Error e) {
188- warning ("Could not set file attributes - %s", e.message);
189- }
190- });
191+ if (!is_admin) {
192+ dir.location.set_attributes_async.begin (info,
193+ GLib.FileQueryInfoFlags.NONE,
194+ GLib.Priority.DEFAULT,
195+ null,
196+ (obj, res) => {
197+ try {
198+ GLib.FileInfo inf;
199+ dir.location.set_attributes_async.end (res, out inf);
200+ } catch (GLib.Error e) {
201+ warning ("Could not set file attributes - %s", e.message);
202+ }
203+ });
204+ }
205 }
206
207 protected void cancel_timeout (ref uint id) {
208
209=== modified file 'src/View/Sidebar.vala'
210--- src/View/Sidebar.vala 2017-06-04 11:12:44 +0000
211+++ src/View/Sidebar.vala 2017-06-05 15:22:19 +0000
212@@ -114,6 +114,12 @@
213 /* Remember path at button press */
214 Gtk.TreePath? click_path = null;
215
216+ bool is_admin {
217+ get {
218+ return (uint)Posix.getuid () == 0;
219+ }
220+ }
221+
222 /* For cancelling async tooltip updates when update_places re-entered */
223 Cancellable? update_cancellable = null;
224
225@@ -547,7 +553,7 @@
226 }
227
228 /* Do not show Trash if running as root (cannot be loaded) */
229- if (Posix.getuid () != 0) {
230+ if (!is_admin) {
231 /* Add trash */
232 add_place (Marlin.PlaceType.BUILT_IN,
233 iter,

Subscribers

People subscribed via source and target branches

to all changes: