-
Notifications
You must be signed in to change notification settings - Fork 203
SG-43999: add custom entity config features #456
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
Open
fauverick
wants to merge
1
commit into
master
Choose a base branch
from
ticket/SG-43999_custom_entity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -329,6 +329,14 @@ def ensure_return_image_urls_support(self) -> bool: | |
| {"version": (3, 3, 0), "label": "return thumbnail URLs"}, False | ||
| ) | ||
|
|
||
| def ensure_custom_entity_config_support(self) -> None: | ||
| """ | ||
| Ensures server has support for the custom entity config API (read, enable, configure, disable), added in v8.88.0. | ||
| """ | ||
| self._ensure_support( | ||
| {"version": (8, 88, 0), "label": "custom entity config API"} | ||
| ) | ||
|
Comment on lines
+336
to
+338
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notes: this version should be updated with the correct version once the feature is rolled out |
||
|
|
||
| def __str__(self) -> str: | ||
| return "ServerCapabilities: host %s, version %s, is_dev %s" % ( | ||
| self.host, | ||
|
|
@@ -3671,6 +3679,152 @@ def user_subscriptions_create( | |
|
|
||
| return response.get("status") == "success" | ||
|
|
||
| def custom_entity_read(self, entity_type: str) -> Dict[str, Any]: | ||
| """ | ||
| Read the current configuration of a Custom Entity. | ||
|
|
||
| >>> sg.custom_entity_read("CustomEntity08") | ||
| { | ||
| "entity_type": "CustomEntity08", | ||
| "enabled": True, | ||
| "display_name": "My Shots", | ||
| "entity_config": {"enable_tasks": True, ...} | ||
| } | ||
|
|
||
| :param str entity_type: The Custom Entity type to read, in its singular | ||
| CamelCase form (e.g. ``"CustomEntity08"``). Required. | ||
| :returns: The entity config snapshot dict with ``entity_type``, ``enabled``, | ||
| ``display_name``, and ``entity_config``. | ||
| :rtype: dict | ||
| :raises shotgun_api3.ShotgunError: if the entity type is invalid (fault code 104). | ||
| """ | ||
| self.server_caps.ensure_custom_entity_config_support() | ||
|
|
||
| return self._call_rpc("custom_entity_read", {"entity_type": entity_type}) | ||
|
|
||
| def custom_entity_enable(self, entity_type: str) -> Dict[str, Any]: | ||
| """ | ||
| Enable a Custom Entity. | ||
|
|
||
| This call is idempotent: if the entity is already enabled the current | ||
| snapshot is returned without error. To set the display name or feature | ||
| flags use :meth:`custom_entity_configure` after enabling. | ||
|
|
||
| >>> sg.custom_entity_enable("CustomEntity08") | ||
| { | ||
| "entity_type": "CustomEntity08", | ||
| "enabled": True, | ||
| "display_name": "Custom Entity08", | ||
| "entity_config": { | ||
| "enable_tasks": False, | ||
| "enable_versions": False, | ||
| "enable_publishes": False, | ||
| "enable_detail_page": True, | ||
| "include_in_search": False, | ||
| "include_in_global_menu": True, | ||
| } | ||
| } | ||
|
|
||
| :param str entity_type: The Custom Entity type to enable, in its singular | ||
| CamelCase form (e.g. ``"CustomEntity08"``). Required. | ||
| :returns: The entity config snapshot dict with ``entity_type``, ``enabled``, | ||
| ``display_name``, and ``entity_config``. | ||
| :rtype: dict | ||
| :raises shotgun_api3.ShotgunError: if the entity type is invalid | ||
| (fault code 104). | ||
| """ | ||
| self.server_caps.ensure_custom_entity_config_support() | ||
|
|
||
| return self._call_rpc("custom_entity_enable", {"entity_type": entity_type}) | ||
|
|
||
| def custom_entity_configure( | ||
| self, | ||
| entity_type: str, | ||
| display_name: Optional[str] = None, | ||
| entity_config: Optional[Dict[str, bool]] = None, | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Update an already-enabled Custom Entity's display name and/or feature flags. | ||
|
|
||
| Only the keys present in ``entity_config`` are mutated; omitted flags | ||
| keep their current values. | ||
|
|
||
| >>> sg.custom_entity_configure("CustomEntity08", display_name="Episode") | ||
| { | ||
| "entity_type": "CustomEntity08", | ||
| "enabled": True, | ||
| "display_name": "Episode", | ||
| "entity_config": {...} | ||
| } | ||
|
|
||
| :param str entity_type: The Custom Entity type to configure, in its singular | ||
| CamelCase form (e.g. ``"CustomEntity08"``). The entity must already be | ||
| enabled. Required. | ||
| :param str display_name: Optional new display name for the entity. | ||
| :param dict entity_config: Optional dict of feature flag booleans. Only the | ||
| flags present are mutated; omitted flags are left unchanged. Keys and | ||
| boolean values are passed through as-is. Recognized flags: | ||
| ``enable_tasks``, ``enable_versions``, ``enable_publishes``, | ||
| ``enable_detail_page``, ``include_in_search``, ``include_in_global_menu``. | ||
| :returns: The updated entity config snapshot dict with ``entity_type``, | ||
| ``enabled``, ``display_name``, and ``entity_config``. | ||
| :rtype: dict | ||
| :raises shotgun_api3.ShotgunError: if the entity type is invalid or not | ||
| yet enabled (fault code 104). | ||
| """ | ||
| self.server_caps.ensure_custom_entity_config_support() | ||
|
|
||
| params = {"entity_type": entity_type} | ||
| if display_name is not None: | ||
| params["display_name"] = display_name | ||
| if entity_config is not None: | ||
| params["entity_config"] = entity_config | ||
|
|
||
| return self._call_rpc("custom_entity_configure", params) | ||
|
|
||
| def custom_entity_disable( | ||
| self, entity_type: str, force: bool = False | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Disable a Custom Entity, clearing its feature flags. | ||
|
|
||
| This call is idempotent: if the entity is already disabled the current | ||
| snapshot is returned without error and the record guard is not checked. | ||
|
|
||
| Disabling a Custom Entity that has existing records does **not** delete the | ||
| data, but it does make the data inaccessible: the records will not appear in | ||
| the UI, will not be returned via the API, and any fields on other entities | ||
| that link to it become broken references. Because this is destructive in | ||
| effect, the server refuses to disable an entity that still has records unless | ||
| ``force`` is ``True``, and the error reports how many records were found. | ||
|
|
||
| >>> sg.custom_entity_disable("CustomEntity08") | ||
| { | ||
| "entity_type": "CustomEntity08", | ||
| "enabled": False, | ||
| "display_name": "My Shots" | ||
| } | ||
|
|
||
| :param str entity_type: The Custom Entity type to disable, in its singular | ||
| CamelCase form (e.g. ``"CustomEntity08"``). Required. | ||
| :param bool force: Disable the entity even if it still has active records. | ||
| Defaults to ``False``, which makes the call fail rather than render | ||
| existing data unreachable. Only a literal ``True`` is accepted; any | ||
| other truthy value is treated as ``False``. | ||
| :returns: The entity config snapshot dict with ``enabled`` set to ``False``. | ||
| :rtype: dict | ||
| :raises shotgun_api3.ShotgunError: if the entity type is invalid | ||
| (fault code 104), or if the entity has active records and ``force`` | ||
| was not set (fault code 104). | ||
| """ | ||
| self.server_caps.ensure_custom_entity_config_support() | ||
|
|
||
| params = {"entity_type": entity_type} | ||
| if force: | ||
| params["force"] = True | ||
|
|
||
| return self._call_rpc("custom_entity_disable", params) | ||
|
|
||
| def _build_opener(self, handler) -> urllib.request.OpenerDirector: | ||
| """ | ||
| Build urllib2 opener with appropriate proxy handler. | ||
|
|
||
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
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.
I don't see the point having enable and disable action as API.
Basically, we want a CRUD for these custom entities. I don't know if Create and Delete are part of the scope. So basically, that should give us only 2 API methods:
Now, we might want to keep the
custom_entity_enableandcustom_entity_disablePython method as shortcuts to call custom_entity_update but then there should not be anything about display name in there.