Add Keywordmanager utility, services & controlpanel #1
Conversation
davisagli
left a comment
There was a problem hiding this comment.
I reviewed the REST services, but not the keywordmanager tool or the frontend yet.
@jnptk Is the keywordmanager tool mostly copied from Products.PloneKeywordManager, or are there specific things you changed that you'd like me to check?
davisagli
left a comment
There was a problem hiding this comment.
It would be good to have functional tests for the API endpoints.
|
@davisagli please review again. The single keyword view is not ready yet. Also, would it be worth the effort to have tests that create a new KeywordIndex so we can test if the |
davisagli
left a comment
There was a problem hiding this comment.
@jnptk Nice work!
would it be worth the effort to have tests that create a new KeywordIndex so we can test if the indexName param in the keyword manager does what its supposed to do?
Nice to have, but not a blocker. Here's an example how to add an index programmatically: https://github.com/collective/collective.taxonomy/blob/53bf912ec7af0c0b0f43582c4146a898e1070be8/src/collective/taxonomy/behavior.py#L142
| @@ -0,0 +1,22 @@ | |||
| MANAGE_KEYWORDS_PERMISSION = "Manage Keywords" | |||
There was a problem hiding this comment.
This should be
| MANAGE_KEYWORDS_PERMISSION = "Manage Keywords" | |
| MANAGE_KEYWORDS_PERMISSION = "kitconcept.keywordmanager: Manage Keywords" |
to match the permission name in permissions.zcml.
(It doesn't really matter, since this is only used to protect the methods on the tool, and it is always called from trusted Python rather than an untrusted Zope template or script, so the permissions are not enforced.)
There was a problem hiding this comment.
I want to off-source the config options here into registry records maybe? For example if a project has a KeywordIndex that you should not be able to manage via the keyword manager you would put it in IGNORE_INDEXES, what do you think?
There was a problem hiding this comment.
@jnptk I would only go to registry records here if there's a need for editing it through the web. A project can already do:
from kitconcept.keywordmanager import config
config.IGNORE_INDEXES += ["my_custom_index"]
There was a problem hiding this comment.
how would one include that python file so plone reads it? I want to write it down in the readme
| catalog.Indexes[indexName].uniqueValues(withLengths=withLengths) | ||
| ) | ||
|
|
||
| # can we turn this into a yield? |
There was a problem hiding this comment.
I think we could but then I would rename the function to iterKeywords, to make it more obvious that it returns a generator. You'll have to change the return type to Generator[x] where x is the current return type, and Generator is imported from typing
|
|
||
| def test_response_invalid_index(self): | ||
| resp = self.api_session.get("/@keywords?idx=Bla") | ||
| assert resp.status_code == 500 |
There was a problem hiding this comment.
Nitpick: usually we want to reserve 500 for errors that are totally unanticipated (because they'll probably trigger an alert in a monitoring system).
In this case I would make the REST service catch the ValueError from the tool, and re-raise it as a BadRequest.
This is low priority to fix though.
| data=json.dumps({"new_keyword": "document", "old_keywords": ["doc"]}), | ||
| headers={"Accept": "application/json"}, | ||
| ) | ||
| assert resp.status_code == 204 |
There was a problem hiding this comment.
Make an assertion to confirm the keyword was updated.
|
@sneridagh @ericof Do you recognize the error when corepack is enabled in the frontend image? https://github.com/kitconcept/kitconcept-keywordmanager/actions/runs/24860661321/job/72785922229?pr=1 |
|
@davisagli how can I get the KeywordIndex a keyword is from to the |
|
@jnptk I would change the route for KeywordView to |
| <p className="description"> | ||
| <FormattedMessage | ||
| id="keyword-manager-description" | ||
| defaultMessage="The Keyword Manager allows you to maintain the keywords used in your intranet. Start by selecting the keyword field you want to manage. You can then sort, filter, rename, merge, or delete individual keywords." |
There was a problem hiding this comment.
This is an add-on that might also be used in sites which are not an intranet.
| defaultMessage="The Keyword Manager allows you to maintain the keywords used in your intranet. Start by selecting the keyword field you want to manage. You can then sort, filter, rename, merge, or delete individual keywords." | |
| defaultMessage="The Keyword Manager allows you to maintain the keywords used in your website. Start by selecting the keyword field you want to manage. You can then sort, filter, rename, merge, or delete individual keywords." |
| selectedKeys !== 'all' && selectedKeys?.size === 0 | ||
| } | ||
| > | ||
| <Icon name={replaceSVG} size="20px" /> |
There was a problem hiding this comment.
We need a better icon here. I thought this one would reload the listing.
| selectedKeys === 'all' | ||
| ? keywords.items?.map((kw) => kw.name) ?? [] | ||
| : [...(selectedKeys as Set<string>)], | ||
| ); |
There was a problem hiding this comment.
This didn't work when I tested today. The whole page reloaded. You may need to add type="button" or add event.preventDefault() (to avoid accidentally triggering form submission) or add event.stopPropagation() to prevent the event from bubbling up to container elements.
|
@jnptk Let me know if you'd like me to take a look at the failing tests. |
No description provided.