-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: master
Are you sure you want to change the base?
Conversation
jrcastro2
commented
Sep 6, 2024
•
edited
Loading
edited
- closes names vocab: allow names vocab to have 2 types of objects CERNDocumentServer/cds-rdm#193
- closes Vocab: Add non-searchable tag CERNDocumentServer/cds-rdm#194
0a560e3
to
eda8b19
Compare
invenio_vocabularies/generators.py
Outdated
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")], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
invenio_vocabularies/permissions.py
Outdated
"""Permission policy.""" | ||
|
||
can_search = [SystemProcess(), AnyUser()] | ||
can_read = [SystemProcess(), AnyUser()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
eda8b19
to
9da1e75
Compare
9a5a2ae
to
88cb173
Compare
# this permission is needed for the /api/vocabularies/ endpoint | ||
can_list_vocabularies = [ | ||
SystemProcess(), | ||
Tags(exclude=["non-searchable"], only_authenticated=True), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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-searchable
explanation, 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"])] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
90d019c
to
b1d6113
Compare
* update props json schema to allow multiple types
b1d6113
to
daf495b
Compare
can_search = [ | ||
SystemProcess(), | ||
IfTags(exclude=["unlisted"], only_authenticated=True), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.