def remove_drafts(e): from cocktail.persistence import datastore from woost.models import (Item, Permission, ContentPermission, MemberPermission, Trigger, ContentTrigger) from woost.models.utils import remove_broken_type remove_broken_type("woost.models.permission.ConfirmDraftPermission", existing_bases=(Item, Permission, ContentPermission)) remove_broken_type("woost.models.permission.ConfirmDraftPermission", existing_bases=(Item, Trigger, ContentTrigger)) for item in Item.select(): for key in "_is_draft", "_draft_source", "_drafts": try: delattr(item, key) except AttributeError: pass datastore.root.pop("woost.models.item.Item.is_draft", None) datastore.root.pop("woost.models.item.Item.draft_source", None) for permission in MemberPermission.select(): for key in ("drafts", "draft_source", "is_draft"): key = "woost.models.item.Item." + key if key in permission.matching_members: permission.matching_members.remove(key)
def test_permission_expression(self): from woost.models import (Item, Publishable, User, ReadPermission, PermissionExpression) self.everybody_role.permissions.append( ReadPermission(matching_items={ "type": "woost.models.publishable.Publishable" }, authorized=True)) i1 = Item() i2 = Item() d1 = Publishable() d2 = Publishable() i1.insert() i2.insert() d1.insert() d2.insert() results = set( Item.select( filters=[PermissionExpression(User(), ReadPermission)])) assert results == set([d1, d2])
def assign_global_identifiers(e): from woost import app from woost.models import Item from woost.models.synchronization import rebuild_manifest for item in Item.select(): item._global_id = app.installation_id + "-" + str(item.id) Item.global_id.rebuild_index() Item.synchronizable.rebuild_index() rebuild_manifest(True)
def remove_owner_field(e): from cocktail.persistence import datastore from woost.models import Item, ContentPermission, MemberPermission # Remove the owner value of every item for item in Item.select(): try: del item._owner except AttributeError: pass # Drop the index for the member full_member_name = "woost.models.item.Item.owner" datastore.root.pop(full_member_name, None) # Purge all references to the owner member from member permissions for permission in MemberPermission.select(): if permission.matching_members: member_count = len(permission.matching_members) try: permission.matching_members.remove(full_member_name) except (KeyError, ValueError): pass else: if member_count == 1: permission.delete() # Purge the 'owned-items' expression from all permissions for permission in ContentPermission.select(): matching_items = permission.matching_items if matching_items: try: filter = permission.matching_items["filter"] except KeyError: pass else: if filter == "owned-items" or (hasattr(filter, "__contains__") and "owned-items" in filter): permission.delete()
def test_add_filters_from_selector(self): from cocktail.schema.expressions import Self from cocktail.persistence import Query results = Item.select( [Item.id.greater(15), Self.search("@localhost", languages=["en"])]) results_count = len(results) browser.open("/en/cms/content/?content_view=flat&search_expanded=true" "&page_size=%d" % (results_count + 1)) admin_login() # Add filters for i, filter_id in enumerate(("member-id", "global_search")): browser.fire_event("css=.new_filter_selector", "click") browser.fire_event("css=.new_filter-%s" % filter_id, "click") assert browser.jquery_count(".filters .filter_list .filter_entry") == 2 # Set values on filters browser.type("filter_operator0", "gt") browser.type("filter_value0", "15") browser.type("filter_value1", "@localhost") browser.click("css=.filters .search_button") browser.wait_for_page_to_load(10000) # Test the returned content rows_count = browser.jquery_count(".collection_display .item_row") assert rows_count == results_count # Supplied values must be preserved between page loads assert browser.get_selected_value("filter_operator0") == "gt" assert browser.get_value("filter_value0") == "15" assert browser.get_value("filter_value1") == "@localhost"
def add_multisite_support(e): from cocktail.persistence import datastore from woost.models import Configuration, Website, Item root = datastore.root # Remove all back-references from the Site and Language models for item in Item.select(): for key in dir(item): if (key == "_site" or key.startswith("_Site_") or key.startswith("_Language_")): delattr(item, key) # Remove the instance of Site from the database site_id = list(Item.qname.index.values(key="woost.main_site"))[0] site = Item.index[site_id] site_state = site.__Broken_state__.copy() site_state["translations"] = dict( (lang, translation.__Broken_state__.copy()) for lang, translation in site_state.pop("_translations").iteritems()) Item.index.remove(site_id) Item.keys.remove(site_id) # Create the configuration object config = Configuration() config.qname = "woost.configuration" config.insert() # Create a website website = Website() website.insert() website.hosts = ["localhost"] config.websites.append(website) # Languages published_languages = [] for lang_id in root["woost.models.language.Language-keys"]: language = Item.index[lang_id] Item.index.remove(lang_id) Item.keys.remove(lang_id) language_state = language.__Broken_state__ config.languages.append(language_state["_iso_code"]) if language_state["_enabled"]: published_languages.append(language_state["_iso_code"]) if list(config.languages) != published_languages: config.published_languages = published_languages # Delete old indexes from the database for key in list(root): if (key.startswith("woost.models.site.Site") or key.startswith("woost.models.language.Language")): del root[key] # Settings that now belong in Configuration, as attributes config.secret_key = site_state.pop("secret_key") # Settings that now belong in Configuration, as regular fields for key in ("login_page", "generic_error_page", "not_found_error_page", "forbidden_error_page", "default_language", "backoffice_language", "heed_client_language", "timezone", "smtp_host", "smtp_user", "smtp_password"): config.set(key, site_state.pop("_" + key)) # Settings that now belong in Configuration, as collections for key in ("publication_schemes", "caching_policies", "renderers", "image_factories", "triggers"): config.set(key, list(site_state.pop("_" + key))) # Settings that now belong in Website, becoming translated fields for key in ("town", "region", "country"): value = site_state.pop("_" + key) for lang in config.languages: website.set(key, value, lang) # Settings that now belong in website, as translated fields for key in ("site_name", "organization_name", "keywords", "description"): for lang, translation_state in site_state["translations"].iteritems(): value = translation_state.pop("_" + key) website.set(key, value, lang) # Settings that now belong in website, as regular fields for key in ("logo", "icon", "home", "organization_url", "address", "postal_code", "phone_number", "fax_number", "email", "https_policy", "https_persistence"): website.set(key, site_state.pop("_" + key)) # Extension specific changes from woost.extensions.blocks import BlocksExtension if BlocksExtension.instance.enabled: config.common_blocks = list(site_state.pop("_common_blocks")) from woost.extensions.audio import AudioExtension if AudioExtension.instance.enabled: config.audio_encoders = list(site_state.pop("_audio_encoders")) config.audio_decoders = list(site_state.pop("_audio_decoders")) from woost.extensions.mailer import MailerExtension if MailerExtension.instance.enabled: from woost.extensions.mailer.mailing import Mailing for mailing in Mailing.select(): language = mailing._language if language: mailing._language = language.__Broken_state__["_iso_code"] from woost.extensions.googleanalytics import GoogleAnalyticsExtension if GoogleAnalyticsExtension.instance.enabled: account = GoogleAnalyticsExtension.instance._account del GoogleAnalyticsExtension.instance._account config.google_analytics_account = account # Rebuild all indexes Item.rebuild_indexes() # Preserve the remaining state datastore.root["woost.models.migration.multisite_leftovers"] = site_state