Beispiel #1
0
 def retract_is_allowed(context):
     """A workflow condition, for system use only, for auto "retract" transition.
     """
     if IFeatureAudit.providedBy(context):
         changes = domain.get_changes(context, "workflow")
         if changes:
             prev_change = changes[0].seq_previous
             if prev_change:
                 return from_state_id == prev_change.audit.status
     return True
 def retract_is_allowed(context):
     """A workflow condition, for system use only, for auto "retract" transition.
     """
     if IFeatureAudit.providedBy(context):
         changes = domain.get_changes(context, "workflow")
         if changes:
             prev_change = changes[0].seq_previous
             if prev_change:
                 return from_state_id == prev_change.audit.status
     return True
Beispiel #3
0
def allow_retract(context, **kw):
    transition = kw.get("transition", None)
    assert isinstance(transition, Transition)
    if interfaces.IFeatureAudit.providedBy(context):
        changes = domain.get_changes(context, "workflow")
        if changes:
            prev_change = changes[0].seq_previous
            if prev_change:
                allow = transition.destination == prev_change.audit.status
    else:
        allow = True
    return allow
Beispiel #4
0
def allow_retract(context, **kw):
    transition = kw.get("transition", None)
    assert isinstance(transition, Transition)
    if interfaces.IFeatureAudit.providedBy(context):
        changes = domain.get_changes(context, "workflow")
        if changes:
            prev_change = changes[0].seq_previous
            if prev_change:
                allow = transition.destination == prev_change.audit.status
    else:
        allow = True
    return allow
Beispiel #5
0
    def get_min_date_active(self):
        """Determine the min_date_active to validate against.
        """
        def is_workflowed_and_draft(instance):
            """is item workflowed, and if so is it in a logical draft state?
            """
            if interfaces.IWorkflowed.providedBy(instance):
                wf = interfaces.IWorkflow(instance)
                return instance.status in wf.get_state_ids(tagged=["draft"],
                                                           restrict=False)
            return False

        instance = removeSecurityProxy(self.context)
        min_date_active = None

        if IFeatureAudit.providedBy(self.context):
            # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data
            # for workflowed items via the UI -- note, ideally we should be
            # able to also control the item's creation active_date.
            #
            # If a workflowed item is in draft state, we do NOT take the
            # date_active of its last change as the min_date_active, but
            # let that min fallback to chamber's creation date...
            if not is_workflowed_and_draft(instance):
                changes = get_changes(instance, "workflow")
                if changes:
                    # then use the "date_active" of the most recent entry
                    min_date_active = changes[-1].date_active

        if not min_date_active:
            # ok, try determine a min_date_active in another way, namely via the
            # start_date of the instance itself (if it supports it) or of the
            # "chamber" the instance "lives" in... !+sitting, session, ...?
            if IGroup.providedBy(instance) or IGroupMember.providedBy(
                    instance):
                start_date = instance.start_date
            else:
                start_date = models.utils.get_chamber_for_context(
                    instance).start_date
            assert start_date is not None, \
                "Cannot determine min_date_active for worklfowed instance: %s" % (instance)
            min_date_active = datetime.datetime.combine(
                start_date, datetime.time())

        # As the precision of the UI-submitted datetime is only to the minute,
        # we adjust min_date_active by a margin of 59 secs earlier to avoid
        # issues of doing 2 transitions in quick succession (within same minute)
        # the 2nd of which could be taken to be too old...
        return min_date_active - datetime.timedelta(seconds=59)
def user_is_state_creator(context):
    """Did the current user create current state - based on workflow log?
    """
    is_state_creator = False
    if IAuditable.providedBy(context):
        current_user = model_utils.get_db_user()
        if current_user:
            for _object_change in reversed(
                    domain.get_changes(context.changes, "workflow")):
                extras = _object_change.extras
                if extras and (extras.get("destination") == context.status):
                    if _object_change.user.login == current_user.login:
                        is_state_creator = True
                break
    return is_state_creator
