File indexing completed on 2024-05-12 05:22:21
0001 /* 0002 SPDX-FileCopyrightText: 2012 Andrius da Costa Ribas <andriusmao@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "file.h" 0010 #include "kgapidrive_export.h" 0011 #include "object.h" 0012 #include "types.h" 0013 0014 #include <QString> 0015 #include <QUrl> 0016 0017 namespace KGAPI2 0018 { 0019 0020 namespace Drive 0021 { 0022 0023 /** 0024 * @brief Permission contains a permission for a file. 0025 * 0026 * Getters and setters' documentation is based on Google Drive's API v2 reference 0027 * @see <a href="https://developers.google.com/drive/v2/reference/permissions">Permissions</a> 0028 * 0029 * @since 2.0 0030 * @author Andrius da Costa Ribas <andriusmao@gmail.com> 0031 * @author Daniel Vrátil <dvratil@redhat.com> 0032 */ 0033 class KGAPIDRIVE_EXPORT Permission : public KGAPI2::Object 0034 { 0035 public: 0036 enum Role { 0037 UndefinedRole = -1, 0038 OwnerRole = 0, 0039 ReaderRole = 1, 0040 WriterRole = 2, 0041 CommenterRole = 3, 0042 OrganizerRole = 4, 0043 FileOrganizerRole = 5, 0044 }; 0045 0046 enum Type { UndefinedType = -1, TypeUser = 0, TypeGroup = 1, TypeDomain = 2, TypeAnyone = 3 }; 0047 0048 /** 0049 * @brief Details of whether the permissions on this shared drive item are 0050 * inherited or directly on this item. This is an output-only field which 0051 * is present only for shared drive items. 0052 */ 0053 class PermissionDetails 0054 { 0055 public: 0056 enum PermissionType { 0057 UndefinedType = -1, 0058 TypeFile = 0, 0059 TypeMember = 1, 0060 }; 0061 0062 PermissionDetails(); 0063 PermissionDetails(const PermissionDetails &other); 0064 ~PermissionDetails(); 0065 bool operator==(const PermissionDetails &other) const; 0066 bool operator!=(const PermissionDetails &other) const 0067 { 0068 return !operator==(other); 0069 } 0070 0071 /** 0072 * @brief The permission type for this user. 0073 */ 0074 PermissionDetails::PermissionType permissionType() const; 0075 0076 /** 0077 * @brief The primary role for this user. 0078 */ 0079 [[nodiscard]] Permission::Role role() const; 0080 0081 /** 0082 * @brief Additional roles for this user. Only commenter is currently possible, 0083 * though more may be supported in the future. 0084 */ 0085 [[nodiscard]] QList<Permission::Role> additionalRoles() const; 0086 0087 /** 0088 * @brief The ID of the item from which this permission is inherited. 0089 * This is an output-only field and is only populated for members of 0090 * the shared drive. 0091 */ 0092 [[nodiscard]] QString inheritedFrom() const; 0093 0094 /** 0095 * @brief Whether this permission is inherited. This field is always populated. This is an output-only field. 0096 */ 0097 [[nodiscard]] bool inherited() const; 0098 0099 private: 0100 class Private; 0101 QScopedPointer<Private> const d; 0102 friend class Private; 0103 friend class Permission; 0104 }; 0105 0106 using PermissionDetailsPtr = QSharedPointer<PermissionDetails>; 0107 using PermissionDetailsList = QList<PermissionDetailsPtr>; 0108 0109 explicit Permission(); 0110 explicit Permission(const Permission &other); 0111 ~Permission() override; 0112 bool operator==(const Permission &other) const; 0113 bool operator!=(const Permission &other) const 0114 { 0115 return !operator==(other); 0116 } 0117 0118 /** 0119 * @brief Returns the id of the permission. 0120 */ 0121 QString id() const; 0122 0123 /** 0124 * @brief Sets the id of the permission. 0125 * 0126 * @param id 0127 */ 0128 void setId(const QString &id); 0129 0130 /** 0131 * @brief Returns a link back to this permission. 0132 */ 0133 QUrl selfLink() const; 0134 0135 /** 0136 * @brief Returns the name of this permission. 0137 */ 0138 QString name() const; 0139 0140 /** 0141 * @brief Returns the primary role for this user. 0142 */ 0143 Permission::Role role() const; 0144 0145 /** 0146 * @brief Sets the primary role for this user. 0147 */ 0148 void setRole(Permission::Role role); 0149 0150 /** 0151 * @brief Returns additional roles for this user. Only commenter is currently allowed. 0152 */ 0153 QList<Role> additionalRoles() const; 0154 0155 /** 0156 * @brief Sets additional roles for this user. Only commenter is currently allowed. 0157 * 0158 * @param additionalRoles 0159 */ 0160 void setAdditionalRoles(const QList<Role> &additionalRoles); 0161 0162 /** 0163 * @brief Returns the account type. 0164 */ 0165 Permission::Type type() const; 0166 0167 /** 0168 * @brief Sets the account type. 0169 * 0170 * @param type 0171 */ 0172 void setType(Permission::Type type); 0173 0174 /** 0175 * @brief Returns the authkey parameter required for this permission. 0176 */ 0177 QString authKey() const; 0178 0179 /** 0180 * @brief Returns whether the link is required for this permission. 0181 */ 0182 bool withLink() const; 0183 0184 /** 0185 * @brief Sets whether the link is required for this permission. 0186 * 0187 * @param withLink 0188 */ 0189 void setWithLink(bool withLink); 0190 0191 /** 0192 * @brief Returns a link to the profile photo, if available. 0193 */ 0194 QUrl photoLink() const; 0195 0196 /** 0197 * @brief Returns the email address or domain name for the entity. 0198 * 0199 * This is not populated in responses. 0200 * You can use the alias "me" as the value for this property to refer to the 0201 * current authorized user. 0202 */ 0203 QString value() const; 0204 0205 /** 0206 * @brief Sets the email address or domain name for the entity. 0207 * 0208 * This is not populated in responses. 0209 * You can use the alias "me" as the value for this property to refer to the 0210 * current authorized user. 0211 * 0212 * @param value 0213 */ 0214 void setValue(const QString &value); 0215 0216 /** 0217 * @brief The email address of the user or group this permission refers to. 0218 * This is an output-only field which is present when the permission type is 0219 * user or group. 0220 */ 0221 QString emailAddress() const; 0222 0223 /** 0224 * @brief The domain name of the entity this permission refers to. 0225 * This is an output-only field which is present when the permission 0226 * type is user, group or domain. 0227 */ 0228 QString domain() const; 0229 0230 /** 0231 * @brief The time at which this permission will expire. 0232 */ 0233 QDateTime expirationDate() const; 0234 0235 /** 0236 * @brief Whether the account associated with this permission has been 0237 * deleted. This field only pertains to user and group permissions. 0238 */ 0239 bool deleted() const; 0240 0241 /** 0242 * @brief Details of whether the permissions on this shared drive 0243 * item are inherited or directly on this item. 0244 */ 0245 Permission::PermissionDetailsList permissionDetails() const; 0246 0247 static PermissionPtr fromJSON(const QByteArray &jsonData); 0248 static PermissionsList fromJSONFeed(const QByteArray &jsonData); 0249 static QByteArray toJSON(const PermissionPtr &permission); 0250 0251 private: 0252 class Private; 0253 Private *const d; 0254 friend class Private; 0255 friend class File::Private; 0256 }; 0257 0258 } /* namespace Drive */ 0259 0260 } /* namespace KGAPI2 */