[gnome-online-accounts/224-ability-to-restrict-which-services-of-a-particular-account-type-are-available] goaprovider: Use /etc/goa.conf to disable features for providers



commit 0318020bae437cb8f6ec8dbcf68ed5e0a5ea95d0
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 29 21:12:12 2022 +0200

    goaprovider: Use /etc/goa.conf to disable features for providers
    
    A new goa.conf file in the system config directory (usually /etc/goa.conf)
    can be used to limit what features respective providers can use. It's a usual
    key file, with group name being the provider type and the keys being boolean
    switches to disable the respective features. Not setting the key or section
    results in the feature being enabled. An example:
    
    [google]
    mail=false
    
    The above will disable mail feature for the Google accounts. A special
    section name "all" can be used to cover every provider. The value in
    respective provider has a precedence, if it exists and contains a valid
    boolean value. A more complicated example can be:
    
    [google]
    calendar=true
    contacts=false
    
    [exchange]
    mail=true
    
    [all]
    calendar=false
    mail=false
    
    The above disables calendar for every provider except 'google', and it also
    disables mail for every provider except 'exchange'. The 'google' has
    disabled 'contacts' as well.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/issues/224

 src/goabackend/goaexchangeprovider.c    |  15 +++-
 src/goabackend/goafedoraprovider.c      |   9 +-
 src/goabackend/goagoogleprovider.c      |  24 ++++--
 src/goabackend/goaimapsmtpprovider.c    |  10 ++-
 src/goabackend/goakerberosprovider.c    |   9 +-
 src/goabackend/goalastfmprovider.c      |  10 ++-
 src/goabackend/goamediaserverprovider.c |   9 +-
 src/goabackend/goaowncloudprovider.c    |  15 +++-
 src/goabackend/goaprovider.c            | 147 +++++++++++++++++++++++++++++++-
 src/goabackend/goaprovider.h            |   4 +
 src/goabackend/goawindowsliveprovider.c |  10 ++-
 src/goabackend/meson.build              |   1 +
 12 files changed, 244 insertions(+), 19 deletions(-)
---
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index 46d43149..826549e1 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -86,6 +86,8 @@ build_object (GoaProvider         *provider,
   GoaExchange *exchange = NULL;
   GoaMail *mail = NULL;
   GoaPasswordBased *password_based = NULL;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   gboolean calendar_enabled;
   gboolean contacts_enabled;
   gboolean mail_enabled;
@@ -115,11 +117,14 @@ build_object (GoaProvider         *provider,
                         NULL);
     }
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
 
   /* Email */
   mail = goa_object_get_mail (GOA_OBJECT (object));
-  mail_enabled = g_key_file_get_boolean (key_file, group, "MailEnabled", NULL);
+  mail_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_MAIL) &&
+                 g_key_file_get_boolean (key_file, group, "MailEnabled", NULL);
   if (mail_enabled)
     {
       if (mail == NULL)
@@ -139,13 +144,17 @@ build_object (GoaProvider         *provider,
     }
 
   /* Calendar */
-  calendar_enabled = g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL);
+  calendar_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_CALENDAR) &&
+                     g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL);
   goa_object_skeleton_attach_calendar (object, NULL, calendar_enabled, FALSE);
 
   /* Contacts */
-  contacts_enabled = g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL);
+  contacts_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_CONTACTS) &&
+                     g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL);
   goa_object_skeleton_attach_contacts (object, NULL, contacts_enabled, FALSE);
 
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   /* Exchange */
   exchange = goa_object_get_exchange (GOA_OBJECT (object));
   if (exchange == NULL)
