Skip to content

Commit d19ac0e

Browse files
committed
Add handling of auto-accept comunities
1 parent 434df0d commit d19ac0e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

caltechdata_api/caltechdata_write.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,21 @@ def send_to_community(
132132
if result.status_code != 202:
133133
raise Exception(result.text)
134134
if publish:
135-
accept_link = result.json()["links"]["actions"]["accept"]
136-
data = comment = {
137-
"payload": {
138-
"content": "This record is accepted automatically with the CaltechDATA API",
139-
"format": "html",
135+
if "accept" in result.json()["links"]["actions"]:
136+
accept_link = result.json()["links"]["actions"]["accept"]
137+
data = comment = {
138+
"payload": {
139+
"content": "This record is accepted automatically with the CaltechDATA API",
140+
"format": "html",
141+
}
140142
}
141-
}
142-
result = requests.post(accept_link, json=data, headers=headers, verify=verify)
143-
if result.status_code != 200:
144-
raise Exception(result.text)
143+
result = requests.post(
144+
accept_link, json=data, headers=headers, verify=verify
145+
)
146+
if result.status_code != 200:
147+
raise Exception(result.text)
148+
# Otherwise we have direct publish permissions and don't need to acccept
149+
# the request
145150
return result
146151

147152

0 commit comments

Comments
 (0)