[libgdata/wip/oholy/documents-shared-drives-support: 3/3] documents: Add gdata_documents_entry_can_edit
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata/wip/oholy/documents-shared-drives-support: 3/3] documents: Add gdata_documents_entry_can_edit
- Date: Mon, 1 Feb 2021 16:13:26 +0000 (UTC)
commit d8663b057a380dbba8d57a4932e684b8d6c13f55
Author: Ondrej Holy <oholy redhat com>
Date: Mon Feb 1 15:18:09 2021 +0100
documents: Add gdata_documents_entry_can_edit
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
docs/reference/gdata-sections.txt.in | 1 +
gdata/gdata-core.symbols | 1 +
gdata/services/documents/gdata-documents-entry.c | 55 ++++++++++++++++++++++++
gdata/services/documents/gdata-documents-entry.h | 2 +
gdata/symbol.map | 1 +
5 files changed, 60 insertions(+)
---
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 8bda2ba9..cd5c9b71 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: UNRELEASED
+ */
+ 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);
@@ -956,6 +974,26 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
} else if (gdata_parser_int64_time_from_json_member (reader, "sharedWithMeDate", P_DEFAULT,
&(priv->shared_with_me_date), &success, error) == TRUE) {
g_free (kind);
return success;
+ } else if (g_strcmp0 (json_reader_get_member_name (reader), "capabilities") == 0) {
+ guint i, members;
+
+ if (json_reader_is_object (reader) == FALSE) {
+ 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);
+
+ gdata_parser_boolean_from_json_member (reader, "canEdit", P_DEFAULT,
&(priv->can_edit), &success, NULL);
+
+ json_reader_end_element (reader);
+ }
+
+ return TRUE;
}
return GDATA_PARSABLE_CLASS (gdata_documents_entry_parent_class)->parse_json (parsable, reader,
user_data, error);
@@ -1457,3 +1495,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: UNRELEASED
+ */
+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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]