Skip to content

Commit 5fe50df

Browse files
committed
Add function to deny community requests
1 parent 5ec9e89 commit 5fe50df

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

caltechdata_api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
caltechdata_edit,
99
caltechdata_unembargo,
1010
caltechdata_accept,
11+
caltechdata_reject,
1112
)
1213
from .customize_schema import customize_schema, validate_metadata
1314
from .get_metadata import get_metadata

caltechdata_api/caltechdata_edit.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,47 @@ def caltechdata_accept(ids, token=None, production=False):
4848
if result.status_code != 200:
4949
raise Exception(result.text)
5050

51+
def caltechdata_reject(ids, token=None, production=False, authors=False):
52+
# Reject a record from a community
53+
54+
# If no token is provided, get from RDMTOK environment variable
55+
if not token:
56+
token = os.environ["RDMTOK"]
57+
58+
if production == True:
59+
if authors:
60+
url = "https://authors.library.caltech.edu"
61+
else:
62+
url = "https://data.caltech.edu"
63+
else:
64+
if authors:
65+
url = "https://authors.caltechlibrary.dev"
66+
else:
67+
url = "https://data.caltechlibrary.dev"
68+
69+
headers = {
70+
"Authorization": "Bearer %s" % token,
71+
"Content-type": "application/json",
72+
}
73+
74+
for idv in ids:
75+
result = requests.get(
76+
url + "/api/records/" + idv + "/draft/review", headers=headers
77+
)
78+
print(url + "/api/records/" + idv + "/draft/review")
79+
if result.status_code != 200:
80+
raise Exception(result.text)
81+
accept_link = result.json()["links"]["actions"]["decline"]
82+
data = comment = {
83+
"payload": {
84+
"content": "This record was declined automatically with the CaltechDATA API",
85+
"format": "html",
86+
}
87+
}
88+
result = requests.post(accept_link, json=data, headers=headers)
89+
if result.status_code != 200:
90+
raise Exception(result.text)
91+
5192

5293
def caltechdata_edit(
5394
idv,

0 commit comments

Comments
 (0)