diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2aed1b0..96f684e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(contacts) add_subdirectory(drives) add_subdirectory(teamdrive) +add_subdirectory(permissions) #add_subdirectory(staticmaps) diff --git a/examples/permissions/CMakeLists.txt b/examples/permissions/CMakeLists.txt new file mode 100644 index 0000000..8751a36 --- /dev/null +++ b/examples/permissions/CMakeLists.txt @@ -0,0 +1,23 @@ +kde_enable_exceptions() + +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR} +) + +set(permissions_example_SRCS main.cpp mainwindow.cpp) +set(permissions_example_HDRS mainwindow.h) +qt5_wrap_ui(permissions_example_SRCS ui/main.ui) + +add_executable(permissions-example + ${permissions_example_SRCS} + ${permissions_example_HDRS_MOC} +) + +target_link_libraries(permissions-example + Qt5::Widgets + Qt5::Core + KF5::GAPICore + KF5::GAPIDrive +) diff --git a/examples/permissions/main.cpp b/examples/permissions/main.cpp new file mode 100644 index 0000000..e3c7e84 --- /dev/null +++ b/examples/permissions/main.cpp @@ -0,0 +1,34 @@ +/* + Copyright (C) 2019 David Barchiesi + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + MainWindow ex; + ex.show(); + + return app.exec(); +} diff --git a/examples/permissions/mainwindow.cpp b/examples/permissions/mainwindow.cpp new file mode 100644 index 0000000..e4e74fa --- /dev/null +++ b/examples/permissions/mainwindow.cpp @@ -0,0 +1,242 @@ +/* + Copyright (C) 2019 David Barchiesi + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + + +#include "mainwindow.h" +#include "ui_main.h" + +#include +#include +#include + +#include +#include + +MainWindow::MainWindow(QWidget * parent): + QMainWindow(parent), + m_ui(new Ui::MainWindow) +{ + /* Initialize GUI */ + m_ui->setupUi(this); + m_ui->errorLabel->setVisible(false); + connect(m_ui->authButton, &QAbstractButton::clicked, + this, &MainWindow::authenticate); + connect(m_ui->getPermissionsButton, &QAbstractButton::clicked, + this, &MainWindow::slotFetchPermissions); + connect(m_ui->permissionsList, &QListWidget::itemSelectionChanged, + this, &MainWindow::permissionSelected); + + // m_account = KGAPI2::AccountPtr::create(); + // m_account->setAccessToken(QStringLiteral("")); + // m_ui->authStatusLabel->setText(QStringLiteral("Authenticated")); + // m_ui->fileIdEdit->setEnabled(true); + // m_ui->fileIdEdit->setText(QStringLiteral("0ABDsfTyhwbTyUk9PVA")); + // m_ui->getPermissionsButton->setEnabled(true); +} + +MainWindow::~MainWindow() +{ + delete m_ui; +} + +void MainWindow::authenticate() +{ + KGAPI2::AccountPtr account(new KGAPI2::Account); + account->setScopes( QList() << KGAPI2::Account::driveScopeUrl() ); + + /* Create AuthJob to retrieve OAuth tokens for the account */ + KGAPI2::AuthJob *authJob = new KGAPI2::AuthJob( + account, + QStringLiteral("554041944266.apps.googleusercontent.com"), + QStringLiteral("mdT1DjzohxN3npUUzkENT0gO")); + connect(authJob, &KGAPI2::Job::finished, + this, &MainWindow::slotAuthJobFinished); +} + +void MainWindow::slotAuthJobFinished(KGAPI2::Job *job) +{ + KGAPI2::AuthJob *authJob = qobject_cast(job); + Q_ASSERT(authJob); + /* Always remember to delete the jobs, otherwise your application will + * leak memory. */ + authJob->deleteLater(); + + if (authJob->error() != KGAPI2::NoError) { + m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(authJob->errorString())); + m_ui->errorLabel->setVisible(true); + return; + } + + m_account = authJob->account(); + // qDebug() << "Got access token" << m_account->accessToken(); + + m_ui->authStatusLabel->setText(QStringLiteral("Authenticated")); + m_ui->fileIdEdit->setEnabled(true); + m_ui->getPermissionsButton->setEnabled(true); +} + +void MainWindow::slotFetchPermissions() +{ + if (m_account.isNull()) { + m_ui->errorLabel->setText(QStringLiteral("Error: Please authenticate first")); + m_ui->errorLabel->setVisible(true); + m_ui->authButton->setVisible(true); + return; + } + + const QString fileId = m_ui->fileIdEdit->text(); + KGAPI2::Drive::PermissionFetchJob *fetchJob = new KGAPI2::Drive::PermissionFetchJob(fileId, m_account, this); + connect(fetchJob, &KGAPI2::Job::finished, + this, &MainWindow::slotPermissionsFetchJobFinished); +} + +void MainWindow::slotPermissionsFetchJobFinished(KGAPI2::Job *job) +{ + KGAPI2::Drive::PermissionFetchJob *fetchJob = qobject_cast(job); + Q_ASSERT(fetchJob); + fetchJob->deleteLater(); + + if (fetchJob->error() != KGAPI2::NoError) { + m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(fetchJob->errorString())); + m_ui->errorLabel->setVisible(true); + return; + } + + /* Get all items the job has retrieved */ + const KGAPI2::ObjectsList objects = fetchJob->items(); + m_ui->permissionsList->clear(); + for (const KGAPI2::ObjectPtr &object : objects) { + const KGAPI2::Drive::PermissionPtr permission = object.dynamicCast(); + + /* Convert the permission to QListWidget item */ + QListWidgetItem *item = new QListWidgetItem(m_ui->permissionsList); + QString displayText; + if (permission->name().isEmpty()) { + displayText = permission->emailAddress(); + } + else { + displayText = QStringLiteral("%0 (%1)").arg(permission->name()).arg(permission->emailAddress()); + } + item->setText(displayText); + item->setData(Qt::UserRole, permission->id()); + + m_ui->permissionsList->addItem(item); + } +} + +void MainWindow::permissionSelected() +{ + bool hasSelection = (m_ui->permissionsList->selectedItems().count() != 0); + + m_ui->permissionDetailsList->clear(); + + if (!hasSelection) { + return; + } + + const QString permissionId = m_ui->permissionsList->selectedItems().at(0)->data(Qt::UserRole).toString(); + const QString fileId = m_ui->fileIdEdit->text(); + KGAPI2::Drive::PermissionFetchJob *fetchJob = new KGAPI2::Drive::PermissionFetchJob(fileId, permissionId, m_account, this); + connect(fetchJob, &KGAPI2::Job::finished, + this, &MainWindow::slotPermissionFetchJobFinished); +} + +void MainWindow::slotPermissionFetchJobFinished(KGAPI2::Job *job) +{ + KGAPI2::Drive::PermissionFetchJob *fetchJob = qobject_cast(job); + Q_ASSERT(fetchJob); + fetchJob->deleteLater(); + + if (fetchJob->error() != KGAPI2::NoError) { + m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(fetchJob->errorString())); + m_ui->errorLabel->setVisible(true); + return; + } + + /* Get all items the job has retrieved */ + const KGAPI2::ObjectsList objects = fetchJob->items(); + for (const KGAPI2::ObjectPtr &object : objects) { + const KGAPI2::Drive::PermissionPtr permission = object.dynamicCast(); + + m_ui->permissionDetailsList->addItem(QStringLiteral("Id: %0").arg(permission->id())); + m_ui->permissionDetailsList->addItem(QStringLiteral("Name: %0").arg(permission->name())); + m_ui->permissionDetailsList->addItem(QStringLiteral("Email: %0").arg(permission->emailAddress())); + m_ui->permissionDetailsList->addItem(QStringLiteral("Type: %0").arg(typeToName(permission->type()))); + m_ui->permissionDetailsList->addItem(QStringLiteral("Role: %0").arg(roleToName(permission->role()))); + m_ui->permissionDetailsList->addItem(QStringLiteral("Permission details count: %0").arg(permission->permissionDetails().size())); + for (int i = 0; i < permission->permissionDetails().size(); ++i) { + KGAPI2::Drive::Permission::PermissionDetailsPtr permissionDetails = permission->permissionDetails().at(i); + m_ui->permissionDetailsList->addItem(QStringLiteral(" [%0] permissionType: %1").arg(i).arg(permissionTypeToName(permissionDetails->permissionType()))); + m_ui->permissionDetailsList->addItem(QStringLiteral(" [%0] role: %1").arg(i).arg(roleToName(permissionDetails->role()))); + m_ui->permissionDetailsList->addItem(QStringLiteral(" [%0] inherited: %1").arg(i).arg(permissionDetails->inherited() ? QStringLiteral("true") : QStringLiteral("false"))); + if (permissionDetails->inherited()) { + m_ui->permissionDetailsList->addItem(QStringLiteral(" [%0] inherited from: %1").arg(i).arg(permissionDetails->inheritedFrom())); + } + } + } +} + +QString MainWindow::roleToName(KGAPI2::Drive::Permission::Role role) +{ + switch (role) { + case KGAPI2::Drive::Permission::OwnerRole: + return QStringLiteral("owner"); + case KGAPI2::Drive::Permission::ReaderRole: + return QStringLiteral("reader"); + case KGAPI2::Drive::Permission::WriterRole: + return QStringLiteral("writer"); + case KGAPI2::Drive::Permission::CommenterRole: + return QStringLiteral("commenter"); + case KGAPI2::Drive::Permission::OrganizerRole: + return QStringLiteral("organizerRole"); + case KGAPI2::Drive::Permission::FileOrganizerRole: + return QStringLiteral("fileOrganizerRole"); + default: + return QString(); + } +} + +QString MainWindow::typeToName(KGAPI2::Drive::Permission::Type type) +{ + switch (type) { + case KGAPI2::Drive::Permission::TypeUser: + return QStringLiteral("user"); + case KGAPI2::Drive::Permission::TypeGroup: + return QStringLiteral("group"); + case KGAPI2::Drive::Permission::TypeDomain: + return QStringLiteral("domain"); + case KGAPI2::Drive::Permission::TypeAnyone: + return QStringLiteral("anyone"); + default: + return QString(); + } +} + +QString MainWindow::permissionTypeToName(KGAPI2::Drive::Permission::PermissionDetails::PermissionType permissionType) +{ + switch (permissionType) { + case KGAPI2::Drive::Permission::PermissionDetails::TypeFile: + return QStringLiteral("file"); + case KGAPI2::Drive::Permission::PermissionDetails::TypeMember: + return QStringLiteral("member"); + default: + return QString(); + } +} diff --git a/examples/permissions/mainwindow.h b/examples/permissions/mainwindow.h new file mode 100644 index 0000000..73a83a7 --- /dev/null +++ b/examples/permissions/mainwindow.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2019 David Barchiesi + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include +#include + +namespace Ui { + class MainWindow; +} + +namespace KGAPI2 { + class Job; +} + + +class MainWindow : public QMainWindow +{ + Q_OBJECT + + public: + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow() override; + + private Q_SLOTS: + /** + * Retrieves tokens from Google that we will use to authenticate + * fursther requests + */ + void authenticate(); + + /** + * Authentication has finished + */ + void slotAuthJobFinished(KGAPI2::Job *job); + + /** + * Retrieves list of all permissions for file id + */ + void slotFetchPermissions(); + + /** + * Permissions listing was fetched. + */ + void slotPermissionsFetchJobFinished(KGAPI2::Job *job); + + /** + * A specific permission in permissions list has been selected. Sends a request + * to Google to retrieve the permission details + */ + void permissionSelected(); + + /** + * Permissions listing was fetched. + */ + void slotPermissionFetchJobFinished(KGAPI2::Job *job); + + private: + Ui::MainWindow *m_ui; + + KGAPI2::AccountPtr m_account; + + QString roleToName(KGAPI2::Drive::Permission::Role role); + QString typeToName(KGAPI2::Drive::Permission::Type type); + QString permissionTypeToName(KGAPI2::Drive::Permission::PermissionDetails::PermissionType permissionType); +}; + +#endif // MAINWINDOW_H diff --git a/examples/permissions/ui/main.ui b/examples/permissions/ui/main.ui new file mode 100644 index 0000000..ffb6789 --- /dev/null +++ b/examples/permissions/ui/main.ui @@ -0,0 +1,180 @@ + + + MainWindow + + + + 0 + 0 + 640 + 486 + + + + MainWindow + + + + + + + + + Authenticate + + + + + + + Not authenticated + + + + + + + + + Qt::Horizontal + + + + + + + + + false + + + File ID + + + + + + + false + + + Fetch Permissions + + + + + + + + + + + + + + 12 + 75 + true + + + + Qt::RightToLeft + + + Permissions + + + Qt::AlignCenter + + + + + + + + + + + + + + + 12 + 75 + true + + + + Qt::RightToLeft + + + Selected Permission Details + + + Qt::AlignCenter + + + + + + + + + + + + + + + + + true + + + + + + + + + 0 + 0 + 640 + 30 + + + + + File + + + + + + + + + Quit + + + + + + + actionQuit + activated() + MainWindow + close() + + + -1 + -1 + + + 319 + 206 + + + + + diff --git a/src/drive/driveservice.cpp b/src/drive/driveservice.cpp index 59b5638..59a95ff 100644 --- a/src/drive/driveservice.cpp +++ b/src/drive/driveservice.cpp @@ -1,329 +1,329 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "driveservice.h" #include "utils.h" #include namespace KGAPI2 { namespace Private { static const QUrl GoogleApisUrl(QStringLiteral("https://www.googleapis.com")); static const QString AppsBasePath(QStringLiteral("/drive/v2/about")); static const QString FilesBasePath(QStringLiteral("/drive/v2/files")); static const QString ChangeBasePath(QStringLiteral("/drive/v2/changes")); static const QString DrivesBasePath(QStringLiteral("/drive/v2/drives")); static const QString TeamdriveBasePath(QStringLiteral("/drive/v2/teamdrives")); } namespace DriveService { QUrl fetchAboutUrl(bool includeSubscribed, qlonglong maxChangeIdCount, qlonglong startChangeId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::AppsBasePath); QUrlQuery query(url); query.addQueryItem(QStringLiteral("includeSubscribed"), Utils::bool2Str(includeSubscribed)); if (maxChangeIdCount > 0) { query.addQueryItem(QStringLiteral("maxChangeIdCount"), QString::number(maxChangeIdCount)); } if (startChangeId > 0) { query.addQueryItem(QStringLiteral("startChangeId"), QString::number(startChangeId)); } url.setQuery(query); return url; } QUrl fetchAppUrl(const QString &appId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::AppsBasePath % QLatin1Char('/') % appId); return url; } QUrl fetchAppsUrl() { QUrl url(Private::GoogleApisUrl); url.setPath(Private::AppsBasePath); return url; } QUrl fetchChildReference(const QString &folderId, const QString &referenceId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1String("/children/") % referenceId); return url; } QUrl fetchChildReferences(const QString &folderId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1String("/children")); return url; } QUrl createChildReference(const QString &folderId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1String("/children")); return url; } QUrl deleteChildReference(const QString &folderId, const QString &referenceId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % folderId % QLatin1String("/children/") % referenceId); return url; } QUrl fetchChangeUrl(const QString &changeId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::ChangeBasePath % QLatin1Char('/') % changeId); return url; } QUrl copyFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/copy")); return url; } QUrl deleteFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId); return url; } QUrl fetchFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId); return url; } QUrl fetchFilesUrl() { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath); return url; } QUrl fetchChangesUrl() { QUrl url(Private::GoogleApisUrl); url.setPath(Private::ChangeBasePath); return url; } QUrl touchFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/touch")); return url; } QUrl trashFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/trash")); return url; } QUrl untrashFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/untrash")); return url; } QUrl uploadMetadataFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); if (!fileId.isEmpty()) { url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId); } else { url.setPath(Private::FilesBasePath); } return url; } QUrl uploadMediaFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); if (!fileId.isEmpty()) { url.setPath(QLatin1String("/upload") % Private::FilesBasePath % QLatin1Char('/') % fileId); } else { url.setPath(QLatin1String("/upload") % Private::FilesBasePath); } return url; } QUrl uploadMultipartFileUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); if (!fileId.isEmpty()) { url.setPath(QLatin1String("/upload") % Private::FilesBasePath % QLatin1Char('/') % fileId); } else { url.setPath(QLatin1String("/upload") % Private::FilesBasePath); } return url; } QUrl fetchParentReferenceUrl(const QString &fileId, const QString &referenceId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/parents/") % referenceId); return url; } QUrl fetchParentReferencesUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/parents")); return url; } QUrl createParentReferenceUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/parents")); return url; } QUrl deleteParentReferenceUrl(const QString &fileId, const QString &referenceId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/parents/") % referenceId); return url; } QUrl fetchPermissionsUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); - url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/premissions")); + url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/permissions")); return url; } QUrl fetchPermissionUrl(const QString &fileId, const QString &permissionId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/permissions/") % permissionId); return url; } QUrl createPermissionUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/permissions")); return url; } QUrl deletePermissionUrl(const QString &fileId, const QString &permissionId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/permissions/") % permissionId); return url; } QUrl modifyPermissionUrl(const QString &fileId, const QString &permissionId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/permissions/") % permissionId); return url; } QUrl fetchRevisionUrl(const QString &fileId, const QString &revisionId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/revisions/") % revisionId); return url; } QUrl fetchRevisionsUrl(const QString &fileId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/revisions")); return url; } QUrl deleteRevisionUrl(const QString &fileId, const QString &revisionId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/revisions/") % revisionId); return url; } QUrl modifyRevisionUrl(const QString &fileId, const QString &revisionId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::FilesBasePath % QLatin1Char('/') % fileId % QLatin1String("/revisions/") % revisionId); return url; } QUrl fetchDrivesUrl(const QString &drivesId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::DrivesBasePath % QLatin1Char('/') % drivesId); return url; } QUrl hideDrivesUrl(const QString &drivesId, bool hide) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::DrivesBasePath % QLatin1Char('/') % drivesId % (hide ? QLatin1String("/hide") : QLatin1String("/unhide"))); return url; } QUrl fetchDrivesUrl() { QUrl url(Private::GoogleApisUrl); url.setPath(Private::DrivesBasePath); return url; } QUrl fetchTeamdriveUrl(const QString &teamdriveId) { QUrl url(Private::GoogleApisUrl); url.setPath(Private::TeamdriveBasePath % QLatin1Char('/') % teamdriveId); return url; } QUrl fetchTeamdrivesUrl() { QUrl url(Private::GoogleApisUrl); url.setPath(Private::TeamdriveBasePath); return url; } } // namespace DriveService } // namespace KGAPI2 diff --git a/src/drive/permission.cpp b/src/drive/permission.cpp index 4aee033..7d8c6ee 100644 --- a/src/drive/permission.cpp +++ b/src/drive/permission.cpp @@ -1,322 +1,456 @@ /* Copyright 2012 Andrius da Costa Ribas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "permission.h" #include "permission_p.h" #include "utils_p.h" #include using namespace KGAPI2; using namespace KGAPI2::Drive; +class Q_DECL_HIDDEN Permission::PermissionDetails::Private +{ + public: + Private() = default; + Private(const Private &other) = default; + + PermissionDetails::PermissionType permissionType = PermissionType::UndefinedType; + Role role; + QList additionalRoles; + QString inheritedFrom; + bool inherited = false; + + static PermissionType permissionTypeFromName(const QString &typeName); + static QString permissionTypeToName(PermissionType permissionType); +}; + +Permission::PermissionDetails::PermissionDetails(): + d(new Private) +{ +} + +Permission::PermissionDetails::PermissionDetails(const Permission::PermissionDetails &other): + d(new Private(*(other.d))) +{ +} + +Permission::PermissionDetails::~PermissionDetails() = default; + +bool Permission::PermissionDetails::operator==(const Permission::PermissionDetails &other) const +{ + GAPI_COMPARE(permissionType); + GAPI_COMPARE(role); + GAPI_COMPARE(additionalRoles); + GAPI_COMPARE(inheritedFrom); + GAPI_COMPARE(inherited); + return true; +} + +QString Permission::PermissionDetails::Private::permissionTypeToName(Permission::PermissionDetails::PermissionType permissionType) +{ + switch (permissionType) { + case Permission::PermissionDetails::TypeFile: + return QStringLiteral("file"); + case Permission::PermissionDetails::TypeMember: + return QStringLiteral("member"); + default: + return QString(); + } +} + +Permission::PermissionDetails::PermissionType Permission::PermissionDetails::Private::permissionTypeFromName(const QString &typeName) +{ + if (typeName == QLatin1String("file")) { + return Permission::PermissionDetails::TypeFile; + } else if (typeName == QLatin1String("member")) { + return Permission::PermissionDetails::TypeMember; + } else { + return Permission::PermissionDetails::UndefinedType; + } +} + +Permission::PermissionDetails::PermissionType Permission::PermissionDetails::permissionType() const +{ + return d->permissionType; +} + +Permission::Role Permission::PermissionDetails::role() const +{ + return d->role; +} + +QList Permission::PermissionDetails::additionalRoles() const +{ + return d->additionalRoles; +} + +QString Permission::PermissionDetails::inheritedFrom() const +{ + return d->inheritedFrom; +} + +bool Permission::PermissionDetails::inherited() const +{ + return d->inherited; +} + Permission::Role Permission::Private::roleFromName(const QString &roleName) { if (roleName == QLatin1String("owner")) { return Permission::OwnerRole; } else if (roleName == QLatin1String("reader")) { return Permission::ReaderRole; } else if (roleName == QLatin1String("writer")) { return Permission::WriterRole; } else if (roleName == QLatin1String("commenter")) { return Permission::CommenterRole; + } else if (roleName == QLatin1String("organizer")) { + return Permission::OrganizerRole; + } else if (roleName == QLatin1String("fileOrganizer")) { + return Permission::FileOrganizerRole; } else { return Permission::UndefinedRole; } } Permission::Type Permission::Private::typeFromName(const QString &typeName) { if (typeName == QLatin1String("user")) { return Permission::TypeUser; } else if (typeName == QLatin1String("group")) { return Permission::TypeGroup; } else if (typeName == QLatin1String("domain")) { return Permission::TypeDomain; } else if (typeName == QLatin1String("anyone")) { return Permission::TypeAnyone; } else { return Permission::UndefinedType; } } QString Permission::Private::roleToName(Permission::Role role) { switch (role) { case Permission::OwnerRole: return QStringLiteral("owner"); case Permission::ReaderRole: return QStringLiteral("reader"); case Permission::WriterRole: return QStringLiteral("writer"); case Permission::CommenterRole: - return QStringLiteral("commented"); + return QStringLiteral("commenter"); + case Permission::OrganizerRole: + return QStringLiteral("organizerRole"); + case Permission::FileOrganizerRole: + return QStringLiteral("fileOrganizerRole"); default: return QString(); } } QString Permission::Private::typeToName(Permission::Type type) { switch (type) { case Permission::TypeUser: return QStringLiteral("user"); case Permission::TypeGroup: return QStringLiteral("group"); case Permission::TypeDomain: return QStringLiteral("domain"); case Permission::TypeAnyone: return QStringLiteral("anyone"); default: return QString(); } } PermissionPtr Permission::Private::fromJSON(const QVariantMap &map) { if (!map.contains(QLatin1String("kind")) || map[QStringLiteral("kind")].toString() != QLatin1String("drive#permission")) { return PermissionPtr(); } PermissionPtr permission(new Permission()); permission->setEtag(map[QStringLiteral("etag")].toString()); permission->d->id = map[QStringLiteral("id")].toString(); permission->d->selfLink = map[QStringLiteral("selfLink")].toUrl(); permission->d->name = map[QStringLiteral("name")].toString(); permission->d->role = Private::roleFromName(map[QStringLiteral("role")].toString()); const QStringList additionalRoles = map[QStringLiteral("additionalRoles")].toStringList(); for (const QString & additionalRole : additionalRoles) { permission->d->additionalRoles << Private::roleFromName(additionalRole); } permission->d->type = Private::typeFromName(map[QStringLiteral("type")].toString()); permission->d->authKey = map[QStringLiteral("authKey")].toString(); permission->d->withLink = map[QStringLiteral("withLink")].toBool(); permission->d->photoLink = map[QStringLiteral("photoLink")].toUrl(); permission->d->value = map[QStringLiteral("value")].toString(); + permission->d->emailAddress = map[QStringLiteral("emailAddress")].toString(); + permission->d->domain = map[QStringLiteral("domain")].toString(); + permission->d->expirationDate = QDateTime::fromString(map[QStringLiteral("expirationDate")].toString(), Qt::ISODate); + permission->d->deleted = map[QStringLiteral("deleted")].toBool(); + + if (map.contains(QStringLiteral("permissionDetails"))) { + const QVariantList permissionDetailsList = map[QStringLiteral("permissionDetails")].toList(); + for (const QVariant &variant : permissionDetailsList) { + const QVariantMap permissionDetailsMap = variant.toMap(); + auto permissionDetails = PermissionDetailsPtr::create(); + permissionDetails->d->permissionType = PermissionDetails::Private::permissionTypeFromName(permissionDetailsMap[QStringLiteral("permissionType")].toString()); + permissionDetails->d->role = Private::roleFromName(permissionDetailsMap[QStringLiteral("role")].toString()); + const QStringList permissionDetailsAdditionalRoles = permissionDetailsMap[QStringLiteral("additionalRoles")].toStringList(); + for (const QString &additionalRole : permissionDetailsAdditionalRoles) { + permissionDetails->d->additionalRoles << Private::roleFromName(additionalRole); + } + permissionDetails->d->inheritedFrom = permissionDetailsMap[QStringLiteral("inheritedFrom")].toString(); + permissionDetails->d->inherited = map[QStringLiteral("inherited")].toBool(); + + permission->d->permissionDetails << permissionDetails; + } + } return permission; } Permission::Private::Private(): role(Permission::UndefinedRole), type(Permission::UndefinedType), withLink(false) { } -Permission::Private::Private(const Private &other): - id(other.id), - selfLink(other.selfLink), - name(other.name), - role(other.role), - additionalRoles(other.additionalRoles), - type(other.type), - authKey(other.authKey), - withLink(other.withLink), - photoLink(other.photoLink), - value(other.value) -{ -} +Permission::Private::Private(const Private &other) = default; Permission::Permission(): KGAPI2::Object(), d(new Private) { } Permission::Permission(const Permission &other): KGAPI2::Object(other), d(new Private(*(other.d))) { } Permission::~Permission() { delete d; } bool Permission::operator==(const Permission &other) const { if (!Object::operator==(other)) { return false; } GAPI_COMPARE(id) GAPI_COMPARE(selfLink) GAPI_COMPARE(name) GAPI_COMPARE(role) GAPI_COMPARE(additionalRoles) GAPI_COMPARE(type) GAPI_COMPARE(authKey) GAPI_COMPARE(withLink) GAPI_COMPARE(photoLink) GAPI_COMPARE(value) + GAPI_COMPARE(emailAddress) + GAPI_COMPARE(domain) + GAPI_COMPARE(expirationDate) + GAPI_COMPARE(deleted) + GAPI_COMPARE(permissionDetails) return true; } QString Permission::id() const { return d->id; } void Permission::setId(const QString &id) { d->id = id; } QUrl Permission::selfLink() const { return d->selfLink; } QString Permission::name() const { return d->name; } Permission::Role Permission::role() const { return d->role; } void Permission::setRole(Permission::Role role) { d->role = role; } QList Permission::additionalRoles() const { return d->additionalRoles; } void Permission::setAdditionalRoles(const QList &additionalRoles) { d->additionalRoles = additionalRoles; } Permission::Type Permission::type() const { return d->type; } void Permission::setType(Permission::Type type) { d->type = type; } QString Permission::authKey() const { return d->authKey; } bool Permission::withLink() const { return d->withLink; } void Permission::setWithLink(bool withLink) { d->withLink = withLink; } QUrl Permission::photoLink() const { return d->photoLink; } QString Permission::value() const { return d->value; } void Permission::setValue(const QString &value) { d->value = value; } +QString Permission::emailAddress() const +{ + return d->emailAddress; +} + +QString Permission::domain() const +{ + return d->domain; +} + +QDateTime Permission::expirationDate() const +{ + return d->expirationDate; +} + +bool Permission::deleted() const +{ + return d->deleted; +} + +Permission::PermissionDetailsList Permission::permissionDetails() const +{ + return d->permissionDetails; +} + PermissionPtr Permission::fromJSON(const QByteArray &jsonData) { QJsonDocument document = QJsonDocument::fromJson(jsonData); if (document.isNull()) { return PermissionPtr(); } const QVariant json = document.toVariant(); const QVariantMap map = json.toMap(); return Private::fromJSON(map); } PermissionsList Permission::fromJSONFeed(const QByteArray &jsonData) { QJsonDocument document = QJsonDocument::fromJson(jsonData); if (document.isNull()) { return PermissionsList(); } const QVariant json = document.toVariant(); const QVariantMap map = json.toMap(); if (!map.contains(QLatin1String("kind")) || map[QStringLiteral("kind")].toString() != QLatin1String("drive#permissionList")) { return PermissionsList(); } PermissionsList permissions; const QVariantList items = map[QStringLiteral("items")].toList(); for (const QVariant & item : items) { const PermissionPtr permission = Private::fromJSON(item.toMap()); if (!permission.isNull()) { permissions << permission; } } return permissions; } QByteArray Permission::toJSON(const PermissionPtr &permission) { QVariantMap map; if (permission->role() != Permission::UndefinedRole) { map[QStringLiteral("role")] = Private::roleToName(permission->role()); } if (permission->type() != Permission::UndefinedType) { map[QStringLiteral("type")] = Private::typeToName(permission->type()); } QVariantList additionalRoles; const auto roles = permission->additionalRoles(); additionalRoles.reserve(roles.size()); for (Permission::Role additionalRole : roles) { additionalRoles << Private::roleToName(additionalRole); } if (!additionalRoles.isEmpty()) { map[QStringLiteral("additionalRoles")] = additionalRoles; } map[QStringLiteral("withLink")] = permission->withLink(); if (!permission->value().isEmpty()) { map[QStringLiteral("value")] = permission->value(); } QJsonDocument document = QJsonDocument::fromVariant(map); return document.toJson(QJsonDocument::Compact); } diff --git a/src/drive/permission.h b/src/drive/permission.h index bc76b0d..f0109a2 100644 --- a/src/drive/permission.h +++ b/src/drive/permission.h @@ -1,187 +1,280 @@ /* Copyright 2012 Andrius da Costa Ribas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef LIBKGAPI2_DRIVEPERMISSION_H #define LIBKGAPI2_DRIVEPERMISSION_H #include "object.h" #include "types.h" #include "file.h" #include "kgapidrive_export.h" #include #include namespace KGAPI2 { namespace Drive { /** * @brief Permission contains a permission for a file. * * Getters and setters' documentation is based on Google Drive's API v2 reference * @see Permissions * * @since 2.0 * @author Andrius da Costa Ribas * @author Daniel Vrátil */ class KGAPIDRIVE_EXPORT Permission: public KGAPI2::Object { public: + enum Role { UndefinedRole = -1, OwnerRole = 0, ReaderRole = 1, WriterRole = 2, CommenterRole = 3, + OrganizerRole = 4, + FileOrganizerRole = 5, }; enum Type { UndefinedType = -1, TypeUser = 0, TypeGroup = 1, TypeDomain = 2, TypeAnyone = 3 }; + /** + * @brief Details of whether the permissions on this shared drive item are + * inherited or directly on this item. This is an output-only field which + * is present only for shared drive items. + */ + class PermissionDetails + { + + public: + enum PermissionType { + UndefinedType = -1, + TypeFile = 0, + TypeMember = 1, + }; + + PermissionDetails(); + PermissionDetails(const PermissionDetails &other); + ~PermissionDetails(); + bool operator==(const PermissionDetails &other) const; + bool operator!=(const PermissionDetails &other) const { return !operator==(other); } + + /** + * @brief The permission type for this user. + */ + PermissionDetails::PermissionType permissionType() const; + + /** + * @brief The primary role for this user. + */ + Permission::Role role() const; + + /** + * @brief Additional roles for this user. Only commenter is currently possible, + * though more may be supported in the future. + */ + QList additionalRoles() const; + + /** + * @brief The ID of the item from which this permission is inherited. + * This is an output-only field and is only populated for members of + * the shared drive. + */ + QString inheritedFrom() const; + + /** + * @brief Whether this permission is inherited. This field is always populated. This is an output-only field. + */ + bool inherited() const; + + private: + class Private; + QScopedPointer const d; + friend class Private; + friend class Permission; + }; + + typedef QSharedPointer PermissionDetailsPtr; + typedef QList PermissionDetailsList; + explicit Permission(); explicit Permission(const Permission &other); ~Permission() override; bool operator==(const Permission &other) const; bool operator!=(const Permission &other) const { return !operator==(other); } /** * @brief Returns the id of the permission. */ QString id() const; /** * @brief Sets the id of the permission. * * @param id */ void setId(const QString &id); /** * @brief Returns a link back to this permission. */ QUrl selfLink() const; /** * @brief Returns the name of this permission. */ QString name() const; /** * @brief Returns the primary role for this user. */ Permission::Role role() const; /** * @brief Sets the primary role for this user. */ void setRole(Permission::Role role); /** * @brief Returns additional roles for this user. Only commenter is currently allowed. */ QList additionalRoles() const; /** * @brief Sets additional roles for this user. Only commenter is currently allowed. * * @param additionalRoles */ void setAdditionalRoles(const QList &additionalRoles); /** * @brief Returns the account type. */ Permission::Type type() const; /** * @brief Sets the account type. * * @param type */ void setType(Permission::Type type); /** * @brief Returns the authkey parameter required for this permission. */ QString authKey() const; /** * @brief Returns whether the link is required for this permission. */ bool withLink() const; /** * @brief Sets whether the link is required for this permission. * * @param withLink */ void setWithLink(bool withLink); /** * @brief Returns a link to the profile photo, if available. */ QUrl photoLink() const; /** * @brief Returns the email address or domain name for the entity. * * This is not populated in responses. * You can use the alias "me" as the value for this property to refer to the * current authorized user. */ QString value() const; /** * @brief Sets the email address or domain name for the entity. * * This is not populated in responses. * You can use the alias "me" as the value for this property to refer to the * current authorized user. * * @param value */ void setValue(const QString &value); + /** + * @brief The email address of the user or group this permission refers to. + * This is an output-only field which is present when the permission type is + * user or group. + */ + QString emailAddress() const; + + /** + * @brief The domain name of the entity this permission refers to. + * This is an output-only field which is present when the permission + * type is user, group or domain. + */ + QString domain() const; + + /** + * @brief The time at which this permission will expire. + */ + QDateTime expirationDate() const; + + /** + * @brief Whether the account associated with this permission has been + * deleted. This field only pertains to user and group permissions. + */ + bool deleted() const; + + /** + * @brief Details of whether the permissions on this shared drive + * item are inherited or directly on this item. + */ + Permission::PermissionDetailsList permissionDetails() const; + static PermissionPtr fromJSON(const QByteArray &jsonData); static PermissionsList fromJSONFeed(const QByteArray &jsonData); static QByteArray toJSON(const PermissionPtr &permission); private: class Private; Private *const d; friend class Private; friend class File::Private; }; } /* namespace Drive */ } /* namespace KGAPI2 */ #endif // LIBKGAPI2_DRIVEPERMISSION_H diff --git a/src/drive/permission_p.h b/src/drive/permission_p.h index 1b8236b..1835d2f 100644 --- a/src/drive/permission_p.h +++ b/src/drive/permission_p.h @@ -1,62 +1,67 @@ /* Copyright 2012 Andrius da Costa Ribas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef LIBKGAPI2_DRIVEPERMISSION_P_H #define LIBKGAPI2_DRIVEPERMISSION_P_H #include "permission.h" namespace KGAPI2 { namespace Drive { class Q_DECL_HIDDEN Permission::Private { public: Private(); Private(const Private &other); QString id; QUrl selfLink; QString name; Role role; QList additionalRoles; Type type; QString authKey; bool withLink; QUrl photoLink; QString value; + QString emailAddress; + QString domain; + QDateTime expirationDate; + bool deleted; + PermissionDetailsList permissionDetails; static Role roleFromName(const QString &roleName); static Type typeFromName(const QString &typeName); static QString roleToName(Permission::Role role); static QString typeToName(Permission::Type type); static PermissionPtr fromJSON(const QVariantMap &map); friend class File::Private; }; } // namespace Drive } // namespace KGAPI2 #endif //LIBKGAPI2_DRIVEPERMISSION_P_H diff --git a/src/drive/permissioncreatejob.cpp b/src/drive/permissioncreatejob.cpp index c0fe439..405ac09 100644 --- a/src/drive/permissioncreatejob.cpp +++ b/src/drive/permissioncreatejob.cpp @@ -1,140 +1,189 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "permissioncreatejob.h" #include "account.h" #include "driveservice.h" #include "permission.h" #include "utils.h" #include #include #include using namespace KGAPI2; using namespace KGAPI2::Drive; +namespace { + static constexpr bool sendNotificationEmailsDefault = true; + static constexpr bool useDomainAdminAccessDefault = false; +} + class Q_DECL_HIDDEN PermissionCreateJob::Private { public: Private(PermissionCreateJob *parent); void processNext(); PermissionsList permissions; QString fileId; + QString emailMessage; + bool sendNotificationEmails; bool supportsAllDrives; + bool useDomainAdminAccess; private: PermissionCreateJob *const q; }; PermissionCreateJob::Private::Private(PermissionCreateJob *parent): + sendNotificationEmails(sendNotificationEmailsDefault), supportsAllDrives(true), + useDomainAdminAccess(useDomainAdminAccessDefault), q(parent) { } void PermissionCreateJob::Private::processNext() { if (permissions.isEmpty()) { q->emitFinished(); return; } const PermissionPtr permission = permissions.takeFirst(); QUrl url = DriveService::createPermissionUrl(fileId); - QUrlQuery withDriveSupportQuery(url); - withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(supportsAllDrives)); - url.setQuery(withDriveSupportQuery); + QUrlQuery query(url); + query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(supportsAllDrives)); + + if (sendNotificationEmails != sendNotificationEmailsDefault) { + query.addQueryItem(QStringLiteral("sendNotificationEmails"), Utils::bool2Str(sendNotificationEmails)); + } + + if (!emailMessage.isEmpty()) { + query.addQueryItem(QStringLiteral("emailMessage"), emailMessage); + } + + if (useDomainAdminAccess != useDomainAdminAccessDefault) { + query.addQueryItem(QStringLiteral("useDomainAdminAccess"), Utils::bool2Str(useDomainAdminAccess)); + } + url.setQuery(query); QNetworkRequest request(url); const QByteArray rawData = Permission::toJSON(permission); q->enqueueRequest(request, rawData, QStringLiteral("application/json")); } PermissionCreateJob::PermissionCreateJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent): CreateJob(account, parent), d(new Private(this)) { d->fileId = fileId; d->permissions << permission; } PermissionCreateJob::PermissionCreateJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent): CreateJob(account, parent), d(new Private(this)) { d->fileId = fileId; d->permissions = permissions; } -PermissionCreateJob::~PermissionCreateJob() +PermissionCreateJob::~PermissionCreateJob() = default; + +QString PermissionCreateJob::emailMessage() const +{ + return d->emailMessage; +} + +void PermissionCreateJob::setEmailMessage(QString emailMessage) { - delete d; + d->emailMessage = emailMessage; +} + +bool PermissionCreateJob::sendNotificationEmails() const +{ + return d->sendNotificationEmails; +} + +void PermissionCreateJob::setSendNotificationEmails(bool sendNotificationEmails) +{ + d->sendNotificationEmails = sendNotificationEmails; } bool PermissionCreateJob::supportsAllDrives() const { return d->supportsAllDrives; } void PermissionCreateJob::setSupportsAllDrives(bool supportsAllDrives) { d->supportsAllDrives = supportsAllDrives; } +bool PermissionCreateJob::useDomainAdminAccess() const +{ + return d->useDomainAdminAccess; +} + +void PermissionCreateJob::setUseDomainAdminAccess(bool useDomainAdminAccess) +{ + d->useDomainAdminAccess = useDomainAdminAccess; +} + void PermissionCreateJob::start() { d->processNext(); } ObjectsList PermissionCreateJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) { const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); ContentType ct = Utils::stringToContentType(contentType); ObjectsList items; if (ct == KGAPI2::JSON) { items << Permission::fromJSON(rawData); } else { setError(KGAPI2::InvalidResponse); setErrorString(tr("Invalid response content type")); emitFinished(); } // Enqueue next item or finish d->processNext(); return items; } diff --git a/src/drive/permissioncreatejob.h b/src/drive/permissioncreatejob.h index fd2990f..3ac91ae 100644 --- a/src/drive/permissioncreatejob.h +++ b/src/drive/permissioncreatejob.h @@ -1,83 +1,123 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KGAPI2_DRIVEPERMISSIONCREATEJOB_H #define KGAPI2_DRIVEPERMISSIONCREATEJOB_H #include "createjob.h" #include "kgapidrive_export.h" namespace KGAPI2 { namespace Drive { class KGAPIDRIVE_EXPORT PermissionCreateJob : public KGAPI2::CreateJob { Q_OBJECT public: explicit PermissionCreateJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionCreateJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent = nullptr); ~PermissionCreateJob() override; + /** + * @brief The plain text custom message to include in notification emails. + */ + QString emailMessage() const; + + /** + * @brief Sets the plain text custom message to include in notification emails. + */ + void setEmailMessage(QString emailMessage); + + /** + * @brief Sets whether to send notification emails when sharing to users + * or groups. This parameter is ignored and an email is sent if the role + * is owner. (Default: true) + */ + bool sendNotificationEmails() const; + + /** + * @brief Whether to send notification emails when sharing to users or + * groups. This parameter is ignored and an email is sent if the role + * is owner. (Default: true) + */ + void setSendNotificationEmails(bool sendNotificationEmails); + /** * @brief Whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; /** * @brief Sets whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + /** + * @brief Issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + bool useDomainAdminAccess() const; + + /** + * @brief Sets to issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + void setUseDomainAdminAccess(bool useDomainAdminAccess); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override; private: class Private; - Private *const d; + QScopedPointer d; friend class Private; }; } // namespace Drive } // namespace KGAPI2 #endif // KGAPI2_DRIVEPERMISSIONCREATEJOB_H diff --git a/src/drive/permissiondeletejob.cpp b/src/drive/permissiondeletejob.cpp index 0b80cde..27f2d33 100644 --- a/src/drive/permissiondeletejob.cpp +++ b/src/drive/permissiondeletejob.cpp @@ -1,126 +1,145 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "permissiondeletejob.h" #include "permission.h" #include "account.h" #include "utils.h" #include "driveservice.h" #include #include using namespace KGAPI2; using namespace KGAPI2::Drive; +namespace { + static constexpr bool useDomainAdminAccessDefault = false; +} + class Q_DECL_HIDDEN PermissionDeleteJob::Private { public: QString fileId; QStringList permissionsIds; bool supportsAllDrives; + bool useDomainAdminAccess; }; PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent): DeleteJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = fileId; d->permissionsIds << permission->id(); } PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const QString &permissionId, const AccountPtr &account, QObject *parent): DeleteJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = fileId; d->permissionsIds << permissionId; } PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent): DeleteJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = fileId; for (const PermissionPtr & permission : qAsConst(permissions)) { d->permissionsIds << permission->id(); } } PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const QStringList &permissionsIds, const AccountPtr &account, QObject *parent): DeleteJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = fileId; d->permissionsIds << permissionsIds; } -PermissionDeleteJob::~PermissionDeleteJob() -{ - delete d; -} +PermissionDeleteJob::~PermissionDeleteJob() = default; bool PermissionDeleteJob::supportsAllDrives() const { return d->supportsAllDrives; } void PermissionDeleteJob::setSupportsAllDrives(bool supportsAllDrives) { d->supportsAllDrives = supportsAllDrives; } +bool PermissionDeleteJob::useDomainAdminAccess() const +{ + return d->useDomainAdminAccess; +} + +void PermissionDeleteJob::setUseDomainAdminAccess(bool useDomainAdminAccess) +{ + d->useDomainAdminAccess = useDomainAdminAccess; +} + void PermissionDeleteJob::start() { if (d->permissionsIds.isEmpty()) { emitFinished(); return; } const QString permissionId = d->permissionsIds.takeFirst(); QUrl url = DriveService::deletePermissionUrl(d->fileId, permissionId); - QUrlQuery withDriveSupportQuery(url); - withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives)); - url.setQuery(withDriveSupportQuery); + QUrlQuery query(url); + query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives)); + if (d->useDomainAdminAccess != useDomainAdminAccessDefault) { + query.addQueryItem(QStringLiteral("useDomainAdminAccess"), Utils::bool2Str(d->useDomainAdminAccess)); + } + url.setQuery(query); QNetworkRequest request(url); enqueueRequest(request); } diff --git a/src/drive/permissiondeletejob.h b/src/drive/permissiondeletejob.h index 6979180..8507955 100644 --- a/src/drive/permissiondeletejob.h +++ b/src/drive/permissiondeletejob.h @@ -1,90 +1,106 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KGAPI2_DRIVEPERMISSIONDELETEJOB_H #define KGAPI2_DRIVEPERMISSIONDELETEJOB_H #include "deletejob.h" #include "kgapidrive_export.h" #include namespace KGAPI2 { namespace Drive { -class KGAPIDRIVE_EXPORT PermissionDeleteJob : KGAPI2::DeleteJob +class KGAPIDRIVE_EXPORT PermissionDeleteJob : public KGAPI2::DeleteJob { Q_OBJECT public: explicit PermissionDeleteJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionDeleteJob(const QString &fileId, const QString &permissionId, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionDeleteJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionDeleteJob(const QString &fileId, const QStringList &permissionsIds, const AccountPtr &account, QObject *parent = nullptr); ~PermissionDeleteJob() override; /** * @brief Whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; /** * @brief Sets whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + /** + * @brief Issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + bool useDomainAdminAccess() const; + + /** + * @brief Sets to issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + void setUseDomainAdminAccess(bool useDomainAdminAccess); + protected: void start() override; private: class Private; - Private *const d; + QScopedPointer d; friend class Private; }; } // namespace Drive } // namespace KGAPI2 #endif // KGAPI2_DRIVEPERMISSIONDELETEJOB_H diff --git a/src/drive/permissionfetchjob.cpp b/src/drive/permissionfetchjob.cpp index 36b6c10..ce0b4c4 100644 --- a/src/drive/permissionfetchjob.cpp +++ b/src/drive/permissionfetchjob.cpp @@ -1,144 +1,161 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "permissionfetchjob.h" #include "driveservice.h" #include "account.h" #include "file.h" #include "permission.h" #include "utils.h" #include #include #include using namespace KGAPI2; using namespace KGAPI2::Drive; +namespace { + static constexpr bool useDomainAdminAccessDefault = false; +} + class Q_DECL_HIDDEN PermissionFetchJob::Private { public: QString fileId; QString permissionId; bool supportsAllDrives; - + bool useDomainAdminAccess; }; PermissionFetchJob::PermissionFetchJob(const QString &fileId, const AccountPtr &account, QObject *parent): FetchJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = fileId; } PermissionFetchJob::PermissionFetchJob(const FilePtr &file, const AccountPtr &account, QObject *parent): FetchJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = file->id(); } PermissionFetchJob::PermissionFetchJob(const QString &fileId, const QString &permissionId, const AccountPtr &account, QObject *parent): FetchJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = fileId; d->permissionId = permissionId; } PermissionFetchJob::PermissionFetchJob(const FilePtr &file, const QString &permissionId, const AccountPtr &account, QObject *parent): FetchJob(account, parent), d(new Private) { d->supportsAllDrives = true; + d->useDomainAdminAccess = useDomainAdminAccessDefault; d->fileId = file->id(); d->permissionId = permissionId; } -PermissionFetchJob::~PermissionFetchJob() -{ - delete d; -} +PermissionFetchJob::~PermissionFetchJob() = default; bool PermissionFetchJob::supportsAllDrives() const { return d->supportsAllDrives; } void PermissionFetchJob::setSupportsAllDrives(bool supportsAllDrives) { d->supportsAllDrives = supportsAllDrives; } +bool PermissionFetchJob::useDomainAdminAccess() const +{ + return d->useDomainAdminAccess; +} + +void PermissionFetchJob::setUseDomainAdminAccess(bool useDomainAdminAccess) +{ + d->useDomainAdminAccess = useDomainAdminAccess; +} + void PermissionFetchJob::start() { QUrl url; if (d->permissionId.isEmpty()) { url = DriveService::fetchPermissionsUrl(d->fileId); } else { url = DriveService::fetchPermissionUrl(d->fileId, d->permissionId); } - QUrlQuery withDriveSupportQuery(url); - withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives)); - url.setQuery(withDriveSupportQuery); - + QUrlQuery query(url); + query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives)); + if (d->useDomainAdminAccess != useDomainAdminAccessDefault) { + query.addQueryItem(QStringLiteral("useDomainAdminAccess"), Utils::bool2Str(d->useDomainAdminAccess)); + } + url.setQuery(query); QNetworkRequest request(url); enqueueRequest(request); } ObjectsList PermissionFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) { ObjectsList items; const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); ContentType ct = Utils::stringToContentType(contentType); if (ct == KGAPI2::JSON) { if (d->permissionId.isEmpty()) { items << Permission::fromJSONFeed(rawData); } else { items << Permission::fromJSON(rawData); } } else { setError(KGAPI2::InvalidResponse); setErrorString(tr("Invalid response content type")); } emitFinished(); return items; } diff --git a/src/drive/permissionfetchjob.h b/src/drive/permissionfetchjob.h index 58d4b01..9259413 100644 --- a/src/drive/permissionfetchjob.h +++ b/src/drive/permissionfetchjob.h @@ -1,86 +1,102 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KGAPI2_DRIVEPERMISSIONFETCHJOB_H #define KGAPI2_DRIVEPERMISSIONFETCHJOB_H #include "fetchjob.h" #include "kgapidrive_export.h" namespace KGAPI2 { namespace Drive { class KGAPIDRIVE_EXPORT PermissionFetchJob : public KGAPI2::FetchJob { Q_OBJECT public: explicit PermissionFetchJob(const QString &fileId, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionFetchJob(const FilePtr &file, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionFetchJob(const QString &fileId, const QString &permissionId, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionFetchJob(const FilePtr &file, const QString &permissionId, const AccountPtr &account, QObject *parent = nullptr); ~PermissionFetchJob() override; /** * @brief Whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; /** * @brief Sets whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + /** + * @brief Issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + bool useDomainAdminAccess() const; + + /** + * @brief Sets to issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + void setUseDomainAdminAccess(bool useDomainAdminAccess); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override; private: class Private; - Private *const d; + QScopedPointer d; friend class Private; }; } // namespace Drive } // namespace KGAPI2 #endif // KGAPI2_DRIVEPERMISSIONFETCHJOB_H diff --git a/src/drive/permissionmodifyjob.cpp b/src/drive/permissionmodifyjob.cpp index d1ab131..4b8d8d8 100644 --- a/src/drive/permissionmodifyjob.cpp +++ b/src/drive/permissionmodifyjob.cpp @@ -1,140 +1,191 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "permissionmodifyjob.h" #include "account.h" #include "driveservice.h" #include "permission.h" #include "utils.h" #include #include #include using namespace KGAPI2; using namespace KGAPI2::Drive; +namespace { + static constexpr bool removeExpirationDefault = false; + static constexpr bool transferOwnershipDefault = false; + static constexpr bool useDomainAdminAccessDefault = false; +} + class Q_DECL_HIDDEN PermissionModifyJob::Private { public: Private(PermissionModifyJob *parent); void processNext(); QString fileId; PermissionsList permissions; bool supportsAllDrives; + bool removeExpiration; + bool transferOwnership; + bool useDomainAdminAccess; private: PermissionModifyJob *q; }; PermissionModifyJob::Private::Private(PermissionModifyJob *parent): supportsAllDrives(true), + removeExpiration(removeExpirationDefault), + transferOwnership(transferOwnershipDefault), + useDomainAdminAccess(useDomainAdminAccessDefault), q(parent) { } void PermissionModifyJob::Private::processNext() { if (permissions.isEmpty()) { q->emitFinished(); return; } const PermissionPtr permission = permissions.takeFirst(); QUrl url = DriveService::modifyPermissionUrl(fileId, permission->id()); - QUrlQuery withDriveSupportQuery(url); - withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(supportsAllDrives)); - url.setQuery(withDriveSupportQuery); + QUrlQuery query(url); + query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(supportsAllDrives)); + + if (removeExpiration != removeExpirationDefault) { + query.addQueryItem(QStringLiteral("removeExpiration"), Utils::bool2Str(removeExpiration)); + } + + if (!transferOwnership != transferOwnershipDefault) { + query.addQueryItem(QStringLiteral("transferOwnership"), Utils::bool2Str(transferOwnership)); + } + + if (!useDomainAdminAccess != useDomainAdminAccessDefault) { + query.addQueryItem(QStringLiteral("useDomainAdminAccess"), Utils::bool2Str(useDomainAdminAccess)); + } + url.setQuery(query); QNetworkRequest request(url); const QByteArray rawData = Permission::toJSON(permission); q->enqueueRequest(request, rawData, QStringLiteral("application/json")); } PermissionModifyJob::PermissionModifyJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent): ModifyJob(account, parent), d(new Private(this)) { d->fileId = fileId; d->permissions << permission; } PermissionModifyJob::PermissionModifyJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent): ModifyJob(account, parent), d(new Private(this)) { d->fileId = fileId; d->permissions << permissions; } -PermissionModifyJob::~PermissionModifyJob() +PermissionModifyJob::~PermissionModifyJob() = default; + +bool PermissionModifyJob::removeExpiration() const +{ + return d->removeExpiration; +} + +void PermissionModifyJob::setRemoveExpiration(bool removeExpiration) { - delete d; + d->removeExpiration = removeExpiration; } bool PermissionModifyJob::supportsAllDrives() const { return d->supportsAllDrives; } void PermissionModifyJob::setSupportsAllDrives(bool supportsAllDrives) { d->supportsAllDrives = supportsAllDrives; } +bool PermissionModifyJob::transferOwnership() const +{ + return d->transferOwnership; +} + +void PermissionModifyJob::setTransferOwnership(bool transferOwnership) +{ + d->transferOwnership = transferOwnership; +} + +bool PermissionModifyJob::useDomainAdminAccess() const +{ + return d->useDomainAdminAccess; +} + +void PermissionModifyJob::setUseDomainAdminAccess(bool useDomainAdminAccess) +{ + d->useDomainAdminAccess = useDomainAdminAccess; +} + void PermissionModifyJob::start() { d->processNext(); } ObjectsList PermissionModifyJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) { const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); ContentType ct = Utils::stringToContentType(contentType); ObjectsList items; if (ct == KGAPI2::JSON) { items << Permission::fromJSON(rawData); } else { setError(KGAPI2::InvalidResponse); setErrorString(tr("Invalid response content type")); emitFinished(); } // Enqueue next item or finish d->processNext(); return items; } diff --git a/src/drive/permissionmodifyjob.h b/src/drive/permissionmodifyjob.h index 0c2a78a..80b3079 100644 --- a/src/drive/permissionmodifyjob.h +++ b/src/drive/permissionmodifyjob.h @@ -1,84 +1,124 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2013 Daniel Vrátil * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KGAPI2_DRIVEPERMISSIONMODIFYJOB_H #define KGAPI2_DRIVEPERMISSIONMODIFYJOB_H #include "modifyjob.h" #include "kgapidrive_export.h" namespace KGAPI2 { namespace Drive { class KGAPIDRIVE_EXPORT PermissionModifyJob : public KGAPI2::ModifyJob { Q_OBJECT public: explicit PermissionModifyJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent = nullptr); explicit PermissionModifyJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent = nullptr); ~PermissionModifyJob() override; + /** + * @brief Whether to remove the expiration date. (Default: false) + */ + bool removeExpiration() const; + + /** + * @brief Sets whether to remove the expiration date. (Default: false) + */ + void setRemoveExpiration(bool removeExpiration); + /** * @brief Whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; /** * @brief Sets whether the request supports both My Drives and shared drives. * * Set to true by default as LibKGAPI supports Team Drives. * * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications * are assumed to support shared drives. */ KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + /** + * @brief Whether changing a role to 'owner' downgrades the current owners + * to writers. Does nothing if the specified role is not 'owner'. + * (Default: false) + */ + bool transferOwnership() const; + + /** + * @brief Sets whether changing a role to 'owner' downgrades the current owners + * to writers. Does nothing if the specified role is not 'owner'. + * (Default: false) + */ + void setTransferOwnership(bool transferOwnership); + + /** + * @brief Issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + bool useDomainAdminAccess() const; + + /** + * @brief Sets to issue the request as a domain administrator; if set to true, + * then the requester will be granted access if the file ID parameter refers + * to a shared drive and the requester is an administrator of the domain to + * which the shared drive belongs. (Default: false) + */ + void setUseDomainAdminAccess(bool useDomainAdminAccess); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override; private: class Private; - Private *const d; + QScopedPointer d; friend class Private; }; } // namespace Drive } // namespace KGAPI2 #endif // KGAPI2_DRIVEPERMISSIONMODIFYJOB_H