Coverage for gws-app/gws/plugin/qfieldcloud/api.py: 100%

201 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Data classes for the QFieldCloud API, based on its ``swagger.yaml``.""" 

2 

3from datetime import datetime 

4from typing import Any, Optional 

5 

6import gws 

7 

8class JobStatusEnum(gws.Enum): 

9 """Status of a job.""" 

10 

11 pending = 'pending' 

12 queued = 'queued' 

13 started = 'started' 

14 finished = 'finished' 

15 stopped = 'stopped' 

16 failed = 'failed' 

17 

18 

19class LastStatusEnum(gws.Enum): 

20 """Last status of a delta.""" 

21 

22 pending = 'pending' 

23 started = 'started' 

24 applied = 'applied' 

25 conflict = 'conflict' 

26 not_applied = 'not_applied' 

27 error = 'error' 

28 ignored = 'ignored' 

29 unpermitted = 'unpermitted' 

30 

31 

32class OrganizationMemberRoleEnum(gws.Enum): 

33 """Role of an organization member.""" 

34 

35 admin = 'admin' 

36 member = 'member' 

37 

38 

39class ProjectCollaboratorRoleEnum(gws.Enum): 

40 """Role of a project collaborator.""" 

41 

42 admin = 'admin' 

43 manager = 'manager' 

44 editor = 'editor' 

45 reporter = 'reporter' 

46 reader = 'reader' 

47 

48 

49class ProjectStatusEnum(gws.Enum): 

50 """Status of a project.""" 

51 

52 ok = 'ok' 

53 busy = 'busy' 

54 failed = 'failed' 

55 

56 

57class TypeEnum(gws.Enum): 

58 """Type of a job.""" 

59 

60 package = 'package' 

61 delta_apply = 'delta_apply' 

62 process_projectfile = 'process_projectfile' 

63 

64 

65# Data Classes 

66 

67 

68class Login(gws.Data): 

69 """Login credentials.""" 

70 

71 password: str 

72 """Password.""" 

73 username: Optional[str] 

74 """User name.""" 

75 email: Optional[str] 

76 """Email address.""" 

77 

78 

79class CompleteUser(gws.Data): 

80 """Full information about the authenticated user.""" 

81 

82 username: str 

83 """User name.""" 

84 type: int 

85 """User type, see ``UserType``.""" 

86 full_name: str 

87 """Full name.""" 

88 avatar_url: str 

89 """URL of the avatar image.""" 

90 email: Optional[str] 

91 """Email address.""" 

92 first_name: Optional[str] 

93 """First name.""" 

94 last_name: Optional[str] 

95 """Last name.""" 

96 

97 

98class PublicInfoUser(gws.Data): 

99 """Public information about a user.""" 

100 

101 username: str 

102 """User name.""" 

103 type: int 

104 """User type, see ``UserType``.""" 

105 full_name: str 

106 """Full name.""" 

107 avatar_url: str 

108 """URL of the avatar image.""" 

109 username_display: str 

110 """User name for display.""" 

111 

112 

113class Delta(gws.Data): 

114 """A single change sent by QField.""" 

115 

116 deltafile_id: str 

117 """Id of the delta payload the delta belongs to.""" 

118 content: Any 

119 """Delta content as sent by QField.""" 

120 id: str 

121 """Delta id.""" 

122 created_by: str 

123 """User who sent the delta.""" 

124 created_at: datetime 

125 """Creation time.""" 

126 updated_at: datetime 

127 """Last update time.""" 

128 status: str 

129 """Delta status.""" 

130 output: str 

131 """Output of the delta application.""" 

132 last_status: Optional[LastStatusEnum] 

133 """Last status.""" 

134 last_feedback: Optional[Any] 

135 """Last feedback.""" 

136 

137 

138class Job(gws.Data): 

139 """A server job, e.g. packaging.""" 

140 

141 type: TypeEnum 

142 """Job type.""" 

143 id: str 

144 """Job id.""" 

145 created_at: datetime 

146 """Creation time.""" 

147 created_by: int 

148 """Id of the user who created the job.""" 

149 project_id: str 

150 """Project id.""" 

151 status: JobStatusEnum 

152 """Job status.""" 

153 updated_at: datetime 

154 """Last update time.""" 

155 started_at: Optional[datetime] 

156 """Start time.""" 

157 finished_at: Optional[datetime] 

158 """Finish time.""" 

159 

160 

161class Organization(gws.Data): 

162 """An organization.""" 

163 

164 username: str 

165 """Organization name.""" 

166 type: int 

167 """User type, see ``UserType``.""" 

168 avatar_url: str 

169 """URL of the avatar image.""" 

170 members: str 

171 """Organization members.""" 

172 organization_owner: str 

173 """Owner of the organization.""" 

174 membership_role: str 

175 """Role of the current user in the organization.""" 

176 membership_role_origin: str 

177 """Origin of the membership role.""" 

178 membership_is_public: bool 

179 """Whether the membership is public.""" 

180 teams: list[str] 

181 """Organization teams.""" 

182 email: Optional[str] 

183 """Email address.""" 

184 

185 

186class OrganizationMember(gws.Data): 

187 """A member of an organization.""" 

188 

189 organization: str 

190 """Organization name.""" 

191 member: str 

192 """Member user name.""" 

193 role: OrganizationMemberRoleEnum 

194 """Member role.""" 

195 is_public: Optional[bool] 

196 """Whether the membership is public.""" 

197 

198 

199class Project(gws.Data): 

200 """A QField Cloud project.""" 

201 

202 id: str 

203 """Project id.""" 

204 name: str 

205 """Project name.""" 

206 owner: str 

207 """Project owner.""" 

208 created_at: datetime 

209 """Creation time.""" 

210 updated_at: datetime 

211 """Last update time.""" 

212 can_repackage: bool 

213 """Whether the project can be packaged again.""" 

214 needs_repackaging: bool 

215 """Whether the project must be packaged again.""" 

216 status: ProjectStatusEnum 

217 """Project status.""" 

218 user_role: str 

219 """Role of the current user in the project.""" 

220 user_role_origin: str 

221 """Origin of the user role.""" 

222 is_shared_datasets_project: bool 

223 """Whether this is a shared datasets project.""" 

224 is_attachment_download_on_demand: bool 

225 """Whether attachments are downloaded on demand.""" 

226 description: Optional[str] 

227 """Project description.""" 

228 private: Optional[bool] 

229 """Whether the project is private.""" 

230 is_public: Optional[bool] 

231 """Whether the project is public.""" 

232 data_last_packaged_at: Optional[datetime] 

233 """Time of the last packaging.""" 

234 data_last_updated_at: Optional[datetime] 

235 """Time of the last data update.""" 

236 shared_datasets_project_id: Optional[str] 

237 """Id of the shared datasets project.""" 

238 is_featured: Optional[bool] 

239 """Whether the project is featured.""" 

240 

241 

242class ProjectCollaborator(gws.Data): 

243 """A collaborator of a project.""" 

244 

245 collaborator: str 

246 """Collaborator user name.""" 

247 project_id: str 

248 """Project id.""" 

249 created_by: str 

250 """User who added the collaborator.""" 

251 updated_by: str 

252 """User who last updated the collaborator.""" 

253 created_at: datetime 

254 """Creation time.""" 

255 updated_at: datetime 

256 """Last update time.""" 

257 role: Optional[ProjectCollaboratorRoleEnum] 

258 """Collaborator role.""" 

259 

260 

261class Team(gws.Data): 

262 """A team in an organization.""" 

263 

264 team: str 

265 """Team name.""" 

266 organization: str 

267 """Organization name.""" 

268 members: list[str] 

269 """Team members.""" 

270 

271 

272class TeamMember(gws.Data): 

273 """A member of a team.""" 

274 

275 member: str 

276 """Member user name.""" 

277 

278 

279## not in swagger.yaml but used in code 

280 

281 

282class Package(gws.Data): 

283 """A project package, as listed for download.""" 

284 

285 files: list[dict] 

286 """Package files.""" 

287 layers: list[dict] 

288 """Package layers.""" 

289 status: JobStatusEnum 

290 """Packaging status.""" 

291 package_id: str 

292 """Package id.""" 

293 packaged_at: datetime 

294 """Packaging time.""" 

295 data_last_updated_at: datetime 

296 """Time of the last data update.""" 

297 

298 

299class AuthProvider(gws.Data): 

300 """An authentication provider offered to the client.""" 

301 

302 type: str 

303 """Provider type.""" 

304 id: str 

305 """Provider id.""" 

306 name: str 

307 """Provider name for display.""" 

308 

309 

310class UserType(gws.Enum): 

311 """Type of a user account.""" 

312 

313 person = 1 

314 organization = 2 

315 team = 3 

316 

317 

318class AuthToken(gws.Data): 

319 """Authentication token and user information returned on login.""" 

320 

321 token: str 

322 """Session token.""" 

323 expires_at: datetime 

324 """Expiration time.""" 

325 username: str 

326 """User name.""" 

327 type: UserType 

328 """User type.""" 

329 full_name: str 

330 """Full name.""" 

331 avatar_url: str 

332 """URL of the avatar image.""" 

333 email: Optional[str] 

334 """Email address.""" 

335 first_name: Optional[str] 

336 """First name.""" 

337 last_name: Optional[str] 

338 """Last name.""" 

339 

340 

341class ServerInfo(gws.Data): 

342 """Server information.""" 

343 

344 version: str 

345 """Server version.""" 

346 auth_providers: list[AuthProvider] 

347 """Available authentication providers.""" 

348 signup_url: str 

349 """URL of the signup page.""" 

350 whitelabel: dict 

351 """Branding options.""" 

352 

353 

354class Status(gws.Data): 

355 """Server status.""" 

356 

357 version: str 

358 """Server version.""" 

359 database: str 

360 """Database status.""" 

361 storage: str 

362 """Storage status.""" 

363 status_page_url: Optional[str] 

364 """URL of the status page.""" 

365 incident_message: Optional[str] 

366 """Incident message.""" 

367 incident_timestamp_utc: Optional[str] 

368 """Incident time.""" 

369 maintenance_message: Optional[str] 

370 """Maintenance message.""" 

371 maintenance_start_timestamp_utc: Optional[str] 

372 """Maintenance start time.""" 

373 maintenance_end_timestamp_utc: Optional[str] 

374 """Maintenance end time.""" 

375 

376 

377class Subscription(gws.Data): 

378 """Subscription of a user.""" 

379 

380 plan_display_name: str 

381 """Plan name for display.""" 

382 active_storage_total_bytes: int 

383 """Total storage available, in bytes.""" 

384 storage_used_bytes: int 

385 """Storage used, in bytes.""" 

386 plan_storage_threshold_warning_bytes: int 

387 """Storage warning threshold, in bytes.""" 

388 plan_storage_threshold_critical_bytes: int 

389 """Storage critical threshold, in bytes.""" 

390 status: str 

391 """Subscription status.""" 

392 

393 

394class PostJobPayload(gws.Data): 

395 """Payload of a job creation request.""" 

396 

397 type: TypeEnum 

398 """Job type.""" 

399 project_id: str 

400 """Project id.""" 

401 

402 

403class DeltasPayload(gws.Data): 

404 """A delta payload (delta file) sent by QField.""" 

405 

406 deltas: list[dict] 

407 """List of deltas.""" 

408 files: list[dict] 

409 """List of files.""" 

410 id: str 

411 """Payload id.""" 

412 project: str 

413 """Project id.""" 

414 version: str 

415 """Delta file format version.""" 

416 

417 

418class StoredDelta(gws.Data): 

419 """A delta as stored on the server and returned to status requests.""" 

420 

421 id: str 

422 """Delta id (the ``uuid`` of the delta).""" 

423 deltafile_id: str 

424 """Id of the delta payload.""" 

425 created_by: str 

426 """Login name of the user who sent the delta.""" 

427 created_at: str 

428 """Creation time.""" 

429 updated_at: str 

430 """Last update time.""" 

431 status: str 

432 """Delta status, e.g. ``STATUS_PENDING`` or ``STATUS_APPLIED``.""" 

433 client_id: str 

434 """Client id.""" 

435 output: Optional[dict] 

436 """Output of the delta application.""" 

437 last_status: str 

438 """Last status, e.g. ``pending`` or ``applied``.""" 

439 last_feedback: Optional[dict] 

440 """Last feedback.""" 

441 content: dict 

442 """Delta content as sent by QField.""" 

443 

444 

445class PackageFile(gws.Data): 

446 """A file in a package.""" 

447 

448 name: str 

449 """File name, relative to the package.""" 

450 size: int 

451 """File size in bytes.""" 

452 uploaded_at: str 

453 """Upload time.""" 

454 is_attachment: bool 

455 """Whether the file is an attachment.""" 

456 md5sum: str 

457 """MD5 checksum, in the format QField expects.""" 

458 last_modified: str 

459 """Modification time.""" 

460 sha256: str 

461 """SHA-256 checksum."""