Exemple #1
0
    def test_Properties(self):
        # ``Properties`` object can be used for any kind of mapping.
        props = Properties()

        props['foo'] = 'foo'
        self.assertEqual(props['foo'], 'foo')
        self.assertEqual(props.get('bar', default='default'), 'default')

        props.bar = 'bar'
        self.assertEqual(props.bar, 'bar')
        self.assertTrue('bar' in props)
        self.assertEqual(sorted(props.keys()), ['bar', 'foo'])

        self.assertEqual(o_getattr(props, '_data'), {'foo': 'foo', 'bar': 'bar'})

        props_copy = copy.copy(props)
        self.assertFalse(props_copy is props)
        self.assertEqual(props_copy.__class__, Properties)
        self.assertEqual(
            o_getattr(props_copy, '_data'),
            o_getattr(props, '_data')
        )

        props_deepcopy = copy.deepcopy(props)
        self.assertFalse(props_deepcopy is props)
        self.assertEqual(props_deepcopy.__class__, Properties)
        self.assertEqual(
            o_getattr(props_deepcopy, '_data'),
            o_getattr(props, '_data')
        )
Exemple #2
0
    def test_ActionContext(self):
        model = BaseNode()
        request = self.layer.new_request()

        ac = ActionContext(model, request, 'tile')
        self.assertTrue(request.environ['action_context'] is ac)
        self.assertTrue(get_action_context(request) is ac)

        self.assertEqual(ac.scope, 'tile')

        request.params['bdajax.action'] = 'ajaxaction'
        self.assertEqual(ac.scope, 'ajaxaction')

        request.params['bdajax.action'] = 'layout'
        self.assertEqual(ac.scope, 'content')

        request.params['contenttile'] = 'contenttile'
        self.assertEqual(ac.scope, 'contenttile')

        class PropNode(BaseNode):
            properties = None

        node = PropNode()
        node.properties = Properties()
        node.properties.default_child = 'a'
        node['a'] = PropNode()
        node['a'].properties = Properties()
        node['a'].properties.default_content_tile = 'default'

        request = self.layer.new_request()
        ac = ActionContext(node, request, 'content')
        self.assertEqual(ac.scope, 'default')
Exemple #3
0
 def js(self):
     js = Properties()
     js.public = ['public.js', 'https://remote.foo/public.js']
     js.protected = [
         'protected.js', 'https://remote.foo/protected.js'
     ]
     return js
Exemple #4
0
 def css(self):
     css = Properties()
     css.public = ['public.css', 'https://remote.foo/public.css']
     css.protected = [
         'protected.css', 'https://remote.foo/protected.css'
     ]
     return css
Exemple #5
0
 def properties(self):
     props = Properties()
     props.in_navtree = True
     props.action_list = True
     props.action_add = True
     props.action_edit = True
     return props
Exemple #6
0
 def properties(self):
     props = Properties()
     props.in_navtree = True
     props.wf_state = True
     props.wf_name = u'dummy'
     # XXX: check in repoze.workflow the intended way for naming
     #      transitions
     props.wf_transition_names = {
         'initial_2_final': 'Finalize',
     }
     return props
Exemple #7
0
    def test_Properties(self):
        # ``Properties`` object can be used for any kind of mapping.
        props = Properties()

        props['foo'] = 'foo'
        self.assertEqual(props['foo'], 'foo')
        self.assertEqual(props.get('bar', default='default'), 'default')

        props.bar = 'bar'
        self.assertEqual(props.bar, 'bar')
        self.assertTrue('bar' in props)
        self.assertEqual(sorted(props.keys()), ['bar', 'foo'])
Exemple #8
0
    def test_Properties(self):
        # ``Properties`` object can be used for any kind of mapping.
        props = Properties()

        props['foo'] = 'foo'
        self.assertEqual(props['foo'], 'foo')
        self.assertEqual(props.get('bar', default='default'), 'default')

        props.bar = 'bar'
        self.assertEqual(props.bar, 'bar')
        self.assertTrue('bar' in props)
        self.assertEqual(sorted(props.keys()), ['bar', 'foo'])
