Skip to content

Commit

Permalink
oai-pmh: read oai sets prefix from app config
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova committed Jan 16, 2024
1 parent bbdd225 commit 73a2188
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
17 changes: 8 additions & 9 deletions invenio_rdm_records/oaiserver/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
class OAIPMHServerService(Service):
"""OAI-PMH service."""

def __init__(self, config, extra_reserved_prefixes=None):
def __init__(self, config, extra_reserved_prefixes={}):
"""Init service with config."""
super().__init__(config)
self.extra_reserved_prefixes = extra_reserved_prefixes or {}
self.extra_reserved_prefixes = extra_reserved_prefixes

@property
def schema(self):
Expand All @@ -53,11 +53,10 @@ def links_item_tpl(self):
self.config.links_item,
)

@property
def reserved_prefixes(self):
def _reserved_prefixes(self):
"""Get OAI-PMH set prefix from config."""
_reserved_prefixes = set([current_app.config["COMMUNITIES_OAI_SETS_PREFIX"]])
return _reserved_prefixes.union(self.extra_reserved_prefixes)
reserved_prefixes = set([current_app.config["COMMUNITIES_OAI_SETS_PREFIX"]])
return reserved_prefixes.union(self.extra_reserved_prefixes)

def _get_one(self, raise_error=True, **kwargs):
"""Retrieve set based on provided arguments."""
Expand All @@ -75,11 +74,11 @@ def _get_one(self, raise_error=True, **kwargs):
def _validate_spec(self, spec):
"""Checks the validity of the provided spec."""
# Reserved for community integration
if spec.startswith(tuple(self.reserved_prefixes)):
if spec.startswith(tuple(self._reserved_prefixes())):
raise ValidationError(
_(
"The spec must not start with any of the following list '{prefix}'.".format(
prefix=list(self.reserved_prefixes)
prefix=list(self._reserved_prefixes())
)
),
field_name="spec",
Expand Down Expand Up @@ -107,7 +106,7 @@ def create(self, identity, data, uow=None):
raise_errors=True,
)
self._validate_spec(valid_data["spec"])
system_created = valid_data["spec"].startswith(tuple(self.reserved_prefixes))
system_created = valid_data["spec"].startswith(tuple(self._reserved_prefixes()))

new_set = OAISet(**valid_data, system_created=system_created)
existing_set, errors = self._get_one(spec=new_set.spec, raise_error=False)
Expand Down
20 changes: 1 addition & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
See https://pytest-invenio.readthedocs.io/ for documentation on which test
fixtures are available.
"""
from invenio_rdm_records.services.permissions import RDMRequestsPermissionPolicy

# Monkey patch Werkzeug 2.1
# Flask-Login uses the safe_str_cmp method which has been removed in Werkzeug
Expand Down Expand Up @@ -173,7 +172,6 @@ def app_config(app_config, mock_datacite_client):
"PIDSTORE_RECID_FIELD",
"RECORDS_PERMISSIONS_RECORD_POLICY",
"RECORDS_REST_ENDPOINTS",
"REQUESTS_PERMISSION_POLICY",
]

for config_key in supported_configurations:
Expand Down Expand Up @@ -352,11 +350,9 @@ def app_config(app_config, mock_datacite_client):

app_config["RDM_RESOURCE_ACCESS_TOKENS_ENABLED"] = True

# Disable the automatic creation of moderation requests after publishing a record.
# Users are verified by default. This will disable the automatic creation of moderation requests after publishing a record.
# When testing unverified users, there is a "unverified_user" fixture for that purpose.
app_config["ACCOUNTS_DEFAULT_USERS_VERIFIED"] = True
app_config["RDM_USER_MODERATION_ENABLED"] = False
app_config["REQUESTS_PERMISSION_POLICY"] = RDMRequestsPermissionPolicy

app_config["COMMUNITIES_OAI_SETS_PREFIX"] = "community-"
return app_config
Expand Down Expand Up @@ -1091,16 +1087,6 @@ def identity_simple(users):
return i


@pytest.fixture()
def anonymous_identity(users):
"""Simple identity fixture."""
user = users[1]
i = Identity(user.id)
i.provides.add(UserNeed(user.id))
i.provides.add(Need(method="system_role", value="any_user"))
return i


@pytest.fixture(scope="module")
def languages_type(app):
"""Lanuage vocabulary type."""
Expand Down Expand Up @@ -1711,8 +1697,6 @@ def verified_user(UserFixture, app, db):
)
u.create(app, db)
u.user.verified_at = datetime.utcnow()
# Dumping `is_verified` requires authenticated user in tests
u.identity.provides.add(Need(method="system_role", value="authenticated_user"))
return u


Expand All @@ -1725,8 +1709,6 @@ def unverified_user(UserFixture, app, db):
)
u.create(app, db)
u.user.verified_at = None
# Dumping `is_verified` requires authenticated user in tests
u.identity.provides.add(Need(method="system_role", value="authenticated_user"))
return u


Expand Down

0 comments on commit 73a2188

Please sign in to comment.