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

Store can_share capability

Store can_share capability from Google Drive API. This is pre-work to
grey-out the 'Share' button for files without Sharing permission in
the Files app.

Bug: 719959
Change-Id: I37281af81aeb5dfcb1a01a503ba4edb10686bf4d
Reviewed-on: https://chromium-review.googlesource.com/1068551Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Sasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560940}
parent 279b0d88
...@@ -51,6 +51,10 @@ message CapabilitiesInfo { ...@@ -51,6 +51,10 @@ message CapabilitiesInfo {
// root, whether the current user can add children to folders in this Team // root, whether the current user can add children to folders in this Team
// Drive. This is always false when the item is not a folder or a Team Drive. // Drive. This is always false when the item is not a folder or a Team Drive.
optional bool can_add_children = 4; optional bool can_add_children = 4;
// Whether the current user can modify the sharing settings for this file. For
// a Team Drive root, whether the current user can share files or folders in
// this Team Drive.
optional bool can_share = 5;
} }
// File specific info, which is a part of ResourceEntry. // File specific info, which is a part of ResourceEntry.
......
...@@ -104,6 +104,8 @@ bool ConvertFileResourceToResourceEntry( ...@@ -104,6 +104,8 @@ bool ConvertFileResourceToResourceEntry(
capabilities.can_rename()); capabilities.can_rename());
converted.mutable_capabilities_info()->set_can_add_children( converted.mutable_capabilities_info()->set_can_add_children(
capabilities.can_add_children()); capabilities.can_add_children());
converted.mutable_capabilities_info()->set_can_share(
capabilities.can_share());
if (input.IsDirectory()) { if (input.IsDirectory()) {
file_info->set_is_directory(true); file_info->set_is_directory(true);
...@@ -170,6 +172,8 @@ void ConvertTeamDriveResourceToResourceEntry( ...@@ -170,6 +172,8 @@ void ConvertTeamDriveResourceToResourceEntry(
capabilities.can_rename_team_drive()); capabilities.can_rename_team_drive());
out_entry->mutable_capabilities_info()->set_can_add_children( out_entry->mutable_capabilities_info()->set_can_add_children(
capabilities.can_add_children()); capabilities.can_add_children());
out_entry->mutable_capabilities_info()->set_can_share(
capabilities.can_share());
} }
void ConvertResourceEntryToFileInfo(const ResourceEntry& entry, void ConvertResourceEntryToFileInfo(const ResourceEntry& entry,
......
...@@ -48,6 +48,14 @@ TEST(ResourceEntryConversionTest, ConvertToResourceEntry_File) { ...@@ -48,6 +48,14 @@ TEST(ResourceEntryConversionTest, ConvertToResourceEntry_File) {
file_resource.set_file_size(892721); file_resource.set_file_size(892721);
file_resource.set_md5_checksum("3b4382ebefec6e743578c76bbd0575ce"); file_resource.set_md5_checksum("3b4382ebefec6e743578c76bbd0575ce");
google_apis::FileResourceCapabilities capabilities;
capabilities.set_can_copy(true);
capabilities.set_can_delete(false);
capabilities.set_can_rename(true);
capabilities.set_can_add_children(false);
capabilities.set_can_share(true);
file_resource.set_capabilities(capabilities);
ResourceEntry entry; ResourceEntry entry;
std::string parent_resource_id; std::string parent_resource_id;
EXPECT_TRUE(ConvertFileResourceToResourceEntry( EXPECT_TRUE(ConvertFileResourceToResourceEntry(
...@@ -81,6 +89,13 @@ TEST(ResourceEntryConversionTest, ConvertToResourceEntry_File) { ...@@ -81,6 +89,13 @@ TEST(ResourceEntryConversionTest, ConvertToResourceEntry_File) {
EXPECT_EQ(file_resource.file_size(), entry.file_info().size()); EXPECT_EQ(file_resource.file_size(), entry.file_info().size());
EXPECT_EQ(file_resource.md5_checksum(), entry.file_specific_info().md5()); EXPECT_EQ(file_resource.md5_checksum(), entry.file_specific_info().md5());
EXPECT_FALSE(entry.file_info().is_directory()); EXPECT_FALSE(entry.file_info().is_directory());
// Capabilities.
EXPECT_TRUE(entry.capabilities_info().can_copy());
EXPECT_FALSE(entry.capabilities_info().can_delete());
EXPECT_TRUE(entry.capabilities_info().can_rename());
EXPECT_FALSE(entry.capabilities_info().can_add_children());
EXPECT_TRUE(entry.capabilities_info().can_share());
} }
TEST(ResourceEntryConversionTest, TEST(ResourceEntryConversionTest,
...@@ -99,6 +114,14 @@ TEST(ResourceEntryConversionTest, ...@@ -99,6 +114,14 @@ TEST(ResourceEntryConversionTest,
file_resource.set_alternate_link(GURL("https://file_link_alternate")); file_resource.set_alternate_link(GURL("https://file_link_alternate"));
// Do not set file size to represent a hosted document. // Do not set file size to represent a hosted document.
google_apis::FileResourceCapabilities capabilities;
capabilities.set_can_copy(false);
capabilities.set_can_delete(true);
capabilities.set_can_rename(false);
capabilities.set_can_add_children(true);
capabilities.set_can_share(false);
file_resource.set_capabilities(capabilities);
ResourceEntry entry; ResourceEntry entry;
std::string parent_resource_id; std::string parent_resource_id;
EXPECT_TRUE(ConvertFileResourceToResourceEntry( EXPECT_TRUE(ConvertFileResourceToResourceEntry(
...@@ -133,6 +156,13 @@ TEST(ResourceEntryConversionTest, ...@@ -133,6 +156,13 @@ TEST(ResourceEntryConversionTest,
// The size should be 0 for a hosted document. // The size should be 0 for a hosted document.
EXPECT_EQ(0, entry.file_info().size()); EXPECT_EQ(0, entry.file_info().size());
EXPECT_FALSE(entry.file_info().is_directory()); EXPECT_FALSE(entry.file_info().is_directory());
// Capabilities.
EXPECT_FALSE(entry.capabilities_info().can_copy());
EXPECT_TRUE(entry.capabilities_info().can_delete());
EXPECT_FALSE(entry.capabilities_info().can_rename());
EXPECT_TRUE(entry.capabilities_info().can_add_children());
EXPECT_FALSE(entry.capabilities_info().can_share());
} }
TEST(ResourceEntryConversionTest, TEST(ResourceEntryConversionTest,
...@@ -423,6 +453,16 @@ TEST(ResourceEntryConversionTest, ...@@ -423,6 +453,16 @@ TEST(ResourceEntryConversionTest,
team_drive_resource->set_name("ABC Team Drive"); team_drive_resource->set_name("ABC Team Drive");
team_drive_resource->set_id("team_drive_id"); team_drive_resource->set_id("team_drive_id");
google_apis::TeamDriveCapabilities team_drive_capabilities;
team_drive_capabilities.set_can_copy(true);
team_drive_capabilities.set_can_delete_team_drive(false);
team_drive_capabilities.set_can_rename_team_drive(true);
// Can_rename is ignored for team drives.
team_drive_capabilities.set_can_rename(false);
team_drive_capabilities.set_can_add_children(false);
team_drive_capabilities.set_can_share(true);
team_drive_resource->set_capabilities(team_drive_capabilities);
ResourceEntry entry; ResourceEntry entry;
std::string parent_resource_id; std::string parent_resource_id;
EXPECT_TRUE(ConvertChangeResourceToResourceEntry(change_resource, &entry, EXPECT_TRUE(ConvertChangeResourceToResourceEntry(change_resource, &entry,
...@@ -437,6 +477,12 @@ TEST(ResourceEntryConversionTest, ...@@ -437,6 +477,12 @@ TEST(ResourceEntryConversionTest,
EXPECT_EQ(util::kDriveTeamDrivesDirLocalId, entry.parent_local_id()); EXPECT_EQ(util::kDriveTeamDrivesDirLocalId, entry.parent_local_id());
EXPECT_EQ("", parent_resource_id); EXPECT_EQ("", parent_resource_id);
EXPECT_FALSE(entry.deleted()); EXPECT_FALSE(entry.deleted());
EXPECT_TRUE(entry.capabilities_info().can_copy());
EXPECT_FALSE(entry.capabilities_info().can_delete());
EXPECT_TRUE(entry.capabilities_info().can_rename());
EXPECT_FALSE(entry.capabilities_info().can_add_children());
EXPECT_TRUE(entry.capabilities_info().can_share());
} }
TEST(ResourceEntryConversionTest, ConvertTeamDriveResourceToResourceEntry) { TEST(ResourceEntryConversionTest, ConvertTeamDriveResourceToResourceEntry) {
......
...@@ -493,7 +493,7 @@ bool UpgradeOldDBVersion15(leveldb::DB* resource_map) { ...@@ -493,7 +493,7 @@ bool UpgradeOldDBVersion15(leveldb::DB* resource_map) {
return resource_map->Write(leveldb::WriteOptions(), &batch).ok(); return resource_map->Write(leveldb::WriteOptions(), &batch).ok();
} }
bool UpgradeOldDBVersions16To17(leveldb::DB* resource_map) { bool UpgradeOldDBVersions16To18(leveldb::DB* resource_map) {
// From 15->16, the field |alternate_url| was moved from FileSpecificData // From 15->16, the field |alternate_url| was moved from FileSpecificData
// to ResourceEntry. Since it isn't saved for directories, we need to do a // to ResourceEntry. Since it isn't saved for directories, we need to do a
// full fetch to get the |alternate_url| fetched for each directory. // full fetch to get the |alternate_url| fetched for each directory.
...@@ -628,10 +628,11 @@ bool ResourceMetadataStorage::UpgradeOldDB( ...@@ -628,10 +628,11 @@ bool ResourceMetadataStorage::UpgradeOldDB(
return UpgradeOldDBVersion15(resource_map.get()); return UpgradeOldDBVersion15(resource_map.get());
case 16: case 16:
case 17: case 17:
return UpgradeOldDBVersions16To17(resource_map.get()); case 18:
return UpgradeOldDBVersions16To18(resource_map.get());
case kDBVersion: case kDBVersion:
static_assert( static_assert(
kDBVersion == 18, kDBVersion == 19,
"database version and this function must be updated together"); "database version and this function must be updated together");
return true; return true;
default: default:
......
...@@ -40,7 +40,7 @@ class ResourceMetadataStorage { ...@@ -40,7 +40,7 @@ class ResourceMetadataStorage {
public: public:
// This should be incremented when incompatibility change is made to DB // This should be incremented when incompatibility change is made to DB
// format. // format.
static constexpr int kDBVersion = 18; static constexpr int kDBVersion = 19;
// Object to iterate over entries stored in this storage. // Object to iterate over entries stored in this storage.
class Iterator { class Iterator {
......
...@@ -346,36 +346,63 @@ class TeamDriveCapabilities { ...@@ -346,36 +346,63 @@ class TeamDriveCapabilities {
// Whether the current user can add children to folders in this Team Drive. // Whether the current user can add children to folders in this Team Drive.
bool can_add_children() const { return can_add_children_; } bool can_add_children() const { return can_add_children_; }
void set_can_add_children(bool can_add_children) {
can_add_children_ = can_add_children;
}
// Whether the current user can comment on files in this Team Drive. // Whether the current user can comment on files in this Team Drive.
bool can_comment() const { return can_comment_; } bool can_comment() const { return can_comment_; }
void set_can_comment(bool can_comment) { can_comment_ = can_comment; }
// Whether files in this Team Drive can be copied by the current user. // Whether files in this Team Drive can be copied by the current user.
bool can_copy() const { return can_copy_; } bool can_copy() const { return can_copy_; }
void set_can_copy(bool can_copy) { can_copy_ = can_copy; }
// Whether this Team Drive can be deleted by the current user. // Whether this Team Drive can be deleted by the current user.
bool can_delete_team_drive() const { return can_delete_team_drive_; } bool can_delete_team_drive() const { return can_delete_team_drive_; }
void set_can_delete_team_drive(bool can_delete_team_drive) {
can_delete_team_drive_ = can_delete_team_drive;
}
// Whether files in this Team Drive can be edited by the current user. // Whether files in this Team Drive can be edited by the current user.
bool can_download() const { return can_download_; } bool can_download() const { return can_download_; }
void set_can_download(bool can_download) { can_download_ = can_download; }
// Whether files in this Team Drive can be edited by current user. // Whether files in this Team Drive can be edited by current user.
bool can_edit() const { return can_edit_; } bool can_edit() const { return can_edit_; }
void set_can_edit(bool can_edit) { can_edit_ = can_edit; }
// Whether the current user can list the children of folders in this Team // Whether the current user can list the children of folders in this Team
// Drive. // Drive.
bool can_list_children() const { return can_list_children_; } bool can_list_children() const { return can_list_children_; }
void set_can_list_children(bool can_list_children) {
can_list_children_ = can_list_children;
}
// Whether the current user can add members to this Team Drive or remove them // Whether the current user can add members to this Team Drive or remove them
// or change their role. // or change their role.
bool can_manage_members() const { return can_manage_members_; } bool can_manage_members() const { return can_manage_members_; }
void set_can_manage_members(bool can_manage_members) {
can_manage_members_ = can_manage_members;
}
// Whether the current user has read access to the Revisions resource of files // Whether the current user has read access to the Revisions resource of files
// in this Team Drive. // in this Team Drive.
bool can_read_revisions() const { return can_read_revisions_; } bool can_read_revisions() const { return can_read_revisions_; }
void set_can_read_revisions(bool can_read_revisions) {
can_read_revisions_ = can_read_revisions;
}
// Whether the current user can remove children from folders in this Team // Whether the current user can remove children from folders in this Team
// Drive. // Drive.
bool can_remove_children() const { return can_remove_children_; } bool can_remove_children() const { return can_remove_children_; }
void set_can_remove_children(bool can_remove_children) {
can_remove_children_ = can_remove_children;
}
// Whether files or folders in this Team Drive can be renamed by the current // Whether files or folders in this Team Drive can be renamed by the current
// user. // user.
bool can_rename() const { return can_rename_; } bool can_rename() const { return can_rename_; }
void set_can_rename(bool can_rename) { can_rename_ = can_rename; }
// Whether this Team Drive can be renamed by the current user. // Whether this Team Drive can be renamed by the current user.
bool can_rename_team_drive() const { return can_rename_team_drive_; } bool can_rename_team_drive() const { return can_rename_team_drive_; }
void set_can_rename_team_drive(bool can_rename_team_drive) {
can_rename_team_drive_ = can_rename_team_drive;
}
// Whether files or folders in this Team Drive can be shared by the current // Whether files or folders in this Team Drive can be shared by the current
// user. // user.
bool can_share() const { return can_share_; } bool can_share() const { return can_share_; }
void set_can_share(bool can_share) { can_share_ = can_share; }
private: private:
bool can_add_children_; bool can_add_children_;
...@@ -418,6 +445,9 @@ class TeamDriveResource { ...@@ -418,6 +445,9 @@ class TeamDriveResource {
void set_name(const std::string& name) { name_ = name; } void set_name(const std::string& name) { name_ = name; }
// Capabilities the current user has on this Team Drive. // Capabilities the current user has on this Team Drive.
const TeamDriveCapabilities& capabilities() const { return capabilities_; } const TeamDriveCapabilities& capabilities() const { return capabilities_; }
void set_capabilities(const TeamDriveCapabilities& capabilities) {
capabilities_ = capabilities;
}
private: private:
friend class DriveAPIParserTest; friend class DriveAPIParserTest;
...@@ -600,27 +630,90 @@ class FileResourceCapabilities { ...@@ -600,27 +630,90 @@ class FileResourceCapabilities {
static std::unique_ptr<FileResourceCapabilities> CreateFrom( static std::unique_ptr<FileResourceCapabilities> CreateFrom(
const base::Value& value); const base::Value& value);
// Whether the current user can add children to this folder. This is always
// false when the item is not a folder.
bool can_add_children() const { return can_add_children_; } bool can_add_children() const { return can_add_children_; }
void set_can_add_children(bool can_add_children) {
can_add_children_ = can_add_children;
}
// Whether the current user can change the restricted download label of this
// file.
bool can_change_restricted_download() const { bool can_change_restricted_download() const {
return can_change_restricted_download_; return can_change_restricted_download_;
} }
void set_can_change_restricted_download(bool can_change_restricted_download) {
can_change_restricted_download_ = can_change_restricted_download;
}
// Whether the current user can comment on this file.
bool can_comment() const { return can_comment_; } bool can_comment() const { return can_comment_; }
void set_can_comment(bool can_comment) { can_comment_ = can_comment; }
// Whether the current user can copy this file. For a Team Drive item, whether
// the current user can copy non-folder descendants of this item, or this item
// itself if it is not a folder.
bool can_copy() const { return can_copy_; } bool can_copy() const { return can_copy_; }
void set_can_copy(bool can_copy) { can_copy_ = can_copy; }
// Whether the current user can delete this file.
bool can_delete() const { return can_delete_; } bool can_delete() const { return can_delete_; }
void set_can_delete(bool can_delete) { can_delete_ = can_delete; }
// Whether the current user can download this file.
bool can_download() const { return can_download_; } bool can_download() const { return can_download_; }
void set_can_download(bool can_download) { can_download_ = can_download; }
// Whether the current user can edit this file.
bool can_edit() const { return can_edit_; } bool can_edit() const { return can_edit_; }
void set_can_edit(bool can_edit) { can_edit_ = can_edit; }
// Whether the current user can list the children of this folder. This is
// always false when the item is not a folder.
bool can_list_children() const { return can_list_children_; } bool can_list_children() const { return can_list_children_; }
void set_can_list_children(bool can_list_children) {
can_list_children_ = can_list_children;
}
// Whether the current user can move this item into a Team Drive. If the item
// is in a Team Drive, this field is equivalent to canMoveTeamDriveItem.
bool can_move_item_into_team_drive() const { bool can_move_item_into_team_drive() const {
return can_move_item_into_team_drive_; return can_move_item_into_team_drive_;
} }
void set_can_move_item_into_team_drive(bool can_move_item_into_team_drive) {
can_move_item_into_team_drive_ = can_move_item_into_team_drive;
}
// Whether the current user can move this Team Drive item by changing its
// parent. Note that a request to change the parent for this item may still
// fail depending on the new parent that is being added. Only populated for
// Team Drive files.
bool can_move_team_drive_item() const { return can_move_team_drive_item_; } bool can_move_team_drive_item() const { return can_move_team_drive_item_; }
void set_can_move_team_drive_item(bool can_move_team_drive_item) {
can_move_team_drive_item_ = can_move_team_drive_item;
}
// Whether the current user can read the revisions resource of this file. For
// a Team Drive item, whether revisions of non-folder descendants of this
// item, or this item itself if it is not a folder, can be read.
bool can_read_revisions() const { return can_read_revisions_; } bool can_read_revisions() const { return can_read_revisions_; }
void set_can_read_revisions(bool can_read_revisions) {
can_read_revisions_ = can_read_revisions;
}
// Whether the current user can read the Team Drive to which this file
// belongs. Only populated for Team Drive files.
bool can_read_team_drive() const { return can_read_team_drive_; } bool can_read_team_drive() const { return can_read_team_drive_; }
void set_can_read_team_drive(bool can_read_team_drive) {
can_read_team_drive_ = can_read_team_drive;
}
// Whether the current user can remove children from this folder. This is
// always false when the item is not a folder.
bool can_remove_children() const { return can_remove_children_; } bool can_remove_children() const { return can_remove_children_; }
void set_can_remove_children(bool can_remove_children) {
can_remove_children_ = can_remove_children;
}
// Whether the current user can rename this file.
bool can_rename() const { return can_rename_; } bool can_rename() const { return can_rename_; }
void set_can_rename(bool can_rename) { can_rename_ = can_rename; }
// Whether the current user can modify the sharing settings for this file.
bool can_share() const { return can_share_; } bool can_share() const { return can_share_; }
void set_can_share(bool can_share) { can_share_ = can_share; }
// Whether the current user can move this file to trash.
bool can_trash() const { return can_trash_; } bool can_trash() const { return can_trash_; }
void set_can_trash(bool can_trash) { can_trash_ = can_trash; }
// Whether the current user can restore this file from trash.
bool can_untrash() const { return can_untrash_; } bool can_untrash() const { return can_untrash_; }
void set_can_untrash(bool can_untrash) { can_untrash_ = can_untrash; }
private: private:
bool can_add_children_; bool can_add_children_;
...@@ -790,6 +883,9 @@ class FileResource { ...@@ -790,6 +883,9 @@ class FileResource {
} }
// Capabilities the current user has on this file resource. // Capabilities the current user has on this file resource.
const FileResourceCapabilities& capabilities() const { return capabilities_; } const FileResourceCapabilities& capabilities() const { return capabilities_; }
void set_capabilities(const FileResourceCapabilities& capabilities) {
capabilities_ = capabilities;
}
private: private:
friend class base::internal::RepeatedMessageConverter<FileResource>; friend class base::internal::RepeatedMessageConverter<FileResource>;
......
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