def finishConstruction(self, ob): """We add the parliament ID if adding a session in contexts not bound to the the parliament in traversal hierarchy """ super(SessionAddForm, self).finishConstruction(ob) if ob.parliament_id is None: ob.parliament_id = model_utils.get_current_parliament().parliament_id
def finishConstruction(self, ob): """We add the parliament ID if adding a session in contexts not bound to the the parliament in traversal hierarchy """ super(SessionAddForm, self).finishConstruction(ob) if ob.parliament_id is None: ob.parliament_id = model_utils.get_current_parliament( ).parliament_id
def __init__(self, context): self.context = context current_parliament = get_current_parliament() if current_parliament: self.object_type = current_parliament.type self.oid = current_parliament.group_id else: self.object_type = None self.oid = None
def can_schedule(workflow): """Determine if the current user can schedule this document type. i.e. if they have the global workflow permission to schedule a document. """ allow = False scheduled_states = workflow.get_state_ids(tagged=[TAG_SCHEDULED]) if scheduled_states: transitions = workflow.get_transitions_to(scheduled_states[0]) if transitions: allow = checkPermission(transitions[0].permission, get_current_parliament()) return allow
def can_schedule(workflow): """Determine if the current user can schedule this document type. i.e. if they have the global workflow permission to schedule a document. """ allow = False scheduled_states = workflow.get_state_ids(tagged=[TAG_SCHEDULED]) if scheduled_states: transitions = workflow.get_transitions_to(scheduled_states[0]) if transitions: allow = checkPermission(transitions[0].permission, get_current_parliament() ) return allow
def _setData(self): """Return the data of the query """ formatter = date.getLocaleFormatter(self.request, "date", "long") data_list = [] results = self.query.all() # if no current parliament, no data try: parliament_id = model_utils.get_current_parliament().parliament_id except: return data_list # government_id = self.__parent__.government_id for result in results: data = {} data["qid"] = "g_%s" % (result.group_id) data["subject"] = result.short_name data["title"] = "%s (%s)" % (result.short_name, result.type) data["result_item_class"] = "workflow-state-%s" % (result.status) _url = "/archive/browse/parliaments/obj-%s" % (parliament_id) if type(result) == domain.Parliament: data["url"] = url.set_url_context(_url) continue elif type(result) == domain.Committee: #data["url"] = url + "/committees/obj-" + str(result.group_id) data["url"] = url.set_url_context( "/groups/%s/%s" % (result.parent_group.group_principal_id, result.group_principal_id)) elif type(result) == domain.PoliticalGroup: data["url"] = url.set_url_context("%s/politicalgroups/obj-%s" % (_url, result.group_id)) elif type(result) == domain.Ministry: data["url"] = url.set_url_context( "%s/governments/obj-%s/ministries/obj-%s" % (_url, government_id, result.group_id)) else: data["url"] = "#" data["status"] = misc.get_wf_state(result) data["status_date"] = formatter.format(result.status_date) data["owner"] = "" data["type"] = _(result.type) data["to"] = "" data_list.append(data) self._data = data_list
def _setData(self): """Return the data of the query """ formatter = date.getLocaleFormatter(self.request, "date", "long") data_list = [] results = self.query.all() # if no current parliament, no data try: parliament_id = model_utils.get_current_parliament().parliament_id except: return data_list # government_id = self.__parent__.government_id for result in results: data = {} data["qid"] = "g_%s" % (result.group_id) data["subject"] = result.short_name data["title"] = "%s (%s)" % (result.short_name, result.type) data["result_item_class"] = "workflow-state-%s" % (result.status) _url = "/archive/browse/parliaments/obj-%s" % (parliament_id) if type(result) == domain.Parliament: data["url"] = url.set_url_context(_url) continue elif type(result) == domain.Committee: #data["url"] = url + "/committees/obj-" + str(result.group_id) data["url"] = url.set_url_context("/groups/%s/%s" % ( result.parent_group.group_principal_id, result.group_principal_id)) elif type(result) == domain.PoliticalGroup: data["url"] = url.set_url_context( "%s/politicalgroups/obj-%s" % (_url, result.group_id)) elif type(result) == domain.Ministry: data["url"] = url.set_url_context( "%s/governments/obj-%s/ministries/obj-%s" % ( _url, government_id, result.group_id)) else: data["url"] = "#" data["status"] = misc.get_wf_state(result) data["status_date"] = formatter.format(result.status_date) data["owner"] = "" data["type"] = _(result.type) data["to"] = "" data_list.append(data) self._data = data_list
def getData(self): """Return the data of the query """ formatter = self.request.locale.dates.getFormatter('date', 'short') data_list = [] results = self.query.all() # if no current parliament, no data try: parliament_id = model_utils.get_current_parliament().parliament_id except: return data_list # government_id = self.__parent__.government_id for result in results: data = {} data['qid']= ( 'g_' + str(result.group_id) ) data['subject'] = result.short_name data['title'] = result.short_name + ' (' + result.type + ')' data['result_item_class'] = 'workflow-state-' + result.status url = "/archive/browse/parliaments/obj-" + str(parliament_id) if type(result) == domain.Parliament: data['url'] = url continue elif type(result) == domain.Committee: #data['url'] = url + '/committees/obj-' + str(result.group_id) data['url'] = ('/groups/' + result.parent_group.group_principal_id + '/' + result.group_principal_id) elif type(result) == domain.PoliticalGroup: data['url'] = url + '/politicalgroups/obj-' + str(result.group_id) elif type(result) == domain.Ministry: data['url'] = url + ('/governments/obj-%s/ministries/obj-%s' % ( str(government_id), str(result.group_id) )) else: data['url'] = '#' data['status'] = misc.get_wf_state(result) data['status_date'] = formatter.format(result.status_date) data['owner'] = "" data['type'] = _(result.type) data['to'] = u"" data_list.append(data) return data_list
def prepare_user_workspaces(event): """Determine the current principal's workspaces, depending on roles and group memberships. "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP" these roles get a parliament-level workspace "bungeni.Minister" "implied" role (by being a member of a ministry group) gets a ministry-level workspace (for each ministry) "zope.Manager", "bungeni.Admin", "bungeni.Owner", "bungeni.Everybody", "bungeni.Anybody" not relevant for user workspaces, no workspaces !+ should these get an owner-level (user) workspace? """ request = event.request application = event.object # is bungeni.core.app.BungeniApp destination_url_path = url.get_destination_url_path(request) def need_to_prepare_workspaces(obj, req): return ( # need only to do it when traversing "/", # obj should be the BungeniApplication model_interfaces.IBungeniApplication.providedBy(obj) and # user is logged in interfaces.IBungeniAuthenticatedSkin.providedBy(req) and ( # either the request should be for a view within /workspace # note: IWorkspaceSectionLayer is applied to the request by # publication.apply_request_layer_by_url() that therefore must # have already been called interfaces.IWorkspaceSectionLayer.providedBy(req) or interfaces.IWorkspaceSchedulingSectionLayer.providedBy(req) or # or the request is for *the* Home Page (as in this case # we still need to know the user workspaces to be able to # redirect appropriately) interfaces.IHomePageLayer.providedBy(req) ) ) if not need_to_prepare_workspaces(application, request): return # initialize a layer data object, for the views in the layer LD = IAnnotations(request)["layer_data"] = misc.bunch( workspaces=[], # workspace containers !+ unique? # !+ role-based workspaces: (role|group, workspace_container) # these are needed by the views, as we need them also here, we just # remember them to not need to calculate them again user_id=None, user_group_ids=None, government_id=None, ministries=None, # list of ministries (that are also workspaces) ) LD.user_id = get_db_user_id() try: parliament = get_current_parliament(None) assert parliament is not None # force exception # we do get_roles under the current parliament as context, but we # must also ensure that the BungeniApp is present somewhere along # the __parent__ stack: parliament.__parent__ = application roles = get_roles(parliament) # "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP" for role_id in roles: if role_id in ("bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"): log.debug("adding parliament workspace %s (for role %s)" % ( parliament, role_id)) LD.workspaces.append(parliament) # "bungeni.Minister" # need to check for ministry groups to which the principal belongs, and # for each such ministry assign a ministry workspace LD.user_group_ids = get_group_ids_for_user_in_parliament( LD.user_id, parliament.group_id) LD.government_id = get_current_parliament_governments( parliament)[0].group_id # IndexError LD.ministries = get_ministries_for_user_in_government( LD.user_id, LD.government_id) log.debug(""" [prepare_user_workspaces] user_id:%s roles:%s parliament:(%s, %s) government_id:%s ministries:%s""" % ( LD.user_id, roles, parliament.full_name, parliament.group_id, LD.government_id, [(m.full_name, m.group_id) for m in LD.ministries] )) for ministry in LD.ministries: log.debug("adding ministry workspace %s" % ministry) LD.workspaces.append(ministry) except (Exception,): debug.log_exc_info(sys.exc_info(), log_handler=log.info) # ensure unique workspaces, preserving order, retaining same list obj ref LD.workspaces[:] = [ workspace for i,workspace in enumerate(LD.workspaces) if LD.workspaces.index(workspace)==i ] # mark each workspace container with IWorkspaceContainer for workspace in LD.workspaces: interface.alsoProvides(workspace, interfaces.IWorkspaceContainer) log.debug(debug.interfaces(workspace)) log.debug(" [prepare_user_workspaces] %s" % debug.interfaces(request)) log.info(""" [prepare_user_workspaces] DONE: for: [request=%s][path=%s][path_info=%s] request.layer_data: %s""" % ( id(request), destination_url_path, request.get("PATH_INFO"), IAnnotations(request).get("layer_data", None)))
def __setitem__(self, name, item): session = Session() current_parliament = get_current_parliament() item.parliament_id = current_parliament.parliament_id session.add(item)
def parliament_id(self): """Vocabularies in the forms get the parliament id from the context, this property returns the id of the current parliament because the workspace is meant only for adding current documents """ return get_current_parliament().group_id
def prepare_user_workspaces(event): """Determine the current principal's workspaces, depending on roles and group memberships. "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP" these roles get a parliament-level workspace "bungeni.Minister" "implied" role (by being a member of a ministry group) gets a ministry-level workspace (for each ministry) "zope.Manager", "bungeni.Admin", "bungeni.Owner", "bungeni.Authenticated", "bungeni.Anonymous" not relevant for user workspaces, no workspaces !+ should these get an owner-level (user) workspace? """ request = event.request application = event.object # is bungeni.core.app.BungeniApp destination_url_path = url.get_destination_url_path(request) def need_to_prepare_workspaces(obj, req): return ( # need only to do it when traversing "/", # obj should be the BungeniApplication model_interfaces.IBungeniApplication.providedBy(obj) and # user is logged in interfaces.IBungeniAuthenticatedSkin.providedBy(req) and ( # either the request should be for a view within /workspace # note: IWorkspaceSectionLayer is applied to the request by # publication.apply_request_layer_by_url() that therefore must # have already been called interfaces.IWorkspaceSectionLayer.providedBy(req) or interfaces.IWorkspaceSchedulingSectionLayer.providedBy(req) or # or the request is for *the* Home Page (as in this case # we still need to know the user workspaces to be able to # redirect appropriately) interfaces.IHomePageLayer.providedBy(req))) if not need_to_prepare_workspaces(application, request): return # initialize a layer data object, for the views in the layer LD = IAnnotations(request)["layer_data"] = misc.bunch( workspaces=[], # workspace containers !+ unique? # !+ role-based workspaces: (role|group, workspace_container) # these are needed by the views, as we need them also here, we just # remember them to not need to calculate them again user_id=None, user_group_ids=None, government_id=None, ministries=None, # list of ministries (that are also workspaces) ) LD.user_id = get_db_user_id() try: parliament = get_current_parliament(None) assert parliament is not None # force exception # we do get_context_roles under the current parliament as context, but # we must also ensure that the BungeniApp is present somewhere along # the __parent__ stack: parliament.__parent__ = application roles = common.get_context_roles(parliament) # "bungeni.Clerk", "bungeni.Speaker", "bungeni.MP" for role_id in roles: if role_id in ("bungeni.Clerk", "bungeni.Speaker", "bungeni.MP"): log.debug("adding parliament workspace %s (for role %s)" % (parliament, role_id)) LD.workspaces.append(parliament) # "bungeni.Minister" # need to check for ministry groups to which the principal belongs, and # for each such ministry assign a ministry workspace LD.user_group_ids = get_group_ids_for_user_in_parliament( LD.user_id, parliament.group_id) LD.government_id = get_current_parliament_governments( parliament)[0].group_id # IndexError LD.ministries = get_ministries_for_user_in_government( LD.user_id, LD.government_id) log.debug( """ [prepare_user_workspaces] user_id:%s roles:%s parliament:(%s, %s) government_id:%s ministries:%s""" % (LD.user_id, roles, parliament.full_name, parliament.group_id, LD.government_id, [(m.full_name, m.group_id) for m in LD.ministries])) for ministry in LD.ministries: log.debug("adding ministry workspace %s" % ministry) LD.workspaces.append(ministry) except (Exception, ): debug.log_exc_info(sys.exc_info(), log_handler=log.info) # ensure unique workspaces, preserving order, retaining same list obj ref LD.workspaces[:] = [ workspace for i, workspace in enumerate(LD.workspaces) if LD.workspaces.index(workspace) == i ] # mark each workspace container with IWorkspaceContainer for workspace in LD.workspaces: interface.alsoProvides(workspace, interfaces.IWorkspaceContainer) log.debug(debug.interfaces(workspace)) log.debug(" [prepare_user_workspaces] %s" % debug.interfaces(request)) log.info(""" [prepare_user_workspaces] DONE: for: [request=%s][path=%s][path_info=%s] request.layer_data: %s""" % (id(request), destination_url_path, request.get("PATH_INFO"), IAnnotations(request).get("layer_data", None)))
def workspace_search(self): """ Search in workspace section, based on views from bungeni.ui.viewlets.workspace """ application = common.get_application() parliament = get_current_parliament(None) parliament.__parent__ = application principal = get_principal() roles = common.get_context_roles(parliament, principal) # minister role, filtering by states and object_type and ministry_id if not roles: user_id = get_db_user_id() government_id = get_current_parliament_governments( parliament)[0].group_id ministries = get_ministries_for_user_in_government( user_id, government_id) if ministries: states = workspace.MinistryArchiveViewlet.states + \ workspace.OralMinistryQuestionsViewlet.states + \ workspace.WrittenMinistryQuestionsViewlet.states + \ workspace.InProgressMinistryItemsViewlet.states states = set(states) ministry_ids = [m.group_id for m in ministries] # filter by object_type (questions only) type_query = self.searcher.query_field('object_type', "Question") query = self.searcher.query_composite(self.searcher.OP_AND, \ (self.query, type_query,)) subqueries = [] for state in states: subqueries.append( self.searcher.query_field('status', state)) state_query = self.searcher.query_composite( self.searcher.OP_OR, subqueries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (query, state_query,)) #filter for ministries ministries_queries = [] for mid in ministry_ids: ministries_queries.append( self.searcher.query_field('ministry_id', str(mid))) m_query = self.searcher.query_composite( self.searcher.OP_OR, ministries_queries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (query, m_query,)) try: results = self.searcher.search( query, 0, self.searcher.get_doccount()) except: results = [] return list(results) # filtering by states and owner if 'bungeni.MP' in roles: states = workspace.MPItemActionRequiredViewlet.states + \ workspace.MPItemDraftViewlet.states + \ workspace.MPItemInProgressViewlet.states + \ workspace.ItemArchiveViewlet.states states = set(states) # filter by owner of PI owner_query = self.searcher.query_field('owner', str(get_db_user_id())) query = self.searcher.query_composite(self.searcher.OP_AND, \ (self.query, owner_query,)) subqueries = [] for state in states: subqueries.append(self.searcher.query_field('status', state)) state_query = self.searcher.query_composite( self.searcher.OP_OR, subqueries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (query, state_query,)) try: results = self.searcher.search(query, 0, self.searcher.get_doccount()) except: results = [] return list(results) # filtering by states if 'bungeni.Clerk' in roles: states = workspace.ClerkItemActionRequiredViewlet.states + \ workspace.ClerkItemsWorkingDraftViewlet.states + \ workspace.ClerkReviewedItemViewlet.states + \ workspace.ItemsApprovedViewlet.states + \ workspace.ItemsPendingScheduleViewlet.states + \ workspace.ItemsScheduledViewlet.states + \ workspace.AllItemArchiveViewlet.states states = set(states) subqueries = [] for state in states: subqueries.append(self.searcher.query_field('status', state)) state_query = self.searcher.query_composite( self.searcher.OP_OR, subqueries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (self.query, state_query,)) try: results = self.searcher.search(query, 0, self.searcher.get_doccount()) except: results = [] return list(results) # no results return False
def workspace_search(self): """ Search in workspace section, based on views from bungeni.ui.viewlets.workspace """ application = common.get_application() parliament = get_current_parliament(None) parliament.__parent__ = application principal = get_principal() roles = common.get_context_roles(parliament, principal) # minister role, filtering by states and object_type and ministry_id if not roles: user_id = get_db_user_id() government_id = get_current_parliament_governments(parliament)[0].group_id ministries = get_ministries_for_user_in_government(user_id, government_id) if ministries: states = workspace.MinistryArchiveViewlet.states + \ workspace.OralMinistryQuestionsViewlet.states + \ workspace.WrittenMinistryQuestionsViewlet.states + \ workspace.InProgressMinistryItemsViewlet.states states = set(states) ministry_ids = [m.group_id for m in ministries] # filter by object_type (questions only) type_query = self.searcher.query_field('object_type', "Question") query = self.searcher.query_composite(self.searcher.OP_AND, \ (self.query, type_query,)) subqueries = [] for state in states: subqueries.append(self.searcher.query_field('status', state)) state_query = self.searcher.query_composite(self.searcher.OP_OR, subqueries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (query, state_query,)) #filter for ministries ministries_queries = [] for mid in ministry_ids: ministries_queries.append(self.searcher.query_field('ministry_id', str(mid))) m_query = self.searcher.query_composite(self.searcher.OP_OR, ministries_queries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (query, m_query,)) try: results = self.searcher.search(query, 0, self.searcher.get_doccount()) except: results = [] return list(results) # filtering by states and owner if 'bungeni.MP' in roles: states = workspace.MPItemActionRequiredViewlet.states + \ workspace.MPItemDraftViewlet.states + \ workspace.MPItemInProgressViewlet.states + \ workspace.ItemArchiveViewlet.states states = set(states) # filter by owner of PI owner_query = self.searcher.query_field('owner', str(get_db_user_id())) query = self.searcher.query_composite(self.searcher.OP_AND, \ (self.query, owner_query,)) subqueries = [] for state in states: subqueries.append(self.searcher.query_field('status', state)) state_query = self.searcher.query_composite(self.searcher.OP_OR, subqueries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (query, state_query,)) try: results = self.searcher.search(query, 0, self.searcher.get_doccount()) except: results = [] return list(results) # filtering by states if 'bungeni.Clerk' in roles: states = workspace.ClerkItemActionRequiredViewlet.states + \ workspace.ClerkItemsWorkingDraftViewlet.states + \ workspace.ClerkReviewedItemViewlet.states + \ workspace.ItemsApprovedViewlet.states + \ workspace.ItemsPendingScheduleViewlet.states + \ workspace.ItemsScheduledViewlet.states + \ workspace.AllItemArchiveViewlet.states states = set(states) subqueries = [] for state in states: subqueries.append(self.searcher.query_field('status', state)) state_query = self.searcher.query_composite(self.searcher.OP_OR, subqueries) query = self.searcher.query_composite(self.searcher.OP_AND, \ (self.query, state_query,)) try: results = self.searcher.search(query, 0, self.searcher.get_doccount()) except: results = [] return list(results) # no results return False