def user_is_state_creator(context):
    """Did the current user create current state - based on workflow log?
    """
    is_state_creator = False
    if IAuditable.providedBy(context):
        current_user = model_utils.get_db_user()
        if current_user:
            for _object_change in reversed(
                    domain.get_changes(context.changes, "workflow")
                ):
                extras = _object_change.extras
                if extras and (extras.get("destination") == context.status):
                    if _object_change.user.login == current_user.login:
                        is_state_creator = True
                break
    return is_state_creator
 def get_min_date_active(self):
     """Determine the min_date_active to validate against.
     """
     
     def is_workflowed_and_draft(instance):
         """is item workflowed, and if so is it in a logical draft state?
         """
         if interfaces.IWorkflowed.providedBy(instance):
             wf = interfaces.IWorkflow(instance)
             return instance.status in wf.get_state_ids(tagged=["draft"],
                 restrict=False)
         return False
     
     instance = removeSecurityProxy(self.context)
     min_date_active = None
     
     if IFeatureAudit.providedBy(self.context):
         # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data 
         # for workflowed items via the UI -- note, ideally we should be 
         # able to also control the item's creation active_date.
         #
         # If a workflowed item is in draft state, we do NOT take the 
         # date_active of its last change as the min_date_active, but
         # let that min fallback to chamber's creation date...
         if not is_workflowed_and_draft(instance):
             changes = get_changes(instance, "workflow")
             if changes:
  	            # then use the "date_active" of the most recent entry
                 min_date_active = changes[-1].date_active
     
     if not min_date_active:
         # ok, try determine a min_date_active in another way, namely via the
         # start_date of the instance itself (if it supports it) or of the 
         # "chamber" the instance "lives" in... !+sitting, session, ...?
         if IGroup.providedBy(instance) or IGroupMember.providedBy(instance):
             start_date = instance.start_date
         else:
             start_date = models.utils.get_chamber_for_context(instance).start_date
         assert start_date is not None, \
             "Cannot determine min_date_active for worklfowed instance: %s" % (instance)
         min_date_active = datetime.datetime.combine(start_date, datetime.time())
     
     # As the precision of the UI-submitted datetime is only to the minute, 
     # we adjust min_date_active by a margin of 59 secs earlier to avoid 
     # issues of doing 2 transitions in quick succession (within same minute) 
     # the 2nd of which could be taken to be too old...
     return min_date_active - datetime.timedelta(seconds=59)
Beispiel #9
0
def default_reports(sitting, event):
    if sitting.status in ("published_agenda", "published_minutes"):
        sitting = removeSecurityProxy(sitting)
        sittings = []
        sittings.append(sitting)
        report = domain.Report()
        session = Session()
        #!+REPORTS(miano, dec-2010) using test request here is not quite right
        # TODO : fix this.
        from zope.publisher.browser import TestRequest
        report.start_date = sitting.start_date
        report.end_date = sitting.end_date
        # owner ID is the ID of the user who performed last workflow change
        for change in reversed(domain.get_changes(sitting, "workflow")):
            owner_id = change.user_id
            break
        assert owner_id is not None, \
            "No user is defined. Are you logged in as Admin?"
        report.owner_id = owner_id
        report.language = get_default_language()
        report.created_date = datetime.datetime.now()
        report.group_id = sitting.group_id
        if sitting.status == 'published_agenda':
            report.short_name = _(u"Sitting Agenda")
            drc = DefaultReportContent(sittings, report.short_name, False)
            report.body_text = DefaultReportView(drc, TestRequest())()
        elif sitting.status == 'published_minutes':
            report.short_name = _(u"Sitting Votes and Proceedings")
            drc = DefaultReportContent(sittings, report.short_name, True)
            report.body_text = DefaultReportView(drc, TestRequest(), False)()
        session.add(report)
        session.flush()
        notify(ObjectCreatedEvent(report))
        sr = domain.SittingReport()
        sr.report = report
        sr.sitting = sitting
        session.add(sr)
        session.flush()
        notify(ObjectCreatedEvent(sr))
