-
Notifications
You must be signed in to change notification settings - Fork 8
/
cached_views.py
54 lines (43 loc) · 1.72 KB
/
cached_views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
""" Cached views used when model was pulled from elasticsearch.
"""
from itertools import chain
from pyramid.httpexceptions import HTTPForbidden
from pyramid.view import view_config
from .interfaces import ICachedItem
def includeme(config):
config.scan(__name__)
@view_config(context=ICachedItem, request_method='GET', name='embedded')
def cached_view_embedded(context, request):
source = context.model.source
allowed = set(source['principals_allowed']['view'])
if allowed.isdisjoint(request.effective_principals):
raise HTTPForbidden()
return source['embedded']
@view_config(context=ICachedItem, request_method='GET', name='object')
def cached_view_object(context, request):
source = context.model.source
allowed = set(source['principals_allowed']['view'])
if allowed.isdisjoint(request.effective_principals):
raise HTTPForbidden()
return source['object']
@view_config(context=ICachedItem, request_method='GET', name='audit')
def cached_view_audit(context, request):
source = context.model.source
allowed = set(source['principals_allowed']['audit'])
if allowed.isdisjoint(request.effective_principals):
raise HTTPForbidden()
return {
'@id': source['object']['@id'],
'audit': source['audit'],
}
@view_config(context=ICachedItem, request_method='GET', name='audit-self')
def cached_view_audit_self(context, request):
source = context.model.source
allowed = set(source['principals_allowed']['audit'])
if allowed.isdisjoint(request.effective_principals):
raise HTTPForbidden()
path = source['object']['@id']
return {
'@id': path,
'audit': [a for a in chain(*source['audit'].values()) if a['path'] == path],
}