[libgdata] [core] Add #defines for GDataAccessRule-related things



commit 464988fc97a1aaa9eebcd8657626a0dab6f33597
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Mar 26 22:57:27 2010 +0000

    [core] Add #defines for GDataAccessRule-related things
    
    from the new defines, which are split across the gAcl, Google Calendar and
    Google Documents namespaces.

 docs/reference/gdata-sections.txt                 |   12 +++++
 gdata/gdata-access-rule.c                         |   17 +++++---
 gdata/gdata-access-rule.h                         |   36 ++++++++++++++++
 gdata/services/calendar/gdata-calendar-calendar.c |    6 ++-
 gdata/services/calendar/gdata-calendar-calendar.h |   46 +++++++++++++++++++++
 gdata/services/documents/gdata-documents-entry.c  |    6 ++-
 gdata/services/documents/gdata-documents-entry.h  |   28 +++++++++++++
 gdata/services/youtube/gdata-youtube-video.h      |    2 +-
 gdata/tests/calendar.c                            |   20 +++++-----
 gdata/tests/documents.c                           |    4 +-
 gdata/tests/general.c                             |    6 +-
 11 files changed, 159 insertions(+), 24 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 3945ef6..be880d5 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -448,6 +448,11 @@ GDataCalendarQueryPrivate
 <SECTION>
 <FILE>gdata-calendar-calendar</FILE>
 <TITLE>GDataCalendarCalendar</TITLE>
+GDATA_CALENDAR_ACCESS_ROLE_READ
+GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY
+GDATA_CALENDAR_ACCESS_ROLE_EDITOR
+GDATA_CALENDAR_ACCESS_ROLE_OWNER
+GDATA_CALENDAR_ACCESS_ROLE_ROOT
 GDataCalendarCalendar
 GDataCalendarCalendarClass
 gdata_calendar_calendar_new
@@ -607,6 +612,10 @@ GDATA_TYPE_ACCESS_HANDLER
 <SECTION>
 <FILE>gdata-access-rule</FILE>
 <TITLE>GDataAccessRule</TITLE>
+GDATA_ACCESS_SCOPE_USER
+GDATA_ACCESS_SCOPE_DOMAIN
+GDATA_ACCESS_SCOPE_DEFAULT
+GDATA_ACCESS_ROLE_NONE
 GDataAccessRule
 GDataAccessRuleClass
 gdata_access_rule_new
@@ -1408,6 +1417,9 @@ GDataPicasaWebFilePrivate
 <SECTION>
 <FILE>gdata-documents-entry</FILE>
 <TITLE>GDataDocumentsEntry</TITLE>
