Skip to content

Commit

Permalink
update to work with latest catalog changes at plone/plone.server#35
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Dec 10, 2016
1 parent 8b62e53 commit 49187a7
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 290 deletions.
53 changes: 21 additions & 32 deletions README.rst
@@ -1,36 +1,21 @@
.. contents::

PLONE.SERVER.GOOGLEOAUTH
========================

A call to plone.server using header :

AUTHORIZATION: bearer GOOGLE_TOKEN

authorizes the user to the one in google with that token

Features
--------

* There is no persistence information about the user

* The configuration is global for all application
PSERVER.ELASTICSEARCH
=====================


Configuration
-------------

Generic global configuration on plone.server utilities section:
config.json can include elasticsearch section::

{
"provides": "plone.server.googleoauth.oauth.IOAuth",
"factory": "plone.server.googleoauth.oauth.OAuth",
"settings": {
"oauth_json": "PATH_TO_JSON_CREDENTIALS_FROM_GOOGLE",
"credentials": "CREDENTIALS_STORAGE",
"client": "plone"
"elasticsearch": {
"index_name_prefix": "plone-",
"connection_settings": {
"endpoints": ["localhost:9200"],
"sniffer_timeout": 0.5
}
}
}


Installation on a site
Expand All @@ -40,23 +25,27 @@ POST SITE_URL/@install

{
'pluggins': [
'plone.server.googleoauth'
'pserver.elasticsearch'
]
}


POST SITE_URL/@catalog

{}

Uninstall on a site
-------------------

DELETE SITE_URL/@catalog

{}


POST SITE_URL/@uninstall

{
'pluggins': [
'plone.server.googleoauth'
'pserver.elasticsearch'
]
}


Events
------

plone.server.auth.events.NewUserLogin
23 changes: 14 additions & 9 deletions config.json
@@ -1,11 +1,16 @@
{
"factory": "pserver.elasticsearch.utility.ElasticSearchUtility",
"provides": "pserver.elasticsearch.utility.IElasticSearchUtility",
"settings": {
"connection_settings": {
"endpoints": ["localhost:9200"],
"sniffer_timeout": 0.5
},
"bulk_size": 50
"applications": ["elasticsearch"],
"elasticsearch": {
"bulk_size": 50,
"index_name_prefix": "plone-",
"connection_settings": {
"endpoints": ["localhost:9200"],
"sniffer_timeout": 0.5
},
"index": {},
"mapping_overrides": {
"*": {
}
}
}
}
}
26 changes: 26 additions & 0 deletions pserver/elasticsearch/__init__.py
@@ -1 +1,27 @@
# -*- coding: utf-8 -*-

app_settings = {
"elasticsearch": {
"bulk_size": 50,
"index_name_prefix": "plone-",
"connection_settings": {
"endpoints": [],
"sniffer_timeout": 0.5
},
"index": {},
"mapping_overrides": {
"*": {}
}
}
}


utility_config = {
"provides": "plone.server.interfaces.ICatalogUtility",
"factory": "pserver.elasticsearch.utility.ElasticSearchUtility",
"settings": {} # all settings are on the global object
}


def includeme(root):
root.add_async_utility(utility_config)
20 changes: 0 additions & 20 deletions pserver/elasticsearch/api.json

This file was deleted.

12 changes: 0 additions & 12 deletions pserver/elasticsearch/configure.zcml

This file was deleted.

23 changes: 0 additions & 23 deletions pserver/elasticsearch/install.py

This file was deleted.

12 changes: 0 additions & 12 deletions pserver/elasticsearch/interfaces.py

This file was deleted.

79 changes: 30 additions & 49 deletions pserver/elasticsearch/schema.py
@@ -1,69 +1,50 @@
from plone.server.interfaces import CATALOG_KEY
from plone.server.interfaces import INDEX_KEY
from plone.server.directives import mergedTaggedValueDict
from zope.component import getUtilitiesFor
from plone.server.catalog.utils import get_index_fields
from plone.server.content import IResourceFactory
from plone.server.content import iterSchemataForType
from zope.schema import getFields
from zope.component import getUtilitiesFor


CATALOG_TYPES = {
'text': {'type': 'text'},
'keyword': {'type': 'keyword'},
'searchabletext': {
'type': 'text',
'index': 'analyzed'
},
'text': {
'type': 'text',
'index': 'not_analyzed'
},
'keyword': {
'type': 'keyword',
'index': 'not_analyzed'
},
'int': {'type': 'integer'},
'date': {'type': 'date'},
'boolean': {'type': 'boolean'},
'binary': {'type': 'binary'},
'float': {'type': 'float'}
}

INDEX_TYPES = {
'analyzed': {'index': 'analyzed'},
'non_analyzed': {'index': 'not_analyzed'}
'float': {'type': 'float'},
'path': {
"type": "text",
"analyzer": "path_analyzer"
}
}


def get_mappings():
from plone.server import app_settings
mapping_overrides = app_settings.get('elasticsearch', {}).get('mapping_overrides', {})
# Mapping calculated from schemas
global_mappings = {}
base_type_overrides = mapping_overrides.get('*', {})
for name, schema in getUtilitiesFor(IResourceFactory):
# For each type
mappings = {}
for schema in iterSchemataForType(name):
# create mapping for content type
catalog = mergedTaggedValueDict(schema, CATALOG_KEY)
index = mergedTaggedValueDict(schema, INDEX_KEY)
for field_name, field in getFields(schema).items():
kind_index = index.get(field_name, False)
kind_catalog = catalog.get(field_name, False)
field_mapping = {}
if kind_catalog:
if kind_catalog == 'object':
# Especial case that is an object
# TODO
pass
field_mapping.update(CATALOG_TYPES[kind_catalog])
if kind_index:
field_mapping.update(INDEX_TYPES[kind_index])

field_name = schema.getName() + '-' + field_name
mappings[field_name] = field_mapping
mappings['accessRoles'] = {
'type': 'keyword',
'index': 'not_analyzed'
}
mappings['accessUsers'] = {
'type': 'keyword',
'index': 'not_analyzed'
}
mappings['path'] = {
'type': 'text',
'analyzer': 'path_analyzer'
}
mappings['uuid'] = {
'type': 'keyword',
'index': 'not_analyzed'
}
type_overrides = base_type_overrides.copy()
type_overrides.update(mapping_overrides.get(name, {}))
for field_name, catalog_info in get_index_fields(name).items():
catalog_type = catalog_info.get('type', 'text')
field_mapping = CATALOG_TYPES[catalog_type]
if field_name in type_overrides:
field_mapping = type_overrides[field_name]
mappings[field_name] = field_mapping
global_mappings[name] = {
'properties': mappings
}
Expand Down

0 comments on commit 49187a7

Please sign in to comment.