Beispiel #10
0
def default_reports(sitting, event):
    if sitting.status in ("published_agenda", "published_minutes"):
        sitting = removeSecurityProxy(sitting)
        sittings = []
        sittings.append(sitting)
        report = domain.Report()
        session = Session()
        #!+REPORTS(miano, dec-2010) using test request here is not quite right
        # TODO : fix this.
        from zope.publisher.browser import TestRequest
        report.start_date = sitting.start_date
        report.end_date = sitting.end_date
        # owner ID is the ID of the user who performed last workflow change
        for change in reversed(domain.get_changes(sitting, "workflow")):
            owner_id = change.user_id
            break
        assert owner_id is not None, \
            "No user is defined. Are you logged in as Admin?"
        report.owner_id = owner_id
        report.language = get_default_language()
        report.created_date = datetime.datetime.now()
        report.group_id = sitting.group_id
        if sitting.status == 'published_agenda':
            report.short_name = _(u"Sitting Agenda")
            drc = DefaultReportContent(sittings, report.short_name, False)
            report.body_text = DefaultReportView(drc, TestRequest())()
        elif sitting.status == 'published_minutes':
            report.short_name = _(u"Sitting Votes and Proceedings")
            drc = DefaultReportContent(sittings, report.short_name, True)
            report.body_text = DefaultReportView(drc, TestRequest(), False)()
        session.add(report)
        session.flush()
        notify(ObjectCreatedEvent(report))
        sr = domain.SittingReport()
        sr.report = report
        sr.sitting = sitting
        session.add(sr)
        session.flush()
        notify(ObjectCreatedEvent(sr))
Beispiel #11
0
 def get_min_date_active(self):
     """Determine the min_date_active to validate against.
     """
     
     def is_workflowed_and_draft(instance):
         """is item workflowed, and if so is it in a logical draft state?
         """
         if interfaces.IWorkflowed.providedBy(instance):
             wf = interfaces.IWorkflow(instance)
             return instance.status in wf.get_state_ids(tagged=["draft"],
                 restrict=False)
         return False
     
     min_date_active = None
     if IFeatureAudit.providedBy(self.context):
         instance = removeSecurityProxy(self.context)
         # !+PASTDATAENTRY(mr, jun-2011) offers a way to enter past data 
         # for workflowed items via the UI -- note, ideally we should be 
         # able to also control the item's creation active_date.
         #
         # If a workflowed item is in draft state, we do NOT take the 
         # date_active of its last change as the min_date_active, but
         # let that min fallback to parliament's creation date...
         if not is_workflowed_and_draft(instance):
             changes = get_changes(instance, "workflow")
             if changes:
  	            # then use the "date_active" of the most recent entry
                 min_date_active = changes[-1].date_active
     if not min_date_active:
         # fallback to current parliament's start_date (cast to a datetime)
         min_date_active = datetime.datetime.combine(
             globalsettings.get_current_parliament().start_date,
             datetime.time())
     # As the precision of the UI-submitted datetime is only to the minute, 
     # we adjust min_date_active by a margin of 59 secs earlier to avoid 
     # issues of doing 2 transitions in quick succession (within same minute) 
     # the 2nd of which could be taken to be too old...
     return min_date_active - datetime.timedelta(seconds=59)
Beispiel #12
0
 def get_feed_entries(self):
     return get_changes(removeSecurityProxy(self.context), "workflow")
Beispiel #13
0
 def append_visible_changes_on_item(item):
     for c in domain.get_changes(item, *self.include_change_actions):
         if interaction.checkPermission("zope.View", c):
             changes.append(c)
Beispiel #14
0
 def append_visible_changes_on_item(item):
     permission = view_permission(item)
     for c in domain.get_changes(item, *self.param_audit_actions):
         if checkPermission(permission, c):
             changes.append(c)
Beispiel #15
0
 def values(self):
     param_audit_actions = feature.get_feature(self.context,
                                               "audit").p.audit_actions
     return domain.get_changes(self.context, *param_audit_action)
Beispiel #16
0
 def values(self):
     return domain.get_changes(self.context, "modify", "add")
Beispiel #17
0
 def get_feed_entries(self):
     return get_changes(removeSecurityProxy(self.context), "workflow")
Beispiel #18
0
 def values(self):
     return domain.get_changes(self.context, "modify", "add")
Beispiel #19
0
 def values(self):
     param_audit_actions = feature.get_feature(self.context, "audit").p.audit_actions
     return domain.get_changes(self.context, *param_audit_action)