Пример #1
0
def _make_space(environ, space_name):
    """
    The details of creating the bags and recipes that make up a space.
    """
    store = environ['tiddlyweb.store']
    member = environ['tiddlyweb.usersign']['name']

    # XXX stub out the clumsy way for now
    # can make this much more declarative

    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Пример #2
0
def _make_space(environ, space_name):
    """
    The details of creating the bags and recipes that make up a space.
    """
    store = environ['tiddlyweb.store']
    member = environ['tiddlyweb.usersign']['name']

    # XXX stub out the clumsy way for now
    # can make this much more declarative

    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Пример #3
0
def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    info_tiddler = Tiddler('SiteInfo', space.public_bag())
    info_tiddler.text = 'Space %s' % space_name
    store.put(info_tiddler)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Пример #4
0
def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = environ['wsgiorg.routing_args'][1]['space_name']
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except NoRecipeError:
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
Пример #5
0
def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = environ['wsgiorg.routing_args'][1]['space_name']
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except NoRecipeError:
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
Пример #6
0
def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = get_route_value(environ, 'space_name')
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except (NoRecipeError, ValueError):
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
Пример #7
0
def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = get_route_value(environ, 'space_name')
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except (NoRecipeError, ValueError):
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
Пример #8
0
def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Пример #9
0
def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    info_tiddler = Tiddler('SiteInfo', space.public_bag())
    info_tiddler.text = 'Space %s' % space_name
    info_tiddler.modifier = store.environ.get('tiddlyweb.usersign',
                                              {}).get('name', 'GUEST')
    store.put(info_tiddler)

    # Duplicate GettingStarted into public bag.
    getting_started_tiddler = Tiddler(GETTING_STARTED_TIDDLER['title'],
                                      GETTING_STARTED_TIDDLER['bag'])
    try:
        getting_started_tiddler = store.get(getting_started_tiddler)
        getting_started_tiddler.bag = space.public_bag()
        store.put(getting_started_tiddler)
    except StoreError:
        pass

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Пример #10
0
def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    info_tiddler = Tiddler('SiteInfo', space.public_bag())
    info_tiddler.text = 'Space %s' % space_name
    info_tiddler.modifier = store.environ.get('tiddlyweb.usersign',
            {}).get('name', 'GUEST')
    store.put(info_tiddler)

    # Duplicate GettingStarted into public bag.
    getting_started_tiddler = Tiddler(GETTING_STARTED_TIDDLER['title'],
            GETTING_STARTED_TIDDLER['bag'])
    try:
        getting_started_tiddler = store.get(getting_started_tiddler)
        getting_started_tiddler.bag = space.public_bag()
        store.put(getting_started_tiddler)
    except StoreError:
        pass

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Пример #11
0
    def _handle_core_request(self, environ, req_uri):
        """
        Override a core request, adding filters or sending 404s where
        necessary to limit the view of entities.

        filtering can be disabled with a custom HTTP header X-ControlView set
        to false
        """
        http_host, host_url = determine_host(environ)

        request_method = environ['REQUEST_METHOD']

        disable_ControlView = environ.get('HTTP_X_CONTROLVIEW') == 'false'
        if http_host != host_url and not disable_ControlView:
            space_name = determine_space(environ, http_host)
            if space_name == None:
                return
            recipe_name = determine_space_recipe(environ, space_name)
            store = environ['tiddlyweb.store']
            try:
                recipe = store.get(Recipe(recipe_name))
            except NoRecipeError, exc:
                raise HTTP404('No recipe for space: %s', exc)

            space = Space(space_name)

            template = recipe_template(environ)
            bags = space.extra_bags()
            for bag, _ in recipe.get_recipe(template):
                bags.append(bag)
            bags.extend(ADMIN_BAGS)

            filter_string = None
            if req_uri.startswith('/recipes') and req_uri.count('/') == 1:
                filter_string = 'oom=name:'
                if recipe_name == space.private_recipe():
                    filter_parts = space.list_recipes()
                else:
                    filter_parts = [space.public_recipe()]
                filter_string += ','.join(filter_parts)
            elif req_uri.startswith('/bags') and req_uri.count('/') == 1:
                filter_string = 'oom=name:'
                filter_parts = bags
                filter_string += ','.join(filter_parts)
            elif req_uri.startswith('/search') and req_uri.count('/') == 1:
                filter_string = 'oom=bag:'
                filter_parts = bags
                filter_string += ','.join(filter_parts)
            else:
                entity_name = req_uri.split('/')[2]
                if '/recipes/' in req_uri:
                    valid_recipes = space.list_recipes()
                    if entity_name not in valid_recipes:
                        raise HTTP404('recipe %s not found' % entity_name)
                else:
                    if entity_name not in bags:
                        raise HTTP404('bag %s not found' % entity_name)

            if filter_string:
                filters, _ = parse_for_filters(filter_string)
                for single_filter in filters:
                    environ['tiddlyweb.filters'].insert(0, single_filter)
