Skip to content

Commit

Permalink
Merge pull request #300 from NASA-PDS/299_group_write_permissions
Browse files Browse the repository at this point in the history
Group Write Permission Fix
  • Loading branch information
collinss-jpl authored Nov 30, 2021
2 parents 6489231 + 4199fb9 commit abec995
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 45 deletions.
19 changes: 13 additions & 6 deletions src/pds_doi_service/core/actions/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,33 +267,40 @@ def run(self, **kwargs):
dois = self._complete_dois(dois)
dois = self._validate_dois(dois)

for doi in dois:
for input_doi in dois:
# Create a JSON format label to send to the service provider
io_doi_label = self._record_service.create_doi_record(doi, content_type=CONTENT_TYPE_JSON)
io_doi_label = self._record_service.create_doi_record(input_doi, content_type=CONTENT_TYPE_JSON)

# If the next step is to release, submit to the service provider and
# use the response label for the local transaction database entry
if not self._review:
# Determine the correct HTTP verb and URL for submission of this DOI
method, url = self._web_client.endpoint_for_doi(doi, self._name)
method, url = self._web_client.endpoint_for_doi(input_doi, self._name)

doi, o_doi_label = self._web_client.submit_content(
output_doi, o_doi_label = self._web_client.submit_content(
url=url, method=method, payload=io_doi_label, content_type=CONTENT_TYPE_JSON
)
# Otherwise, DOI object is ready to be logged
else:
output_doi = input_doi

# Otherwise, if the next step is review, the label we've already
# created has marked all the Doi's as being the "review" step
# so its ready to be submitted to the local transaction history
transaction = self.m_transaction_builder.prepare_transaction(
self._node, self._submitter, doi, input_path=self._input, output_content_type=CONTENT_TYPE_JSON
self._node,
self._submitter,
output_doi,
input_path=input_doi.input_source,
output_content_type=CONTENT_TYPE_JSON,
)

# Commit the transaction to the local database
transaction.log()

# Append the latest version of the Doi object to return
# as a label
output_dois.append(doi)
output_dois.append(output_doi)
# Propagate input format exceptions, force flag should not affect
# these being raised and certain callers (such as the API) look
# for this exception specifically
Expand Down
19 changes: 11 additions & 8 deletions src/pds_doi_service/core/actions/reserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,32 @@ def run(self, **kwargs):
dois = self._complete_dois(dois)
dois = self._validate_dois(dois)

for doi in dois:
for input_doi in dois:
# Create the JSON request label to send
io_doi_label = self._record_service.create_doi_record(doi, content_type=CONTENT_TYPE_JSON)
io_doi_label = self._record_service.create_doi_record(input_doi, content_type=CONTENT_TYPE_JSON)

# Submit the Reserve request
# Determine the correct HTTP verb and URL for submission of this DOI
method, url = self._web_client.endpoint_for_doi(doi, self._name)
method, url = self._web_client.endpoint_for_doi(input_doi, self._name)

doi, o_doi_label = self._web_client.submit_content(
output_doi, o_doi_label = self._web_client.submit_content(
method=method, url=url, payload=io_doi_label, content_type=CONTENT_TYPE_JSON
)

# Log the inputs and outputs of this transaction
transaction = self.m_transaction_builder.prepare_transaction(
self._node, self._submitter, doi, input_path=self._input, output_content_type=CONTENT_TYPE_JSON
self._node,
self._submitter,
output_doi,
input_path=input_doi.input_source,
output_content_type=CONTENT_TYPE_JSON,
)

# Commit the transaction to the local database
transaction.log()

# Append the latest version of the Doi object to return
# as a label
output_dois.append(doi)
# Append the latest version of the Doi object to return as a label
output_dois.append(output_doi)

# Propagate input format exceptions, force flag should not affect
# these being raised and certain callers (such as the API) look
Expand Down
2 changes: 1 addition & 1 deletion src/pds_doi_service/core/actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def run(self, **kwargs):

for doi in dois:
transaction = self.m_transaction_builder.prepare_transaction(
self._node, self._submitter, doi, input_path=self._input, output_content_type=CONTENT_TYPE_JSON
self._node, self._submitter, doi, input_path=doi.input_source, output_content_type=CONTENT_TYPE_JSON
)

transaction.log()
Expand Down
10 changes: 10 additions & 0 deletions src/pds_doi_service/core/db/doi_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
Contains classes and functions for interfacing with the local transaction
database (SQLite3).
"""
import os
import sqlite3
import stat
from collections import OrderedDict
from datetime import datetime
from datetime import timedelta
Expand Down Expand Up @@ -94,6 +96,14 @@ def create_connection(self):
except Error as my_error:
logger.error("Failed to connect to database, reason: %s", my_error)

# Make sure Database has proper group permissions set
st = os.stat(self.m_database_name)
has_group_rw = bool(st.st_mode & stat.S_IRGRP & stat.S_IWGRP)

if not has_group_rw:
logger.debug("Setting group read/write bits on database %s", self.m_database_name)
os.chmod(self.m_database_name, st.st_mode | stat.S_IRGRP | stat.S_IWGRP)

def get_connection(self, table_name=None):
"""
Returns a connection to the SQLite database. If a connection does
Expand Down
4 changes: 1 addition & 3 deletions src/pds_doi_service/core/entities/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class DoiStatus(str, Enum):
An error has occurred with the DOI submission.
Unknown -
Default starting state for DOI transactions.
Reserve_not_submitted -
DOI reserve request in local database, but not published/released.
Used for testing of the reserve action.
Reserved -
DOI reserve request submitted, but not yet published/released.
Draft -
Expand Down Expand Up @@ -127,3 +124,4 @@ class Doi:
date_record_added: Optional[datetime] = None
date_record_updated: Optional[datetime] = None
event: Optional[DoiEvent] = None
input_source: Optional[str] = None
20 changes: 19 additions & 1 deletion src/pds_doi_service/core/input/input_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ def _read_from_path(self, path):
Returns
-------
dois : list[doi]
The list of Doi objects parsed from the provided path.
Raises
-------
InputFormatException
If an error is encountered while reading a local file.
Expand All @@ -526,6 +531,12 @@ def _read_from_path(self, path):

logger.error(msg)
raise InputFormatException(msg)

# Make a note of where we can find the original input file that
# resulted in these DOI's so we can save it to the transaction
# history later on
for doi in dois:
doi.input_source = path
else:
logger.info("File %s has unsupported extension, ignoring", path)
else:
Expand Down Expand Up @@ -580,7 +591,14 @@ def _read_from_remote(self, input_url):
temp_file.write(response.content)
temp_file.seek(0)

return self._read_from_path(temp_file.name)
dois = self._read_from_path(temp_file.name)

# Update input source to point to original URL, as the temp file paths
# assigned by _read_from_path no longer exist
for doi in dois:
doi.input_source = input_url

return dois

def parse_dois_from_input_file(self, input_file):
"""
Expand Down
2 changes: 2 additions & 0 deletions src/pds_doi_service/core/outputs/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from . import datacite_test
from . import doi_validator_test
from . import osti_test
from . import transaction_test


def suite():
suite = unittest.TestSuite()
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(datacite_test))
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(doi_validator_test))
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(osti_test))
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(transaction_test))
return suite
1 change: 1 addition & 0 deletions src/pds_doi_service/core/outputs/test/data/pds4_bundle.xml
Loading

0 comments on commit abec995

Please sign in to comment.