Exemple #9
0
 def make_item(self, info_name, info):
     model = self.model
     request = self.request
     props = Properties()
     query = make_query(factory=info_name)
     url = make_url(request, node=model, resource='add', query=query)
     props.url = url
     target = make_url(request, node=model, query=query)
     props.target = target
     props.title = info.title
     icon = info.icon
     if not icon:
         icon = app_config().default_node_icon
     props.icon = icon
     return props
Exemple #10
0
 def items(self):
     ret = list()
     addables = self.model.nodeinfo.addables
     if not addables:
         return ret
     for addable in addables:
         info = getNodeInfo(addable)
         if not info:
             continue
         query = make_query(factory=addable)
         url = make_url(self.request, node=self.model,
                        resource='add', query=query)
         target = make_url(self.request, node=self.model, query=query)
         props = Properties()
         props.url = url
         props.target = target
         props.title = info.title
         props.icon = info.icon
         ret.append(props)
     return ret
Exemple #11
0
 def properties(self):
     props = Properties()
     props.in_navtree = True
     props.action_list = True
     props.action_add = True
     props.action_edit = True
     return props
Exemple #12
0
 def properties(self):
     props = Properties()
     props.in_navtree = False
     props.editable = False
     props.mainmenu_empty_title = True
     props.default_child = 'users'
     return props
Exemple #13
0
    def test_MergedAssets(self):
        request = self.layer.new_request()
        assets = MergedAssets(request)

        assets.merged_js_assets = Properties()
        assets.merged_js_assets.public = [(static_resources, 'script1.js')]
        assets.merged_js_assets.protected = [(static_resources, 'script2.js')]

        assets.merged_css_assets = Properties()
        assets.merged_css_assets.public = [(static_resources, 'style1.css')]
        assets.merged_css_assets.protected = [(static_resources, 'style2.css')]

        assets.merged_print_css_assets = Properties()
        assets.merged_print_css_assets.public = [(static_resources,
                                                  'print1.css')]
        assets.merged_print_css_assets.protected = [(static_resources,
                                                     'print2.css')]

        expected = 'console.log("script1");\n\n'
        self.assertEqual(assets.merged_js, expected)
        expected = '.style1 { display: block; }\n\n'
        self.assertEqual(assets.merged_css, expected)
        expected = '.print1 { display: none; }\n\n'
        self.assertEqual(assets.merged_print_css, expected)

        with self.layer.authenticated('max'):
            res = assets.merged_js
        expected = 'console.log("script1");\n\nconsole.log("script2");\n\n'
        self.assertEqual(res, expected)

        with self.layer.authenticated('max'):
            res = assets.merged_css
        expected = '.style1 { display: block; }\n\n.style2 { display: block; }\n\n'
        self.assertEqual(res, expected)

        with self.layer.authenticated('max'):
            res = assets.merged_print_css
        expected = '.print1 { display: none; }\n\n.print2 { display: none; }\n\n'
        self.assertEqual(res, expected)
Exemple #14
0
 def transitions(self):
     self.do_transition()
     ret = list()
     try:
         workflow = self.workflow
         transitions = workflow.get_transitions(
             self.model, self.request, from_state=self.model.state)
     except (WorkflowError, AttributeError) as e:
         logger.error("transitions error: %s" % str(e))
         return ret
     workflow_tsf = self.model.workflow_tsf
     for transition in transitions:
         query = make_query(do_transition=transition['name'])
         target = make_url(self.request, node=self.model, query=query)
         props = Properties()
         props.target = target
         if workflow_tsf:
             props.title = workflow_tsf(transition['name'])
         else:
             props.title = transition['name']
         ret.append(props)
     return ret
