Beispiel #1
0
    def breadcrumbs(self):
        cxt = self.context
        cxts = list(reversed(list(lineage(cxt))))
        r = self.request
        if not r.view_name:
            if self.is_current_context_object:
                cmd_name = 'detail'
            else:
                cmd_name = 'list'
            cxts = cxts[:-1]
        else:
            cmd_name = r.view_name

        if cmd_name in self.backend_mgr.actions:
            ca = self.backend_mgr.actions[cmd_name]
            if self.is_current_context_object:
                _label = ca['_label'] if '_label' in ca else ('%s@' + cmd_name)
                _label = _label % cxt.object
            else:
                _label = ca['_label'] if '_label' in ca else \
                    (self.backend_mgr.display_name + '@' + cmd_name)
        else:
            _label = '@' + cmd_name

        return [{
            'url': r.resource_url(c),
            'label': u'%s' % c,
        } for c in cxts] + [_label, ]
Beispiel #2
0
def copy_community_to_box(community):
    log.info("Connecting to Box.")
    box = BoxClient(find_box(community), get_current_registry().settings)

    def realize_archive(archive, folder, path=''):
        contents = box.contents(folder)
        for name, item in archive.items():
            subpath = path + '/' + name
            if isinstance(item, ArchiveFolder):
                if name in contents:
                    log.info("Exists folder %s", subpath)
                    subfolder = contents[name]
                    assert subfolder.type == 'folder', subpath
                else:
                    log.info("Creating folder %s", subpath)
                    subfolder = folder.create_subfolder(name)
                realize_archive(item, subfolder, subpath)
            else:
                name = slugify(name)
                subpath = "%s (%s)" % (subpath, name)
                if name in contents:
                    log.info("Exists file %s", subpath)
                    assert contents[name].type == 'file', subpath
                else:
                    log.info("Uploading file %s", subpath)
                    folder.upload_stream(item.open(), name)

    path = reversed([o.__name__ for o in lineage(community) if o.__name__])
    folder = box.get_or_make('Karl Archive', *path)

    realize_archive(archive(community), folder)
    community.archive_status = 'reviewing'
    if getattr(community, 'archive_copied', None) is not None:
        del community.archive_copied
    log.info("Finished copying to box: %s", resource_path(community))
    def breadcrumbs(self):
        cxt = self.context
        cxts = list(reversed(list(lineage(cxt))))
        r = self.request
        if not r.view_name:
            if self.is_current_context_object:
                cmd_name = 'detail'
            else:
                cmd_name = 'list'
            # cxts = cxts[:-1]
        else:
            cmd_name = r.view_name

        _label = '@' + cmd_name
        for aconf in self.admin_mgr.actions:
            if cmd_name == aconf.name:
                if self.is_current_context_object:
                    _label = aconf.get_label(cxt.object)
                else:
                    _label = aconf.get_label()
                break

        return [{
            'url': r.resource_url(c),
            'label': u'%s' % c,
        } for c in cxts] + [_label, ]
Beispiel #4
0
def copy_community_to_box(community):
    log.info("Connecting to Box.")
    box = BoxClient(find_box(community), get_current_registry().settings)

    def realize_archive(archive, folder, path):
        for name, item in archive.items():
            subpath = path + (name, )
            log.info("Copying %s", '/' + '/'.join(subpath))
            if isinstance(item, ArchiveFolder):
                if name in folder:
                    subfolder = folder[name]
                else:
                    subfolder = folder.mkdir(name)
                realize_archive(item, subfolder, subpath)
            else:
                folder.upload(name, item.open())

    path = reversed([o.__name__ for o in lineage(community) if o.__name__])
    folder = box.root().get_or_make('Karl Archive', *path)
    if folder:
        raise ValueError(
            'Cannot archive community, folder already exists: %s' %
            ('/' + '/'.join(path)))

    realize_archive(archive(community), folder, tuple(path))
    community.archive_status = 'reviewing'
    log.info("Finished copying to box: %s", resource_path(community))
Beispiel #5
0
    def breadcrumbs(self):
        cxt = self.context
        cxts = list(reversed(list(lineage(cxt))))
        r = self.request
        if not r.view_name:
            if self.is_current_context_object:
                cmd_name = 'detail'
            else:
                cmd_name = 'list'
            # cxts = cxts[:-1]
        else:
            cmd_name = r.view_name

        _label = '@' + cmd_name
        for aconf in self.admin_mgr.actions:
            if cmd_name == aconf.name:
                if self.is_current_context_object:
                    _label = aconf.get_label(cxt.object)
                else:
                    _label = aconf.get_label()
                break

        return [{
            'url': r.resource_url(c),
            'label': u'%s' % c,
        } for c in cxts] + [
            _label,
        ]
def _validate_post_pool(node, resources: list, post_pool: IPool):
    for resource in resources:
        if post_pool in lineage(resource):
            continue
        post_pool_path = resource_path(post_pool)
        msg = "You can only add references inside {}".format(post_pool_path)
        raise colander.Invalid(node, msg)
