[evolution-ews/gnome-3-30] I#14 - Let edit Permissions of root message folder



commit 344dd030e4edf7c63d97a5a13d85418048870bb1
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 6 17:55:19 2018 +0200

    I#14 - Let edit Permissions of root message folder
    
    Closes https://gitlab.gnome.org/GNOME/evolution-ews/issues/14

 src/configuration/e-ews-config-utils.c            | 58 +++++++++++++----------
 src/configuration/e-ews-edit-folder-permissions.c | 46 +++++++++---------
 src/server/e-ews-connection.c                     | 38 ++-------------
 src/server/e-ews-folder.c                         | 26 ++++++++++
 src/server/e-ews-folder.h                         |  4 +-
 src/server/e-ews-item-change.c                    | 13 +++++
 src/server/e-ews-item-change.h                    |  2 +
 7 files changed, 106 insertions(+), 81 deletions(-)
---
diff --git a/src/configuration/e-ews-config-utils.c b/src/configuration/e-ews-config-utils.c
index c3185f75..5ddf4c55 100644
--- a/src/configuration/e-ews-config-utils.c
+++ b/src/configuration/e-ews-config-utils.c
@@ -993,50 +993,61 @@ static void
 action_folder_permissions_mail_cb (GtkAction *action,
                                    EShellView *shell_view)
 {
-       gchar *folder_path = NULL;
+       EShell *shell;
        EShellWindow *shell_window;
+       ESourceRegistry *registry;
        GtkWindow *parent;
        CamelStore *store = NULL;
        CamelEwsStore *ews_store;
-       gchar *str_folder_id;
+       EwsFolderId *folder_id = NULL;
+       gchar *folder_path = NULL;
 
        if (!get_ews_store_from_folder_tree (shell_view, &folder_path, &store))
                return;
 
        ews_store = CAMEL_EWS_STORE (store);
        g_return_if_fail (ews_store != NULL);
-       g_return_if_fail (folder_path != NULL);
 
        shell_window = e_shell_view_get_shell_window (shell_view);
        parent = GTK_WINDOW (shell_window);
+       shell = e_shell_window_get_shell (shell_window);
+       registry = e_shell_get_registry (shell);
+
+       if (folder_path && *folder_path) {
+               gchar *str_folder_id = NULL;
 
-       str_folder_id = camel_ews_store_summary_get_folder_id_from_name (ews_store->summary, folder_path);
-       if (!str_folder_id) {
-               e_notice (parent, GTK_MESSAGE_ERROR, _("Cannot edit permissions of folder ā€œ%sā€, choose other 
folder."), folder_path);
+               str_folder_id = camel_ews_store_summary_get_folder_id_from_name (ews_store->summary, 
folder_path);
+               if (!str_folder_id) {
+                       e_notice (parent, GTK_MESSAGE_ERROR, _("Cannot edit permissions of folder ā€œ%sā€, 
choose other folder."), folder_path);
+               } else {
+                       gchar *str_change_key;
+
+                       str_change_key = camel_ews_store_summary_get_change_key (
+                               ews_store->summary, str_folder_id, NULL);
+
+                       folder_id = e_ews_folder_id_new (str_folder_id, str_change_key, FALSE);
+
+                       g_free (str_change_key);
+               }
+
+               g_free (str_folder_id);
        } else {
-               EShell *shell;
+               g_clear_pointer (&folder_path, g_free);
+
+               folder_id = e_ews_folder_id_new ("msgfolderroot", NULL, TRUE);
+       }
+
+       if (folder_id) {
                ESource *source;
-               ESourceRegistry *registry;
                CamelService *service;
                CamelSettings *settings;
-               EwsFolderId *folder_id;
-               gchar *str_change_key;
                const gchar *uid;
 
-               shell = e_shell_window_get_shell (shell_window);
-               registry = e_shell_get_registry (shell);
-
                service = CAMEL_SERVICE (store);
                uid = camel_service_get_uid (service);
                source = e_source_registry_ref_source (registry, uid);
                g_return_if_fail (source != NULL);
 
-               str_change_key = camel_ews_store_summary_get_change_key (
-                       ews_store->summary, str_folder_id, NULL);
-
-               folder_id = e_ews_folder_id_new (
-                       str_folder_id, str_change_key, FALSE);
-
                settings = camel_service_ref_settings (service);
 
                e_ews_edit_folder_permissions (
@@ -1045,20 +1056,17 @@ action_folder_permissions_mail_cb (GtkAction *action,
                        source,
                        CAMEL_EWS_SETTINGS (settings),
                        camel_service_get_display_name (service),
-                       folder_path,
+                       folder_path ? folder_path : camel_service_get_display_name (service),
                        folder_id,
                        E_EWS_FOLDER_TYPE_MAILBOX);
 
                g_object_unref (settings);
-
                g_object_unref (source);
-               g_free (str_folder_id);
-               g_free (str_change_key);
-               e_ews_folder_id_free (folder_id);
        }
 
        g_object_unref (store);
        g_free (folder_path);
+       e_ews_folder_id_free (folder_id);
 }
 
 static void
@@ -1177,7 +1185,7 @@ ews_ui_update_actions_mail_cb (EShellView *shell_view,
                g_object_unref (session);
 
        ews_ui_enable_actions (action_group, mail_account_context_entries, G_N_ELEMENTS 
(mail_account_context_entries), account_node, online);
-       ews_ui_enable_actions (action_group, mail_folder_context_entries, G_N_ELEMENTS 
(mail_folder_context_entries), folder_node, online);
+       ews_ui_enable_actions (action_group, mail_folder_context_entries, G_N_ELEMENTS 
(mail_folder_context_entries), account_node || folder_node, online);
        ews_ui_enable_actions (action_group, global_ews_entries, G_N_ELEMENTS (global_ews_entries), 
has_ews_account, online);
 }
 
diff --git a/src/configuration/e-ews-edit-folder-permissions.c 
b/src/configuration/e-ews-edit-folder-permissions.c
index 86e2b625..5a6d9904 100644
--- a/src/configuration/e-ews-edit-folder-permissions.c
+++ b/src/configuration/e-ews-edit-folder-permissions.c
@@ -1002,28 +1002,30 @@ e_ews_edit_folder_permissions (GtkWindow *parent,
 
        row++;
 
-       label = gtk_label_new (_("Folder ID:"));
-       g_object_set (
-               G_OBJECT (label),
-               "hexpand", FALSE,
-               "vexpand", FALSE,
-               "xalign", 0.0,
-               NULL);
-
-       widget = gtk_entry_new ();
-       g_object_set (
-               G_OBJECT (widget),
-               "hexpand", TRUE,
-               "vexpand", FALSE,
-               "xalign", 0.0,
-               "has-frame", FALSE,
-               "editable", FALSE,
-               "can-focus", FALSE,
-               "text", folder_id->id,
-               NULL);
-
-       gtk_grid_attach (grid, label, 0, row, 1, 1);
-       gtk_grid_attach (grid, widget, 1, row, 1, 1);
+       if (!folder_id->is_distinguished_id) {
+               label = gtk_label_new (_("Folder ID:"));
+               g_object_set (
+                       G_OBJECT (label),
+                       "hexpand", FALSE,
+                       "vexpand", FALSE,
+                       "xalign", 0.0,
+                       NULL);
+
+               widget = gtk_entry_new ();
+               g_object_set (
+                       G_OBJECT (widget),
+                       "hexpand", TRUE,
+                       "vexpand", FALSE,
+                       "xalign", 0.0,
+                       "has-frame", FALSE,
+                       "editable", FALSE,
+                       "can-focus", FALSE,
+                       "text", folder_id->id,
+                       NULL);
+
+               gtk_grid_attach (grid, label, 0, row, 1, 1);
+               gtk_grid_attach (grid, widget, 1, row, 1, 1);
+       }
 
        row++;
 
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index e365d2fc..977c5255 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -4336,32 +4336,6 @@ e_ews_connection_sync_folder_items_sync (EEwsConnection *cnc,
        return success;
 }
 
-static void
-ews_append_folder_id_to_msg (ESoapMessage *msg,
-                             const gchar *email,
-                             const EwsFolderId *fid)
-{
-       g_return_if_fail (msg != NULL);
-       g_return_if_fail (fid != NULL);
-
-       if (fid->is_distinguished_id)
-               e_soap_message_start_element (msg, "DistinguishedFolderId", NULL, NULL);
-       else
-               e_soap_message_start_element (msg, "FolderId", NULL, NULL);
-
-       e_soap_message_add_attribute (msg, "Id", fid->id, NULL, NULL);
-       if (fid->change_key)
-               e_soap_message_add_attribute (msg, "ChangeKey", fid->change_key, NULL, NULL);
-
-       if (fid->is_distinguished_id && email) {
-               e_soap_message_start_element (msg, "Mailbox", NULL, NULL);
-               e_ews_message_write_string_parameter (msg, "EmailAddress", NULL, email);
-               e_soap_message_end_element (msg);
-       }
-
-       e_soap_message_end_element (msg);
-}
-
 static void
 ews_append_folder_ids_to_msg (ESoapMessage *msg,
                               const gchar *email,
@@ -4372,7 +4346,7 @@ ews_append_folder_ids_to_msg (ESoapMessage *msg,
        for (l = folder_ids; l != NULL; l = g_slist_next (l)) {
                const EwsFolderId *fid = l->data;
 
-               ews_append_folder_id_to_msg (msg, email, fid);
+               e_ews_folder_id_append_to_msg (msg, email, fid);
        }
 }
 
@@ -5579,7 +5553,7 @@ e_ews_connection_create_items (EEwsConnection *cnc,
 
        if (fid) {
                e_soap_message_start_element (msg, "SavedItemFolderId", "messages", NULL);
-               ews_append_folder_id_to_msg (msg, cnc->priv->email, fid);
+               e_ews_folder_id_append_to_msg (msg, cnc->priv->email, fid);
                e_soap_message_end_element (msg);
        }
 
@@ -8985,7 +8959,7 @@ e_ews_connection_get_folder_permissions (EEwsConnection *cnc,
        e_soap_message_end_element (msg); /* FolderShape */
 
        e_soap_message_start_element (msg, "FolderIds", "messages", NULL);
-       ews_append_folder_id_to_msg (msg, cnc->priv->email, folder_id);
+       e_ews_folder_id_append_to_msg (msg, cnc->priv->email, folder_id);
        e_soap_message_end_element (msg);
 
        e_ews_message_write_footer (msg);
@@ -9098,9 +9072,7 @@ e_ews_connection_set_folder_permissions (EEwsConnection *cnc,
                        TRUE);
 
        e_soap_message_start_element (msg, "FolderChanges", "messages", NULL);
-       e_ews_message_start_item_change (
-               msg, E_EWS_ITEMCHANGE_TYPE_FOLDER,
-               folder_id->id, folder_id->change_key, 0);
+       e_ews_message_start_folder_change (msg, cnc->priv->email, folder_id);
 
        e_soap_message_start_element (msg, "SetFolderField", NULL, NULL);
        e_ews_message_write_string_parameter_with_attribute (msg, "FieldURI", NULL, NULL, "FieldURI", 
"folder:PermissionSet");
@@ -9520,7 +9492,7 @@ e_ews_connection_get_folder_info (EEwsConnection *cnc,
        e_soap_message_end_element (msg); /* FolderShape */
 
        e_soap_message_start_element (msg, "FolderIds", "messages", NULL);
-       ews_append_folder_id_to_msg (msg, mail_id, folder_id);
+       e_ews_folder_id_append_to_msg (msg, mail_id, folder_id);
        e_soap_message_end_element (msg);
 
        e_ews_message_write_footer (msg);
diff --git a/src/server/e-ews-folder.c b/src/server/e-ews-folder.c
index 5245d1a8..86538882 100644
--- a/src/server/e-ews-folder.c
+++ b/src/server/e-ews-folder.c
@@ -364,6 +364,32 @@ e_ews_folder_id_is_equal (const EwsFolderId *a,
        return TRUE;
 }
 
+void
+e_ews_folder_id_append_to_msg (ESoapMessage *msg,
+                              const gchar *email,
+                              const EwsFolderId *fid)
+{
+       g_return_if_fail (msg != NULL);
+       g_return_if_fail (fid != NULL);
+
+       if (fid->is_distinguished_id)
+               e_soap_message_start_element (msg, "DistinguishedFolderId", NULL, NULL);
+       else
+               e_soap_message_start_element (msg, "FolderId", NULL, NULL);
+
+       e_soap_message_add_attribute (msg, "Id", fid->id, NULL, NULL);
+       if (fid->change_key)
+               e_soap_message_add_attribute (msg, "ChangeKey", fid->change_key, NULL, NULL);
+
+       if (fid->is_distinguished_id && email) {
+               e_soap_message_start_element (msg, "Mailbox", NULL, NULL);
+               e_ews_message_write_string_parameter (msg, "EmailAddress", NULL, email);
+               e_soap_message_end_element (msg);
+       }
+
+       e_soap_message_end_element (msg);
+}
+
 const gchar *
 e_ews_folder_get_name (const EEwsFolder *folder)
 {
diff --git a/src/server/e-ews-folder.h b/src/server/e-ews-folder.h
index 8de06fba..4164fc3a 100644
--- a/src/server/e-ews-folder.h
+++ b/src/server/e-ews-folder.h
@@ -90,7 +90,9 @@ void          e_ews_folder_id_free (EwsFolderId *fid);
 gboolean       e_ews_folder_id_is_equal (const EwsFolderId *a,
                                          const EwsFolderId *b,
                                          gboolean check_change_key);
-
+void           e_ews_folder_id_append_to_msg (ESoapMessage *msg,
+                                              const gchar *email,
+                                              const EwsFolderId *fid);
 gchar *                e_ews_folder_utils_escape_name                  (const gchar *folder_name);
 gchar *                e_ews_folder_utils_unescape_name                (const gchar *escaped_folder_name);
 
diff --git a/src/server/e-ews-item-change.c b/src/server/e-ews-item-change.c
index 4f827f97..732e0a8f 100644
--- a/src/server/e-ews-item-change.c
+++ b/src/server/e-ews-item-change.c
@@ -26,6 +26,19 @@
 #include "e-ews-message.h"
 #include "e-ews-item-change.h"
 
+void
+e_ews_message_start_folder_change (ESoapMessage *msg,
+                                  const gchar *email,
+                                  const EwsFolderId *folder_id)
+{
+       g_return_if_fail (msg != NULL);
+       g_return_if_fail (folder_id != NULL);
+
+       e_soap_message_start_element (msg, "FolderChange", NULL, NULL);
+       e_ews_folder_id_append_to_msg (msg, email, folder_id);
+       e_soap_message_start_element (msg, "Updates", NULL, NULL);
+}
+
 void
 e_ews_message_start_item_change (ESoapMessage *msg,
                                  EEwsItemChangeType type,
diff --git a/src/server/e-ews-item-change.h b/src/server/e-ews-item-change.h
index 44b33925..523f2a09 100644
--- a/src/server/e-ews-item-change.h
+++ b/src/server/e-ews-item-change.h
@@ -22,6 +22,7 @@
 #ifndef E_EWS_ITEM_CHANGE_H
 #define E_EWS_ITEM_CHANGE_H
 
+#include "e-ews-folder.h"
 #include "e-soap-message.h"
 #include "e-soap-response.h"
 
@@ -34,6 +35,7 @@ typedef enum {
        E_EWS_ITEMCHANGE_TYPE_RECURRINGMASTER,
 } EEwsItemChangeType;
 
+void e_ews_message_start_folder_change (ESoapMessage *msg, const gchar *email, const EwsFolderId *folder_id);
 void e_ews_message_start_item_change (ESoapMessage *msg, EEwsItemChangeType type,
                                     const gchar *itemid, const gchar *changekey,
                                     gint instance_index);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]