9#include "permissioncreatejob.h"
10#include "driveservice.h"
11#include "permission.h"
14#include <QNetworkReply>
15#include <QNetworkRequest>
19using namespace KGAPI2::Drive;
23static constexpr bool sendNotificationEmailsDefault =
true;
24static constexpr bool useDomainAdminAccessDefault =
false;
27class Q_DECL_HIDDEN PermissionCreateJob::Private
30 Private(PermissionCreateJob *parent);
33 PermissionsList permissions;
36 bool sendNotificationEmails;
37 bool supportsAllDrives =
true;
38 bool useDomainAdminAccess;
41 PermissionCreateJob *
const q;
44PermissionCreateJob::Private::Private(PermissionCreateJob *parent)
45 : sendNotificationEmails(sendNotificationEmailsDefault)
46 , useDomainAdminAccess(useDomainAdminAccessDefault)
51void PermissionCreateJob::Private::processNext()
53 if (permissions.isEmpty()) {
58 const PermissionPtr permission = permissions.takeFirst();
60 QUrl url = DriveService::createPermissionUrl(fileId);
63 query.addQueryItem(QStringLiteral(
"supportsAllDrives"), Utils::bool2Str(supportsAllDrives));
65 if (sendNotificationEmails != sendNotificationEmailsDefault) {
66 query.addQueryItem(QStringLiteral(
"sendNotificationEmails"), Utils::bool2Str(sendNotificationEmails));
69 if (!emailMessage.isEmpty()) {
70 query.addQueryItem(QStringLiteral(
"emailMessage"), emailMessage);
73 if (useDomainAdminAccess != useDomainAdminAccessDefault) {
74 query.addQueryItem(QStringLiteral(
"useDomainAdminAccess"), Utils::bool2Str(useDomainAdminAccess));
78 QNetworkRequest request(url);
80 const QByteArray rawData = Permission::toJSON(permission);
81 q->enqueueRequest(request, rawData, QStringLiteral(
"application/json"));
84PermissionCreateJob::PermissionCreateJob(
const QString &fileId,
const PermissionPtr &permission,
const AccountPtr &
account,
QObject *
parent)
86 , d(new Private(this))
89 d->permissions << permission;
92PermissionCreateJob::PermissionCreateJob(
const QString &fileId,
const PermissionsList &permissions,
const AccountPtr &account,
QObject *parent)
94 , d(new Private(this))
97 d->permissions = permissions;
100PermissionCreateJob::~PermissionCreateJob() =
default;
102QString PermissionCreateJob::emailMessage()
const
104 return d->emailMessage;
107void PermissionCreateJob::setEmailMessage(
const QString &emailMessage)
109 d->emailMessage = emailMessage;
112bool PermissionCreateJob::sendNotificationEmails()
const
114 return d->sendNotificationEmails;
117void PermissionCreateJob::setSendNotificationEmails(
bool sendNotificationEmails)
119 d->sendNotificationEmails = sendNotificationEmails;
122bool PermissionCreateJob::supportsAllDrives()
const
124 return d->supportsAllDrives;
127void PermissionCreateJob::setSupportsAllDrives(
bool supportsAllDrives)
129 d->supportsAllDrives = supportsAllDrives;
132bool PermissionCreateJob::useDomainAdminAccess()
const
134 return d->useDomainAdminAccess;
137void PermissionCreateJob::setUseDomainAdminAccess(
bool useDomainAdminAccess)
139 d->useDomainAdminAccess = useDomainAdminAccess;
142void PermissionCreateJob::start()
147ObjectsList PermissionCreateJob::handleReplyWithItems(
const QNetworkReply *reply,
const QByteArray &rawData)
150 ContentType ct = Utils::stringToContentType(contentType);
152 if (ct == KGAPI2::JSON) {
153 items << Permission::fromJSON(rawData);
166#include "moc_permissioncreatejob.cpp"
Abstract superclass for all jobs that create new objects on the server.
CreateJob(QObject *parent=nullptr)
Constructor for jobs that don't require authentication.
virtual ObjectsList items() const
void setErrorString(const QString &errorString)
Set job error description to errorString.
AccountPtr account() const
Returns account used to authenticate requests.
virtual void emitFinished()
Emits Job::finished() signal.
void setError(KGAPI2::Error error)
Set job error to error.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
A job to fetch a single map tile described by a StaticMapUrl.
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
void setQuery(const QString &query, ParsingMode mode)
QString toString() const const