Skip to content

Add Keywordmanager utility, services & controlpanel #1

Draft
jnptk wants to merge 44 commits intomainfrom
keywordmanager
Draft

Add Keywordmanager utility, services & controlpanel #1
jnptk wants to merge 44 commits intomainfrom
keywordmanager

Conversation

@jnptk
Copy link
Copy Markdown
Member

@jnptk jnptk commented Mar 30, 2026

No description provided.

@jnptk jnptk requested a review from davisagli March 30, 2026 09:03
Copy link
Copy Markdown
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

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?

Comment thread backend/src/kitconcept/keywordmanager/services/configure.zcml Outdated
Comment thread backend/src/kitconcept/keywordmanager/services/configure.zcml
Comment thread backend/src/kitconcept/keywordmanager/services/delete.py Outdated
Comment thread backend/src/kitconcept/keywordmanager/services/delete.py
Comment thread backend/src/kitconcept/keywordmanager/services/get.py Outdated
Comment thread backend/src/kitconcept/keywordmanager/services/update.py Outdated
Comment thread backend/src/kitconcept/keywordmanager/services/delete.py Outdated
Comment thread backend/src/kitconcept/keywordmanager/services/update.py Outdated
Copy link
Copy Markdown
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

It would be good to have functional tests for the API endpoints.

@jnptk jnptk requested a review from davisagli April 22, 2026 12:58
@jnptk
Copy link
Copy Markdown
Member Author

jnptk commented Apr 22, 2026

@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 indexName param in the keyword manager does what its supposed to do?

Copy link
Copy Markdown
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

@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

Comment thread frontend/packages/volto-keywordmanager/src/reducers/keywordIndexes.js Outdated
Comment thread frontend/packages/volto-keywordmanager/src/reducers/keywordIndexes.js Outdated
@@ -0,0 +1,22 @@
MANAGE_KEYWORDS_PERMISSION = "Manage Keywords"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be

Suggested change
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.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

how would one include that python file so plone reads it? I want to write it down in the readme

Comment thread backend/src/kitconcept/keywordmanager/tool.py Outdated
catalog.Indexes[indexName].uniqueValues(withLengths=withLengths)
)

# can we turn this into a yield?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make an assertion to confirm the keyword was updated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work here.

Comment thread frontend/packages/volto-keywordmanager/src/reducers/keywords.js Outdated
Comment thread frontend/packages/volto-keywordmanager/src/reducers/keywords.js Outdated
@davisagli
Copy link
Copy Markdown
Member

@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

@jnptk
Copy link
Copy Markdown
Member Author

jnptk commented Apr 28, 2026

@davisagli how can I get the KeywordIndex a keyword is from to the KeywordView component? It works for now because standard Plone only has the Subject KeywordIndex and the keyword manager falls back to querying this index by default but if a user wants to view a keyword from a different index it won't work because the component doesn't know where the keyword came from so the keyword manager will query the Subject index...

@davisagli
Copy link
Copy Markdown
Member

@jnptk I would change the route for KeywordView to path: '/controlpanel/keyword-manager/:keywordIndex/:id', and pass the index name as part of the path.

<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."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an add-on that might also be used in sites which are not an intranet.

Suggested change
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" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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>)],
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@davisagli
Copy link
Copy Markdown
Member

@jnptk Let me know if you'd like me to take a look at the failing tests.

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.

2 participants