-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkflows.py
More file actions
603 lines (492 loc) · 25.2 KB
/
workflows.py
File metadata and controls
603 lines (492 loc) · 25.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
"""This class takes a base URL as an argument when it's initialized,
which is the endpoint for the RESTFUL API that we'll be interacting with.
The create(), read(), update(), and delete() methods each correspond to
the CRUD operations that can be performed on the API """
import json
from ..common import Parameter
class Workflows(Parameter):
"""
This class takes a base URL as an argument when it's initialized,
which is the endpoint for the RESTFUL API that
we'll be interacting with. The create(), read(), update(), and delete()
methods each correspond to the CRUD
operations that can be performed on the API """
def __init__(self, client, workflow_uid):
self.client = client
self.workflow_uid = workflow_uid
super().__init__(self.client)
self.path = "workflows"
def find(self):
"""
The Get all Workflows request retrieves the details of all the Workflows of a stack.
:return: the result of a GET request to the specified URL, using the headers specified in the
client object.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack("api_key").workflows().find().json()
-------------------------------
"""
url = self.path
return self.client.get(url, headers = self.client.headers, params = self.params)
def fetch(self):
"""
The Get a Single Workflow request retrieves the comprehensive details of a specific Workflow of a stack.
:return: The fetch method returns the response from the Get an workflow request, which contains
comprehensive information about a specific version of an workflow of a stack.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows('workflow_uid').fetch().json()
-------------------------------
"""
if self.workflow_uid is None:
raise Exception('workflow uid is required')
url = f"{self.path}/{self.workflow_uid}"
return self.client.get(url, headers = self.client.headers, params = self.params)
def create(self, data):
"""
The Create a Workflow request allows you to create a Workflow.
:param data: The data parameter is the payload that you want to send in the request body. It
should be a dictionary or a JSON serializable object that you want to send as the request body
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> data = {
>>> "workflow":{
>>> "workflow_stages":[
>>> {
>>> "color":"#2196f3",
>>> "SYS_ACL":{
>>> "roles":{
>>> "uids":[
>>> ]
>>> },
>>> "users":{
>>> "uids":[
>>> "$all"
>>> ]
>>> },
>>> "others":{
>>> }
>>> },
>>> "next_available_stages":[
>>> "$all"
>>> ],
>>> "allStages":true,
>>> "allUsers":true,
>>> "specificStages":false,
>>> "specificUsers":false,
>>> "entry_lock":"$none",
>>> "name":"Review"
>>> },
>>> {
>>> "color":"#74ba76",
>>> "SYS_ACL":{
>>> "roles":{
>>> "uids":[
>>> ]
>>> },
>>> "users":{
>>> "uids":[
>>> "$all"
>>> ]
>>> },
>>> "others":{
>>> }
>>> },
>>> "allStages":true,
>>> "allUsers":true,
>>> "specificStages":false,
>>> "specificUsers":false,
>>> "next_available_stages":[
>>> "$all"
>>> ],
>>> "entry_lock":"$none",
>>> "name":"Complete"
>>> }
>>> ],
>>> "admin_users":{
>>> "users":[
>>> ]
>>> },
>>> "name":"Workflow",
>>> "enabled":true,
>>> "branches":[
>>> "main",
>>> "development"
>>> ],
>>> "content_types":[
>>> "$all"
>>> ]
>>> }
>>> }
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().create(data).json()
-------------------------------
"""
data = json.dumps(data)
return self.client.post(self.path, headers = self.client.headers, data=data, params = self.params)
def update(self, data):
"""
The Add or Update Workflow request allows you to add a workflow stage or update the details of the existing stages of a workflow.
:param data: The `data` parameter is the data that you want to update. It should be a dictionary
or an object that can be serialized to JSON
:return: Json, with updated workflow details.
-------------------------------
[Example:]
>>> data = {
>>> "workflow":{
>>> "workflow_stages":[
>>> {
>>> "color":"#2196f3",
>>> "SYS_ACL":{
>>> "roles":{
>>> "uids":[
>>> ]
>>> },
>>> "users":{
>>> "uids":[
>>> "$all"
>>> ]
>>> },
>>> "others":{
>>> }
>>> },
>>> "next_available_stages":[
>>> "$all"
>>> ],
>>> "allStages":true,
>>> "allUsers":true,
>>> "specificStages":false,
>>> "specificUsers":false,
>>> "entry_lock":"$none",
>>> "name":"Review"
>>> },
>>> {
>>> "color":"#74ba76",
>>> "SYS_ACL":{
>>> "roles":{
>>> "uids":[
>>> ]
>>> },
>>> "users":{
>>> "uids":[
>>> "$all"
>>> ]
>>> },
>>> "others":{
>>> }
>>> },
>>> "allStages":true,
>>> "allUsers":true,
>>> "specificStages":false,
>>> "specificUsers":false,
>>> "next_available_stages":[
>>> "$all"
>>> ],
>>> "entry_lock":"$none",
>>> "name":"Complete"
>>> }
>>> ],
>>> "admin_users":{
>>> "users":[
>>> ]
>>> },
>>> "name":"Workflow",
>>> "enabled":true,
>>> "branches":[
>>> "main",
>>> "development"
>>> ],
>>> "content_types":[
>>> "$all"
>>> ]
>>> }
>>> }
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows("workflow_uid").update(data).json()
-------------------------------
"""
if self.workflow_uid is None:
raise Exception('workflow uid is required')
url = f"{self.path}/{self.workflow_uid}"
data = json.dumps(data)
return self.client.put(url, headers = self.client.headers, data=data, params = self.params)
def delete(self):
"""
The Delete Workflow request allows you to delete a workflow.
:return: The delete() method returns the status code and message as a response.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = result = client.stack('api_key').workflows('workflow_uid').delete().json()
-------------------------------
"""
if self.workflow_uid is None:
raise Exception('workflow uid is required')
url = f"{self.path}/{self.workflow_uid}"
return self.client.delete(url, headers = self.client.headers, params = self.params)
def disable(self):
"""
The Disable Workflow request allows you to disable a workflow.
:return: Json, with updated workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> file_path = "tests/resources/mock_content_types/import_content_types.json"
>>> result = client.stack('api_key').workflows('workflow_uid').disable().json()
-------------------------------
"""
if self.workflow_uid is None:
raise Exception('workflow uid is required')
url = f"{self.path}/{self.workflow_uid}/disable"
return self.client.get(url, headers = self.client.headers, params = self.params)
def enable(self):
"""
The Enable Workflow request allows you to enable a workflow.
:return: Json, with updated workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows('workflow_uid').export().json()
-------------------------------
"""
if self.workflow_uid is None:
raise Exception('workflow uid is required')
url = f"{self.path}/{self.workflow_uid}/enable"
return self.client.get(url, headers = self.client.headers, params = self.params)
def set_workflow_stage(self, content_type_uid, entry_uid, data):
"""
The Set Entry Workflow Stage request allows you to either set a particular workflow stage of an entry or update the workflow stage details of an entry.
:param content_type_uid: The content type uid is a unique identifier for a specific content type
in your system. It helps identify the type of content you are working with
:param entry_uid: The entry_uid parameter is the unique identifier of the entry that you want to
set the workflow stage for
:param data: The `data` parameter is a dictionary that contains the information needed to set
the workflow stage for a specific entry. It should include the following key-value pairs:
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> data = {
>>> "workflow": {
>>> "workflow_stage": {
>>> "comment": "Workflow Comment",
>>> "due_date": "Thu Dec 01 2018",
>>> "notify": false,
>>> "uid": "workflow_stage_uid",
>>> "assigned_to": [{
>>> "uid": "user_uid",
>>> "name": "Username",
>>> "email": "user_email_id"
>>> }],
>>> "assigned_by_roles": [{
>>> "uid": "role_uid",
>>> "name": "Role name"
>>> }]
>>> }
>>> }
>>> }
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().set_workflow_stage('content_type_uid', 'entry_uid', data).json()
-------------------------------
"""
if content_type_uid is None:
raise Exception('Content type uid is required')
if entry_uid is None:
raise Exception('Entry uid is required')
url = f"content_types/{content_type_uid}/entries/{entry_uid}/workflow"
data = json.dumps(data)
return self.client.post(url, headers = self.client.headers, data = data, params = self.params)
def create_publish_rule(self, data):
"""
The Create Publish Rules request allows you to create publish rules for the workflow of a stack.
:param data: The `data` parameter is a dictionary that contains the information needed to create
a publishing rule. This dictionary should include the necessary fields such as the rule name,
conditions, and actions. The exact structure of the `data` dictionary will depend on the
requirements of the API you are using
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> data = {
>>> "publishing_rule":{
>>> "workflow":"workflow_uid",
>>> "actions":[],
>>> "branches":[
>>> "main",
>>> "development"
>>> ],
>>> "content_types":[
>>> "$all"
>>> ],
>>> "locales":[
>>> "en-us"
>>> ],
>>> "environment":"environment_uid",
>>> "approvers":{
>>> "users":[
>>> "user_uids"
>>> ],
>>> "roles":[
>>> "role_uids"
>>> ]
>>> },
>>> "workflow_stage":"workflow_stage_uid",
>>> "disable_approver_publishing":false
>>> }
>>> }
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().create_publish_rule(data).json()
-------------------------------
"""
url = f"{self.path}/publishing_rules"
data = json.dumps(data)
return self.client.post(url, headers = self.client.headers, data = data, params = self.params)
def update_publish_rule(self, rule_uid, data):
"""
The Update Publish Rules request allows you to add a publish rule or update the details of the existing publish rules of a workflow.
:param rule_uid: The `rule_uid` parameter is the unique identifier of the publishing rule that
you want to update
:param data: The `data` parameter is a dictionary that contains the updated information for the
publishing rule. It should include the fields and values that need to be updated for the rule
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> data = {
>>> "publishing_rule": {
>>> "workflow": "workflow_uid",
>>> "actions": [],
>>> "branches": [
>>> "main",
>>> "development"
>>> ],
>>> "content_types": ["$all"],
>>> "locales": ["en-us"],
>>> "environment": "environment_uid",
>>> "approvers": {
>>> "users": ["user_uid"],
>>> "roles": ["role_uid"]
>>> },
>>> "workflow_stage": "workflow_stage_uid",
>>> "disable_approver_publishing": false
>>> }
>>> }
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().update_publish_rule('rule_uid', data).json()
-------------------------------
"""
if rule_uid is None:
raise Exception('Rule uid is required')
url = f"{self.path}/publishing_rules/{rule_uid}"
data = json.dumps(data)
return self.client.put(url, headers = self.client.headers, data = data, params = self.params)
def delete_publish_rule(self, rule_uid):
"""
The Delete Publish Rules request allows you to delete an existing publish rule.
:param rule_uid: The `rule_uid` parameter is the unique identifier of the publishing rule that
you want to delete. It is used to specify which rule should be deleted from the system
:return: the result of the `client.delete()` method, which is likely a response object or a
boolean indicating the success of the deletion.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().delete_publish_rule('rule_uid').json()
-------------------------------
"""
if rule_uid is None:
raise Exception('Rule uid is required')
url = f"{self.path}/publishing_rules/{rule_uid}"
return self.client.delete(url, headers = self.client.headers, params = self.params)
def fetch_publish_rule(self, rule_uid):
"""
The Get a Single Publish Rule request retrieves the comprehensive details of a specific publish rule of a Workflow.
:param rule_uid: The `rule_uid` parameter is the unique identifier of the publishing rule that
you want to fetch. It is used to specify which rule you want to retrieve from the server
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().fetch_publish_rule('rule_uid').json()
-------------------------------
"""
if rule_uid is None:
raise Exception('Rule uid is required')
url = f"{self.path}/publishing_rules/{rule_uid}"
return self.client.get(url, headers = self.client.headers, params = self.params)
def fetch_publish_rules(self):
"""
The Get all Publish Rules request retrieves the details of all the Publish rules of a workflow.
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().fetch_publish_rules().json()
-------------------------------
"""
url = f"{self.path}/publishing_rules"
return self.client.get(url, headers = self.client.headers, params = self.params)
def fetch_publish_rule_content_type(self, content_type_uid):
"""
The Get Publish Rules by Content Types request allows you to retrieve details of a Publish Rule applied to a specific content type of your stack.
:param content_type_uid: The `content_type_uid` parameter is a unique identifier for a specific
content type. It is used to fetch the publish rule content type with the given identifier
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().fetch_publish_rule_content_type('content_type_uid').json()
-------------------------------
"""
if content_type_uid is None:
raise Exception('Content type uid is required')
url = f"{self.path}/content_type/{content_type_uid}"
return self.client.get(url, headers = self.client.headers, params = self.params)
def publish_request_approval(self, content_type_uid, entry_uid):
"""
This multipurpose request allows you to either send a publish request or accept/reject a received publish request.
:param content_type_uid: The content type uid is a unique identifier for a specific content type
in your system. It is used to specify the type of content you are working with
:param entry_uid: The entry_uid parameter is the unique identifier of the entry that you want to
request approval for. It is used to specify which entry you want to perform the workflow action
on
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().publish_request_approval('content_type_uid', 'entry_uid').json()
-------------------------------
"""
if content_type_uid is None:
raise Exception('Content type uid is required')
if entry_uid is None:
raise Exception('Entry uid is required')
url = f"content_types/{content_type_uid}/entries/{entry_uid}/workflow"
return self.client.get(url, headers = self.client.headers, params = self.params)
def fetch_tasks(self):
"""
The Get all Tasks request retrieves a list of all tasks assigned to you.
:return: Json, with workflow details.
-------------------------------
[Example:]
>>> import contentstack_management
>>> client = contentstack_management.Client(authtoken='your_authtoken')
>>> result = client.stack('api_key').workflows().logs().json()
-------------------------------
"""
url = "user/assignments"
return self.client.get(url, headers = self.client.headers, params = self.params)