summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2021-02-01 15:18:09 +0100
committerOndrej Holy <oholy@redhat.com>2021-02-11 18:03:53 +0100
commitcd53cd6402c0348ce8a85c1d319c0e3a8445563b (patch)
treeb7258579840a51997fcd81814f3349b0c34e76c2
parentb9f9e357884b1346b62a4d516b64fcae1eb38deb (diff)
downloadlibgdata-wip/oholy/documents-shared-drives-support.tar.gz
documents: Add gdata_documents_entry_can_editwip/oholy/documents-shared-drives-support
Entries on Shared Drives, or Shared with me are not always editable. Let's add gdata_documents_entry_can_edit to allow GVfsBackendGoogle to set file permissions accordingly. It would be nice to make also canDelete, canRename and canListChildren available, but it would require libgdata port to Drive API v3 unfortunatelly. Relates: https://gitlab.gnome.org/GNOME/gvfs/-/merge_requests/114
-rw-r--r--docs/reference/gdata-sections.txt.in1
-rw-r--r--gdata/gdata-core.symbols1
-rw-r--r--gdata/services/documents/gdata-documents-entry.c58
-rw-r--r--gdata/services/documents/gdata-documents-entry.h2
-rw-r--r--gdata/symbol.map1
5 files changed, 63 insertions, 0 deletions
diff --git a/docs/reference/gdata-sections.txt.in b/docs/reference/gdata-sections.txt.in
index 2eaf94a2..42139e44 100644
--- a/docs/reference/gdata-sections.txt.in
+++ b/docs/reference/gdata-sections.txt.in
@@ -1563,6 +1563,7 @@ gdata_documents_entry_get_document_properties
gdata_documents_entry_add_documents_property
gdata_documents_entry_remove_documents_property
gdata_documents_entry_get_shared_with_me_date
+gdata_documents_entry_can_edit
<SUBSECTION Standard>
gdata_documents_entry_get_type
GDATA_DOCUMENTS_ENTRY
diff --git a/gdata/gdata-core.symbols b/gdata/gdata-core.symbols
index fc6d8faa..606df7c3 100644
--- a/gdata/gdata-core.symbols
+++ b/gdata/gdata-core.symbols
@@ -652,6 +652,7 @@ gdata_documents_entry_writers_can_invite
gdata_documents_entry_get_last_modified_by
gdata_documents_entry_is_deleted
gdata_documents_entry_get_shared_with_me_date
+gdata_documents_entry_can_edit
gdata_documents_query_get_type
gdata_documents_query_new
gdata_documents_query_new_with_limits
diff --git a/gdata/services/documents/gdata-documents-entry.c b/gdata/services/documents/gdata-documents-entry.c
index 62219bb5..b9b1ffe2 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -136,6 +136,7 @@ struct _GDataDocumentsEntryPrivate {
goffset file_size; /* bytes */
GList *properties; /* GDataDocumentsProperty */
gint64 shared_with_me_date;
+ gboolean can_edit;
};
enum {
@@ -149,6 +150,7 @@ enum {
PROP_QUOTA_USED,
PROP_FILE_SIZE,
PROP_SHARED_WITH_ME_DATE,
+ PROP_CAN_EDIT,
};
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GDataDocumentsEntry, gdata_documents_entry, GDATA_TYPE_ENTRY,
@@ -326,6 +328,19 @@ gdata_documents_entry_class_init (GDataDocumentsEntryClass *klass)
"Shared with me date", "The time at which this file was shared with the user.",
-1, G_MAXINT64, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GDataDocumentsEntry:can-edit:
+ *
+ * Indicates whether the current user can edit this file.
+ *
+ * Since: 0.18.0
+ */
+ g_object_class_install_property (gobject_class, PROP_CAN_EDIT,
+ g_param_spec_boolean ("can-edit",
+ "Can edit?", "Indicates whether the current user can edit this file.",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static gboolean
@@ -455,6 +470,9 @@ gdata_documents_entry_get_property (GObject *object, guint property_id, GValue *
case PROP_SHARED_WITH_ME_DATE:
g_value_set_int64 (value, priv->shared_with_me_date);
break;
+ case PROP_CAN_EDIT:
+ g_value_set_boolean (value, priv->can_edit);
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -955,6 +973,29 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
return success;
} else if (gdata_parser_int64_time_from_json_member (reader, "sharedWithMeDate", P_DEFAULT, &(priv->shared_with_me_date), &success, error) == TRUE) {
return success;
+ } else if (g_strcmp0 (json_reader_get_member_name (reader), "capabilities") == 0) {
+ guint i, members;
+
+ if (!json_reader_is_object (reader)) {
+ g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
+ /* Translators: the parameter is an error message */
+ _("Error parsing JSON: %s"),
+ "JSON node ‘capabilities’ is not an object.");
+ return FALSE;
+ }
+
+ for (i = 0, members = (guint) json_reader_count_members (reader); i < members; i++) {
+ json_reader_read_element (reader, i);
+
+ if (gdata_parser_boolean_from_json_member (reader, "canEdit", P_DEFAULT, &(priv->can_edit), &success, error) == TRUE) {
+ json_reader_end_element (reader);
+ break;
+ }
+
+ json_reader_end_element (reader);
+ }
+
+ return success;
}
return GDATA_PARSABLE_CLASS (gdata_documents_entry_parent_class)->parse_json (parsable, reader, user_data, error);
@@ -1456,3 +1497,20 @@ gdata_documents_entry_get_shared_with_me_date (GDataDocumentsEntry *self)
g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (self), -1);
return self->priv->shared_with_me_date;
}
+
+/**
+ * gdata_documents_entry_can_edit:
+ * @self: a #GDataDocumentsEntry
+ *
+ * Gets the #GDataDocumentsEntry:can-edit property.
+ *
+ * Return value: %TRUE if the current user can edit this file, %FALSE otherwise
+ *
+ * Since: 0.18.0
+ */
+gboolean
+gdata_documents_entry_can_edit (GDataDocumentsEntry *self)
+{
+ g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (self), FALSE);
+ return self->priv->can_edit;
+}
diff --git a/gdata/services/documents/gdata-documents-entry.h b/gdata/services/documents/gdata-documents-entry.h
index a8ec8003..4dd0e591 100644
--- a/gdata/services/documents/gdata-documents-entry.h
+++ b/gdata/services/documents/gdata-documents-entry.h
@@ -127,6 +127,8 @@ gboolean gdata_documents_entry_remove_documents_property (GDataDocumentsEntry *s
gint64 gdata_documents_entry_get_shared_with_me_date (GDataDocumentsEntry *self);
+gboolean gdata_documents_entry_can_edit (GDataDocumentsEntry *self);
+
G_END_DECLS
#endif /* !GDATA_DOCUMENTS_ENTRY_H */
diff --git a/gdata/symbol.map b/gdata/symbol.map
index b1cdfeff..9b9c8de1 100644
--- a/gdata/symbol.map
+++ b/gdata/symbol.map
@@ -330,6 +330,7 @@ global:
gdata_documents_entry_set_writers_can_invite;
gdata_documents_entry_writers_can_invite;
gdata_documents_entry_get_shared_with_me_date;
+ gdata_documents_entry_can_edit;
gdata_documents_feed_get_type;
gdata_documents_folder_get_type;
gdata_documents_folder_new;