Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from brandicted/develop
Browse files Browse the repository at this point in the history
Develop -> master.. for readthedocs testing.
  • Loading branch information
chartpath committed Apr 5, 2015
2 parents d355278 + edfc752 commit efa7b54
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/source/acls.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Nefertari ACLs
===========
ACLs
====

.. automodule:: nefertari.acl
:members:
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Changelog
=========

* :release:`0.1.0 <2015-05-06>`
* :support:`0` Initial release after two years of development as "Presto". Now with database engines! Originally extracted and generalized from the Brandicted API which only used MongoDB.
9 changes: 7 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinxcontrib.fulltoc',
'releases'
]

releases_github_path = 'brandicted/nefertari'
releases_debug = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand All @@ -57,9 +62,9 @@
# built documents.
#
# The short X.Y version.
version = '1.0'
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '1.0'
release = '0.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
5 changes: 5 additions & 0 deletions docs/source/elasticsearch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Elasticsearch Support
=====================

Nefertari uses `Elasticsearch <https://www.elastic.co/products/elasticsearch>`_ behind the scenes for most read/GET views.

9 changes: 6 additions & 3 deletions docs/source/engines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ Engines API:


Common API
==========
----------

.. if this changes, it must be updated in docs for nefertari{-sqla|mongodb}
.. TODO: figure out how to include common elements in templates
**BaseMixin**
Mixin with a most of the API of *BaseDocument*. *BaseDocument* subclasses from this mixin.
Expand Down Expand Up @@ -52,8 +55,8 @@ Common API
**relationship_cls(field, model_cls)**
Return class which is pointed to by relationship field *field* from model *model_cls*.

Fields abstractions
===================
Field abstractions
-------------------

* BigIntegerField
* BooleanField
Expand Down
4 changes: 4 additions & 0 deletions docs/source/example_project.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Example Project
===============

For an example of how to use Nefertari see the `Example Project <https://github.com/brandicted/nefertari-example>`_.
10 changes: 5 additions & 5 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Getting started

To get started, follow these steps:

0. Install nefertari::
0. Install nefertari and either nefertari-sqla or nefertari-mongodb for the database backend you want to use::

pip install nefertari
pip install nefertari nefertari-sqla nefertari-mongodb


1. `First, create a normal Pyramid app <http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/firstapp.html#firstapp-chapter>`_. In the "main" module, import nefertari and then declare your resources like so::
Expand Down Expand Up @@ -65,8 +65,8 @@ And here is the content of our ``acl.py``. Check out ACLs that are included in N

.. code-block:: ini
# Set 'nefertari.engine' to the dotted path of the engine you want.
nefertari.engine = nefertari.engine.sqla
# Set 'nefertari.engine' to the engine you want (e.g. nefertari_sqla or nefertari_mongodb)
nefertari.engine = <engine>
# Elasticsearh settings
elasticsearch.hosts = localhost:9200
Expand All @@ -76,7 +76,7 @@ And here is the content of our ``acl.py``. Check out ACLs that are included in N
# Dependine on the engine you chose, provide database-specific settings.
# E.g. for sqla:
sqlalchemy.url = postgresql://user:password@host:port/dbname
sqlalchemy.url = postgresql://<host>:<port>/dbname
# For mongo:
mongodb.host = localhost
Expand Down
7 changes: 6 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Nefertari, queen of APIs
==================================
========================

Github: `<http://github.com/brandicted/nefertari>`_

She is a REST API framework for Pyramid that uses Elasticsearch and optionally other backends.

Expand All @@ -21,6 +23,9 @@ Contents
getting_started
engines
acls
elasticsearch
example_project
changelog


Indices and tables
Expand Down
40 changes: 14 additions & 26 deletions nefertari/acl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pyramid.security import (ALL_PERMISSIONS, Allow, Everyone, Deny)

from nefertari.json_httpexceptions import JHTTPNotFound
from pyramid.security import (
ALL_PERMISSIONS, Allow, Everyone, Deny,
Authenticated)


class BaseACL(object):
Expand Down Expand Up @@ -32,7 +32,8 @@ def __getitem__(self, key):
assert(self.__context_class__)

id_field = self.__context_class__.id_field()
obj = self.__context_class__.get(**{id_field: key})
obj = self.__context_class__.get(
__raise=True, **{id_field: key})
obj.__acl__ = self.context_acl(obj)
obj.__parent__ = self
obj.__name__ = key
Expand Down Expand Up @@ -72,32 +73,19 @@ def context_acl(self, context):
]


class AuthenticatedUserACLMixin(object):
""" User level ACL mixin. Mix it with your ACL class that sets
``self.user`` to a currently authenticated user.
class AuthenticatedReadACL(BaseACL):
""" Authenticated users' ACL.
Grants access:
* collection 'create' to everyone.
* item 'update', 'delete' to owner.
* item 'index', 'show' to everyone.
Gives read access to all Authenticated users.
Gives delete, create, update access to admin only.
"""

def __init__(self, request):
super(AuthenticatedUserACLMixin, self).__init__(request)
self.acl = (Allow, Everyone, 'create')
super(AuthenticatedReadACL, self).__init__(request)
self.acl = (Allow, Authenticated, ['index', 'show'])

def context_acl(self, context):
return [
(Allow, str(context.id), 'update'),
(Allow, Everyone, ['index', 'show']),
(Deny, str(context.id), 'delete'),
(Allow, 'g:admin', ALL_PERMISSIONS),
(Allow, Authenticated, ['index', 'show']),
]

def __getitem__(self, key):
if not self.user:
raise JHTTPNotFound

obj = self.user
obj.__acl__ = self.context_acl(obj)
obj.__parent__ = self
obj.__name__ = key
return obj
5 changes: 5 additions & 0 deletions nefertari/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ def value_error_view(context, request):
return JHTTPBadRequest("Bad or missing value '%s'" % context.message)


def error_view(context, request):
return JHTTPBadRequest(context.message)


def includeme(config):
config.add_view(key_error_view, context=KeyError)
config.add_view(value_error_view, context=ValueError)
config.add_view(error_view, context=Exception)
2 changes: 2 additions & 0 deletions requirements.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ pytest-cov==1.8.1
mock
webtest
Sphinx
sphinxcontrib-fulltoc
releases

-e .

0 comments on commit efa7b54

Please sign in to comment.