Exemple #15
0
 def properties(self):
     props = Properties()
     props.in_navtree = True
     props.action_up = True
     props.action_up_tile = 'content'
     props.action_add = True
     props.default_content_tile = 'listing'
     return props
Exemple #16
0
 def make_item(self, info_name, info):
     model = self.model
     request = self.request
     props = Properties()
     query = make_query(factory=info_name)
     url = make_url(request, node=model, resource='add', query=query)
     props.url = url
     target = make_url(request, node=model, query=query)
     props.target = target
     props.title = info.title
     icon = info.icon
     if not icon:
         icon = app_config().default_node_icon
     props.icon = icon
     return props
Exemple #17
0
from pyramid.static import static_view
from yafowil.common import ascii_extractor
from cone.app.model import Properties


static_resources = static_view('static', use_subpath=True)


# user and group form field definitions for yafowil
# overwrite or extend in integration __init__
# XXX: future -> yafowil form field properties editor
# XXX: far future -> yafowil JS form editor
# XXX: user and group form schema definitions should then be resolved in order
#      yafowil browser based cfg -> default cfg -> general default
form_field_definitions = Properties()
form_field_definitions.user = dict()
form_field_definitions.group = dict()
_user = form_field_definitions.user
_group = form_field_definitions.group


_user['default'] = dict()
_user['default']['chain'] = 'field:label:error:text'
_user['default']['required'] = False
_user['default']['protected'] = False


_user['id'] = dict()
_user['id']['chain'] = 'field:*ascii:*exists:label:error:text'
_user['id']['props'] = dict()
_user['id']['props']['ascii'] = True
Exemple #18
0
from pyramid.security import (
    Everyone,
    Allow,
    Deny,
    ALL_PERMISSIONS,
)
from cone.app.model import Properties

admin_permissions = ['view', 'add', 'edit', 'delete', 'manage_membership']

UGM_DEFAULT_ACL = [
    (Allow, 'role:editor', ['view', 'manage_membership']),
    (Allow, 'role:admin', admin_permissions),
    (Allow, 'role:owner', admin_permissions),
    (Allow, 'role:manager', admin_permissions + ['manage']),
    (Allow, Everyone, ['login']),
    (Deny, Everyone, ALL_PERMISSIONS),
]

# user and group factory defaults
factory_defaults = Properties()
factory_defaults.user = dict()
factory_defaults.group = dict()
factory_defaults.role = dict()
Exemple #19
0
 def properties(self):
     props = Properties()
     props.editable = True
     return props
Exemple #20
0
 def properties(self):
     props = Properties()
     props.editable = True
     return props
Exemple #21
0
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.config import Configurator
from pyramid.static import static_view
from yafowil.resources import YafowilResources as YafowilResourcesBase
from zope.component import getGlobalSiteManager
import importlib
import logging
import pyramid_chameleon
import pyramid_zcml
import sys

logger = logging.getLogger('cone.app')

# configuration
cfg = Properties()

# used main template
cfg.main_template = 'cone.app.browser:templates/main.pt'

# default node icon
cfg.default_node_icon = 'glyphicon glyphicon-asterisk'

# XXX: move resource registration to browser package
# XXX: support developmenet and production mode