diff --git a/src/goabackend/goafedoraprovider.c b/src/goabackend/goafedoraprovider.c
index b8d1c6f7..14131893 100644
--- a/src/goabackend/goafedoraprovider.c
+++ b/src/goabackend/goafedoraprovider.c
@@ -348,6 +348,8 @@ build_object (GoaProvider         *provider,
 {
   GoaAccount   *account;
   GoaTicketing *ticketing = NULL;
+  GKeyFile     *goa_conf;
+  const gchar  *provider_type;
   gboolean      ticketing_enabled;
   gboolean      ret = FALSE;
 
@@ -360,10 +362,15 @@ build_object (GoaProvider         *provider,
                                                                             error))
     goto out;
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
 
   ticketing = goa_object_get_ticketing (GOA_OBJECT (object));
-  ticketing_enabled = g_key_file_get_boolean (key_file, group, "TicketingEnabled", NULL);
+  ticketing_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_TICKETING) &&
+                      g_key_file_get_boolean (key_file, group, "TicketingEnabled", NULL);
+
+  g_clear_pointer (&goa_conf, g_key_file_free);
 
   if (ticketing_enabled)
     {
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index 70f81aac..658b66c1 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -306,6 +306,8 @@ build_object (GoaProvider         *provider,
 {
   GoaAccount *account = NULL;
   GoaMail *mail = NULL;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   gchar *uri_caldav;
   gchar *uri_drive;
   gboolean ret = FALSE;
@@ -327,12 +329,15 @@ build_object (GoaProvider         *provider,
                                                                             error))
     goto out;
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
   email_address = goa_account_get_identity (account);
 
   /* Email */
   mail = goa_object_get_mail (GOA_OBJECT (object));
-  mail_enabled = g_key_file_get_boolean (key_file, group, "MailEnabled", NULL);
+  mail_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_MAIL) &&
+                 g_key_file_get_boolean (key_file, group, "MailEnabled", NULL);
   if (mail_enabled)
     {
       if (mail == NULL)
@@ -362,32 +367,39 @@ build_object (GoaProvider         *provider,
     }
 
   /* Calendar */
-  calendar_enabled = g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL);
+  calendar_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_CALENDAR) &&
+                     g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL);
   uri_caldav = g_strconcat ("https://apidata.googleusercontent.com/caldav/v2/";, email_address, "/user", 
NULL);
   goa_object_skeleton_attach_calendar (object, uri_caldav, calendar_enabled, FALSE);
   g_free (uri_caldav);
 
   /* Contacts */
-  contacts_enabled = g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL);
+  contacts_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_CONTACTS) &&
+                     g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL);
   goa_object_skeleton_attach_contacts (object,
                                        "https://www.googleapis.com/.well-known/carddav";,
                                        contacts_enabled,
                                        FALSE);
 
   /* Photos */
-  photos_enabled = g_key_file_get_boolean (key_file, group, "PhotosEnabled", NULL);
+  photos_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_PHOTOS) &&
+                   g_key_file_get_boolean (key_file, group, "PhotosEnabled", NULL);
   goa_object_skeleton_attach_photos (object, photos_enabled);
 
   /* Files */
-  files_enabled = g_key_file_get_boolean (key_file, group, "FilesEnabled", NULL);
+  files_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_FILES) 
&&
+                  g_key_file_get_boolean (key_file, group, "FilesEnabled", NULL);
   uri_drive = g_strconcat ("google-drive://", email_address, "/", NULL);
   goa_object_skeleton_attach_files (object, uri_drive, files_enabled, FALSE);
   g_free (uri_drive);
 
   /* Printers */
