Skip to content

Commit

Permalink
allowRolesToAddKeywords -> roles_allowed_to_add_keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Sep 19, 2015
1 parent ad5939a commit a6d0a2e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 41 deletions.
18 changes: 8 additions & 10 deletions Products/Archetypes/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

from plone.app.widgets import base as base_widgets
from plone.app.widgets import utils
from plone.registry.interfaces import IRegistry
from plone.uuid.interfaces import IUUID

from zope.component import getUtility

import json

_marker = []
Expand Down Expand Up @@ -1215,18 +1218,13 @@ def _base_args(self, context, field, request):
membership = getToolByName(context, 'portal_membership')
user = membership.getAuthenticatedMember()

try:
site_properties = getToolByName(
context, 'portal_properties')['site_properties']
allowRolesToAddKeywords = site_properties.getProperty(
'allowRolesToAddKeywords', None)
except AttributeError:
allowRolesToAddKeywords = False
registry = getUtility(IRegistry)
roles_allowed_to_add_keywords = registry.get(
'plone.roles_allowed_to_add_keywords', [])

allowNewItems = False
if allowRolesToAddKeywords and [
role for role in user.getRolesInContext(context)
if role in allowRolesToAddKeywords]:
if [role for role in user.getRolesInContext(context)
if role in roles_allowed_to_add_keywords]:
allowNewItems = True

args.setdefault('pattern_options', {})
Expand Down
6 changes: 3 additions & 3 deletions Products/Archetypes/skins/archetypes/widgets/keyword.pt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<metal:use use-macro="field_macro | context/widgets/field/macros/edit">
<tal:define metal:fill-slot="widget_body" define="contentKeywords accessor;
allowedKeywords python: context.collectKeywords(fieldName, field.accessor, widget.vocab_source);
site_props context/portal_properties/site_properties|nothing;
format widget/format | string:select;
allowRolesToAddKeywords site_props/allowRolesToAddKeywords|nothing;">
registry context/portal_registry;
roles_allowed_to_add_keywords python:registry['plone.roles_allowed_to_add_keywords'];">

<div tal:attributes="id string:$fieldName-tags;"
class="tagsContainer">
Expand Down Expand Up @@ -120,7 +120,7 @@
<div class="visualClear"><!-- --></div>
</div>

<tal:condition condition="python:not widget.roleBasedAdd or (allowRolesToAddKeywords and [role for role in user.getRolesInContext(context) if role in allowRolesToAddKeywords])">
<tal:condition condition="python:not widget.roleBasedAdd or (roles_allowed_to_add_keywords and [role for role in user.getRolesInContext(context) if role in roles_allowed_to_add_keywords])">
<dl class="newTagsSection">
<label for="subject_keywords">
<dt class="newTagsTitle">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<body>
<h1>Keyword multiple select enhancement test - refs PLIP ticket #11017.</h1>

<p>The PLIP adds an accessible, jQuery-based widget,
<p>The PLIP adds an accessible, jQuery-based widget,
which includes both a scrollbar and checkboxes.</p>

<p>This file is basically a copy of ../keyword.pt, with QUnit added, and
slight modifications to make it run in a static, standalone way,
<p>This file is basically a copy of ../keyword.pt, with QUnit added, and
slight modifications to make it run in a static, standalone way,
looking somewhat realistic, although Plone's css messes up QUnit's a little.</p>

<p>---</p>
Expand All @@ -36,9 +36,9 @@ <h2 id="qunit-userAgent"></h2>

<p>---</p>
<h2>Manual Test</h2>

<!-- Keyword Widgets -->

<metal:view_macro define-macro="view"
tal:define="kssClassesView context/@@kss_field_decorator_view;
getKssClasses nocall:kssClassesView/getKssClassesInlineEditable;">
Expand All @@ -53,15 +53,15 @@ <h2>Manual Test</h2>
</ul>
</div>
</metal:view_macro>

<metal:define define-macro="edit">
<metal:use use-macro="field_macro | context/widgets/field/macros/edit">
<tal:define metal:fill-slot="widget_body" define="contentKeywords accessor;
allowedKeywords python: context.collectKeywords(fieldName, field.accessor, widget.vocab_source);
site_props context/portal_properties/site_properties|nothing;
format widget/format | string:select;
allowRolesToAddKeywords site_props/allowRolesToAddKeywords|nothing;">

