[libgdata/wip/pwithnall/calendar-acls] calendar: WIP work to support v3 ACLs



commit db1ba535fb1c13d38f2db7169bcc259b29971b12
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu May 14 13:42:55 2015 +0100

    calendar: WIP work to support v3 ACLs

 .../services/calendar/gdata-calendar-access-rule.c |  189 ++++++++++++++++++++
 .../services/calendar/gdata-calendar-access-rule.h |  120 +++++++++++++
 gdata/services/calendar/gdata-calendar-calendar.h  |   46 -----
 3 files changed, 309 insertions(+), 46 deletions(-)
---
diff --git a/gdata/services/calendar/gdata-calendar-access-rule.c 
b/gdata/services/calendar/gdata-calendar-access-rule.c
new file mode 100644
index 0000000..0173f52
--- /dev/null
+++ b/gdata/services/calendar/gdata-calendar-access-rule.c
@@ -0,0 +1,189 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2015 <philip tecnocode co uk>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * SECTION:gdata-calendar-access-rule
+ * @short_description: GData Calendar access rule object
+ * @stability: Stable
+ * @include: gdata/services/calendar/gdata-access-rule.h
+ *
+ * #GDataCalendarAccessRule is a subclass of #GDataAccessRule to represent a TODO generic access rule from 
an access control list (ACL).
+ * It is returned by the ACL methods implemented in the #GDataAccessHandler interface.
+ *
+ * Access rules should be inserted to the %GDATA_LINK_ACCESS_CONTROL_LIST URI of the feed or entry they 
should be applied to. This will return a
+ * %GDATA_SERVICE_ERROR_CONFLICT error if a rule already exists on that feed or entry for that scope type 
and value.
+ *
+ * TODO
+ * <example>
+ *     <title>Adding a Rule to the Access Control List for an Entry</title>
+ *     <programlisting>
+ *     GDataService *service;
+ *     GDataEntry *entry;
+ *     GDataFeed *acl_feed;
+ *     GDataAccessRule *rule, *new_rule;
+ *     GError *error = NULL;
+ *
+ *     /<!-- -->* Retrieve a GDataEntry which will have a new rule inserted into its ACL. *<!-- -->/
+ *     service = build_my_service ();
+ *     entry = get_the_entry (service);
+ *
+ *     /<!-- -->* Create and insert a new access rule for example gmail com which grants them _no_ 
permissions on the entry.
+ *      * In a real application, the GDataEntry subclass would define its own access roles which are more 
useful. For example,
+ *      * GDataDocumentsEntry defines access roles for users who can read (but not write) a Google Document, 
and users who
+ *      * can also write to the document. *<!-- -->/
+ *     rule = gdata_access_rule_new (NULL);
+ *     gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE); /<!-- -->* or, for example, 
GDATA_DOCUMENTS_ACCESS_ROLE_READER *<!-- -->/
+ *     gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "example gmail com"); /<!-- -->* e-mail 
address of the user the ACL applies to *<!-- -->/
+ *
+ *     acl_link = gdata_entry_look_up_link (entry, GDATA_LINK_ACCESS_CONTROL_LIST);
+ *     new_rule = GDATA_ACCESS_RULE (gdata_service_insert_entry (GDATA_SERVICE (service), gdata_link_get_uri 
(acl_link), GDATA_ENTRY (rule),
+ *                                                               NULL, &error));
+ *     g_object_unref (acl_link);
+ *
+ *     g_object_unref (rule);
+ *     g_object_unref (entry);
+ *     g_object_unref (service);
+ *
+ *     if (error != NULL) {
+ *             g_error ("Error inserting access rule: %s", error->message);
+ *             g_error_free (error);
+ *             return;
+ *     }
+ *
+ *     /<!-- -->* Potentially do something with the new_rule here, such as store its ID for later use. *<!-- 
-->/
+ *
+ *     g_object_unref (new_rule);
+ *     </programlisting>
+ * </example>
+ *
+ * Since: UNRELEASED
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
+#include "gdata-access-rule.h"
+#include "gdata-parser.h"
+#include "gdata-types.h"
+#include "gdata-private.h"
+
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data,
+            GError **error);
+static gboolean
+post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error);
+
+G_DEFINE_TYPE (GDataCalendarAccessRule, gdata_calendar_access_rule,
+               GDATA_TYPE_ACCESS_RULE)
+
+static void
+gdata_calendar_access_rule_class_init (GDataAccessRuleClass *klass)
+{
+       GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+       GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
+
+       parsable_class->parse_json = parse_json;
+       parsable_class->post_parse_json = post_parse_json;
+
+       entry_class->kind_term = "calendar#aclRule";
+}
+
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
+{
+       GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
+       gboolean success;
+       gchar *scope_type = NULL;
+
+       if (gdata_parser_string_from_json_member (reader, "authKey", P_REQUIRED | P_NON_EMPTY, &(priv->key), 
&success, error) == TRUE ||
+           gdata_parser_string_from_json_member (reader, "emailAddress", P_REQUIRED | P_NON_EMPTY, 
&(priv->email), &success, error) == TRUE ||
+           gdata_parser_string_from_json_member (reader, "domain", P_REQUIRED | P_NON_EMPTY, 
&(priv->domain), &success, error) == TRUE ||
+           gdata_parser_string_from_json_member (reader, "role", P_REQUIRED | P_NON_EMPTY, &(priv->role), 
&success, error) == TRUE) {
+               return success;
+       } else if (gdata_parser_string_from_json_member (reader, "type", P_REQUIRED | P_NON_EMPTY, 
&scope_type, &success, error) == TRUE) {
+               if (g_strcmp0 (scope_type, "anyone") == 0) {
+                       priv->scope_type = g_strdup (GDATA_ACCESS_SCOPE_DEFAULT);
+               } else {
+                       priv->scope_type = scope_type;
+                       scope_type = NULL;
+               }
+
+               g_free (scope_type);
+               return success;
+       }
+
+       return GDATA_PARSABLE_CLASS (gdata_calendar_access_rule_parent_class)->parse_json (parsable, reader, 
user_data, error);
+}
+
+static gboolean
+post_parse_json (GDataParsable *parsable, gpointer user_data, GError **error)
+{
+       GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
+
+       if (g_strcmp0 (priv->scope_type, "group") == 0 || g_strcmp0 (priv->scope_type, "user") == 0) {
+               if (priv->email == NULL || priv->email[0] == '\0') {
+                       g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING,
+                                    /* Translators: the parameter is an error message */
+                                    _("Error parsing JSON: %s"),
+                                    "Permission type ‘group’ or ‘user’ needs an ‘emailAddress’ property.");
+                       return FALSE;
+               } else {
+                       priv->scope_value = priv->email;
+                       priv->email = NULL;
+               }
+       } else if (g_strcmp0 (priv->scope_type, "domain") == 0) {
+               if (priv->domain == NULL || priv->domain[0] == '\0') {
+                       g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING,
+                                    /* Translators: the parameter is an error message */
+                                    _("Error parsing JSON: %s"),
+                                    "Permission type ‘domain’ needs a ‘domain’ property.");
+                       return FALSE;
+               } else {
+                       priv->scope_value = priv->domain;
+                       priv->domain = NULL;
+               }
+       }
+
+       return TRUE;
+}
+
+/**
+ * gdata_calendar_access_rule_new:
+ * @id: the access rule's ID, or %NULL
+ *
+ * Creates a new #GDataCalendarAccessRule with the given ID and default
+ * properties.
+ *
+ * Return value: (transfer null): a new #GDataCalendarAccessRule; unref with
+ *   g_object_unref()
+ *
+ * Since: UNRELEASED
+ */
+GDataCalendarAccessRule *
+gdata_calendar_access_rule_new (const gchar *id)
+{
+       GObject *retval = NULL;  /* owned */
+
+       retval = g_object_new (GDATA_TYPE_CALENDAR_ACCESS_RULE,
+                              "id", id,
+                              NULL);
+       return GDATA_CALENDAR_ACCESS_RULE (retval);
+}
diff --git a/gdata/services/calendar/gdata-calendar-access-rule.h 
b/gdata/services/calendar/gdata-calendar-access-rule.h
new file mode 100644
index 0000000..94419c3
--- /dev/null
+++ b/gdata/services/calendar/gdata-calendar-access-rule.h
@@ -0,0 +1,120 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * GData Client
+ * Copyright (C) Philip Withnall 2015 <philip tecnocode co uk>
+ *
+ * GData Client is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GData Client is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GDATA_CALENDAR_ACCESS_RULE_H
+#define GDATA_CALENDAR_ACCESS_RULE_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gdata/gdata-access-rule.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GDATA_CALENDAR_ACCESS_ROLE_READ:
+ *
+ * The users specified by the #GDataAccessRule have read-only access to the calendar.
+ *
+ * Since: 0.7.0
+ */
+#define GDATA_CALENDAR_ACCESS_ROLE_READ "http://schemas.google.com/gCal/2005#read";
+
+/**
+ * GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY:
+ *
+ * The users specified by the #GDataAccessRule can only see the free/busy information on the calendar; not 
event details.
+ *
+ * Since: 0.7.0
+ */
+#define GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY "http://schemas.google.com/gCal/2005#freebusy";
+
+/**
+ * GDATA_CALENDAR_ACCESS_ROLE_EDITOR:
+ *
+ * The users specified by the #GDataAccessRule have full edit access to the calendar, except they can't 
change the calendar's access rules.
+ *
+ * Since: 0.7.0
+ */
+#define GDATA_CALENDAR_ACCESS_ROLE_EDITOR "http://schemas.google.com/gCal/2005#editor";
+
+/**
+ * GDATA_CALENDAR_ACCESS_ROLE_OWNER:
+ *
+ * The users specified by the #GDataAccessRule have full owner access to the calendar.
+ *
+ * Since: 0.7.0
+ */
+#define GDATA_CALENDAR_ACCESS_ROLE_OWNER "http://schemas.google.com/gCal/2005#owner";
+
+/**
+ * GDATA_CALENDAR_ACCESS_ROLE_ROOT:
+ *
+ * The users specified by the #GDataAccessRule have full administrator access to the calendar server.
+ * This is only available in Google Apps For Your Domain.
+ *
+ * Since: 0.7.0
+ */
+#define GDATA_CALENDAR_ACCESS_ROLE_ROOT "http://schemas.google.com/gCal/2005#root";
+
+#define GDATA_TYPE_CALENDAR_ACCESS_RULE                (gdata_calendar_access_rule_get_type ())
+#define GDATA_CALENDAR_ACCESS_RULE(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), 
GDATA_TYPE_CALENDAR_ACCESS_RULE, GDataCalendarAccessRule))
+#define GDATA_CALENDAR_ACCESS_RULE_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), 
GDATA_TYPE_CALENDAR_ACCESS_RULE, GDataCalendarAccessRuleClass))
+#define GDATA_IS_CALENDAR_ACCESS_RULE(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), 
GDATA_TYPE_CALENDAR_ACCESS_RULE))
+#define GDATA_IS_CALENDAR_ACCESS_RULE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), 
GDATA_TYPE_CALENDAR_ACCESS_RULE))
+#define GDATA_CALENDAR_ACCESS_RULE_GET_CLASS(o)        (G_TYPE_INSTANCE_GET_CLASS ((o), 
GDATA_TYPE_CALENDAR_ACCESS_RULE, GDataCalendarAccessRuleClass))
+
+/**
+ * GDataAccessRule:
+ *
+ * All the fields in the #GDataCalendarAccessRule structure are private and
+ * should never be accessed directly.
+ *
+ * Since: UNRELEASED
+ */
+typedef struct {
+       GDataAccessRule parent;
+} GDataCalendarAccessRule;
+
+/**
+ * GDataCalendarAccessRuleClass:
+ *
+ * All the fields in the #GDataCalendarAccessRuleClass structure are private
+ * and should never be accessed directly.
+ *
+ * Since: UNRELEASED
+ */
+typedef struct {
+       /*< private >*/
+       GDataAccessRuleClass parent;
+
+       /*< private >*/
+       /* Padding for future expansion */
+       void (*_g_reserved0) (void);
+       void (*_g_reserved1) (void);
+} GDataAccessRuleClass;
+
+GType gdata_calendar_access_rule_get_type (void) G_GNUC_CONST;
+
+GDataAccessRule *
+gdata_calendar_access_rule_new (const gchar *id) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+
+G_END_DECLS
+
+#endif /* !GDATA_CALENDAR_ACCESS_RULE_H */
diff --git a/gdata/services/calendar/gdata-calendar-calendar.h 
b/gdata/services/calendar/gdata-calendar-calendar.h
index 37a368f..01106e2 100644
--- a/gdata/services/calendar/gdata-calendar-calendar.h
+++ b/gdata/services/calendar/gdata-calendar-calendar.h
@@ -28,52 +28,6 @@
 
 G_BEGIN_DECLS
 