-  printers_enabled = g_key_file_get_boolean (key_file, group, "PrintersEnabled", NULL);
+  printers_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_PRINTERS) &&
+                     g_key_file_get_boolean (key_file, group, "PrintersEnabled", NULL);
   goa_object_skeleton_attach_printers (object, printers_enabled);
 
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   if (just_added)
     {
       goa_account_set_mail_disabled (account, !mail_enabled);
diff --git a/src/goabackend/goaimapsmtpprovider.c b/src/goabackend/goaimapsmtpprovider.c
index 811d48c9..abaa4d94 100644
--- a/src/goabackend/goaimapsmtpprovider.c
+++ b/src/goabackend/goaimapsmtpprovider.c
@@ -90,6 +90,8 @@ build_object (GoaProvider         *provider,
   GoaAccount *account = NULL;
   GoaMail *mail = NULL;
   GoaPasswordBased *password_based = NULL;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   gboolean enabled;
   gboolean imap_accept_ssl_errors;
   gboolean imap_use_ssl;
@@ -132,11 +134,17 @@ build_object (GoaProvider         *provider,
                         NULL);
     }
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
 
   /* Email */
   mail = goa_object_get_mail (GOA_OBJECT (object));
-  enabled = g_key_file_get_boolean (key_file, group, "Enabled", NULL);
+  enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_MAIL) &&
+            g_key_file_get_boolean (key_file, group, "Enabled", NULL);
+
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   if (enabled)
     {
       if (mail == NULL)
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index f4d28fd7..7aa03271 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -380,6 +380,8 @@ build_object (GoaProvider         *provider,
 {
   GoaAccount   *account;
   GoaTicketing *ticketing = NULL;
+  GKeyFile     *goa_conf;
+  const gchar  *provider_type;
   gboolean      ticketing_enabled;
   gboolean      ret = FALSE;
 
@@ -392,10 +394,15 @@ build_object (GoaProvider         *provider,
                                                                               error))
     goto out;
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
 
   ticketing = goa_object_get_ticketing (GOA_OBJECT (object));
-  ticketing_enabled = g_key_file_get_boolean (key_file, group, "TicketingEnabled", NULL);
+  ticketing_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_TICKETING) &&
+                      g_key_file_get_boolean (key_file, group, "TicketingEnabled", NULL);
+
+  g_clear_pointer (&goa_conf, g_key_file_free);
 
   if (ticketing_enabled)
     {
diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c
index 15a2d745..575108d8 100644
--- a/src/goabackend/goalastfmprovider.c
+++ b/src/goabackend/goalastfmprovider.c
@@ -100,6 +100,8 @@ build_object (GoaProvider         *provider,
 {
   GoaAccount *account;
   GoaMusic *music = NULL;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   gboolean music_enabled;
   gboolean ret = FALSE;
 
@@ -115,11 +117,17 @@ build_object (GoaProvider         *provider,
                                                                             error))
     goto out;
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
 
   /* Music */
   music = goa_object_get_music (GOA_OBJECT (object));
-  music_enabled = g_key_file_get_boolean (key_file, group, "MusicEnabled", NULL);
+  music_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_MUSIC) 
&&
+                  g_key_file_get_boolean (key_file, group, "MusicEnabled", NULL);
+
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   if (music_enabled)
     {
       if (music == NULL)
diff --git a/src/goabackend/goamediaserverprovider.c b/src/goabackend/goamediaserverprovider.c
index 9ffd2a06..7c2d61ca 100644
--- a/src/goabackend/goamediaserverprovider.c
+++ b/src/goabackend/goamediaserverprovider.c
@@ -88,6 +88,8 @@ build_object (GoaProvider        *provider,
   gboolean ret;
   GoaAccount *account;
   GoaMediaServer *mediaserver;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   const gchar *udn;
   gboolean photos_enabled;
 
@@ -106,13 +108,18 @@ build_object (GoaProvider        *provider,
                                                                                   error))
     goto out;
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
   udn = goa_account_get_identity (account);
 
   /* Photos */
-  photos_enabled = g_key_file_get_boolean (key_file, group, "PhotosEnabled", NULL);
+  photos_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_PHOTOS) &&
+                   g_key_file_get_boolean (key_file, group, "PhotosEnabled", NULL);
   goa_object_skeleton_attach_photos (object, photos_enabled);
 
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   /* Media Server */
   mediaserver = goa_object_get_media_server (GOA_OBJECT (object));
   if (mediaserver == NULL)
diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
index 10734beb..0ec38566 100644
--- a/src/goabackend/goaowncloudprovider.c
+++ b/src/goabackend/goaowncloudprovider.c
@@ -136,6 +136,8 @@ build_object (GoaProvider         *provider,
   gchar *uri_webdav;
   GoaPasswordBased *password_based = NULL;
   GUri *uri = NULL;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   gboolean accept_ssl_errors;
   gboolean calendar_enabled;
   gboolean contacts_enabled;
@@ -168,6 +170,8 @@ build_object (GoaProvider         *provider,
                         NULL);
     }
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
   identity = goa_account_get_identity (account);
   uri_string = g_key_file_get_string (key_file, group, "Uri", NULL);
@@ -193,23 +197,28 @@ build_object (GoaProvider         *provider,
   accept_ssl_errors = g_key_file_get_boolean (key_file, group, "AcceptSslErrors", NULL);
 
   /* Calendar */
-  calendar_enabled = g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL);
+  calendar_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_CALENDAR) &&
+                     g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL);
   uri_caldav = uri_to_string_with_path (uri, CALDAV_ENDPOINT);
   goa_object_skeleton_attach_calendar (object, uri_caldav, calendar_enabled, accept_ssl_errors);
   g_free (uri_caldav);
 
   /* Contacts */
-  contacts_enabled = g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL);
+  contacts_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, 
GOA_PROVIDER_FEATURE_CONTACTS) &&
+                     g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL);
   uri_carddav = uri_to_string_with_path (uri, CARDDAV_ENDPOINT);
   goa_object_skeleton_attach_contacts (object, uri_carddav, contacts_enabled, accept_ssl_errors);
   g_free (uri_carddav);
 
   /* Files */
