Class: GoogleDrive::Acl
- Inherits:
-
Object
- Object
- GoogleDrive::Acl
- Extended by:
- Forwardable
- Includes:
- Enumerable, Util
- Defined in:
- lib/google_drive/acl.rb
Overview
ACL (access control list) of a spreadsheet.
Use GoogleDrive::Spreadsheet#acl to get GoogleDrive::Acl object. See GoogleDrive::Spreadsheet#acl for usage example.
This code is based on github.com/guyboertje/gdata-spreadsheet-ruby .
Constant Summary
Constants included from Util
Util::EXT_TO_CONTENT_TYPE, Util::IMPORTABLE_CONTENT_TYPE_MAP
Instance Method Summary collapse
-
#delete(entry) ⇒ Object
Deletes an ACL entry.
-
#initialize(session, file) ⇒ Acl
constructor
private
A new instance of Acl.
- #inspect ⇒ Object
-
#push(params_or_entry, options = {}) ⇒ Object
Adds a new entry.
- #update_role(entry) ⇒ Object private
Methods included from Util
concat_url, construct_and_query, construct_query, convert_params, delegate_api_methods, encode_query, get_singleton_class, h
Constructor Details
#initialize(session, file) ⇒ Acl
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Acl.
21 22 23 24 25 26 27 28 29 |
# File 'lib/google_drive/acl.rb', line 21 def initialize(session, file) @session = session @file = file = @session.drive_service.( @file.id, fields: '*', supports_all_drives: true ) @entries = ..map { |perm| AclEntry.new(perm, self) } end |
Instance Method Details
#delete(entry) ⇒ Object
Deletes an ACL entry.
e.g.
spreadsheet.acl.delete(spreadsheet.acl[1])
87 88 89 90 91 92 |
# File 'lib/google_drive/acl.rb', line 87 def delete(entry) @session.drive_service.( @file.id, entry.id, supports_all_drives: true ) @entries.delete(entry) end |
#inspect ⇒ Object
107 108 109 |
# File 'lib/google_drive/acl.rb', line 107 def inspect format("\#<%p %p>", self.class, @entries) end |
#push(params_or_entry, options = {}) ⇒ Object
Adds a new entry. entry
is either a GoogleDrive::AclEntry or a Hash with keys :type
, :email_address
, :domain
, :role
and :allow_file_discovery
. See GoogleDrive::AclEntry#type and GoogleDrive::AclEntry#role for the document of the fields.
Also you can pass the second hash argument options
, which specifies optional query parameters for the API. Possible keys of options
are,
-
:email_message – A custom message to include in notification emails
-
:send_notification_email – Whether to send notification emails when sharing to users or groups. (Default: true)
-
:transfer_ownership – Whether to transfer ownership to the specified user and downgrade the current owner to a writer. This parameter is required as an acknowledgement of the side effect. (Default: false)
e.g.
# A specific user can read or write.
spreadsheet.acl.push(
{type: "user", email_address: "[email protected]", role: "reader"})
spreadsheet.acl.push(
{type: "user", email_address: "[email protected]", role: "writer"})
# Share with a Google Apps domain.
spreadsheet.acl.push(
{type: "domain", domain: "gimite.net", role: "reader"})
# Publish on the Web.
spreadsheet.acl.push(
{type: "anyone", role: "reader"})
# Anyone who knows the link can read.
spreadsheet.acl.push(
{type: "anyone", allow_file_discovery: false, role: "reader"})
# Set ACL without sending notification emails
spreadsheet.acl.push(
{type: "user", email_address: "[email protected]", role: "reader"},
{send_notification_email: false})
See here for parameter detais: developers.google.com/drive/v3/reference/permissions/create
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/google_drive/acl.rb', line 70 def push(params_or_entry, = {}) entry = params_or_entry.is_a?(AclEntry) ? params_or_entry : AclEntry.new(params_or_entry) = @session.drive_service.( @file.id, entry.params, **{ fields: '*', supports_all_drives: true }.merge() ) new_entry = AclEntry.new(, self) @entries.push(new_entry) new_entry end |
#update_role(entry) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/google_drive/acl.rb', line 95 def update_role(entry) = @session.drive_service.( @file.id, entry.id, { role: entry.role }, fields: '*', supports_all_drives: true ) entry. = entry end |