Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/CSCFAIRADM-375-local-env' into C…
Browse files Browse the repository at this point in the history
…SCFAIRADM-375-local-env
  • Loading branch information
Toni Nurmi committed Dec 8, 2020
2 parents 9281466 + 7d22609 commit a148d5d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ ubuntu-xenial-16.04-cloudimg-console.log
.ropeproject/
.venv_metax/
.env
*.pem
*.pem
/src/log
7 changes: 4 additions & 3 deletions ENV_VARS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ copy .env.template to .env and fill following variables manually

| Name | Description | example |
| ------------------------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| DACITE_PREFIX | | |
| DACITE_URL | | |
| DATACITE_PREFIX | | |
| DATACITE_URL | | |
| DATACITE_ETSIN_URL_TEMPLATE | | |
| DATACITE_USERNAME | | |
| DATACITE_PASSWORD | | |
| DJANGO_SECRET_KEY | replace with proper django secret key | |
| ERROR_FILES_PATH | | /home/user/repo-root/logs/errors |
| ES_CONFIG_DIR | | /home/user/repo-root/src/metax_api/tasks/refdata/refdata_indexer/resources/es-config/ |
Expand All @@ -19,7 +20,7 @@ copy .env.template to .env and fill following variables manually
| METAX_DATABASE_PASSWORD | postgres owner of the database | |
| METAX_DATABASE_PORT | | 5432 |
| METAX_DATABASE_USER | | username |
| OAJ_BASE_URL | | |
| OAI_BASE_URL | | |
| ORG_FILE_PATH | | /home/user/repo-root/src/metax_api/tasks/refdata/refdata_indexer/resources/organizations/organizations.csv |
| RABBIT_MQ_PASSWORD | | guest |
| RABBIT_MQ_USER | | guest |
Expand Down
8 changes: 8 additions & 0 deletions src/metax_api/models/catalog_record_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def _post_create_operations(self, pid_type=None):
def is_draft_for_another_dataset(self):
return hasattr(self, 'draft_of') and self.draft_of is not None

def has_next_draft(self):
return hasattr(self, 'next_draft') and self.next_draft is not None

def _save_as_draft(self):
"""
Inherit here to always allow drafts in v2 api since the whole workflow is based on them
Expand Down Expand Up @@ -1207,6 +1210,11 @@ def create_new_version(self):
'Can\'t create new version. Dataset is a draft for another published dataset: %s'
% self.draft_of.identifier
)
elif self.has_next_draft():
raise Http400(
'Can\'t create new version. Dataset has an unmerged draft: %s'
% self.next_draft.identifier
)
elif not self.catalog_versions_datasets():
raise Http400('Data catalog does not allow dataset versioning')
elif self.state == self.STATE_DRAFT:
Expand Down
7 changes: 4 additions & 3 deletions src/metax_api/settings/.env.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ALLOWED_HOSTS=metax.csc.local,20.20.20.20
AUTH_SERVER_LOGOUT_URL=<required>
DACITE_PREFIX=<required>
DACITE_URL=<required>
DATACITE_PREFIX=<required>
DATACITE_URL=<required>
DATACITE_ETSIN_URL_TEMPLATE=<required>
DATACITE_USERNAME=<required>
DATACITE_PASSWORD=<required>
DEBUG=on
DJANGO_ENV=local
DJANGO_SECRET_KEY=<required>
Expand All @@ -17,7 +18,7 @@ METAX_DATABASE=<required>
METAX_DATABASE_HOST=localhost
METAX_DATABASE_PASSWORD=<required>
METAX_DATABASE_USER=<required>
OAJ_BASE_URL=http:<required>
OAI_BASE_URL=http:<required>
RABBIT_MQ_HOSTS=<required>
RABBIT_MQ_PASSWORD=<required>
RABBIT_MQ_PORT=<required>
Expand Down
6 changes: 3 additions & 3 deletions src/metax_api/settings/components/externals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)

OAI = {
"BASE_URL": env("OAJ_BASE_URL"),
"BASE_URL": env("OAI_BASE_URL"),
"BATCH_SIZE": 25,
"REPOSITORY_NAME": "Metax",
"ETSIN_URL_TEMPLATE": "http://etsin.something.fi/dataset/%s",
Expand All @@ -20,8 +20,8 @@
"USERNAME": env("DATACITE_USERNAME"),
"PASSWORD": env("DATACITE_PASSWORD"),
"ETSIN_URL_TEMPLATE": env("DATACITE_ETSIN_URL_TEMPLATE"),
"PREFIX": env("DACITE_PREFIX"),
"URL": env("DACITE_URL"),
"PREFIX": env("DATACITE_PREFIX"),
"URL": env("DATACITE_URL"),
}
REMS = {
"ENABLED": env("REMS_ENABLED"),
Expand Down
11 changes: 11 additions & 0 deletions src/metax_api/tests/api/rpc/v2/views/dataset_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ def test_version_from_draft(self):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
self.assertTrue('draft' in response.data['detail'][0], response.data)

def test_draft_blocks_version_creation(self):
"""
Don't allow new versions if there are unmerged drafts for a dataset
"""
response = self.client.post('/rpc/v2/datasets/create_draft?identifier=1')
self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.data)

response = self.client.post('/rpc/v2/datasets/create_new_version?identifier=1')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
self.assertTrue('unmerged draft' in response.data['detail'][0], response.data)

@responses.activate
def test_authorization(self):
"""
Expand Down

0 comments on commit a148d5d

Please sign in to comment.