def group_id(self):
     if IDoc.providedBy(self.context):
         if hasattr(self.context, "group_id") and self.context.group is not None:
             return IDCDescriptiveProperties(self.context.group).short_title
         elif hasattr(self.context, "chamber_id"):
             return IDCDescriptiveProperties(self.context.chamber).short_tile
     return translate("n/a", context=get_request())
예제 #2
0
def propagate_parent_assigned_group_role(child_doc):
    """Propagate the role of the group that is assigned to the parent doc of 
    this child doc.
    """
    from bungeni.models.interfaces import IDoc
    assert IDoc.providedBy(child_doc), "Not a Doc: %s" % (child_doc)

    def get_parent_doc_assigned_group(child_doc):
        parent_group_assignments = child_doc.head.sa_group_assignments
        for group_assignment in parent_group_assignments:
            # !+QUALIFIED_FEATURES(mr, apr-2013) may need to "qualify" each assignment!
            # !+MULTI_ASSIGNMENTS_MULTI_MEMBERSHIPS(mr, apr-2013) for now we just
            # take the first assigned group we find, but this is obvioulsy
            # incorrect! Need to determine: in case doc has been assigned to
            # more than one group, within which is the current user acting
            # (keeping in mind, also that the current user may be member of more
            # than one group that the doc is assigned to!).
            #!+GROUP_ASSIGNMENT.GROUP assert isinstance(group, domain.Group), group
            return group_assignment.principal

    pag = parent_assigned_group = get_parent_doc_assigned_group(child_doc)
    assert pag is not None, child_doc
    # !+ is this constraint correct?
    assert child_doc.group is pag, \
        "!+GROUP child doc [%s] group [%s] must be the assigned group [%s] for parent doc [%s]" % (
            child_doc, child_doc.group, pag, child_doc.head)
    utils.set_role(pag.group_role, pag.principal_name, child_doc)
예제 #3
0
 def group_id(self):
     if IDoc.providedBy(self.context):
         if hasattr(self.context, "group_id") and self.context.group is not None:
             return IDCDescriptiveProperties(self.context.group).short_title
         elif hasattr(self.context, "chamber_id"):
             return IDCDescriptiveProperties(self.context.chamber).short_tile
     return translate("n/a", context=get_request())
예제 #4
0
def assign_role_group(doc):
    """Assign the role of the doc's group, to the group itself, onto doc.
    """
    # !+PrincipalRoleMapContextData infer role from context data
    from bungeni.models.interfaces import IDoc
    assert IDoc.providedBy(doc), "Not a Doc: %s" % (doc)
    if doc.group is not None:
        utils.assign_role(doc.group.group_role, doc.group.principal_name, doc)
예제 #5
0
 def expand_containers(self, items, containers, _url, chain=(), context=None):
     #seen_context = False
     _url = _url.rstrip("/")
     current = False
     
     for key, container in containers:
         assert IAlchemistContainer.providedBy(container)
         
         # do not include doc containers for docs who do not specifically 
         # declare the parent group instance as a workspace.group_name
         if IDoc.implementedBy(container.domain_model):
             group = get_group_for_context(container)
             assert IGroup.providedBy(group)
             doc_type_key = naming.polymorphic_identity(container.domain_model)
             if not group.is_type_workspaced(doc_type_key):
                 continue
         
         label = container.domain_model.__name__
         descriptor = utils.get_descriptor(container.domain_model)
         order = 999
         if descriptor:
             order = descriptor.order
             label = getattr(descriptor, "container_name", None) or \
                 getattr(descriptor, "display_name", None)
         
         if context is not None:
             current = container.__name__ == context.__name__
         selected = not len(chain) and current
         if current:
             #seen_context = True
             nodes = self.expand(chain)
         else:
             nodes = ()
         
         key_url = "%s/%s" % (_url, key)
         items.append({
                 "id": self.get_nav_entry_id(key_url),
                 "order": order,
                 "label": translate(label, 
                     target_language=get_default_language(),
                     domain="bungeni"),
                 "url": key_url,
                 "current": current,
                 "selected": selected,
                 "kind": "container",
                 "nodes": nodes,
             })
     items.sort(key=lambda item:(item['order'], item['label']))
예제 #6
0
def propagate_parent_assigned_group_role(child_doc):
    """Propagate the role of the group that is assigned to the parent doc of 
    this child doc.
    """
    from bungeni.models.interfaces import IDoc
    assert IDoc.providedBy(child_doc), "Not a Doc: %s" % (child_doc)
    assert child_doc.group is None, "!+GROUP_ID must be unset! %s" % (child_doc)
    def get_parent_doc_assigned_group(child_doc):
        parent_group_assignments = child_doc.head.group_assignment
        for ag in parent_group_assignments:
            # !+QUALIFIED_FEATURES(mr, apr-2013) may need to "qualify" each assignment!
            # !+MULTI_ASSIGNMENTS_MULTI_MEMBERSHIPS(mr, apr-2013) for now we just
            # take the first assigned group we find, but this is obvioulsy 
            # incorrect! Need to determine: in case doc has been assigned to 
            # more than one group, within which is the current user acting
            # (keeping in mind, also that the current user may be member of more
            # than one group that the doc is assigned to!).
            return ag.group
    pag = parent_assigned_group = get_parent_doc_assigned_group(child_doc)
    assert pag is not None, child_doc
    utils.assign_role(pag.group_role, pag.principal_name, child_doc)
예제 #7
0
 def _query(self, **kw):
     session = Session()
     user = utils.get_login_user()
     reverse = True if (kw.get("sort_dir", "desc") == "desc") else False
     results = []
     domain_status = self.item_status_filter(kw)
     for domain_class, status in domain_status.iteritems():
         if IDoc.implementedBy(domain_class):
             query = session.query(domain_class
                 ).filter(domain_class.status.in_(status)
                 ).enable_eagerloads(False
                 ).join(domain.UserSubscription
                 ).filter(domain.UserSubscription.principal_id == user.user_id)
             query = self.filter_group(query, domain_class, kw)
             query = self.filter_title(query, domain_class, kw)
             #filter on status_date
             query = self.filter_status_date(query, domain_class, kw)
             query = self.order_query(query, domain_class, kw, reverse)
             results.extend(query.all())
     count = len(results)
     if (kw.get("sort_on", None) and kw.get("sort_dir", None)):
         results.sort(key=lambda x: getattr(x, str(kw.get("sort_on"))),
                      reverse=reverse)
     return (results, count)
예제 #8
0
 def _query(self, **kw):
     session = Session()
     user = utils.get_login_user()
     reverse = True if (kw.get("sort_dir", "desc") == "desc") else False
     results = []
     domain_status = self.item_status_filter(kw)
     for domain_class, status in domain_status.iteritems():
         if IDoc.implementedBy(domain_class):
             query = session.query(domain_class).filter(
                 domain_class.status.in_(status)
             ).enable_eagerloads(False).join(
                 domain.UserSubscription).filter(
                     domain.UserSubscription.principal_id == user.user_id)
             query = self.filter_group(query, domain_class, kw)
             query = self.filter_title(query, domain_class, kw)
             #filter on status_date
             query = self.filter_status_date(query, domain_class, kw)
             query = self.order_query(query, domain_class, kw, reverse)
             results.extend(query.all())
     count = len(results)
     if (kw.get("sort_on", None) and kw.get("sort_dir", None)):
         results.sort(key=lambda x: getattr(x, str(kw.get("sort_on"))),
                      reverse=reverse)
     return (results, count)