-/**
- * GDATA_CALENDAR_ACCESS_ROLE_READ:
- *
- * The users specified by the #GDataAccessRule have read-only access to the calendar.
- *
- * Since: 0.7.0
- **/
-#define GDATA_CALENDAR_ACCESS_ROLE_READ "http://schemas.google.com/gCal/2005#read";
-
-/**
- * GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY:
- *
- * The users specified by the #GDataAccessRule can only see the free/busy information on the calendar; not 
event details.
- *
- * Since: 0.7.0
- **/
-#define GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY "http://schemas.google.com/gCal/2005#freebusy";
-
-/**
- * GDATA_CALENDAR_ACCESS_ROLE_EDITOR:
- *
- * The users specified by the #GDataAccessRule have full edit access to the calendar, except they can't 
change the calendar's access rules.
- *
- * Since: 0.7.0
- **/
-#define GDATA_CALENDAR_ACCESS_ROLE_EDITOR "http://schemas.google.com/gCal/2005#editor";
-
-/**
- * GDATA_CALENDAR_ACCESS_ROLE_OWNER:
- *
- * The users specified by the #GDataAccessRule have full owner access to the calendar.
- *
- * Since: 0.7.0
- **/
-#define GDATA_CALENDAR_ACCESS_ROLE_OWNER "http://schemas.google.com/gCal/2005#owner";
-
-/**
- * GDATA_CALENDAR_ACCESS_ROLE_ROOT:
- *
- * The users specified by the #GDataAccessRule have full administrator access to the calendar server.
- * This is only available in Google Apps For Your Domain.
- *
- * Since: 0.7.0
- **/
-#define GDATA_CALENDAR_ACCESS_ROLE_ROOT "http://schemas.google.com/gCal/2005#root";
-
 #define GDATA_TYPE_CALENDAR_CALENDAR           (gdata_calendar_calendar_get_type ())
 #define GDATA_CALENDAR_CALENDAR(o)             (G_TYPE_CHECK_INSTANCE_CAST ((o), 
GDATA_TYPE_CALENDAR_CALENDAR, GDataCalendarCalendar))
 #define GDATA_CALENDAR_CALENDAR_CLASS(k)       (G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_CALENDAR_CALENDAR, 
GDataCalendarCalendarClass))


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