mirror of
https://github.com/Cian-H/invenio-config-iform.git
synced 2025-12-23 05:21:57 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
087cafa3ae | ||
|
|
14e9e0557a | ||
|
|
8669f5dcda | ||
|
|
62256b346f |
6
.github/workflows/tests.yml
vendored
6
.github/workflows/tests.yml
vendored
@@ -23,13 +23,13 @@ jobs:
|
||||
python-version: [3.8, 3.9]
|
||||
requirements-level: [pypi]
|
||||
db-service: [postgresql13]
|
||||
search-service: [elasticsearch7]
|
||||
search-service: [opensearch2]
|
||||
include:
|
||||
- db-service: postgresql13
|
||||
DB_EXTRAS: "postgresql"
|
||||
|
||||
- search-service: elasticsearch7
|
||||
SEARCH_EXTRAS: "elasticsearch7"
|
||||
- search-service: opensearch2
|
||||
SEARCH_EXTRAS: "opensearch2"
|
||||
|
||||
env:
|
||||
DB: ${{ matrix.db-service }}
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
|
||||
Changes
|
||||
=======
|
||||
|
||||
Version v0.10.1 (release 2022-11-17)
|
||||
|
||||
- global: add function
|
||||
|
||||
Version 0.10.0 (released 2022-10-13)
|
||||
|
||||
- global: migrate to v10 (#101)
|
||||
|
||||
Version 0.9.1 (released 2022-05-30)
|
||||
|
||||
- ci(publish): ping babel version (#99)
|
||||
|
||||
@@ -15,7 +15,6 @@ encoding = utf-8
|
||||
|
||||
[jinja2: **/templates/**.*]
|
||||
encoding = utf-8
|
||||
extensions = jinja2.ext.autoescape, jinja2.ext.with_
|
||||
|
||||
# Extraction from JavaScript files
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ release = __version__
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
language = "en"
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
|
||||
@@ -10,7 +10,13 @@
|
||||
|
||||
from .ext import InvenioConfigTugraz
|
||||
from .generators import RecordIp
|
||||
from .utils import get_identity_from_user_by_email
|
||||
|
||||
__version__ = "0.9.1"
|
||||
__version__ = "0.10.1"
|
||||
|
||||
__all__ = ("__version__", "InvenioConfigTugraz", "RecordIp")
|
||||
__all__ = (
|
||||
"__version__",
|
||||
"InvenioConfigTugraz",
|
||||
"RecordIp",
|
||||
"get_identity_from_user_by_email",
|
||||
)
|
||||
|
||||
@@ -151,10 +151,10 @@ The succinct encoding of the permissions for your instance gives you
|
||||
- great flexibility by defining your own actions, generators and policies
|
||||
"""
|
||||
|
||||
from elasticsearch_dsl.query import Q
|
||||
from flask import current_app, request
|
||||
from invenio_access.permissions import any_user
|
||||
from invenio_records_permissions.generators import Generator
|
||||
from invenio_search.engine import dsl
|
||||
|
||||
|
||||
class RecordIp(Generator):
|
||||
@@ -208,10 +208,10 @@ class RecordIp(Generator):
|
||||
|
||||
if not visible:
|
||||
# If user ip is not on the list, and If the record contains 'singleip' will not be seen
|
||||
return ~Q("match", **{"access.access_right": "singleip"})
|
||||
return ~dsl.Q("match", **{"access.access_right": "singleip"})
|
||||
|
||||
# Lists all records
|
||||
return Q("match_all")
|
||||
return dsl.Q("match_all")
|
||||
|
||||
def check_permission(self):
|
||||
"""Check for User IP address in config variable."""
|
||||
|
||||
32
invenio_config_tugraz/utils.py
Normal file
32
invenio_config_tugraz/utils.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2022 Graz University of Technology.
|
||||
#
|
||||
# invenio-config-tugraz is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the MIT License; see LICENSE file for more
|
||||
# details.
|
||||
|
||||
"""Utils file."""
|
||||
|
||||
from flask_principal import Identity
|
||||
from invenio_access import any_user
|
||||
from invenio_access.utils import get_identity
|
||||
from invenio_accounts import current_accounts
|
||||
|
||||
|
||||
def get_identity_from_user_by_email(email: str = None) -> Identity:
|
||||
"""Get the user specified via email or ID."""
|
||||
if email is None:
|
||||
raise ValueError("the email has to be set to get a identity")
|
||||
|
||||
user = current_accounts.datastore.get_user(email)
|
||||
|
||||
if user is None:
|
||||
raise LookupError(f"user with {email} not found")
|
||||
|
||||
identity = get_identity(user)
|
||||
|
||||
# TODO: this is a temporary solution. this should be done with data from the db
|
||||
identity.provides.add(any_user)
|
||||
|
||||
return identity
|
||||
10
setup.cfg
10
setup.cfg
@@ -37,16 +37,18 @@ python_requires = >=3.8
|
||||
zip_safe = False
|
||||
install_requires =
|
||||
# keep this dependencies identical to invenio-app-rdm
|
||||
invenio-rdm-records>=0.35.16,<0.36.0
|
||||
invenio-rdm-records>=0.39.0,<0.40.0
|
||||
invenio-cache>=1.1.1,<1.2.0
|
||||
|
||||
[options.extras_require]
|
||||
tests =
|
||||
pytest-black>=0.3.0,<0.3.10
|
||||
sphinx>=4.2.0,<5
|
||||
Sphinx>=4.5.0
|
||||
pytest-invenio>=1.4.7
|
||||
elasticsearch7 =
|
||||
invenio-search[elasticsearch7]>=1.4.2,<2.0
|
||||
# elasticsearch7 =
|
||||
# invenio-search[elasticsearch7]>=2.1.0,<3.0.0
|
||||
opensearch2 =
|
||||
invenio-search[opensearch2]>=2.1.0,<3.0.0
|
||||
|
||||
[options.entry_points]
|
||||
invenio_base.apps =
|
||||
|
||||
Reference in New Issue
Block a user