registry context/portal_registry;
roles_allowed_to_add_keywords python:registry['plone.roles_allowed_to_add_keywords'];">

<div tal:condition="allowedKeywords" id="existingTagsSection">
<tal:comment tal:replace="nothing">
dl semantically associates selector name with values
Expand All @@ -70,20 +70,20 @@ <h2>Manual Test</h2>
<label for="subject">
<dt id="existingTagsTitle">
<span i18n:translate="label_existing_tags">
Select from existing tags.
Select from existing tags.
</span>
</dt>
<span id="existingTagsHelp" class="formHelp" i18n:translate="label_existingTagsHelp">
Use Control/Command/Shift keys to select multiple tags.
<tal:comment tal:replace="nothing">
Type-to-skip functionality with javascipt enabled
currently is described as
"Hover and type the first letter to skip through tags."
However, on touch-driven devices, vertical hover typically
scrolls the page, so horizontal hover is necessary to enable this.
Alternatively, clicking any of the tags also enables type-to-skip.
So the text could technically be extended to handle this special case
as "Hover or click and type the first letter to skip through tags.",
Type-to-skip functionality with javascipt enabled
currently is described as
"Hover and type the first letter to skip through tags."
However, on touch-driven devices, vertical hover typically
scrolls the page, so horizontal hover is necessary to enable this.
Alternatively, clicking any of the tags also enables type-to-skip.
So the text could technically be extended to handle this special case
as "Hover or click and type the first letter to skip through tags.",
but I think this would be confusing to the majority of users.
</tal:comment>
</span>
Expand Down Expand Up @@ -122,9 +122,9 @@ <h2>Manual Test</h2>
<span id="oneOrMoreTagsSelected" i18n:translate="label_oneOrMoreTagsSelected">% tags currently selected.</span>
<tal:comment tal:replace="nothing">
Call js to modify this widget with both a scrollbar and checkboxes.
There may be a better place to put this js call;
There may be a better place to put this js call;
examples exist in others' widget.py and js files,
but having it here covers cases where some but not all select elements
but having it here covers cases where some but not all select elements
call js to be modified.
Todo: The #subject should eventually refer to the template variable.
</tal:comment>
Expand All @@ -145,7 +145,7 @@ <h2>Manual Test</h2>
id string:${fieldName}_${repeat/keyword/number};
checked python:test(context.unicodeTestIn(keyword, value), 'checked', None);
value keyword" />
<label
<label
tal:content="keyword"
tal:attributes="for string:${fieldName}_${repeat/keyword/number}">
An existing tag
Expand All @@ -159,13 +159,13 @@ <h2>Manual Test</h2>
</dl>
<div class="visualClear"><!-- --></div>
</div>
<tal:condition condition="python:not widget.roleBasedAdd or (allowRolesToAddKeywords and [role for role in user.getRolesInContext(context) if role in allowRolesToAddKeywords])">

<tal:condition condition="python:not widget.roleBasedAdd or (roles_allowed_to_add_keywords and [role for role in user.getRolesInContext(context) if role in roles_allowed_to_add_keywords])">
<dl id="newTagsSection">
<label for="subject_keywords">
<dt id="newTagsTitle">
<span i18n:translate="label_new_tags">
Create and apply new tags.
Create and apply new tags.
</span>
</dt>
<span id="newTagsHelp" i18n:translate="label_newTagsHelp" class="formHelp">
Expand All @@ -174,7 +174,7 @@ <h2>Manual Test</h2>
</label>
<br />
<dd id="newTags">
<textarea
<textarea
id="entered_subjects"
name="subject:lines"
rows="4"
Expand All @@ -186,16 +186,16 @@ <h2>Manual Test</h2>
</dd>
</dl>
</tal:condition>

</tal:define>
</metal:use>
</metal:define>

<div metal:define-macro="search">
<div metal:use-macro="context/widgets/keyword/macros/edit">
</div>
</div>

</body>

</html>
Expand Down

0 comments on commit a6d0a2e

Please sign in to comment.