# JS resources
cfg.js = Properties()
cfg.js.public = [
    '++resource++bdajax/overlay.js', '++resource++bdajax/bdajax.js',
    '++resource++bdajax/bdajax_bs3.js', 'static/public.js'
Exemple #22
0
from node.ext.ldap import LDAPProps
from node.ext.ldap import testLDAPConnectivity
from node.ext.ldap.ugm import GroupsConfig
from node.ext.ldap.ugm import RolesConfig
from node.ext.ldap.ugm import UsersConfig
from node.ext.ldap.ugm._api import EXPIRATION_DAYS
from node.utils import instance_property
from odict import odict
from pyramid.i18n import TranslationStringFactory
import logging

logger = logging.getLogger('cone.ldap')
_ = TranslationStringFactory('cone.ldap')

# settings config
ldap_cfg = Properties()

# gets set by main hook
ldap_cfg.server_config = ''
ldap_cfg.users_config = ''
ldap_cfg.groups_config = ''
ldap_cfg.roles_config = ''

# user and group factory defaults
factory_defaults = Properties()
factory_defaults.user = dict()
factory_defaults.group = dict()
factory_defaults.role = dict()


class LDAPServerSettings(UGMSettings):
 def js(self):
     js = Properties()
     js.public = ['public.js', 'https://remote.foo/public.js']
     js.protected = ['protected.js', 'https://remote.foo/protected.js']
     return js
 def css(self):
     css = Properties()
     css.public = ['public.css', 'https://remote.foo/public.css']
     css.protected = ['protected.css', 'https://remote.foo/protected.css']
     return css
Exemple #25
0
 def properties(self):
     props = Properties()
     return props
Exemple #26
0
from cone.app.model import BaseNode
from cone.app.model import Metadata
from cone.app.model import Properties
from cone.app.model import XMLProperties
from cone.ugm.localmanager import LocalManagerConfigAttributes
from cone.ugm.utils import general_settings
from node.utils import instance_property
from pyramid.i18n import TranslationStringFactory
import os

_ = TranslationStringFactory('cone.ugm')

ugm_cfg = Properties()
ugm_cfg.ugm_settings = ''
ugm_cfg.lm_settings = ''

# XXX: move cone.ugm.model.factory_defaults here


class UGMSettings(BaseNode):
    config_file = None

    def __call__(self):
        self.attrs()

    @instance_property
    def attrs(self):
        config_file = self.config_file
        if not os.path.isfile(config_file):
            msg = 'Configuration file {} not exists.'.format(config_file)
            raise ValueError(msg)
Exemple #27
0
from pyramid.static import static_view
from yafowil.resources import YafowilResources as YafowilResourcesBase
from zope.component import adapter
from zope.component import getGlobalSiteManager
from zope.interface import Interface
from zope.interface import implementer
import logging
import model
import os
import pyramid_zcml


logger = logging.getLogger('cone.app')

# configuration
cfg = Properties()

# authentication provider (expect ``node.ext.ugm.Ugm`` API)
cfg.auth = None

# used main template
cfg.main_template = 'cone.app.browser:templates/main.pt'

# default node icon
cfg.default_node_icon = 'glyphicon glyphicon-asterisk'

# JS resources
cfg.js = Properties()
cfg.js.public = [
    '++resource++bdajax/overlay.js',
    '++resource++bdajax/bdajax.js',
Exemple #28
0
 def properties(self):
     props = Properties()
     props.icon = 'glyphicon glyphicon-info-sign'
     return props
Exemple #29
0
from pyramid.config import Configurator
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from zope.component import getGlobalSiteManager
from cone.app.model import (
    AppRoot,
    AppSettings,
    Properties,
)
from cone.app.browser import forbidden_view

# XXX: is this needed anywhere? If not, let's remove it.
APP_PATH = os.environ.get('APP_PATH', '')

# configuration
cfg = Properties()

# authentication providers (expect ``node.ext.ugm.Ugm`` like API)
cfg.auth = list()

# used main template
cfg.main_template = 'cone.app.browser:templates/main.pt'

# default node icon
cfg.default_node_icon = 'static/images/default_node_icon.png'

# JS resources
cfg.js = Properties()
cfg.js.public = [
    'static/cdn/jquery.min.js',
    'static/cdn/jquery.tools.min.js',
Exemple #30
0
 def properties(self):
     props = Properties()
     props.in_navtree = True
     return props
Exemple #31
0
 def properties(self):
     props = Properties()
     props.in_navtree = True
     return props
Exemple #32
0
 def properties(self):
     props = Properties()
     props.icon = 'glyphicon glyphicon-info-sign'
     props.mainmenu_display_children = True
     return props