Skip to content

Commit

Permalink
Merge 3db7b24 into 81e22e5
Browse files Browse the repository at this point in the history
  • Loading branch information
tisto committed Jun 10, 2017
2 parents 81e22e5 + 3db7b24 commit 99ed744
Show file tree
Hide file tree
Showing 21 changed files with 889 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
1.0a18 (unreleased)
-------------------

New Features:

- Add @controlpanels endpoint.
[jaroel,timo]

- tweaks to README.rst
[tkimnguyen]

Expand Down
3 changes: 3 additions & 0 deletions docs/source/_json/controlpanels_get.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /plone/@controlpanels HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
15 changes: 15 additions & 0 deletions docs/source/_json/controlpanels_get.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Content-Type: application/json

[
{
"@id": "http://localhost:55001/plone/@controlpanels/mail",
"group": "General",
"title": "Mail"
},
{
"@id": "http://localhost:55001/plone/@controlpanels/editing",
"group": "Content",
"title": "Editing"
}
]
3 changes: 3 additions & 0 deletions docs/source/_json/controlpanels_get_item.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /plone/@controlpanels/editing HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
98 changes: 98 additions & 0 deletions docs/source/_json/controlpanels_get_item.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"@id": "http://localhost:55001/plone/@controlpanel/editing",
"data": {
"available_editors": [
"TinyMCE",
"None"
],
"default_editor": "TinyMCE",
"enable_link_integrity_checks": true,
"ext_editor": false,
"lock_on_ttw_edit": true
},
"group": "Content",
"schema": {
"fieldsets": [
{
"fields": [
"available_editors",
"default_editor",
"ext_editor",
"enable_link_integrity_checks",
"lock_on_ttw_edit"
],
"id": "default",
"title": "Default"
}
],
"properties": {
"available_editors": {
"additionalItems": true,
"default": [
"TinyMCE",
"None"
],
"description": "Available editors in the portal.",
"items": {
"description": "",
"title": "",
"type": "string"
},
"title": "Available editors",
"type": "array",
"uniqueItems": false
},
"default_editor": {
"choices": [
[
"TinyMCE",
"TinyMCE"
],
[
"None",
"None"
]
],
"default": "TinyMCE",
"description": "Select the default wysiwyg editor. Users will be able to choose their own or select to use the site default.",
"enum": [
"TinyMCE",
"None"
],
"enumNames": [
"TinyMCE",
"None"
],
"title": "Default editor",
"type": "string"
},
"enable_link_integrity_checks": {
"default": true,
"description": "Determines if the users should get warnings when they delete or move content that is linked from inside the site.",
"title": "Enable link integrity checks",
"type": "boolean"
},
"ext_editor": {
"default": false,
"description": "Determines if the external editor feature is enabled. This feature requires a special client-side application installed. The users also have to enable this in their preferences.",
"title": "Enable External Editor feature",
"type": "boolean"
},
"lock_on_ttw_edit": {
"default": true,
"description": "Disabling locking here will only affect users editing content through the Plone web UI. Content edited via WebDAV clients will still be subject to locking.",
"title": "Enable locking for through-the-web edits",
"type": "boolean"
}
},
"required": [
"available_editors",
"default_editor"
],
"type": "object"
},
"title": "Editing"
}
8 changes: 8 additions & 0 deletions docs/source/_json/controlpanels_patch.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PATCH /plone/@controlpanels/editing HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

{
"default_editor": "CKeditor",
"ext_editor": True,
}
Empty file.
78 changes: 78 additions & 0 deletions docs/source/controlpanels.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Control Panels
==============

Control panels in Plone allow you to configure the global site setup of a
Plone site. The @controlpanels endpoint in plone.restapi allows you to list
all existing control panels in a Plone site and to retrieve or edit the
settings of a specific control panel.

Most of the settings in the Plone control panels are based on plone.registry (since Plone 5.x). Therefore you can also use the @registry endpoint to
retrieve or manipulate site settings. The @controlpanels endpoint just gives
developers are more a convenience way of accessing the settings and makes it
easier to render control panels on the front-end.


.. note:: This is currently only implemented for Plone 5.


Listing Control Panels
----------------------

A list of all existing control panels in the portal can be retrieved by
sending a GET request to the @controlpanels endpoint::

.. http:example:: curl httpie python-requests
:request: _json/controlpanels_get.req

Response::

.. literalinclude:: _json/controlpanels_get.resp
:language: http


The following fields are returned:

- @id: hypermedia link to the control panel
- title: the title of the control panel
- group: the group where the control panel should show up (e.g. General, Content, Users, Security, Advanced, Add-on Configuration)


Retrieve a single Control Panel
-------------------------------

To retrieve a single control panel, send a GET request to the URL of the
control panel::

.. http:example:: curl httpie python-requests
:request: _json/controlpanels_get_item.req

Response::

.. literalinclude:: _json/controlpanels_get_item.resp
:language: http


The following fields are returned:

- @id: hypermedia link to the control panel
- title: title of the control panel
- group: group name of the control panel
- schema: JSON Schema of the control panel
- data: current values of the control panel


Updating a Control Panel with PATCH
-----------------------------------

To update the settings on a control panel send a PATCH request to control panel
resource::

