Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-searchable tags #398

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jrcastro2
Copy link
Contributor

@jrcastro2 jrcastro2 commented Sep 6, 2024

Comment on lines 17 to 29
class AnyUser(Generator):
"""Allows any user."""

def needs(self, **kwargs):
"""Enabling Needs."""
return [any_user]

def query_filter(self, **kwargs):
"""Match only searchable values in search."""
return dsl.Q(
"bool",
must_not=[dsl.Q("term", tags="non-searchable")],
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class AnyUser(Generator):
"""Allows any user."""
def needs(self, **kwargs):
"""Enabling Needs."""
return [any_user]
def query_filter(self, **kwargs):
"""Match only searchable values in search."""
return dsl.Q(
"bool",
must_not=[dsl.Q("term", tags="non-searchable")],
)
class Tags(Generator):
"""Search filter based on tags."""
def __init__(self, include=None, exclude=None):
...
def query_filter(self, **kwargs):
"""Search based on configured tags."""
return dsl.Q(
"bool",
must=[dsl.Q("term", tags=self.include)],
must_not=[dsl.Q("term", tags=self.exclude)],
)
  • major: I would not reuse the name AnyUser since we might start mixing them up and misinterpret its meaning
  • minor: defining a Tags generator might be a more flexible approach since it allows us to combine like the following:
class VocabularyPermissionPolicy:

    can_search = [
        SystemProcess(), 
        Administration(),
        Tags(exclude=["non-searchable"])
    ]

This assumes that Administration() makes sure that admins search/see everything (which I'm not sure if is the case today).

"""Permission policy."""

can_search = [SystemProcess(), AnyUser()]
can_read = [SystemProcess(), AnyUser()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
can_read = [SystemProcess(), AnyUser()]
can_read = [SystemProcess()]

minor: reads should always be possible, since we just want to control the search behaviour for end-users

@jrcastro2 jrcastro2 changed the title Add deprecation Add non-searchable tags Sep 23, 2024
@jrcastro2 jrcastro2 force-pushed the add-deprecation branch 3 times, most recently from 9a5a2ae to 88cb173 Compare September 23, 2024 08:59
# this permission is needed for the /api/vocabularies/ endpoint
can_list_vocabularies = [
SystemProcess(),
Tags(exclude=["non-searchable"], only_authenticated=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side question, for me to understand how this works. How can I know what tags are available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it's only documented in the RFC: https://github.com/inveniosoftware/rfcs/blob/fdb09b8b86263607364c8cc554b3a6580ccba2e2/rfcs/rdm-0077-vocabulary-harvesting.md#data-model

There is PR adding the non-searchableexplanation, however maybe we should document htis better in the docs (?)

can_search = [SystemProcess(), AnyUser()]
can_read = [SystemProcess(), AnyUser()]
can_search = [SystemProcess(), Tags(exclude=["non-searchable"])]
can_read = [SystemProcess(), Tags(exclude=["non-searchable"])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really what we want here that nobody at all can search non-searchable names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People with admin permission can search for it. If there is other permissions that should have access to it let me know. But to me it makes sense that only administrators do have.

invenio_vocabularies/services/generators.py Outdated Show resolved Hide resolved
invenio_vocabularies/services/generators.py Outdated Show resolved Hide resolved
invenio_vocabularies/contrib/names/permissions.py Outdated Show resolved Hide resolved
invenio_vocabularies/services/generators.py Outdated Show resolved Hide resolved
invenio_vocabularies/services/generators.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vocab: Add non-searchable tag
5 participants