-  files_enabled = g_key_file_get_boolean (key_file, group, "FilesEnabled", NULL);
+  files_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_FILES) 
&&
+                  g_key_file_get_boolean (key_file, group, "FilesEnabled", NULL);
   uri_webdav = get_webdav_uri (uri);
   goa_object_skeleton_attach_files (object, uri_webdav, files_enabled, accept_ssl_errors);
   g_free (uri_webdav);
 
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   if (just_added)
     {
       goa_account_set_calendar_disabled (account, !calendar_enabled);
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 7996150e..89e01f10 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -373,6 +373,151 @@ goa_provider_get_provider_group (GoaProvider *self)
   return GOA_PROVIDER_GET_CLASS (self)->get_provider_group (self);
 }
 
+static const gchar *
+goa_get_feature_alias (GoaProviderFeatures feature)
+{
+  switch (feature) {
+  case GOA_PROVIDER_FEATURE_MAIL:
+    return "mail";
+  case GOA_PROVIDER_FEATURE_CALENDAR:
+    return "calendar";
+  case GOA_PROVIDER_FEATURE_CONTACTS:
+    return "contacts";
+  case GOA_PROVIDER_FEATURE_CHAT:
+    return "chat";
+  case GOA_PROVIDER_FEATURE_DOCUMENTS:
+    return "documents";
+  case GOA_PROVIDER_FEATURE_PHOTOS:
+    return "photos";
+  case GOA_PROVIDER_FEATURE_FILES:
+    return "files";
+  case GOA_PROVIDER_FEATURE_TICKETING:
+    return "ticketing";
+  case GOA_PROVIDER_FEATURE_READ_LATER:
+    return "read-later";
+  case GOA_PROVIDER_FEATURE_PRINTERS:
+    return "printers";
+  case GOA_PROVIDER_FEATURE_MAPS:
+    return "maps";
+  case GOA_PROVIDER_FEATURE_MUSIC:
+    return "music";
+  case GOA_PROVIDER_FEATURE_TODO:
+    return "todo";
+  case GOA_PROVIDER_FEATURE_BRANDED:
+  case GOA_PROVIDER_FEATURE_INVALID:
+    break;
+  }
+  return NULL;
+}
+
+/**
+ * goa_util_open_goa_conf:
+ *
+ * Reads goa.conf file from the system config directory and
+ * returns it for use for example by goa_util_provider_feature_is_enabled().
+ * It returns %NULL, when the file cannot be opened.
+ *
+ * Free the returned #GKeyFile with g_key_file_free(), when no longer needed.
+ *
+ * Returns: (nullable) (transfer full): a new #GKeyFile containing goa.conf
+ *    file, or %NULL, when it cannot be opened.
+ *
+ * Since: 3.48
+ */
+GKeyFile *
+goa_util_open_goa_conf (void)
+{
+  GKeyFile *goa_conf;
+  GError *error = NULL;
+
+  goa_conf = g_key_file_new ();
+  if (!g_key_file_load_from_file (goa_conf, GOA_CONF_FILENAME, G_KEY_FILE_NONE, &error))
+    {
+      g_debug ("Failed to load '%s': %s", GOA_CONF_FILENAME, error ? error->message : "Unknown error");
+      g_clear_error (&error);
+      g_key_file_free (goa_conf);
+      goa_conf = NULL;
+    }
+
+  return goa_conf;
+}
+
+/**
+ * goa_util_provider_feature_is_enabled:
+ * @goa_conf: (nullable): a #GKeyFile with loaded goa.conf file, or %NULL
+ * @provider_type: a provider type string
+ * @feature: a feature to check, one of %GoaProviderFeatures
+ *
+ * Checks in the @goa_conf, whether the @provider_type can use
+ * the @feature. The @goa_conf is a %GKeyFile returned by
+ * goa_util_open_goa_conf(), it can be %NULL, in which case
+ * the @feature is considered enabled.
+ *
+ * Returns: %TRUE, when the @feature is enabled, %FALSE otherwise
+ *
+ * Since: 3.48
+ */
+gboolean
+goa_util_provider_feature_is_enabled (GKeyFile *goa_conf,
+                                     const gchar *provider_type,
+                                     GoaProviderFeatures feature)
+{
+  GError *error = NULL;
+  const gchar *feature_alias;
+  gboolean enabled;
+
+  if (!goa_conf)
+    return TRUE;
+
+  g_return_val_if_fail (provider_type != NULL, TRUE);
+
+  feature_alias = goa_get_feature_alias (feature);
+  g_return_val_if_fail (feature_alias != NULL, TRUE);
+
+  enabled = g_key_file_get_boolean (goa_conf, provider_type, feature_alias, &error);
+  if (error)
+    {
+      g_clear_error (&error);
+      enabled = g_key_file_get_boolean (goa_conf, "all", feature_alias, &error);
+      if (error)
+        {
+          g_clear_error (&error);
+          enabled = TRUE;
+        }
+    }
+
+  return enabled;
+}
+
+static GoaProviderFeatures
+goa_provider_filter_features (GoaProvider *self,
+                             GoaProviderFeatures features)
+{
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
+  guint i;
+
+  goa_conf = goa_util_open_goa_conf ();
+  if (!goa_conf)
+    return features;
+
+  provider_type = goa_provider_get_provider_type (self);
+
+  for (i = 0; provider_features_info[i].property != NULL; i++)
+    {
+      GoaProviderFeatures feature = provider_features_info[i].feature;
+      if ((features & feature) != 0 &&
+         !goa_util_provider_feature_is_enabled (goa_conf, provider_type, feature))
+        {
+          features = features & (~feature);
+        }
+    }
+
+  g_key_file_free (goa_conf);
+
+  return features;
+}
+
 /**
  * goa_provider_get_provider_features:
  * @self: A #GoaProvider.
@@ -389,7 +534,7 @@ goa_provider_get_provider_features (GoaProvider *self)
 {
   g_return_val_if_fail (GOA_IS_PROVIDER (self), GOA_PROVIDER_FEATURE_INVALID);
   g_return_val_if_fail (GOA_PROVIDER_GET_CLASS (self)->get_provider_features != NULL, 
GOA_PROVIDER_FEATURE_INVALID);
-  return GOA_PROVIDER_GET_CLASS (self)->get_provider_features (self);
+  return goa_provider_filter_features (self, GOA_PROVIDER_GET_CLASS (self)->get_provider_features (self));
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index c4bcf91c..c26ca7a6 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -108,6 +108,10 @@ GtkWidget *goa_util_add_row_switch_from_keyfile_with_blurb (GtkGrid      *grid,
                                                             const gchar  *label_text,
                                                             const gchar  *key,
                                                             const gchar  *blurb);
+GKeyFile *     goa_util_open_goa_conf                  (void);
+gboolean       goa_util_provider_feature_is_enabled    (GKeyFile *goa_conf,
+                                                        const gchar *provider_type,
+                                                        GoaProviderFeatures feature);
 
 G_END_DECLS
 
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index 608767a3..466718c2 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -273,6 +273,8 @@ build_object (GoaProvider         *provider,
 {
   GoaAccount *account = NULL;
   GoaMail *mail = NULL;
+  GKeyFile *goa_conf;
+  const gchar *provider_type;
   gboolean mail_enabled;
   gboolean ret = FALSE;
   const gchar *email_address;
@@ -287,12 +289,18 @@ build_object (GoaProvider         *provider,
                                                                               error))
     goto out;
 
+  provider_type = goa_provider_get_provider_type (provider);
+  goa_conf = goa_util_open_goa_conf ();
   account = goa_object_get_account (GOA_OBJECT (object));
   email_address = goa_account_get_presentation_identity (account);
 
   /* Email */
   mail = goa_object_get_mail (GOA_OBJECT (object));
-  mail_enabled = g_key_file_get_boolean (key_file, group, "MailEnabled", NULL);
+  mail_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_MAIL) &&
+                 g_key_file_get_boolean (key_file, group, "MailEnabled", NULL);
+
+  g_clear_pointer (&goa_conf, g_key_file_free);
+
   if (mail_enabled)
     {
       if (mail == NULL)
diff --git a/src/goabackend/meson.build b/src/goabackend/meson.build
index f5382b34..17325cd7 100644
--- a/src/goabackend/meson.build
+++ b/src/goabackend/meson.build
@@ -97,6 +97,7 @@ cflags = [
   '-DG_LOG_DOMAIN="GoaBackend"',
   '-DGOA_API_IS_SUBJECT_TO_CHANGE',
   '-DGOA_BACKEND_COMPILATION',
+  '-DGOA_CONF_FILENAME="@0@"'.format(join_paths(get_option('sysconfdir'), 'goa.conf')),
   '-DPACKAGE_LOCALE_DIR="@0@"'.format(goa_localedir),
   '-DPACKAGE_WEB_EXTENSIONS_DIR="@0@"'.format(join_paths(goa_pkglibdir, 'web-extensions'))
 ]


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