+GDATA_DOCUMENTS_ACCESS_ROLE_OWNER
+GDATA_DOCUMENTS_ACCESS_ROLE_ROOT
+GDATA_DOCUMENTS_ACCESS_ROLE_READER
 GDataDocumentsEntry
 GDataDocumentsEntryClass
 gdata_documents_entry_get_path
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index ea77bd8..756680a 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -83,27 +83,28 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
 	/**
 	 * GDataAccessRule:role:
 	 *
-	 * The role of the person concerned by this ACL.
+	 * The role of the person concerned by this ACL. By default, this can only be %GDATA_ACCESS_ROLE_NONE. Services may extend it with
+	 * their own namespaced roles.
 	 *
 	 * Since: 0.3.0
 	 **/
 	g_object_class_install_property (gobject_class, PROP_ROLE,
 				g_param_spec_string ("role",
 					"Role", "The role of the person concerned by this ACL.",
-					NULL,
+					GDATA_ACCESS_ROLE_NONE,
 					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
 	/**
 	 * GDataAccessRule:scope-type:
 	 *
-	 * Specifies to whom this access rule applies.
+	 * Specifies to whom this access rule applies. For example, %GDATA_ACCESS_SCOPE_USER or %GDATA_ACCESS_SCOPE_DEFAULT.
 	 *
 	 * Since: 0.3.0
 	 **/
 	g_object_class_install_property (gobject_class, PROP_SCOPE_TYPE,
 				g_param_spec_string ("scope-type",
 					"Scope type", "Specifies to whom this access rule applies.",
-					NULL,
+					GDATA_ACCESS_SCOPE_DEFAULT,
 					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
 	/**
@@ -156,6 +157,10 @@ gdata_access_rule_new (const gchar *id)
 	 * setting it from parse_xml() to fail (duplicate element). */
 	g_get_current_time (&(rule->priv->edited));
 
+	/* Set up the role and scope type */
+	rule->priv->role = g_strdup (GDATA_ACCESS_ROLE_NONE);
+	rule->priv->scope_type = g_strdup (GDATA_ACCESS_SCOPE_DEFAULT);
+
 	return rule;
 }
 
@@ -255,7 +260,7 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 
 			scope_value = xmlGetProp (node, (xmlChar*) "value");
 
-			if (xmlStrcmp (scope_type, (xmlChar*) "default") == 0 && scope_value == NULL) {
+			if (xmlStrcmp (scope_type, (xmlChar*) GDATA_ACCESS_SCOPE_DEFAULT) == 0 && scope_value == NULL) {
 				xmlFree (scope_type);
 				return gdata_parser_error_required_property_missing (node, "value", error);
 			}
@@ -372,7 +377,7 @@ gdata_access_rule_set_scope (GDataAccessRule *self, const gchar *type, const gch
 {
 	g_return_if_fail (GDATA_IS_ACCESS_RULE (self));
 	g_return_if_fail (type != NULL);
-	g_return_if_fail ((strcmp (type, "default") == 0 && value == NULL) || value != NULL);
+	g_return_if_fail ((strcmp (type, GDATA_ACCESS_SCOPE_DEFAULT) == 0 && value == NULL) || value != NULL);
 
 	g_free (self->priv->scope_type);
 	self->priv->scope_type = g_strdup (type);
diff --git a/gdata/gdata-access-rule.h b/gdata/gdata-access-rule.h
index 8a8510c..f39d5c6 100644
--- a/gdata/gdata-access-rule.h
+++ b/gdata/gdata-access-rule.h
@@ -28,6 +28,42 @@
 
 G_BEGIN_DECLS
 
+/**
+ * GDATA_ACCESS_SCOPE_USER:
+ *
+ * The #GDataAccessRule applies to a single individual, whose e-mail address is given in #GDataAccessRule:scope-value.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_ACCESS_SCOPE_USER "user"
+
+/**
+ * GDATA_ACCESS_SCOPE_DOMAIN:
+ *
+ * The #GDataAccessRule applies to all users in a Google Apps For Your Domain domain, given in #GDataAccessRule:scope-value.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_ACCESS_SCOPE_DOMAIN "domain"
+
+/**
+ * GDATA_ACCESS_SCOPE_DEFAULT:
+ *
+ * The #GDataAccessRule applies to all users.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_ACCESS_SCOPE_DEFAULT "default"
+
+/**
+ * GDATA_ACCESS_ROLE_NONE:
+ *
+ * The users specified by the #GDataAccessRule have no rights.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_ACCESS_ROLE_NONE "none"
+
 #define GDATA_TYPE_ACCESS_RULE		(gdata_access_rule_get_type ())
 #define GDATA_ACCESS_RULE(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_ACCESS_RULE, GDataAccessRule))
 #define GDATA_ACCESS_RULE_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_ACCESS_RULE, GDataAccessRuleClass))
diff --git a/gdata/services/calendar/gdata-calendar-calendar.c b/gdata/services/calendar/gdata-calendar-calendar.c
index b7ada7d..425422a 100644
--- a/gdata/services/calendar/gdata-calendar-calendar.c
+++ b/gdata/services/calendar/gdata-calendar-calendar.c
@@ -25,6 +25,10 @@
  *
  * #GDataCalendarCalendar is a subclass of #GDataEntry to represent a calendar from Google Calendar.
  *
+ * #GDataCalendarCalendar implements #GDataAccessHandler, meaning the access rules to it can be modified using that interface. As well as the
+ * access roles defined for the base #GDataAccessRule (e.g. %GDATA_ACCESS_ROLE_NONE), #GDataCalendarCalendar has its own, such as
+ * %GDATA_CALENDAR_ACCESS_ROLE_EDITOR and %GDATA_CALENDAR_ACCESS_ROLE_FREE_BUSY.
+ *
  * For more details of Google Calendar's GData API, see the <ulink type="http" url="http://code.google.com/apis/calendar/docs/2.0/reference.html";>
  * online documentation</ulink>.
  **/
@@ -184,7 +188,7 @@ gdata_calendar_calendar_init (GDataCalendarCalendar *self)
 static gboolean
 is_owner_rule (GDataAccessRule *rule)
 {
-	return (strcmp (gdata_access_rule_get_role (rule), "http://schemas.google.com/gCal/2005#owner";) == 0) ? TRUE : FALSE;
+	return (strcmp (gdata_access_rule_get_role (rule), GDATA_CALENDAR_ACCESS_ROLE_OWNER) == 0) ? TRUE : FALSE;
 }
 
 static void
diff --git a/gdata/services/calendar/gdata-calendar-calendar.h b/gdata/services/calendar/gdata-calendar-calendar.h
index 5c626bb..d2b8941 100644
--- a/gdata/services/calendar/gdata-calendar-calendar.h
+++ b/gdata/services/calendar/gdata-calendar-calendar.h
@@ -28,6 +28,52 @@
 
 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))
diff --git a/gdata/services/documents/gdata-documents-entry.c b/gdata/services/documents/gdata-documents-entry.c
index 0b6e0bf..6271293 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -26,6 +26,10 @@
  * #GDataDocumentsEntry is a subclass of #GDataEntry to represent a Google Documents entry, which is then further subclassed
  * to give specific document types.
  *
+ * #GDataDocumentsEntry implements #GDataAccessHandler, meaning the access rules to it can be modified using that interface. As well as the
+ * access roles defined for the base #GDataAccessRule (e.g. %GDATA_ACCESS_ROLE_NONE), #GDataDocumentsEntry has its own, such as
+ * %GDATA_DOCUMENTS_ACCESS_ROLE_OWNER and %GDATA_DOCUMENTS_ACCESS_ROLE_READER.
+ *
  * For more details of Google Documents' GData API, see the <ulink type="http://code.google.com/apis/document/docs/2.0/developers_guide_protocol.html";>
  * online documentation</ulink>.
  *
@@ -202,7 +206,7 @@ _gdata_documents_entry_init_edited (GDataDocumentsEntry *self)
 static gboolean
 is_owner_rule (GDataAccessRule *rule)
 {
-	return (strcmp (gdata_access_rule_get_role (rule), "owner") == 0) ? TRUE : FALSE;
+	return (strcmp (gdata_access_rule_get_role (rule), GDATA_DOCUMENTS_ACCESS_ROLE_OWNER) == 0) ? TRUE : FALSE;
 }
 
 static void
diff --git a/gdata/services/documents/gdata-documents-entry.h b/gdata/services/documents/gdata-documents-entry.h
index b3ab722..3b332d8 100644
--- a/gdata/services/documents/gdata-documents-entry.h
+++ b/gdata/services/documents/gdata-documents-entry.h
@@ -29,6 +29,34 @@
 
 G_BEGIN_DECLS
 
+/**
+ * GDATA_DOCUMENTS_ACCESS_ROLE_OWNER:
+ *
+ * The users specified by the #GDataAccessRule have full owner access to the document. This allows them to modify the access rules and delete
+ * the document, amongst other things.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_DOCUMENTS_ACCESS_ROLE_OWNER "owner"
+
+/**
+ * GDATA_DOCUMENTS_ACCESS_ROLE_WRITER:
+ *
+ * The users specified by the #GDataAccessRule have write access to the document. They cannot modify the access rules or delete the document.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_DOCUMENTS_ACCESS_ROLE_WRITER "writer"
+
+/**
+ * GDATA_DOCUMENTS_ACCESS_ROLE_READER:
+ *
+ * The users specified by the #GDataAccessRule have read-only access to the document.
+ *
+ * Since: 0.7.0
+ **/
+#define GDATA_DOCUMENTS_ACCESS_ROLE_READER "reader"
+
 #define GDATA_TYPE_DOCUMENTS_ENTRY		(gdata_documents_entry_get_type ())
 #define GDATA_DOCUMENTS_ENTRY(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_DOCUMENTS_ENTRY, GDataDocumentsEntry))
 #define GDATA_DOCUMENTS_ENTRY_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_DOCUMENTS_ENTRY, GDataDocumentsEntryClass))
diff --git a/gdata/services/youtube/gdata-youtube-video.h b/gdata/services/youtube/gdata-youtube-video.h
index 83ae6fb..82b8cd1 100644
--- a/gdata/services/youtube/gdata-youtube-video.h
+++ b/gdata/services/youtube/gdata-youtube-video.h
@@ -103,7 +103,7 @@ G_BEGIN_DECLS
  * @GDATA_YOUTUBE_PERMISSION_DENIED: the action is denied for everyone
  * @GDATA_YOUTUBE_PERMISSION_MODERATED: the action is moderated by the video owner
  *
- * Permissions for #GDataYouTubeAction<!-- -->s which can be set on a #GDataYouTubeVideo using gdata_youtube_video_set_access_control().
+ * Permissions for actions which can be set on a #GDataYouTubeVideo using gdata_youtube_video_set_access_control().
  *
  * The only actions which can have the %GDATA_YOUTUBE_PERMISSION_MODERATED permission are %GDATA_YOUTUBE_ACTION_RATE and %GDATA_YOUTUBE_ACTION_COMMENT.
  *
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index ee18292..ddac509 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -584,12 +584,12 @@ test_acls_insert_rule (gconstpointer service)
 
 	rule = gdata_access_rule_new (NULL);
 
-	gdata_access_rule_set_role (rule, "http://schemas.google.com/gCal/2005#editor";);
-	g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, "http://schemas.google.com/gCal/2005#editor";);
+	gdata_access_rule_set_role (rule, GDATA_CALENDAR_ACCESS_ROLE_EDITOR);
+	g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, GDATA_CALENDAR_ACCESS_ROLE_EDITOR);
 
-	gdata_access_rule_set_scope (rule, "user", "darcy gmail com");
+	gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "darcy gmail com");
 	gdata_access_rule_get_scope (rule, &scope_type, &scope_value);
-	g_assert_cmpstr (scope_type, ==, "user");
+	g_assert_cmpstr (scope_type, ==, GDATA_ACCESS_SCOPE_USER);
 	g_assert_cmpstr (scope_value, ==, "darcy gmail com");
 
 	/* Check the XML */
@@ -612,9 +612,9 @@ test_acls_insert_rule (gconstpointer service)
 	g_clear_error (&error);
 
 	/* Check the properties of the returned rule */
-	g_assert_cmpstr (gdata_access_rule_get_role (new_rule), ==, "http://schemas.google.com/gCal/2005#editor";);
+	g_assert_cmpstr (gdata_access_rule_get_role (new_rule), ==, GDATA_CALENDAR_ACCESS_ROLE_EDITOR);
 	gdata_access_rule_get_scope (new_rule, &scope_type, &scope_value);
-	g_assert_cmpstr (scope_type, ==, "user");
+	g_assert_cmpstr (scope_type, ==, GDATA_ACCESS_SCOPE_USER);
 	g_assert_cmpstr (scope_value, ==, "darcy gmail com");
 	gdata_access_rule_get_edited (new_rule, &edited);
 	g_assert_cmpuint (edited.tv_sec, >, 0);
@@ -667,8 +667,8 @@ test_acls_update_rule (gconstpointer service)
 	g_object_unref (feed);
 
 	/* Update the rule */
-	gdata_access_rule_set_role (rule, "http://schemas.google.com/gCal/2005#read";);
-	g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, "http://schemas.google.com/gCal/2005#read";);
+	gdata_access_rule_set_role (rule, GDATA_CALENDAR_ACCESS_ROLE_READ);
+	g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, GDATA_CALENDAR_ACCESS_ROLE_READ);
 
 	/* Send the update to the server */
 	new_rule = gdata_access_handler_update_rule (GDATA_ACCESS_HANDLER (calendar), GDATA_SERVICE (service), rule, NULL, &error);
