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 3 commits into
base: master
Choose a base branch
from

Conversation

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
@jrcastro2 jrcastro2 force-pushed the add-deprecation branch 2 times, most recently from 90d019c to b1d6113 Compare October 11, 2024 14:21
Comment on lines +23 to +26
can_search = [
SystemProcess(),
IfTags(exclude=["unlisted"], only_authenticated=True),
]
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_search = [
SystemProcess(),
IfTags(exclude=["unlisted"], only_authenticated=True),
]
can_search = [
SystemProcess(),
IfTags(exclude=["unlisted"]),
AuthenticatedUser(),
]

minor: wouldn't that be a bit possible in terms of reusing/composing with existing generators? The only_authenticated parameter feels a bit ad-hoc

links_tpl=self.links_item_tpl,
)
if many:
return self.result_list(self, identity, results)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there permission needed to read many? I had this thought seeing the permission required below

"type": "boolean"
},
{
"type": "array"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is array wanted and maybe copied from somewhere else? It might be difficult to have good search queries with arrays.

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.

names vocab: allow names vocab to have 2 types of objects Vocab: Add non-searchable tag
5 participants