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)
def update_space_settings(environ, name): """ Read a tiddler named by SPACE_SERVER_SETTINGS in the current space's public bag. Parse each line as a key:value pair which is then injected tiddlyweb.query. The goal here is to allow a space member to force incoming requests to use specific settings, such as alpha or externalized. """ store = environ['tiddlyweb.store'] space = Space(name) bag_name = space.public_bag() tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name) data_text = '' try: tiddler = store.get(tiddler) data_text = tiddler.text except StoreError: pass for line in data_text.split('\n'): try: key, value = line.split(':', 1) key = key.rstrip().lstrip() value = value.rstrip().lstrip() try: environ['tiddlyweb.query'][key].append(value) except KeyError: environ['tiddlyweb.query'][key] = [value] except ValueError: pass
def _validate_subscription(environ, name, recipe): """ Determine if this space can be subscribed to. We know that the space exists, what we want to determine here is if it has been blacklisted or already been subscribed. """ space = Space(name) if name in environ['tiddlyweb.config'].get('blacklisted_spaces', []): raise HTTP409('Subscription not allowed to space: %s' % name) elif [space.public_bag(), ''] in recipe: raise HTTP409('Space already subscribed: %s' % name) return space
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)
def update_space_settings(environ, name): """ Read a tiddler named by SPACE_SERVER_SETTINGS in the current space's public bag. Parse each line as a key:value pair which is then injected tiddlyweb.query. The goal here is to allow a space member to force incoming requests to use specific settings, such as alpha or externalized. """ store = environ['tiddlyweb.store'] space = Space(name) bag_name = space.public_bag() tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name) data_text = '' try: tiddler = store.get(tiddler) data_text = tiddler.text except StoreError: return _figure_default_index(environ, bag_name, space), False query_strings = [] index = '' lazy = False for line in data_text.split('\n'): try: key, value = line.split(':', 1) key = key.rstrip().lstrip() value = value.rstrip().lstrip() if key == 'index': index = value elif key == 'lazy': if value.lower() == 'true': lazy = True else: query_strings.append('%s=%s' % (key, value)) except ValueError: pass index = _figure_default_index(environ, bag_name, space, index) query_string = ';'.join(query_strings) filters, leftovers = parse_for_filters(query_string, environ) environ['tiddlyweb.filters'].extend(filters) query_data = parse_qs(leftovers, keep_blank_values=True) environ['tiddlyweb.query'].update(dict( [(key, [value for value in values]) for key, values in query_data.items()])) return index, lazy
def update_space_settings(environ, name): """ Read a tiddler named by SPACE_SERVER_SETTINGS in the current space's public bag. Parse each line as a key:value pair which is then injected tiddlyweb.query. The goal here is to allow a space member to force incoming requests to use specific settings, such as alpha or externalized. """ store = environ['tiddlyweb.store'] space = Space(name) bag_name = space.public_bag() tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name) data_text = '' try: tiddler = store.get(tiddler) data_text = tiddler.text except StoreError: return _figure_default_index(environ, bag_name, space), False query_strings = [] index = '' lazy = False for line in data_text.split('\n'): try: key, value = line.split(':', 1) key = key.rstrip().lstrip() value = value.rstrip().lstrip() if key == 'index': index = value elif key == 'lazy': if value.lower() == 'true': lazy = True else: query_strings.append('%s=%s' % (key, value)) except ValueError: pass index = _figure_default_index(environ, bag_name, space, index) query_string = ';'.join(query_strings) filters, leftovers = parse_for_filters(query_string, environ) environ['tiddlyweb.filters'].extend(filters) query_data = parse_qs(leftovers, keep_blank_values=True) environ['tiddlyweb.query'].update( dict([(key, [value for value in values]) for key, values in query_data.items()])) return index, lazy
def _do_unsubscriptions(space_name, unsubscriptions, public_recipe_list, private_recipe_list, store): """ Remove unsubscriptions from the space represented by public_recipe_list and private_recipe_list. """ for space in unsubscriptions: if space == space_name: raise HTTP409('Attempt to unsubscribe self') try: unsubscribed_space = Space(space) bag = unsubscribed_space.public_bag() public_recipe_list.remove([bag, ""]) private_recipe_list.remove([bag, ""]) except ValueError, exc: raise HTTP409('Invalid content for unsubscription: %s' % exc)
def update_space_settings(environ, name): """ Read a tiddler named by SPACE_SERVER_SETTINGS in the current space's public bag. Parse each line as a key:value pair which is then injected tiddlyweb.query. The goal here is to allow a space member to force incoming requests to use specific settings, such as beta or externalized. """ store = environ['tiddlyweb.store'] # double assign to avoid later updates to the defaults environ['tiddlyweb.space_settings'] = {} environ['tiddlyweb.space_settings'].update(DEFAULT_SERVER_SETTINGS) try: space = Space(name) except ValueError: return bag_name = space.public_bag() tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name) data_text = '' try: tiddler = store.get(tiddler) data_text = tiddler.text except StoreError: data_text = '' query_strings = [] for line in data_text.split('\n'): try: key, value = line.split(':', 1) key = key.strip() value = value.strip() if key in SERVER_SETTINGS_KEYS: environ['tiddlyweb.space_settings'][key] = value else: query_strings.append('%s=%s' % (key, value)) except ValueError: pass # XXX: Disable the default new user app switcher temporarily # TODO: Turn this back on when the app switcher is more complete #_figure_default_index(environ, bag_name, space) environ['tiddlyweb.space_settings']['extra_query'] = ';'.join( query_strings)
def update_space_settings(environ, name): """ Read a tiddler named by SPACE_SERVER_SETTINGS in the current space's public bag. Parse each line as a key:value pair which is then injected tiddlyweb.query. The goal here is to allow a space member to force incoming requests to use specific settings, such as alpha or externalized. """ store = environ['tiddlyweb.store'] # double assign to avoid later updates to the defaults environ['tiddlyweb.space_settings'] = {} environ['tiddlyweb.space_settings'].update(DEFAULT_SERVER_SETTINGS) try: space = Space(name) except ValueError: return bag_name = space.public_bag() tiddler = Tiddler(SPACE_SERVER_SETTINGS, bag_name) data_text = '' try: tiddler = store.get(tiddler) data_text = tiddler.text except StoreError: data_text = '' query_strings = [] for line in data_text.split('\n'): try: key, value = line.split(':', 1) key = key.strip() value = value.strip() if key in SERVER_SETTINGS_KEYS: environ['tiddlyweb.space_settings'][key] = value else: query_strings.append('%s=%s' % (key, value)) except ValueError: pass # XXX: Disable the default new user app switcher temporarily # TODO: Turn this back on when the app switcher is more complete #_figure_default_index(environ, bag_name, space) environ['tiddlyweb.space_settings'][ 'extra_query'] = ';'.join(query_strings)
store_structure['recipes']['frontpage_private']['policy']['read'] = ['R:ADMIN'] store_structure['recipes']['frontpage_private']['recipe'].append( ('frontpage_private', '')) 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': [
store_structure['recipes']['frontpage_private']['recipe'].append( ('frontpage_private', '')) 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': [
def test_public_bag(): space = Space('cat') assert space.public_bag() == 'cat_public'