Kgapi

permissiondeletejob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "permissiondeletejob.h"
10#include "driveservice.h"
11#include "permission.h"
12#include "utils.h"
13
14#include <QNetworkRequest>
15#include <QUrlQuery>
16
17using namespace KGAPI2;
18using namespace KGAPI2::Drive;
19
20namespace
21{
22static constexpr bool useDomainAdminAccessDefault = false;
23}
24
25class Q_DECL_HIDDEN PermissionDeleteJob::Private
26{
27public:
28 QString fileId;
29 QStringList permissionsIds;
30 bool supportsAllDrives;
31 bool useDomainAdminAccess;
32};
33
34PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const PermissionPtr &permission, const AccountPtr &account, QObject *parent)
35 : DeleteJob(account, parent)
36 , d(new Private)
37{
38 d->supportsAllDrives = true;
39 d->useDomainAdminAccess = useDomainAdminAccessDefault;
40 d->fileId = fileId;
41 d->permissionsIds << permission->id();
42}
43
44PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const QString &permissionId, const AccountPtr &account, QObject *parent)
45 : DeleteJob(account, parent)
46 , d(new Private)
47{
48 d->supportsAllDrives = true;
49 d->useDomainAdminAccess = useDomainAdminAccessDefault;
50 d->fileId = fileId;
51 d->permissionsIds << permissionId;
52}
53
54PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const PermissionsList &permissions, const AccountPtr &account, QObject *parent)
55 : DeleteJob(account, parent)
56 , d(new Private)
57{
58 d->supportsAllDrives = true;
59 d->useDomainAdminAccess = useDomainAdminAccessDefault;
60 d->fileId = fileId;
61 for (const PermissionPtr &permission : std::as_const(permissions)) {
62 d->permissionsIds << permission->id();
63 }
64}
65
66PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, const QStringList &permissionsIds, const AccountPtr &account, QObject *parent)
67 : DeleteJob(account, parent)
68 , d(new Private)
69{
70 d->supportsAllDrives = true;
71 d->useDomainAdminAccess = useDomainAdminAccessDefault;
72 d->fileId = fileId;
73 d->permissionsIds << permissionsIds;
74}
75
76PermissionDeleteJob::~PermissionDeleteJob() = default;
77
78bool PermissionDeleteJob::supportsAllDrives() const
79{
80 return d->supportsAllDrives;
81}
82
83void PermissionDeleteJob::setSupportsAllDrives(bool supportsAllDrives)
84{
85 d->supportsAllDrives = supportsAllDrives;
86}
87
88bool PermissionDeleteJob::useDomainAdminAccess() const
89{
90 return d->useDomainAdminAccess;
91}
92
93void PermissionDeleteJob::setUseDomainAdminAccess(bool useDomainAdminAccess)
94{
95 d->useDomainAdminAccess = useDomainAdminAccess;
96}
97
98void PermissionDeleteJob::start()
99{
100 if (d->permissionsIds.isEmpty()) {
101 emitFinished();
102 return;
103 }
104
105 const QString permissionId = d->permissionsIds.takeFirst();
106 QUrl url = DriveService::deletePermissionUrl(d->fileId, permissionId);
107 QUrlQuery query(url);
108 query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives));
109 if (d->useDomainAdminAccess != useDomainAdminAccessDefault) {
110 query.addQueryItem(QStringLiteral("useDomainAdminAccess"), Utils::bool2Str(d->useDomainAdminAccess));
111 }
112 url.setQuery(query);
113 QNetworkRequest request(url);
114
115 enqueueRequest(request);
116}
117
118#include "moc_permissiondeletejob.cpp"
Abstract superclass for all jobs that delete resources from Google.
Definition deletejob.h:25
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
void setQuery(const QString &query, ParsingMode mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:54:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.