@@ -678,9 +678,9 @@ test_acls_update_rule (gconstpointer service)
 	g_object_unref (rule);
 
 	/* Check the properties of the returned rule */
-	g_assert_cmpstr (gdata_access_rule_get_role (new_rule), ==, "http://schemas.google.com/gCal/2005#read";);
+	g_assert_cmpstr (gdata_access_rule_get_role (new_rule), ==, GDATA_CALENDAR_ACCESS_ROLE_READ);
 	gdata_access_rule_get_scope (new_rule, &scope_type, &scope_value);
-	g_assert_cmpstr (scope_type, ==, "user");
+	g_assert_cmpstr (scope_type, ==, GDATA_ACCESS_SCOPE_USER);
 	g_assert_cmpstr (scope_value, ==, "darcy gmail com");
 	gdata_access_rule_get_edited (new_rule, &edited);
 	g_assert_cmpuint (edited.tv_sec, >, 0);
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index 26c39c1..54f17e3 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -572,8 +572,8 @@ test_new_document_with_collaborator (gconstpointer service)
 
 	/* New access rule */
 	access_rule = gdata_access_rule_new (NULL);
-	gdata_access_rule_set_role (access_rule, "writer");
-	gdata_access_rule_set_scope (access_rule, "user", "libgdata test gmail com");
+	gdata_access_rule_set_role (access_rule, GDATA_DOCUMENTS_ACCESS_ROLE_WRITER);
+	gdata_access_rule_set_scope (access_rule, GDATA_ACCESS_SCOPE_USER, "libgdata test gmail com");
 
 	/* Set access rules */
 	new_access_rule = gdata_access_handler_insert_rule (GDATA_ACCESS_HANDLER (new_document), GDATA_SERVICE (service), access_rule, NULL, &error);
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 5ed1e86..f65df70 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -672,8 +672,8 @@ test_access_rule_get_xml (void)
 	g_assert_cmpuint (edited.tv_sec, >, 0); /* current time */
 
 	/* Set the properties more conventionally */
-	gdata_access_rule_set_role (rule, "writer");
-	gdata_access_rule_set_scope (rule, "user", "foo example com");
+	gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE);
+	gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "foo example com");
 
 	/* Check the generated XML's OK */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (rule));
@@ -684,7 +684,7 @@ test_access_rule_get_xml (void)
 				"<title type='text'>writer</title>"
 				"<id>an-id</id>"
 				"<category term='http://schemas.google.com/acl/2007#accessRule' scheme='http://schemas.google.com/g/2005#kind'/>"
-				"<gAcl:role value='writer'/>"
+				"<gAcl:role value='none'/>"
 				"<gAcl:scope type='user' value='foo example com'/>"
 			 "</entry>");
 



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