Skip to content

Commit dc030c2

Browse files
author
Taverne Sylvain
committed
FormGenerator: Add ACL to forced authentification
1 parent 7864e4f commit dc030c2

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

forms_generator.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# Import from ikaaro
2626
from ikaaro.forms import AutoForm, SelectWidget, TextWidget, BooleanCheckBox
27-
from ikaaro.forms import RTEWidget, XHTMLBody, DateWidget
27+
from ikaaro.forms import RTEWidget, XHTMLBody, BooleanRadio
2828
from ikaaro.table import OrderedTable, OrderedTableFile
2929
from ikaaro.table_views import OrderedTable_View
3030

@@ -33,7 +33,6 @@
3333

3434
# Import from shop
3535
from cross_selling_views import AddProduct_View
36-
from datatypes import ProductPathDataType
3736
from products.models import get_real_datatype
3837
from products.enumerate import Datatypes
3938
from registry import shop_widgets
@@ -62,8 +61,7 @@ def get_widget(cls, widget_name):
6261

6362
class ShopForm_Display(AutoForm):
6463

65-
access = True
66-
64+
access = 'is_allowed_to_view_for_authenticated'
6765

6866
def get_submit_value(self):
6967
context = get_context()
@@ -72,7 +70,6 @@ def get_submit_value(self):
7270
submit_value = property(get_submit_value, None, None, '')
7371

7472

75-
7673
def get_title(self, context):
7774
return context.resource.get_title()
7875

@@ -177,7 +174,7 @@ class ShopForm(OrderedTable):
177174
class_views = ['display', 'edit', 'view', 'add_record']
178175

179176
display = ShopForm_Display()
180-
view = OrderedTable_View(search_template=None)
177+
view = OrderedTable_View(search_template=None, access='is_admin')
181178
edit = AutomaticEditView()
182179

183180
add_product = AddProduct_View()
@@ -191,15 +188,19 @@ class ShopForm(OrderedTable):
191188
SelectWidget('widget', title=MSG(u'Widget')),
192189
]
193190

194-
edit_widgets = [TextWidget('submit_value', title=MSG(u'Submit value')),
195-
TextWidget('to_addr', title=MSG(u'To addr')),
196-
RTEWidget('introduction', title=MSG(u'Introduction')),
197-
RTEWidget('final_message', title=MSG(u'Final message'))]
191+
edit_widgets = [
192+
TextWidget('submit_value', title=MSG(u'Submit value')),
193+
TextWidget('to_addr', title=MSG(u'To addr')),
194+
RTEWidget('introduction', title=MSG(u'Introduction')),
195+
RTEWidget('final_message', title=MSG(u'Final message')),
196+
BooleanRadio('must_be_authentificated',
197+
title=MSG(u'Must be authentificated to see form'))]
198198

199199
edit_schema = {'submit_value': Unicode(multilingual=True, mandatory=True),
200200
'to_addr': Email(mandatory=True),
201201
'introduction': XHTMLBody(multilingual=True),
202-
'final_message': XHTMLBody(multilingual=True)}
202+
'final_message': XHTMLBody(multilingual=True),
203+
'must_be_authentificated': Boolean}
203204

204205
@classmethod
205206
def get_metadata_schema(cls):

website.py

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ def search_on_website(self, queries):
143143
return self.parent.search(query)
144144

145145

146+
def is_allowed_to_view_for_authenticated(self, user, resource):
147+
if (resource.has_property('must_be_authentificated') and
148+
resource.get_property('must_be_authentificated')):
149+
return self.is_authenticated(user, resource)
150+
return self.is_allowed_to_view(user, resource)
151+
152+
146153
register_resource_class(ShopWebSite)
147154
register_document_type(ShopWebSite, WebSite.class_id)
148155

0 commit comments

Comments
 (0)