Skip to content

Commit

Permalink
dbio.project: make default post-submit state SUBMITTED
Browse files Browse the repository at this point in the history
  • Loading branch information
RayPlante committed Mar 28, 2024
1 parent 67a5942 commit f293a8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions python/nistoar/midas/dbio/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _restore_last_published_data(self, prec: ProjectRecord, message: str=None,
prec.data = pubrec.data

if reset_state:
prec.status.set_state(status.PUBLISHED)
prec.status.set_state(pubrec.status.state)
prec.status.act(self.STATUS_ACTION_RESTORE, message or defmsg)
prec.save()

Expand Down Expand Up @@ -930,7 +930,7 @@ def submit(self, id: str, message: str=None, _prec=None) -> status.RecordStatus:
if _prec.data.get('@version', '1.0.0') == '1.0.0':
message = "Initial version " + poststat
else:
message = "Revision " + postat
message = "Revision " + poststat

# record provenance record
self.dbcli.record_action(Action(Action.PROCESS, _prec.id, self.who, message, {"name": "submit"}))
Expand Down Expand Up @@ -964,6 +964,7 @@ def _submit(self, prec: ProjectRecord) -> str:
not due to anything the client did, but rather reflects a system problem
(e.g. from a downstream service).
"""
endstate = status.SUBMITTED # or could be status.PUBLISHED
try:
latestcli = self.dbcli.client_for(f"{self.dbcli.project}_latest", AUTOADMIN)
versioncli = self.dbcli.client_for(f"{self.dbcli.project}_version", AUTOADMIN)
Expand All @@ -974,8 +975,10 @@ def _submit(self, prec: ProjectRecord) -> str:
recd['id'] += "/pdr:v/" + recd['data'].get("@version", "0")
version = ProjectRecord(versioncli.project, deepcopy(recd), versioncli)

# Fix permissions
# Fix permissions, state
for pubrec in (latest, version):
pubrec.status.set_state(endstate)

# no one can delete, write, or admin (except superusers)
pubrec.acls.revoke_perm_from_all(ACLs.DELETE)
pubrec.acls.revoke_perm_from_all(ACLs.WRITE)
Expand All @@ -993,7 +996,7 @@ def _submit(self, prec: ProjectRecord) -> str:
self.log.error("%s: Problem with default publication submission: %s", prec.id, str(ex))
raise SubmissionFailed() from ex

return status.PUBLISHED
return endstate



Expand Down
6 changes: 4 additions & 2 deletions python/tests/nistoar/midas/dbio/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def test_restore_last_published_data(self):

pubcli = self.project.dbcli.client_for(self.project.dbcli.project + "_latest")
pubrec = project.ProjectRecord(pubcli.project, recd, pubcli)
pubrec.status.set_state(status.SUBMITTED)
pubrec.save()
pubrec = pubcli.get_record_for(recd['id'])
self.assertEqual(pubrec.id, recd['id'])
Expand All @@ -182,7 +183,7 @@ def test_restore_last_published_data(self):
prec = self.project.get_record(prec.id)
self.assertEqual(prec.data.get('color'), "red")
self.assertIsNone(prec.data.get('title'))
self.assertEqual(prec.status.state, status.PUBLISHED)
self.assertEqual(prec.status.state, status.SUBMITTED)

def test_delete_revision(self):
self.create_service()
Expand All @@ -198,6 +199,7 @@ def test_delete_revision(self):

pubcli = self.project.dbcli.client_for(self.project.dbcli.project + "_latest")
pubrec = project.ProjectRecord(pubcli.project, recd, pubcli)
pubrec.status.set_state(status.PUBLISHED)
pubrec.save()
pubrec = pubcli.get_record_for(recd['id'])
self.assertEqual(pubrec.id, recd['id'])
Expand Down Expand Up @@ -422,7 +424,7 @@ def test_submit(self):
prec = self.project.get_record(prec.id)
self.assertEqual(prec.data.get("@version"), "1.0.0")
self.assertEqual(prec.data.get("@id"), "ark:/88434/mdm1-0003")
self.assertEqual(prec.status.state, "published")
self.assertEqual(prec.status.state, "submitted")

pubcli = self.project.dbcli.client_for(self.project.dbcli.project+"_latest")
pubrec = pubcli.get_record_for(prec.data["@id"])
Expand Down
2 changes: 1 addition & 1 deletion python/tests/nistoar/midas/dbio/wsgi/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ def test_process(self):
self.assertIn("200 ", self.resp[0])
resp = self.body2dict(body)

self.assertEqual(resp['state'], 'published')
self.assertEqual(resp['state'], 'submitted')
self.assertEqual(resp['action'], 'submit')
self.assertIn('modified', resp)
self.assertIn('since', resp)
Expand Down

0 comments on commit f293a8a

Please sign in to comment.