Skip to content

Commit

Permalink
Merge pull request #135 from nih-sparc/fix-new-task-id-bug
Browse files Browse the repository at this point in the history
fixed bug adding subtasks
  • Loading branch information
egauzens authored Dec 14, 2022
2 parents 81cee9e + 2c70041 commit 3b34fa6
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,53 +960,53 @@ def create_wrike_task():

# add the file as an attachment to the newly created ticket
files = request.files
new_task_id = ""
if files and 'attachment' in files and 'data' in resp.json() and resp.json()["data"] != []:
new_task_id = resp.json()["data"][0]["id"]
attachment = files['attachment']
file_data = attachment.read()
file_name = attachment.filename
content_type = attachment.content_type
headers = {
'Authorization': 'Bearer ' + Config.WRIKE_TOKEN,
'X-File-Name': file_name,
'content-type': content_type,
'X-Requested-With': 'XMLHttpRequest'
if 'data' in resp.json() and resp.json()["data"] != []:
new_task_id = resp.json()["data"][0]["id"]
if files and 'attachment' in files:
attachment = files['attachment']
file_data = attachment.read()
file_name = attachment.filename
content_type = attachment.content_type
headers = {
'Authorization': 'Bearer ' + Config.WRIKE_TOKEN,
'X-File-Name': file_name,
'content-type': content_type,
'X-Requested-With': 'XMLHttpRequest'
}
attachment_url = "https://www.wrike.com/api/v4/tasks/" + new_task_id + "/attachments"

try:
requests.post(
url=attachment_url,
data=file_data,
headers=headers
)
except Exception as e:
print(e)

# create copies of all the templates subtasks and add them to the newly created ticket
for subTaskId in templateSubTaskIds:
subTaskTemplateUrl = 'https://www.wrike.com/api/v4/tasks/' + subTaskId
subTaskTemplateResp = requests.get(
url = subTaskTemplateUrl,
headers=hed
)
if 'data' in subTaskTemplateResp.json() and subTaskTemplateResp.json()["data"] != []:
subTaskData = {
"title": subTaskTemplateResp.json()["data"][0]["title"],
"description": subTaskTemplateResp.json()["data"][0]["description"],
"customStatus": subTaskTemplateResp.json()["data"][0]["customStatusId"],
"followers": subTaskTemplateResp.json()["data"][0]["followerIds"],
"responsibles": subTaskTemplateResp.json()["data"][0]["responsibleIds"],
"follow": False,
"superTasks": [new_task_id],
"dates": {"type": "Backlog"}
}
attachment_url = "https://www.wrike.com/api/v4/tasks/" + new_task_id + "/attachments"

try:
requests.post(
url=attachment_url,
data=file_data,
headers=headers
url=url,
json=subTaskData,
headers=hed
)
except Exception as e:
print(e)

# create copies of all the templates subtasks and add them to the newly created ticket
for subTaskId in templateSubTaskIds:
subTaskTemplateUrl = 'https://www.wrike.com/api/v4/tasks/' + subTaskId
subTaskTemplateResp = requests.get(
url = subTaskTemplateUrl,
headers=hed
)
if 'data' in subTaskTemplateResp.json() and subTaskTemplateResp.json()["data"] != []:
subTaskData = {
"title": subTaskTemplateResp.json()["data"][0]["title"],
"description": subTaskTemplateResp.json()["data"][0]["description"],
"customStatus": subTaskTemplateResp.json()["data"][0]["customStatusId"],
"followers": subTaskTemplateResp.json()["data"][0]["followerIds"],
"responsibles": subTaskTemplateResp.json()["data"][0]["responsibleIds"],
"follow": False,
"superTasks": [new_task_id],
"dates": {"type": "Backlog"}
}
requests.post(
url=url,
json=subTaskData,
headers=hed
)

if (resp.status_code == 200):
if 'userEmail' in form and form['userEmail'] is not None:
Expand Down

0 comments on commit 3b34fa6

Please sign in to comment.