Commit f36dd274 authored by Sasha Morrissey's avatar Sasha Morrissey Committed by Commit Bot

Fixed 'Share' option to open drive.google.com for Team Drives

Fixed 'Share' option to open drive.google.com for files and folders in
Team Drives.

Previously, the URL opened was just the alternateUrl (views the file
or folder in drive.google.com). Appending ?userstoinvite="" opens the
sharing dialog.

In the future, this URL will be returned from the Drive API.

The file/folder should open in drive.google.com with the sharing dialog
open.

Test: Right-click on a file or folder in Team Drives and select 'Share'.
Bug: 716301
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Id7d738fd1b16f67af3a012426b8eea0032489450
Reviewed-on: https://chromium-review.googlesource.com/1065834
Commit-Queue: Sasha Morrissey <sashab@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Reviewed-by: default avatarTatsuhisa Yamaguchi <yamaguchi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560962}
parent e05251ec
...@@ -85,7 +85,6 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto, ...@@ -85,7 +85,6 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto,
properties->shared_with_me.reset(new bool(shared_with_me)); properties->shared_with_me.reset(new bool(shared_with_me));
properties->shared.reset(new bool(entry_proto.shared())); properties->shared.reset(new bool(entry_proto.shared()));
properties->starred.reset(new bool(entry_proto.starred())); properties->starred.reset(new bool(entry_proto.starred()));
properties->alternate_url.reset(new std::string(entry_proto.alternate_url()));
const drive::PlatformFileInfoProto& file_info = entry_proto.file_info(); const drive::PlatformFileInfoProto& file_info = entry_proto.file_info();
properties->size.reset(new double(file_info.size())); properties->size.reset(new double(file_info.size()));
...@@ -95,6 +94,24 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto, ...@@ -95,6 +94,24 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto,
base::Time::FromInternalValue(entry_proto.last_modified_by_me()) base::Time::FromInternalValue(entry_proto.last_modified_by_me())
.ToJsTime())); .ToJsTime()));
if (entry_proto.has_alternate_url()) {
properties->alternate_url.reset(
new std::string(entry_proto.alternate_url()));
// Set |share_url| to a modified version of |alternate_url| that opens the
// sharing dialog for files and folders (add ?userstoinvite="" to the URL).
// TODO(sashab): Add an endpoint to the Drive API that generates this URL,
// instead of manually modifying it here.
GURL share_url = GURL(entry_proto.alternate_url());
GURL::Replacements replacements;
std::string new_query =
(share_url.has_query() ? share_url.query() + "&" : "") +
"userstoinvite=%22%22";
replacements.SetQueryStr(new_query);
properties->share_url.reset(
new std::string(share_url.ReplaceComponents(replacements).spec()));
}
if (!entry_proto.has_file_specific_info()) if (!entry_proto.has_file_specific_info())
return; return;
......
...@@ -176,7 +176,8 @@ enum EntryPropertyName { ...@@ -176,7 +176,8 @@ enum EntryPropertyName {
shared, shared,
starred, starred,
externalFileUrl, externalFileUrl,
alternateUrl alternateUrl,
shareUrl
}; };
// Entry property visibility for setEntryTag(); // Entry property visibility for setEntryTag();
...@@ -305,8 +306,12 @@ dictionary EntryProperties { ...@@ -305,8 +306,12 @@ dictionary EntryProperties {
// externalfile:// URL to open the file in browser. // externalfile:// URL to open the file in browser.
DOMString? externalFileUrl; DOMString? externalFileUrl;
// https:// URL to open the file in the Drive website. // https:// URL to open the file or folder in the Drive website.
DOMString? alternateUrl; DOMString? alternateUrl;
// https:// URL to open the file or folder in the Drive website with the
// sharing dialog open.
DOMString? shareUrl;
}; };
// Information about total and remaining size on the mount point. // Information about total and remaining size on the mount point.
......
...@@ -31,6 +31,7 @@ var IconSet; ...@@ -31,6 +31,7 @@ var IconSet;
* croppedThumbnailUrl: (string|undefined), * croppedThumbnailUrl: (string|undefined),
* externalFileUrl: (string|undefined), * externalFileUrl: (string|undefined),
* alternateUrl: (string|undefined), * alternateUrl: (string|undefined),
* shareUrl: (string|undefined),
* imageWidth: (number|undefined), * imageWidth: (number|undefined),
* imageHeight: (number|undefined), * imageHeight: (number|undefined),
* imageRotation: (number|undefined), * imageRotation: (number|undefined),
......
...@@ -71,26 +71,40 @@ function DriveShareAction(entry, volumeManager, ui) { ...@@ -71,26 +71,40 @@ function DriveShareAction(entry, volumeManager, ui) {
* @param {!Array<!Entry>} entries * @param {!Array<!Entry>} entries
* @param {!ActionModelUI} ui * @param {!ActionModelUI} ui
* @param {!VolumeManagerWrapper} volumeManager * @param {!VolumeManagerWrapper} volumeManager
* @return {DriveShareAction|DriveManageAction} * @return {DriveShareAction}
*/ */
DriveShareAction.create = function(entries, volumeManager, ui) { DriveShareAction.create = function(entries, volumeManager, ui) {
if (entries.length !== 1) if (entries.length !== 1)
return null; return null;
return new DriveShareAction(entries[0], volumeManager, ui);
// The share URL for Team Drives currently does not support embedding. For
// Team Drives entries, instead point the user to the 'Manage' action.
var entry = entries[0];
if (util.isTeamDriveEntry(entry)) {
return new DriveManageAction(entry, volumeManager, ui);
}
return new DriveShareAction(entry, volumeManager, ui);
}; };
/** /**
* @override * @override
*/ */
DriveShareAction.prototype.execute = function() { DriveShareAction.prototype.execute = function() {
// For Team Drives entries, open the Sharing dialog in a new window.
if (util.isTeamDriveEntry(this.entry_)) {
chrome.fileManagerPrivate.getEntryProperties(
[this.entry_], ['shareUrl'], function(results) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
if (results.length != 1) {
console.error(
'getEntryProperties for shareUrl should return 1 entry ' +
'(returned ' + results.length + ')');
return;
}
if (results[0].shareUrl === undefined) {
console.error('getEntryProperties shareUrl is undefined');
return;
}
util.visitURL(results[0].shareUrl);
}.bind(this));
return;
}
this.ui_.shareDialog.showEntry(this.entry_, function(result) { this.ui_.shareDialog.showEntry(this.entry_, function(result) {
if (result == ShareDialog.Result.NETWORK_ERROR) if (result == ShareDialog.Result.NETWORK_ERROR)
this.ui_.errorDialog.show(str('SHARE_ERROR'), null, null, null); this.ui_.errorDialog.show(str('SHARE_ERROR'), null, null, null);
...@@ -478,6 +492,10 @@ DriveManageAction.prototype.execute = function() { ...@@ -478,6 +492,10 @@ DriveManageAction.prototype.execute = function() {
'(returned ' + results.length + ')'); '(returned ' + results.length + ')');
return; return;
} }
if (results[0].alternateUrl === undefined) {
console.error('getEntryProperties alternateUrl is undefined');
return;
}
util.visitURL(results[0].alternateUrl); util.visitURL(results[0].alternateUrl);
}.bind(this)); }.bind(this));
}; };
...@@ -686,6 +704,7 @@ ActionsModel.prototype.initialize = function() { ...@@ -686,6 +704,7 @@ ActionsModel.prototype.initialize = function() {
} }
// All entries need to be on the same volume to execute ActionsModel // All entries need to be on the same volume to execute ActionsModel
// commands. // commands.
// TODO(sashab): Move this to util.js.
for (var i = 1; i < this.entries_.length; i++) { for (var i = 1; i < this.entries_.length; i++) {
var volumeInfoToCompare = var volumeInfoToCompare =
this.volumeManager_.getVolumeInfo(this.entries_[i]); this.volumeManager_.getVolumeInfo(this.entries_[i]);
......
...@@ -301,12 +301,10 @@ function testTeamDriveDirectoryEntry(callback) { ...@@ -301,12 +301,10 @@ function testTeamDriveDirectoryEntry(callback) {
var actions = model.getActions(); var actions = model.getActions();
assertEquals(3, Object.keys(actions).length); assertEquals(3, Object.keys(actions).length);
// "Share" is enabled for Team Drive directories, and is the same as the // "Share" is enabled for Team Drive directories.
// "Manage in Drive" action.
var shareAction = actions[ActionsModel.CommonActionId.SHARE]; var shareAction = actions[ActionsModel.CommonActionId.SHARE];
assertTrue(!!shareAction); assertTrue(!!shareAction);
assertTrue(shareAction.canExecute()); assertTrue(shareAction.canExecute());
assertTrue(shareAction instanceof DriveManageAction);
// "Manage in drive" is enabled for Team Drive directories. // "Manage in drive" is enabled for Team Drive directories.
var manageAction = var manageAction =
......
...@@ -190,6 +190,8 @@ testcase.shareDirectoryDrive = function() { ...@@ -190,6 +190,8 @@ testcase.shareDirectoryDrive = function() {
share('photos'); share('photos');
}; };
// TODO(sashab): Add tests for sharing a file on Team Drives.
/** /**
* Tests managing a hosted file (gdoc) on Drive. * Tests managing a hosted file (gdoc) on Drive.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment