# HG changeset patch # User Paul Boddie # Date 1358707668 -3600 # Node ID d4b3a51c6d05bfab7c897b6d63a468977e39dfba # Parent c9ca36e232e084da02456a263326275f02f2ac2f Fixed the initialisation of ACLs and made the access keyword implement the same permission semantics as the page-level permissions. diff -r c9ca36e232e0 -r d4b3a51c6d05 MoinForms.py --- a/MoinForms.py Sun Jan 20 18:24:06 2013 +0100 +++ b/MoinForms.py Sun Jan 20 19:47:48 2013 +0100 @@ -10,8 +10,7 @@ from compiler.ast import Const, Dict, Discard, List, Module, Stmt from MoinMoin.action import do_show from MoinMoin.Page import Page -from MoinMoin.security import parseACL -from MoinMoin import wikiutil +from MoinMoin import security, wikiutil from MoinSupport import * import re @@ -107,17 +106,24 @@ user = self.request.user - # Use the page permissions if no access definition is given. + # Use the access definition if one is given. - if not self.attributes.has_key("access"): - return user and getattr(user.may, action)(self.pagename) + if self.attributes.has_key("access"): + access = self.attributes["access"] + acl = security.AccessControlList(self.request.cfg, [access]) + policy = lambda request, pagename, username, action: acl.may(request, username, action) - # Otherwise use the access definition. + # Otherwise, use the page permissions. else: - access = self.attributes["access"] - acl = parseACL(self.request, access) - return user and acl.may(self.request, user.name, action) + policy = security._check + + # The "read" action is only satisfied by the "admin" role. + + return user and ( + action != "read" and policy(self.request, self.pagename, user.name, action) or + action == "read" and policy(self.request, self.pagename, user.name, "admin") + ) def validateFields(self, fields, structure): @@ -317,6 +323,15 @@ return self.handler.checkPermissions("write") + def can_read(self): + + """ + Permit reading of form data using the form attributes or page + permissions. + """ + + return self.handler.checkPermissions("read") + # Form and field information. def getFormStructure(text, request, path=None, structure=None): diff -r c9ca36e232e0 -r d4b3a51c6d05 pages/HelpOnMoinForms --- a/pages/HelpOnMoinForms Sun Jan 20 18:24:06 2013 +0100 +++ b/pages/HelpOnMoinForms Sun Jan 20 19:47:48 2013 +0100 @@ -250,28 +250,24 @@ By default, the usage of forms and the storage of form data is restricted according to the permissions granted for a given user for the page on which each form appears. This is summarised in the following table: || '''Page Permission''' || '''Access to Form and Form Data''' || +|| `admin` || May read form data || || `delete` || May delete form data (since the entire page may also be deleted) || || `read` || ''Permission grants no additional access'' || || `write` || May submit forms and store form data || Thus, on any page for which a user only has read access, any form will by default be visible but not usable for submitting data. -However, it is possible to change these restrictions by specifying an `access` keyword which defines the permissions that an unprivileged user has when using the form. For example: +However, it is possible to override these restrictions by specifying an `access` keyword which defines a different set of permissions that applies to a user when using the form. For example: {{{{ -{{{#!form fragment=exampleform5 access=All:write +{{{#!form fragment=exampleform5 access='All:write' ... }}} }}}} -Here, unprivileged users - those who may not change the page and thus change the form definition - may submit the form and store their submissions. The following table summarises the different `access` options: +Here, unprivileged users - those who may have been forbidden from changing the page and thus changing the form definition - may submit the form and store their submissions. The above table also summarises the permissions that may be specified along with their effects. -|| '''Access Option''' || '''Access to Form and Form Data''' || -|| `delete` || May delete form data || -|| `read` || May read form data || -|| `write` || May submit forms and store form data || - -The `access` keyword supports conventional [[HelpOnAccessControlLists|ACL]] syntax. +The `access` keyword supports the conventional [[HelpOnAccessControlLists|ACL]] syntax, and where spaces are present in the specified value, quotes should be placed around the value itself and not the `access` keyword and equals sign as well. === Extending the Default Form Handler ===