-
Notifications
You must be signed in to change notification settings - Fork 0
Add Keywordmanager utility, services & controlpanel #1
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
111 commits
Select commit
Hold shift + click to select a range
f28c11d
wip
jnptk 04a0f9b
first working
jnptk 5fdf327
make format
jnptk 5f48385
add endpoint to get KeywordIndex indexes
jnptk ef8cfa3
add pagination
jnptk a7b577f
missing things for choosing the index thats queried
jnptk 28bd1a5
rename endpoint to [at]keywords
jnptk f264a46
make endpoint only available for site root
jnptk a9d8fcf
add manage keywords permission
jnptk 2c358b3
rename action path
jnptk a32eef3
request data validation
jnptk e390427
add tests for keywords service get & fix get methods reply
jnptk d15d190
more tests
jnptk 23e095d
fix query building in get method
jnptk 52fbd94
even more tests
jnptk 04e1092
different fixes & styling
jnptk 49ea914
prepare for to make endpoint traversable + fixes & styling
jnptk 532b9b9
make endpoint traverseable
jnptk e4d3307
make format
jnptk 8adddf7
fix typo in function import
jnptk f17560d
various styling fixes
jnptk d1bb2fd
rework single keyword view to use search endpoint
jnptk 97d943f
fix cursor for buttons outside the table
jnptk 58360fe
typing for km utility
jnptk dccb6db
implement sorting mechanisms & styling
jnptk 886a0e5
fix tests
jnptk 0d41438
don't return sorted keywords
jnptk 8dcc3dc
support custom KeywordIndexes & more improvements
jnptk 66717a3
remove shadow from buttons
jnptk 99e5130
update confirm modal
jnptk 3c79c07
move modals out of KeywordManager.tsx & more
jnptk 8427764
reuse DeleteModal component
jnptk ffe68ff
Fix babel.config.js, extract i18n
davisagli efb3e5a
Run make format
davisagli ca97f10
Fix storybook config
davisagli 0dd894d
fix typos
jnptk 274e1cd
remove unicode fallback for python 2
jnptk 4f07d0b
remove fallback for archetypes
jnptk abc1d54
update permission name in config
jnptk ab4227f
pagination & styling for keyword view
jnptk 5b0910f
add option to filter by type
jnptk df09bdb
add filtering options in keyword view
jnptk bf7a769
make keyword view aware of the index a keyword is from
jnptk 3656bb9
update to volto 19.0.0-alpha.33
jnptk 7e865fe
styling + a bunch of fixes
jnptk f07af32
don't reload the entire page when sorting
jnptk 6655f3e
hide choice of keyword index if there is only one
jnptk b6ece78
update locales
jnptk 4eeaeba
show text if no search results
jnptk 96a980b
naming
jnptk 047aaad
remove action column, show delete button on the keyword pills
jnptk 53ddc84
dynamically get index field from object
jnptk ee1d71a
make delete endpoint context aware
jnptk 65baed6
fix keyword deletion in individual keyword view
jnptk 2c9f56a
update scaffold, fix missing ts type declarations
jnptk f45579c
fix type declarations for react-toastify
jnptk 048d9f8
fix selected row hover
jnptk 5b547dd
truncate keyword pills with show more button
jnptk 2039e64
update keyword manager description
jnptk dd73947
remove unused import
jnptk 18641e1
add loading indicator while bulk keyword changes are being processed
jnptk ce731d7
align show more button with keyword pills
jnptk 91f6f58
display path & title on separate lines in keyword view
jnptk f27645d
fix bulk delete doing nothing in keyword view
jnptk 394b486
locales
jnptk fd7375e
make format
jnptk 41a1c8e
remove direct dependency of react-aria-components
jnptk 1434903
use Table component from react-aria-components (from 'catalog:') & so…
jnptk 9c43d80
few fixes
jnptk 68321d7
show toast after successful/failed actions
jnptk b7fd33c
rename & merge: use "edit" (pencil) icon instead
jnptk bff5a0b
fix sorting icon in table header
jnptk 8313f42
style table heading
jnptk 36d7ac1
refactor toasts, add toasts for individual keyword view
jnptk e0e1dca
remove pagination from keywords view
jnptk 7df21b7
add a11y complient pagination component
jnptk 67d3fa1
refactor table in individual keyword view
jnptk 5a3311a
improvement to the styles
jnptk c0fd064
border styles
jnptk 34e5b26
remove unused import
jnptk 8d19830
consistent placeholder styling
jnptk aaa0940
fix table inner text alignment
jnptk dcf79f0
fix filter button
jnptk e836c54
remove unused import
jnptk 26a793d
fix services tests
jnptk 282cc3d
add changelog entries
jnptk 5ca5d10
fix keyword index selection
jnptk 3d6ff19
fix search button in individual keyword view
jnptk 5735836
fix multi-select fields in individual keyword view not showing select…
jnptk 82e9a9b
add confimation dialog to single keyword delete button
jnptk 1793f79
more specific texts for rename modal if only one keyword is selected
jnptk 9d82358
improve toast messages & add translations
jnptk 5c8389d
add VLT as dev dependency
jnptk 0e243af
move to scss
jnptk 19983df
fix text wrap with ellipsis in individual keyword filters
jnptk 8b24684
fix color of trash icon in rows
jnptk e85c028
improve a11y
jnptk d0e16dd
make format
jnptk 96ccd53
remove box-shadow on buttons
jnptk 8f219c1
fix cursor not pointing in row delete
jnptk 5df2a56
use custom Select to fix popover position in rename modal
jnptk 505b31b
fix overflowing select values
jnptk 0bd4b10
replace temp popover fix with upstream fix
jnptk 38e381f
fix sorting icons
jnptk e7d5e3f
fix keyword deletion
jnptk db58601
fix keyword deletion from single item (via pills)
jnptk adeb3a9
move KeywordList component
jnptk f1578ba
update error message
jnptk fb7744e
update README.md
jnptk 4090f00
update README.md
jnptk 62903d6
remove docs workflow
jnptk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| MANAGE_KEYWORDS_PERMISSION = "Manage Keywords" | ||
|
|
||
| # Meta type of the keyword indexes. If you're one of those crazy people that use | ||
| # custom indexes, you'll want to update this. | ||
| META_TYPE = "KeywordIndex" | ||
|
|
||
| # indexes of META_TYPE we know we don't want to manage, because bad things(tm) | ||
| # will happen | ||
| IGNORE_INDEXES = [ | ||
| "object_provides", | ||
| "allowedRolesAndUsers", | ||
| "getRawRelatedItems", | ||
| "getEventType", | ||
| "block_types", | ||
| ] | ||
|
|
||
| # A list of indexes that should always be reindexed when merging or deleting | ||
| # keywords on objects. Most people won't need this. | ||
| ALWAYS_REINDEX = ( | ||
| # 'Subject', | ||
| "SearchableText", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,22 @@ | ||
| """Module where all interfaces, events and exceptions live.""" | ||
|
|
||
| from zope.interface import Interface | ||
| from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
|
|
||
|
|
||
| class IBrowserLayer(IDefaultBrowserLayer): | ||
| """Marker interface that defines a browser layer.""" | ||
|
|
||
|
|
||
| class IKeywordManager(Interface): | ||
| """A utility that allows to manage keywords""" | ||
|
|
||
| def change(old_keywords, new_keyword): | ||
| """Updates all objects using the old_keywords. | ||
|
|
||
| Objects using the old_keywords will be using the new_keywords | ||
| afterwards. | ||
| """ | ||
|
|
||
| def delete(keywords): | ||
| """Removes the keywords from all objects using it.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| <configure xmlns="http://namespaces.zope.org/zope"> | ||
|
|
||
| <!-- -*- extra stuff goes here -*- --> | ||
| <permission | ||
| id="kitconcept.keywordmanager.ManageKeywords" | ||
| title="kitconcept.keywordmanager: Manage Keywords" | ||
| /> | ||
|
|
||
| </configure> |
7 changes: 6 additions & 1 deletion
7
backend/src/kitconcept/keywordmanager/profiles/default/rolemap.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <rolemap> | ||
| <permissions> | ||
| <!-- -*- extra stuff goes here -*- --> | ||
| <permission acquire="True" | ||
| name="kitconcept.keywordmanager: Manage Keywords" | ||
| > | ||
| <role name="Manager" /> | ||
| <role name="Site Administrator" /> | ||
| </permission> | ||
| </permissions> | ||
| </rolemap> |
File renamed without changes.
38 changes: 38 additions & 0 deletions
38
backend/src/kitconcept/keywordmanager/services/configure.zcml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <configure | ||
| xmlns="http://namespaces.zope.org/zope" | ||
| xmlns:browser="http://namespaces.zope.org/browser" | ||
| xmlns:plone="http://namespaces.plone.org/plone" | ||
| i18n_domain="plone.keywordmanager" | ||
| > | ||
|
|
||
| <plone:service | ||
| method="GET" | ||
| factory=".get.KeywordsGet" | ||
| for="plone.base.interfaces.IPloneSiteRoot" | ||
| permission="kitconcept.keywordmanager.ManageKeywords" | ||
| name="@keywords" | ||
| /> | ||
| <plone:service | ||
| method="DELETE" | ||
| factory=".delete.KeywordsDelete" | ||
| for="plone.base.interfaces.IPloneSiteRoot" | ||
| permission="kitconcept.keywordmanager.ManageKeywords" | ||
| name="@keywords" | ||
| /> | ||
| <plone:service | ||
| method="PATCH" | ||
| factory=".update.KeywordsPatch" | ||
| for="plone.base.interfaces.IPloneSiteRoot" | ||
| permission="kitconcept.keywordmanager.ManageKeywords" | ||
| name="@keywords" | ||
| /> | ||
|
|
||
| <plone:service | ||
| method="GET" | ||
| factory=".get.KeywordIndexesGet" | ||
| for="plone.base.interfaces.IPloneSiteRoot" | ||
| permission="kitconcept.keywordmanager.ManageKeywords" | ||
| name="@keyword-indexes" | ||
| /> | ||
|
jnptk marked this conversation as resolved.
|
||
|
|
||
| </configure> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from kitconcept.keywordmanager.interfaces import IKeywordManager | ||
| from plone.restapi.deserializer import json_body | ||
| from plone.restapi.services import Service | ||
| from zExceptions import BadRequest | ||
| from zope.component import getUtility | ||
|
|
||
|
|
||
| class KeywordsDelete(Service): | ||
| def reply(self): | ||
| data = json_body(self.request) | ||
| km = getUtility(IKeywordManager) | ||
| keywords = data.get("items") or [] | ||
|
|
||
| if not isinstance(keywords, list): | ||
| raise BadRequest("") | ||
| if not keywords: | ||
| raise BadRequest("") | ||
|
|
||
|
jnptk marked this conversation as resolved.
|
||
| km.delete(keywords) | ||
|
|
||
| return self.reply_no_content() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from kitconcept.keywordmanager.interfaces import IKeywordManager | ||
| from plone.restapi.batching import HypermediaBatch | ||
| from plone.restapi.services import Service | ||
| from zope.component import getUtility | ||
|
|
||
|
|
||
| class KeywordsGet(Service): | ||
| def reply(self): | ||
| km = getUtility(IKeywordManager) | ||
| query = {"withLengths": True} | ||
| if idx := self.request.form.get("idx"): | ||
| query = {"indexName": idx} | ||
|
|
||
| keywords = km.getKeywords(**query) | ||
|
|
||
| batch = HypermediaBatch(self.request, keywords) | ||
| items = {{"name": name, "total": count} for name, count in batch} | ||
|
|
||
| keywords_data = { | ||
| "@id": batch.canonical_url, | ||
| "items": items, | ||
| "items_total": batch.items_total, | ||
| } | ||
| if batch.links: | ||
| keywords_data["batching"] = batch.links | ||
| return keywords_data | ||
|
|
||
|
|
||
| class KeywordIndexesGet(Service): | ||
| def reply(self): | ||
| km = getUtility(IKeywordManager) | ||
| return km.getKeywordIndexes() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from kitconcept.keywordmanager.interfaces import IKeywordManager | ||
| from plone.restapi.deserializer import json_body | ||
| from plone.restapi.services import Service | ||
| from zExceptions import BadRequest | ||
| from zope.component import getUtility | ||
|
|
||
|
|
||
| class KeywordsPatch(Service): | ||
| def reply(self): | ||
| data = json_body(self.request) | ||
| km = getUtility(IKeywordManager) | ||
|
|
||
| new_keyword = data.get("new_keyword") or "" | ||
| old_keywords = data.get("old_keywords") or [] | ||
|
|
||
| if not isinstance(new_keyword, str): | ||
| raise BadRequest("") | ||
| if not new_keyword: | ||
| raise BadRequest("") | ||
| if not isinstance(old_keywords, list): | ||
| raise BadRequest("") | ||
| if not old_keywords: | ||
| raise BadRequest("") | ||
|
|
||
| km.change(new_keyword, old_keywords) | ||
|
|
||
| return self.reply_no_content() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be
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.
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?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.
@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:
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.
how would one include that python file so plone reads it? I want to write it down in the readme