Пример #12
0
frontpage_policy = store_structure['bags']['frontpage_public']['policy']
spaces = {
    'system-theme': 'TiddlySpace default theme',
    'system-info': 'TiddlySpace default information tiddlers',
    'system-plugins': 'TiddlySpace system plugins',
    'system-images': 'TiddlySpace default images and icons',
}

#  setup system space public bags and recipes
for space_name, description in spaces.items():
    space = Space(space_name)
    public_bag_name = space.public_bag()
    private_bag_name = space.private_bag()
    public_recipe_name = space.public_recipe()
    private_recipe_name = space.private_recipe()

    store_structure['bags'][public_bag_name] = {
        'desc': description,
        'policy': frontpage_policy,
    }
    store_structure['bags'][private_bag_name] = deepcopy(
        store_structure['bags'][public_bag_name])
    store_structure['bags'][private_bag_name]['policy']['read'] = ['R:ADMIN']

    store_structure['recipes'][public_recipe_name] = {
        'desc': description,
        'recipe': [
            ('system', ''),
            ('tiddlyspace', ''),
            (public_bag_name, ''),
Пример #13
0
frontpage_policy = store_structure['bags']['frontpage_public']['policy']
spaces = {
    'system-theme': 'TiddlySpace default theme',
    'system-info': 'TiddlySpace default information tiddlers',
    'system-plugins': 'TiddlySpace system plugins',
    'system-images': 'TiddlySpace default images and icons',
    'system-applications': 'TiddlySpace default applications'
}

#  setup system space public bags and recipes
for space_name, description in spaces.items():
    space = Space(space_name)
    public_bag_name = space.public_bag()
    private_bag_name = space.private_bag()
    public_recipe_name = space.public_recipe()
    private_recipe_name = space.private_recipe()

    store_structure['bags'][public_bag_name] = {
        'desc': description,
        'policy': frontpage_policy,
    }
    store_structure['bags'][private_bag_name] = deepcopy(
        store_structure['bags'][public_bag_name])
    store_structure['bags'][private_bag_name]['policy']['read'] = ['R:ADMIN']

    store_structure['recipes'][public_recipe_name] = {
        'desc': description,
        'recipe': [
            ('system', ''),
            ('tiddlyspace', ''),
            (public_bag_name, ''),
Пример #14
0
def test_private_recipe():
    space = Space('cat')
    assert space.private_recipe() == 'cat_private'
Пример #15
0
    def _handle_core_request(self, environ, req_uri, start_response):
        """
        Override a core request, adding filters or sending 404s where
        necessary to limit the view of entities.

        filtering can be disabled with a custom HTTP header X-ControlView set
        to false
        """
        http_host, host_url = determine_host(environ)

        disable_ControlView = environ.get('HTTP_X_CONTROLVIEW') == 'false'
        if http_host != host_url and not disable_ControlView:
            space_name = determine_space(environ, http_host)
            if space_name == None:
                return None
            recipe_name = determine_space_recipe(environ, space_name)
            store = environ['tiddlyweb.store']
            try:
                recipe = store.get(Recipe(recipe_name))
            except NoRecipeError, exc:
                raise HTTP404('No recipe for space: %s', exc)

            space = Space(space_name)

            template = recipe_template(environ)
            bags = space.extra_bags()
            for bag, _ in recipe.get_recipe(template):
                bags.append(bag)
            bags.extend(ADMIN_BAGS)

            search_string = None
            if req_uri.startswith('/recipes') and req_uri.count('/') == 1:
                serialize_type, mime_type = get_serialize_type(environ)
                serializer = Serializer(serialize_type, environ)

                if recipe_name == space.private_recipe():
                    recipes = space.list_recipes()
                else:
                    recipes = [space.public_recipe()]

                def lister():
                    for recipe in recipes:
                        yield Recipe(recipe)

                return list_entities(environ, start_response, mime_type,
                    lister, serializer.list_recipes)

            elif req_uri.startswith('/bags') and req_uri.count('/') == 1:
                serialize_type, mime_type = get_serialize_type(environ)
                serializer = Serializer(serialize_type, environ)

                def lister():
                    for bag in bags:
                        yield Bag(bag)

                return list_entities(environ, start_response, mime_type,
                        lister, serializer.list_bags)

            elif req_uri.startswith('/search') and req_uri.count('/') == 1:
                search_string = ' OR '.join(['bag:%s' % bag
                    for bag in bags])
            else:
                entity_name = urllib.unquote(
                        req_uri.split('/')[2]).decode('utf-8')
                if '/recipes/' in req_uri:
                    valid_recipes = space.list_recipes()
                    if entity_name not in valid_recipes:
                        raise HTTP404('recipe %s not found due to ControlView'
                                % entity_name)
                else:
                    if entity_name not in bags:
                        raise HTTP404('bag %s not found due to ControlView'
                                % entity_name)

            if search_string:
                search_query = environ['tiddlyweb.query'].get('q', [''])[0]
                environ['tiddlyweb.query.original'] = search_query
                if search_query:
                    search_query = '%s AND (%s)' % (search_query,
                            search_string)
                    environ['tiddlyweb.query']['q'][0] = search_query
                else:
                    search_query = '(%s)' % search_string
                    environ['tiddlyweb.query']['q'] = [search_query]
Пример #16
0
    def _handle_core_request(self, environ, req_uri, start_response):
        """
        Override a core request, adding filters or sending 404s where
        necessary to limit the view of entities.

        filtering can be disabled with a custom HTTP header X-ControlView set
        to false
        """
        http_host, host_url = determine_host(environ)

        disable_ControlView = environ.get('HTTP_X_CONTROLVIEW') == 'false'
        if http_host != host_url and not disable_ControlView:
            space_name = determine_space(environ, http_host)
            if space_name == None:
                return None
            recipe_name = determine_space_recipe(environ, space_name)
            store = environ['tiddlyweb.store']
            try:
                recipe = store.get(Recipe(recipe_name))
            except NoRecipeError, exc:
                raise HTTP404('No recipe for space: %s', exc)

            space = Space(space_name)

            template = recipe_template(environ)
            bags = space.extra_bags()
            for bag, _ in recipe.get_recipe(template):
                bags.append(bag)
            bags.extend(ADMIN_BAGS)

            search_string = None
            if req_uri.startswith('/recipes') and req_uri.count('/') == 1:
                serialize_type, mime_type = get_serialize_type(environ)
                serializer = Serializer(serialize_type, environ)

                if recipe_name == space.private_recipe():
                    recipes = space.list_recipes()
                else:
                    recipes = [space.public_recipe()]

                def lister():
                    for recipe in recipes:
                        yield Recipe(recipe)

                return list_entities(environ, start_response, mime_type,
                                     lister, serializer.list_recipes)

            elif req_uri.startswith('/bags') and req_uri.count('/') == 1:
                serialize_type, mime_type = get_serialize_type(environ)
                serializer = Serializer(serialize_type, environ)

                def lister():
                    for bag in bags:
                        yield Bag(bag)

                return list_entities(environ, start_response, mime_type,
                                     lister, serializer.list_bags)

            elif req_uri.startswith('/search') and req_uri.count('/') == 1:
                search_string = ' OR '.join(['bag:%s' % bag for bag in bags])
            else:
                entity_name = urllib.unquote(
                    req_uri.split('/')[2]).decode('utf-8')
                if '/recipes/' in req_uri:
                    valid_recipes = space.list_recipes()
                    if entity_name not in valid_recipes:
                        raise HTTP404(
                            'recipe %s not found due to ControlView' %
                            entity_name)
                else:
                    if entity_name not in bags:
                        raise HTTP404('bag %s not found due to ControlView' %
                                      entity_name)

            if search_string:
                search_query = environ['tiddlyweb.query'].get('q', [''])[0]
                environ['tiddlyweb.query.original'] = search_query
                if search_query:
                    search_query = '%s AND (%s)' % (search_query,
                                                    search_string)
                    environ['tiddlyweb.query']['q'][0] = search_query
                else:
                    search_query = '(%s)' % search_string
                    environ['tiddlyweb.query']['q'] = [search_query]
Пример #17
0
def test_private_recipe():
    space = Space('cat')
    assert space.private_recipe() == 'cat_private'
Пример #18
0
    def _handle_core_request(self, environ, req_uri):
        """
        Override a core request, adding filters or sending 404s where
        necessary to limit the view of entities.

        filtering can be disabled with a custom HTTP header X-ControlView set
        to false
        """
        http_host, host_url = determine_host(environ)

        request_method = environ['REQUEST_METHOD']

        disable_ControlView = environ.get('HTTP_X_CONTROLVIEW') == 'false'
        if http_host != host_url and not disable_ControlView:
            space_name = determine_space(environ, http_host)
            if space_name == None:
                return
            recipe_name = determine_space_recipe(environ, space_name)
            store = environ['tiddlyweb.store']
            try:
                recipe = store.get(Recipe(recipe_name))
            except NoRecipeError, exc:
                raise HTTP404('No recipe for space: %s', exc)

            space = Space(space_name)

            template = recipe_template(environ)
            bags = space.extra_bags()
            for bag, _ in recipe.get_recipe(template):
                bags.append(bag)
            bags.extend(ADMIN_BAGS)

            filter_string = None
            if req_uri.startswith('/recipes') and req_uri.count('/') == 1:
                filter_string = 'oom=name:'
                if recipe_name == space.private_recipe():
                    filter_parts = space.list_recipes()
                else:
                    filter_parts = [space.public_recipe()]
                filter_string += ','.join(filter_parts)
            elif req_uri.startswith('/bags') and req_uri.count('/') == 1:
                filter_string = 'oom=name:'
                filter_parts = bags
                filter_string += ','.join(filter_parts)
            elif req_uri.startswith('/search') and req_uri.count('/') == 1:
                filter_string = 'oom=bag:'
                filter_parts = bags
                filter_string += ','.join(filter_parts)
            else:
                entity_name = req_uri.split('/')[2]
                if '/recipes/' in req_uri:
                    valid_recipes = space.list_recipes()
                    if entity_name not in valid_recipes:
                        raise HTTP404('recipe %s not found' % entity_name)
                else:
                    if entity_name not in bags:
                        raise HTTP404('bag %s not found' % entity_name)

            if filter_string:
                filters, _ = parse_for_filters(filter_string)
                for single_filter in filters:
                    environ['tiddlyweb.filters'].insert(0, single_filter)