.. http:example:: curl httpie python-requests
:request: _json/controlpanels_patch.req

A successful response to a PATCH request will be indicated by a :term:`204 No Content` response::

HTTP/1.1 204 No Content

.. literalinclude:: _json/controlpanels_patch.resp
:language: http
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Contents
serialization
searching
vocabularies
controlpanels
customization
conventions

Expand Down
145 changes: 145 additions & 0 deletions src/plone/restapi/controlpanels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer, Interface, Attribute
from zope.component import adapter
from Products.CMFCore.utils import getToolByName

from Products.CMFPlone.interfaces.controlpanel import IDateAndTimeSchema
from Products.CMFPlone.interfaces.controlpanel import IEditingSchema
from Products.CMFPlone.interfaces.controlpanel import ILanguageSchema
from Products.CMFPlone.interfaces.controlpanel import IMailSchema
from Products.CMFPlone.interfaces.controlpanel import INavigationSchema
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
from Products.CMFPlone.interfaces.controlpanel import ISearchSchema
from Products.CMFPlone.interfaces.controlpanel import ISocialMediaSchema
from Products.CMFPlone.interfaces.controlpanel import IImagingSchema
from Products.CMFPlone.interfaces.controlpanel import IMarkupSchema
from Products.CMFPlone.interfaces.controlpanel import ISecuritySchema


class IControlpanel(Interface):
__name__ = Attribute('Name of the controlpanel in the URL')
title = Attribute('Title of this controlpanel')
group = Attribute('Group name of this controlpanel')
schema = Attribute('Registry schema of this controlpanel')

configlet_id = Attribute('Id the configlet, ie MailHost')
configlet_category_id = Attribute('Category of the configlet, ie plone-general') # noqa


@implementer(IControlpanel)
class RegistryConfigletPanel(object):
configlet = None
configlet_id = None
configlet_category_id = None
schema = None

schema_prefix = 'plone'

def _get_configlet(self):
configlet_data = self.portal_cp.enumConfiglets(
self.configlet_category_id
)
for action in configlet_data:
if action['id'] == self.configlet_id:
return action

def _get_group_title(self):
groups = [
g for g in self.portal_cp.getGroups()
if g['id'] == self.configlet['category']
]
return [g['title'] for g in groups][0]

def __init__(self, context, request):
self.context = context
self.request = request

self.portal_cp = getToolByName(self.context, 'portal_controlpanel')

self.configlet = self._get_configlet()
if self.configlet:
self.title = self.configlet['title']
self.group = self._get_group_title()


# General

@adapter(Interface, Interface)
class DateTimeControlpanel(RegistryConfigletPanel):
schema = IDateAndTimeSchema
configlet_id = 'DateAndTime'
configlet_category_id = 'plone-general'


@adapter(Interface, Interface)
class LanguageControlpanel(RegistryConfigletPanel):
schema = ILanguageSchema
configlet_id = 'LanguageSettings'
configlet_category_id = 'plone-general'


@adapter(Interface, Interface)
class MailControlpanel(RegistryConfigletPanel):
schema = IMailSchema
configlet_id = 'MailHost'
configlet_category_id = 'plone-general'


@adapter(Interface, Interface)
class NavigationControlpanel(RegistryConfigletPanel):
schema = INavigationSchema
configlet_id = 'NavigationSettings'
configlet_category_id = 'plone-general'


@adapter(Interface, Interface)
class SiteControlpanel(RegistryConfigletPanel):
schema = ISiteSchema
configlet_id = 'PloneReconfig'
configlet_category_id = 'plone-general'


@adapter(Interface, Interface)
class SearchControlpanel(RegistryConfigletPanel):
schema = ISearchSchema
configlet_id = 'SearchSettings'
configlet_category_id = 'plone-general'


@adapter(Interface, Interface)
class SocialMediaControlpanel(RegistryConfigletPanel):
schema = ISocialMediaSchema
configlet_id = 'socialmedia'
configlet_category_id = 'plone-general'


# Content

@adapter(Interface, Interface)
class EditingControlpanel(RegistryConfigletPanel):
schema = IEditingSchema
configlet_id = 'EditingSettings'
configlet_category_id = 'plone-content'


@adapter(Interface, Interface)
class ImagingControlpanel(RegistryConfigletPanel):
schema = IImagingSchema
configlet_id = 'ImagingSettings'
configlet_category_id = 'plone-content'


@adapter(Interface, Interface)
class MarkupControlpanel(RegistryConfigletPanel):
schema = IMarkupSchema
configlet_id = 'MarkupSettings'
configlet_category_id = 'plone-content'


# Security

@adapter(Interface, Interface)
class SecurityControlpanel(RegistryConfigletPanel):
schema = ISecuritySchema
configlet_id = 'SecuritySettings'
configlet_category_id = 'plone-security'
4 changes: 4 additions & 0 deletions src/plone/restapi/deserializer/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
<adapter factory=".atfields.FileFieldDeserializer" />
<adapter factory=".atfields.ReferenceFieldDeserializer" />
</configure>

<configure zcml:condition="have plone-5">
<adapter factory=".controlpanels.ControlpanelDeserializeFromJson" />
</configure>

</configure>

0 comments on commit 99ed744

Please sign in to comment.