Beispiel #7
0
def copy_community_to_box(community):
    log.info("Connecting to Box.")
    box = BoxClient(find_box(community), get_current_registry().settings)

    def realize_archive(archive, folder, path, copied):
        for name, item in archive.items():
            subpath = path + (name,)
	    copied.append(subpath)
            log.info("Copying (%d) %s", len(copied), '/' + '/'.join(subpath))
            if isinstance(item, ArchiveFolder):
                if name in folder:
                    subfolder = folder[name]
                else:
                    subfolder = folder.mkdir(name)
                realize_archive(item, subfolder, subpath, copied)
            else:
                folder.upload(name, item.open())

    path = reversed([o.__name__ for o in lineage(community) if o.__name__])
    folder = box.root().get_or_make('Karl Archive', *path)
    if folder:
        raise ValueError(
            'Cannot archive community, folder already exists: %s' % (
                '/' + '/'.join(path)))

    copied = []
    realize_archive(archive(community), folder, tuple(path), copied)
    community.archive_status = 'reviewing'
    log.info("Finished copying to box: %s", resource_path(community))
Beispiel #8
0
def _validate_post_pool(node, resources: list, post_pool: IPool):
    for resource in resources:
        if post_pool in lineage(resource):
            continue
        post_pool_path = resource_path(post_pool)
        msg = 'You can only add references inside {}'.format(post_pool_path)
        raise colander.Invalid(node, msg)
Beispiel #9
0
def get_acl_lineage(resource) -> []:
    """Return :term:`ACL` of the `resource` inclusive inherited acl."""
    acl_all = []
    parent = getattr(resource, '__parent__', None)
    for location in lineage(parent):
        acl = _get_acl(location, default=[])
        for ace in acl:
            acl_all.append(ace)
    return acl_all
Beispiel #10
0
def deferred_groups_default(node: SchemaNode, kw: dict) -> []:
    """Return badge groups."""
    from adhocracy_core.resources.badge import IBadgeGroup  # no circle imports
    context = kw['context']
    parents = [x for x in lineage(context)][1:]
    groups = []
    for parent in parents:
        if IBadgeGroup.providedBy(parent):
            groups.append(parent)
        else:
            break
    return groups
Beispiel #11
0
def deferred_groups_default(node: SchemaNode, kw: dict) -> []:
    """Return badge groups."""
    from adhocracy_core.resources.badge import IBadgeGroup  # no circle imports
    context = kw['context']
    parents = [x for x in lineage(context)][1:]
    groups = []
    for parent in parents:
        if IBadgeGroup.providedBy(parent):
            groups.append(parent)
        else:
            break
    return groups
Beispiel #12
0
def get_local_roles_all(resource) -> dict:
    """Return the :term:`local roles <local role>` of the resource and its parents.

    The `creator` role is ignored.
    """
    local_roles_all = defaultdict(set)
    for location in lineage(resource):
        local_roles = get_local_roles(location)
        for principal, roles in local_roles.items():
            roles_without_creator = filter(lambda x: x != CREATOR_ROLEID,
                                           roles)
            local_roles_all[principal].update(roles_without_creator)
    return local_roles_all
Beispiel #13
0
def get_local_roles_all(resource) -> dict:
    """Return the :term:`local role`s of the resource and its parents.

    The `creator`role is not inherited by children.
    """
    local_roles_all = defaultdict(set)
    local_roles_all.update(get_local_roles(resource))
    for location in lineage(resource.__parent__):
        local_roles = get_local_roles(location)
        for principal, roles in local_roles.items():
            roles_without_creator = filter(lambda x: x != CREATOR_ROLEID,
                                           roles)
            local_roles_all[principal].update(roles_without_creator)
    return local_roles_all
def get_local_roles_all(resource) -> dict:
    """Return the :term:`local role`s of the resource and its parents.

    The `creator`role is not inherited by children.
    """
    local_roles_all = defaultdict(set)
    local_roles_all.update(get_local_roles(resource))
    for location in lineage(resource.__parent__):
        local_roles = get_local_roles(location)
        for principal, roles in local_roles.items():
            roles_without_creator = filter(lambda x: x != CREATOR_ROLEID,
                                           roles)
            local_roles_all[principal].update(roles_without_creator)
    return local_roles_all
Beispiel #15
0
def find_tenant(resource):
    """
    Finds the tenant node in the resource tree to which ``resource``
    belongs. The tenant node is the immediate child of root.

    :returns: ``resource``, if ``resource`` is the tenant node, None if
        ``resource`` is root, else the tenant node.
    """
    lin = list(lineage(resource))
    if len(lin) == 1:
        # resource is root, so we cannot find a tenant
        return None
    else:
        # Root is last element (lin[-1]), tenant is 2nd last.
        return lin[-2]
Beispiel #16
0
 def breadcrumbs(self):
     return reversed(list(lineage(self.context)))
Beispiel #17
0
 def breadcrumbs(self):
     items = []
     for obj in lineage(self.context):
         if self.request.has_permission(security.PERM_VIEW, obj):
             items.append(obj)
     return reversed(items)