8#include "permission_p.h"
11#include <QJsonDocument>
14using namespace KGAPI2::Drive;
16class Q_DECL_HIDDEN
Permission::PermissionDetails::Private
20 Private(
const Private &other) =
default;
22 PermissionDetails::PermissionType permissionType = PermissionType::UndefinedType;
24 QList<Role> additionalRoles;
25 QString inheritedFrom;
26 bool inherited =
false;
28 static PermissionType permissionTypeFromName(
const QString &typeName);
29 static QString permissionTypeToName(PermissionType permissionType);
32Permission::PermissionDetails::PermissionDetails()
38 : d(new Private(*(other.d)))
42Permission::PermissionDetails::~PermissionDetails() =
default;
54QString Permission::PermissionDetails::Private::permissionTypeToName(Permission::PermissionDetails::PermissionType permissionType)
56 switch (permissionType) {
57 case Permission::PermissionDetails::TypeFile:
58 return QStringLiteral(
"file");
59 case Permission::PermissionDetails::TypeMember:
60 return QStringLiteral(
"member");
66Permission::PermissionDetails::PermissionType Permission::PermissionDetails::Private::permissionTypeFromName(
const QString &typeName)
68 if (typeName == QLatin1StringView(
"file")) {
69 return Permission::PermissionDetails::TypeFile;
70 }
else if (typeName == QLatin1StringView(
"member")) {
71 return Permission::PermissionDetails::TypeMember;
73 return Permission::PermissionDetails::UndefinedType;
79 return d->permissionType;
89 return d->additionalRoles;
94 return d->inheritedFrom;
102Permission::Role Permission::Private::roleFromName(
const QString &roleName)
105 return Permission::OwnerRole;
107 return Permission::ReaderRole;
109 return Permission::WriterRole;
111 return Permission::CommenterRole;
112 }
else if (roleName == QLatin1StringView(
"organizer")) {
113 return Permission::OrganizerRole;
114 }
else if (roleName == QLatin1StringView(
"fileOrganizer")) {
115 return Permission::FileOrganizerRole;
117 return Permission::UndefinedRole;
121Permission::Type Permission::Private::typeFromName(
const QString &typeName)
123 if (typeName == QLatin1StringView(
"user")) {
124 return Permission::TypeUser;
125 }
else if (typeName == QLatin1StringView(
"group")) {
126 return Permission::TypeGroup;
127 }
else if (typeName == QLatin1StringView(
"domain")) {
128 return Permission::TypeDomain;
129 }
else if (typeName == QLatin1StringView(
"anyone")) {
130 return Permission::TypeAnyone;
132 return Permission::UndefinedType;
136QString Permission::Private::roleToName(Permission::Role
role)
139 case Permission::OwnerRole:
140 return QStringLiteral(
"owner");
141 case Permission::ReaderRole:
142 return QStringLiteral(
"reader");
143 case Permission::WriterRole:
144 return QStringLiteral(
"writer");
145 case Permission::CommenterRole:
146 return QStringLiteral(
"commenter");
147 case Permission::OrganizerRole:
148 return QStringLiteral(
"organizerRole");
149 case Permission::FileOrganizerRole:
150 return QStringLiteral(
"fileOrganizerRole");
156QString Permission::Private::typeToName(Permission::Type
type)
159 case Permission::TypeUser:
160 return QStringLiteral(
"user");
161 case Permission::TypeGroup:
162 return QStringLiteral(
"group");
163 case Permission::TypeDomain:
164 return QStringLiteral(
"domain");
165 case Permission::TypeAnyone:
166 return QStringLiteral(
"anyone");
172PermissionPtr Permission::Private::fromJSON(
const QVariantMap &map)
174 if (!
map.contains(QLatin1StringView(
"kind")) || map[QStringLiteral(
"kind")].
toString() != QLatin1StringView(
"drive#permission")) {
175 return PermissionPtr();
178 PermissionPtr permission(
new Permission());
179 permission->setEtag(map[QStringLiteral(
"etag")].
toString());
180 permission->d->id =
map[QStringLiteral(
"id")].toString();
181 permission->d->selfLink =
map[QStringLiteral(
"selfLink")].toUrl();
182 permission->d->name =
map[QStringLiteral(
"name")].toString();
184 permission->d->role = Private::roleFromName(map[QStringLiteral(
"role")].
toString());
186 const QStringList
additionalRoles =
map[QStringLiteral(
"additionalRoles")].toStringList();
188 permission->d->additionalRoles << Private::roleFromName(additionalRole);
191 permission->d->type = Private::typeFromName(map[QStringLiteral(
"type")].
toString());
192 permission->d->authKey =
map[QStringLiteral(
"authKey")].toString();
193 permission->d->withLink =
map[QStringLiteral(
"withLink")].toBool();
194 permission->d->photoLink =
map[QStringLiteral(
"photoLink")].toUrl();
195 permission->d->value =
map[QStringLiteral(
"value")].toString();
196 permission->d->emailAddress =
map[QStringLiteral(
"emailAddress")].toString();
197 permission->d->domain =
map[QStringLiteral(
"domain")].toString();
199 permission->d->deleted =
map[QStringLiteral(
"deleted")].toBool();
201 if (
map.contains(QStringLiteral(
"permissionDetails"))) {
202 const QVariantList permissionDetailsList =
map[QStringLiteral(
"permissionDetails")].toList();
203 for (
const QVariant &variant : permissionDetailsList) {
204 const QVariantMap permissionDetailsMap = variant.toMap();
207 PermissionDetails::Private::permissionTypeFromName(permissionDetailsMap[QStringLiteral(
"permissionType")].
toString());
209 const QStringList permissionDetailsAdditionalRoles = permissionDetailsMap[QStringLiteral(
"additionalRoles")].toStringList();
210 for (
const QString &additionalRole : permissionDetailsAdditionalRoles) {
213 permissionDetails->d->inheritedFrom = permissionDetailsMap[QStringLiteral(
"inheritedFrom")].toString();
223Permission::Private::Private()
224 :
role(Permission::UndefinedRole)
225 ,
type(Permission::UndefinedType)
230Permission::Private::Private(
const Private &other) =
default;
232Permission::Permission()
238Permission::Permission(
const Permission &other)
240 , d(new Private(*(other.d)))
244Permission::~Permission()
249bool Permission::operator==(
const Permission &other)
const
251 if (!Object::operator==(other)) {
304 return d->additionalRoles;
354 return d->emailAddress;
364 return d->expirationDate;
374 return d->permissionDetails;
377PermissionPtr Permission::fromJSON(
const QByteArray &jsonData)
381 return PermissionPtr();
384 const QVariantMap map = json.
toMap();
386 return Private::fromJSON(map);
389PermissionsList Permission::fromJSONFeed(
const QByteArray &jsonData)
393 return PermissionsList();
395 const QVariant json = document.
toVariant();
396 const QVariantMap
map = json.
toMap();
397 if (!
map.contains(QLatin1StringView(
"kind")) || map[QStringLiteral(
"kind")].
toString() != QLatin1StringView(
"drive#permissionList")) {
398 return PermissionsList();
401 PermissionsList permissions;
402 const QVariantList items =
map[QStringLiteral(
"items")].toList();
403 for (
const QVariant &item : items) {
404 const PermissionPtr permission = Private::fromJSON(item.toMap());
405 if (!permission.
isNull()) {
406 permissions << permission;
412QByteArray Permission::toJSON(
const PermissionPtr &permission)
416 if (permission->role() != Permission::UndefinedRole) {
417 map[QStringLiteral(
"role")] = Private::roleToName(permission->role());
419 if (permission->type() != Permission::UndefinedType) {
420 map[QStringLiteral(
"type")] = Private::typeToName(permission->type());
424 const auto roles = permission->additionalRoles();
426 for (Permission::Role additionalRole : roles) {
433 map[QStringLiteral(
"withLink")] = permission->withLink();
435 if (!permission->value().isEmpty()) {
436 map[QStringLiteral(
"value")] = permission->value();
Details of whether the permissions on this shared drive item are inherited or directly on this item.
PermissionDetails::PermissionType permissionType() const
The permission type for this user.
QList< Permission::Role > additionalRoles() const
Additional roles for this user.
bool inherited() const
Whether this permission is inherited.
QString inheritedFrom() const
The ID of the item from which this permission is inherited.
Permission::Role role() const
The primary role for this user.
Permission contains a permission for a file.
void setWithLink(bool withLink)
Sets whether the link is required for this permission.
bool withLink() const
Returns whether the link is required for this permission.
Permission::Type type() const
Returns the account type.
QString value() const
Returns the email address or domain name for the entity.
QUrl selfLink() const
Returns a link back to this permission.
void setAdditionalRoles(const QList< Role > &additionalRoles)
Sets additional roles for this user.
QString authKey() const
Returns the authkey parameter required for this permission.
void setId(const QString &id)
Sets the id of the permission.
QString id() const
Returns the id of the permission.
void setRole(Permission::Role role)
Sets the primary role for this user.
QUrl photoLink() const
Returns a link to the profile photo, if available.
bool deleted() const
Whether the account associated with this permission has been deleted.
void setType(Permission::Type type)
Sets the account type.
Permission::Role role() const
Returns the primary role for this user.
Permission::PermissionDetailsList permissionDetails() const
Details of whether the permissions on this shared drive item are inherited or directly on this item.
QString emailAddress() const
The email address of the user or group this permission refers to.
QDateTime expirationDate() const
The time at which this permission will expire.
void setValue(const QString &value)
Sets the email address or domain name for the entity.
QString name() const
Returns the name of this permission.
QList< Role > additionalRoles() const
Returns additional roles for this user.
QString domain() const
The domain name of the entity this permission refers to.
char * toString(const EngineQuery &query)
A job to fetch a single map tile described by a StaticMapUrl.
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonDocument fromVariant(const QVariant &variant)
bool isNull() const const
QByteArray toJson(JsonFormat format) const const
QVariant toVariant() const const
QSharedPointer< T > create(Args &&... args)
bool isNull() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QMap< QString, QVariant > toMap() const const