Kgapi

permissionfetchjob.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 "permissionfetchjob.h"
10#include "driveservice.h"
11#include "file.h"
12#include "permission.h"
13#include "utils.h"
14
15#include <QNetworkReply>
16#include <QNetworkRequest>
17#include <QUrlQuery>
18
19using namespace KGAPI2;
20using namespace KGAPI2::Drive;
21
22namespace
23{
24static constexpr bool useDomainAdminAccessDefault = false;
25}
26
27class Q_DECL_HIDDEN PermissionFetchJob::Private
28{
29public:
30 QString fileId;
31 QString permissionId;
32 bool supportsAllDrives;
33 bool useDomainAdminAccess;
34};
35
36PermissionFetchJob::PermissionFetchJob(const QString &fileId, const AccountPtr &account, QObject *parent)
37 : FetchJob(account, parent)
38 , d(new Private)
39{
40 d->supportsAllDrives = true;
41 d->useDomainAdminAccess = useDomainAdminAccessDefault;
42 d->fileId = fileId;
43}
44
45PermissionFetchJob::PermissionFetchJob(const FilePtr &file, const AccountPtr &account, QObject *parent)
46 : FetchJob(account, parent)
47 , d(new Private)
48{
49 d->supportsAllDrives = true;
50 d->useDomainAdminAccess = useDomainAdminAccessDefault;
51 d->fileId = file->id();
52}
53
54PermissionFetchJob::PermissionFetchJob(const QString &fileId, const QString &permissionId, const AccountPtr &account, QObject *parent)
55 : FetchJob(account, parent)
56 , d(new Private)
57{
58 d->supportsAllDrives = true;
59 d->useDomainAdminAccess = useDomainAdminAccessDefault;
60 d->fileId = fileId;
61 d->permissionId = permissionId;
62}
63
64PermissionFetchJob::PermissionFetchJob(const FilePtr &file, const QString &permissionId, const AccountPtr &account, QObject *parent)
65 : FetchJob(account, parent)
66 , d(new Private)
67{
68 d->supportsAllDrives = true;
69 d->useDomainAdminAccess = useDomainAdminAccessDefault;
70 d->fileId = file->id();
71 d->permissionId = permissionId;
72}
73
74PermissionFetchJob::~PermissionFetchJob() = default;
75
76bool PermissionFetchJob::supportsAllDrives() const
77{
78 return d->supportsAllDrives;
79}
80
81void PermissionFetchJob::setSupportsAllDrives(bool supportsAllDrives)
82{
83 d->supportsAllDrives = supportsAllDrives;
84}
85
86bool PermissionFetchJob::useDomainAdminAccess() const
87{
88 return d->useDomainAdminAccess;
89}
90
91void PermissionFetchJob::setUseDomainAdminAccess(bool useDomainAdminAccess)
92{
93 d->useDomainAdminAccess = useDomainAdminAccess;
94}
95
96void PermissionFetchJob::start()
97{
98 QUrl url;
99 if (d->permissionId.isEmpty()) {
100 url = DriveService::fetchPermissionsUrl(d->fileId);
101 } else {
102 url = DriveService::fetchPermissionUrl(d->fileId, d->permissionId);
103 }
104
105 QUrlQuery query(url);
106 query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives));
107 if (d->useDomainAdminAccess != useDomainAdminAccessDefault) {
108 query.addQueryItem(QStringLiteral("useDomainAdminAccess"), Utils::bool2Str(d->useDomainAdminAccess));
109 }
110 url.setQuery(query);
111 QNetworkRequest request(url);
112 enqueueRequest(request);
113}
114
115ObjectsList PermissionFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
116{
118
119 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
120 ContentType ct = Utils::stringToContentType(contentType);
121 if (ct == KGAPI2::JSON) {
122 if (d->permissionId.isEmpty()) {
123 items << Permission::fromJSONFeed(rawData);
124 } else {
125 items << Permission::fromJSON(rawData);
126 }
127 } else {
129 setErrorString(tr("Invalid response content type"));
130 }
131
132 emitFinished();
133 return items;
134}
135
136#include "moc_permissionfetchjob.cpp"
Abstract superclass for all jobs that fetch resources from Google.
Definition fetchjob.h:25
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition fetchjob.cpp:41
void setErrorString(const QString &errorString)
Set job error description to errorString.
Definition job.cpp:401
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
void setError(KGAPI2::Error error)
Set job error to error.
Definition job.cpp:386
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
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QVariant header(QNetworkRequest::KnownHeaders header) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
void setQuery(const QString &query, ParsingMode mode)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.