def get_user_client_uid(self, default=None): """Returns the id of the client the current user belongs to """ client = api.get_current_client() if client: return api.get_uid(client) return default
def update(self): """Before template render hook """ super(BatchFolderContentsView, self).update() if self.context.portal_type == "BatchFolder": self.request.set("disable_border", 1) # By default, only users with AddBatch permissions for the current # context can add batches. self.context_actions = { _("Add"): { "url": "createObject?type_name=Batch", "permission": AddBatch, "icon": "++resource++bika.lims.images/add.png" } } # If current user is a client contact and current context is not a # Client, then modify the url for Add action so the Batch gets created # inside the Client object to which the current user belongs. The # reason is that Client contacts do not have privileges to create # Batches inside portal/batches if not IClient.providedBy(self.context): # Get the client the current user belongs to client = api.get_current_client() if client and check_permission(AddBatch, client): add_url = self.context_actions[_("Add")]["url"] add_url = "{}/{}".format(api.get_url(client), add_url) self.context_actions[_("Add")]["url"] = add_url del (self.context_actions[_("Add")]["permission"])
def is_logged_user_from_external_client(): """Returns whether the current user belongs to an external client """ client = api.get_current_client() if client and is_external_client(client): return True return False
def show_partitions(self): if self.flat_listing: return False if api.get_current_client(): # If current user is a client contact, delegate to ShowPartitions return api.get_setup().getShowPartitions() return True
def before_render(self): # Additional columns self.add_columns() # Remove unnecessary columns self.hide_columns() # Apply client filter, if necessary client = api.get_current_client() if client: query = dict(getClientUID=api.get_uid(client)) self.listing.contentFilter.update(query) for rv in self.listing.review_states: if "contentFilter" not in rv: rv["contentFilter"] = {} rv["contentFilter"].update(query) # Render the Add button self.listing.context_actions = {} batches = api.get_portal().batches if security.check_permission(AddBatch, batches): url = api.get_url(batches) self.listing.context_actions = { _("Add"): { "url": "{}/createObject?type_name=Batch".format(url), "icon": "++resource++bika.lims.images/add.png"} }
def update(self): """Called before the listings renders """ super(PatientsView, self).update() # Render the Add button. We need to do this here because patients live # inside site.patients folder self.context_actions = {} patients = api.get_portal().patients if security.check_permission(AddPatient, patients): self.context_actions = { _("Add"): { "url": "createObject?type_name=Patient", "icon": "++resource++bika.lims.images/add.png" } } # If the current user is a client contact, display those patients that # belong to same client or that do not belong to any client client = api.get_current_client() if client: query = dict(client_uid=[api.get_uid(client), "-1"]) # We add UID "-1" to also include Patients w/o Client assigned self.contentFilter.update(query) for rv in self.review_states: rv["contentFilter"].update(query) # If the current context is a Client, remove the title column if IClient.providedBy(self.context): self.remove_column('getPrimaryReferrerTitle')
def update(self): """Called before the listings renders """ super(PatientsView, self).update() # Render the Add button. We need to do this here because patients live # inside site.patients folder self.context_actions = {} patients = api.get_portal().patients if security.check_permission(AddPatient, patients): self.context_actions = { _("Add"): { "url": "createObject?type_name=Patient", "icon": "++resource++bika.lims.images/add.png"} } # If the current user is a client contact, display those patients that # belong to same client or that do not belong to any client client = api.get_current_client() if client: query = dict(client_uid=[api.get_uid(client), "-1"]) # We add UID "-1" to also include Patients w/o Client assigned self.contentFilter.update(query) for rv in self.review_states: rv["contentFilter"].update(query) # If the current context is a Client, remove the title column if IClient.providedBy(self.context): self.remove_column('getPrimaryReferrerTitle')
def before_render(self): # Additional columns self.add_columns() # Remove unnecessary columns self.hide_columns() # Apply client filter, if necessary client = api.get_current_client() if client: query = dict(getClientUID=api.get_uid(client)) self.listing.contentFilter.update(query) for rv in self.listing.review_states: if "contentFilter" not in rv: rv["contentFilter"] = {} rv["contentFilter"].update(query) # Render the Add button self.listing.context_actions = {} batches = api.get_portal().batches if security.check_permission(AddBatch, batches): url = api.get_url(batches) self.listing.context_actions = { _("Add"): { "url": "{}/createObject?type_name=Batch".format(url), "icon": "++resource++bika.lims.images/add.png" } }
def __call__(self): client = api.get_current_client() if client: url = api.get_url(client) ar_count = self.get_ar_count() return self.request.response.redirect("{}/ar_add?ar_count={}" .format(url, ar_count)) return super(AnalysisRequestAddView, self).__call__()
def __call__(self): client = api.get_current_client() if client: url = api.get_url(client) ar_count = self.get_ar_count() return self.request.response.redirect( "{}/ar_add?ar_count={}".format(url, ar_count)) return super(AnalysisRequestAddView, self).__call__()
def get_partitions(self): """Returns whether this viewlet is visible or not """ # If current user is a client contact, rely on Setup's ShowPartitions if api.get_current_client(): if not api.get_setup().getShowPartitions(): return [] return self.context.getDescendants()
def current_user_can_edit(self): """Returns true if the current user can edit this Doctor. """ user_client = api.get_current_client() if user_client: # The current user is a client contact. This user can only edit # this doctor if it has the same client assigned client_uid = api.get_uid(user_client) doctor_client = self.getPrimaryReferrer() return doctor_client and api.get_uid(doctor_client) == client_uid return True
def hide_columns(self): # Columns to hide hide = ["Title", "BatchDate", "Description",] if api.get_current_client(): # Hide client-specific columns hide.extend(["Client", "ClientID"]) # Remove the columns from all review_states for rv in self.listing.review_states: rv_columns = rv.get("columns", self.listing.columns.keys()) rv_columns = filter(lambda col: col not in hide, rv_columns) rv["columns"] = rv_columns
def before_render(self): """Before template render hook """ # If the current user is a client contact, display those analysis # requests that belong to same client only super(AnalysisRequestsView, self).before_render() client = api.get_current_client() if client: self.contentFilter['path'] = { "query": "/".join(client.getPhysicalPath()), "level": 0} # No need to display the Client column self.remove_column('Client')
def is_visible(self): """Returns whether the viewlet must be visible or not """ logged_client = api.get_current_client() if not logged_client: # Current user is from Lab, display always return True # Only display the viewlet if the current user does belong to an # Internal Client. It does not make sense to display this viewlet if # the user is from an external client, cause in such case, there is no # need to warn him/her. He/She expects that their own Patients, Cases # and Doctors are private already return is_internal_client(logged_client)
def isVisible(self, field, mode="view", default="visible"): if IBatch.providedBy(self.context.aq_parent): return "hidden" if mode == "edit": client = api.get_current_client() if client: # If current user is a client contact and the batch this Sample # is assigned to does not have a client assigned (e.g., the # batch was assigned by lab personnel), hide this field batch = self.context.getBatch() if batch and batch.getClient() != client: return "invisible" return default
def get_clients_vocabulary(self): client = api.get_current_client() if client: # Current user is a client contact. Load only this client return DisplayList([(api.get_uid(client), api.get_title(client))]) # Current user is not a client contact. Load all active clients query = dict(portal_type="Client", is_active=True) clients = api.search(query, "portal_catalog") clients = map(lambda cl: [api.get_uid(cl), api.get_title(cl)], clients) clients.sort(lambda x, y: cmp(x[1].lower(), y[1].lower())) # Lab personnel can set a Patient to be visible for all Clients clients.insert(0, ['', '']) return DisplayList(clients)
def hide_columns(self): # Columns to hide hide = [ "Title", "BatchDate", "Description", ] if api.get_current_client(): # Hide client-specific columns hide.extend(["Client", "ClientID"]) # Remove the columns from all review_states for rv in self.listing.review_states: rv_columns = rv.get("columns", self.listing.columns.keys()) rv_columns = filter(lambda col: col not in hide, rv_columns) rv["columns"] = rv_columns
def get_partitions(self): """Returns whether this viewlet is visible or not """ partitions = [] # If current user is a client contact, rely on Setup's ShowPartitions client = api.get_current_client() if client: if not api.get_setup().getShowPartitions(): return partitions partitions = self.context.getDescendants() if client: # Do not display partitions for Internal use return filter(lambda part: not part.getInternalUse(), partitions) return partitions
def before_render(self): """Before template render hook """ # If the current user is a client contact, display those analysis # requests that belong to same client only super(SamplesView, self).before_render() client = api.get_current_client() if client: self.contentFilter['path'] = { "query": "/".join(client.getPhysicalPath()), "level": 0} # No need to display the Client column self.remove_column('Client') # remove query filter for root samples when listing is flat if self.flat_listing: self.contentFilter.pop("isRootAncestor", None)
def is_visible(self): """Returns whether the viewlet must be visible or not """ if self.context.isTemporary(): # Temporary object, not yet created return False logged_client = api.get_current_client() if not logged_client: # Current user is from Lab, display always return True # Only display the viewlet if the current user does belong to an # Internal Client. It does not make sense to display this viewlet if # the user is from an external client, cause in such case, he/she will # only be able to see the its own patients return is_internal_client(logged_client)
def before_render(self): # Add stored review state print_stickers = { "id": "print_stickers", "title": _("Print stickers"), "url": "workflow_action?action=print_stickers" } base_column_ids = self.listing.columns.keys() hide = ["getDateVerified", "getDatePublished"] columns = filter(lambda col: col not in hide, base_column_ids) stored = { "id": "stored", "title": _("Stored"), "contentFilter": { "review_state": ("stored",), "sort_on": "created", "sort_order": "descending", }, "transitions": [], "custom_transitions": [print_stickers], "columns": columns, } utils.add_review_state(self.listing, stored, after="published") # Add the column Date Stored to the "stored" review state column_values = { "title": _("Date stored"), "index": "getDateStored", "attr": "getId", "toggle": True} utils.add_column(self.listing, "getDateStored", column_values, after="getDateReceived", review_states=("stored",)) # Add Samples Container column, but only if the current user logged in # is not a client contact if not api.get_current_client(): column_values = { "title": _("Storage"), "attr": "getSamplesContainerID", "replace_url": "getSamplesContainerURL", "toggle": True } utils.add_column(self.listing, "getSamplesContainer", column_values, after="getDateStored", review_states=("stored", ))
def get_clients_vocabulary(self): """ Vocabulary list with clients :return: A DisplayList object """ if self.getBatches() or self.getAnalysisRequests(): # Allow to change the client if there are no ARs associated client = self.getPrimaryReferrer() if not client: # Maybe all Batches and ARs assigned to this Doctor belong to # the same Client.. If so, just assign this client by default client_uids = map(lambda ar: ar.getClientUID, self.getAnalysisRequests()) client_uids = list(set(client_uids)) if len(client_uids) > 1: # More than one client assigned! return DisplayList([('', '')]) clients = map(lambda batch: batch.getClient(), self.getBatches(full_objects=True)) client_uids += map(lambda client: api.get_uid(client), clients) client_uids = list(set(client_uids)) if len(client_uids) > 1: # More than one client assigned! return DisplayList([('', '')]) client = api.get_object_by_uid(client_uids[0]) return DisplayList([(api.get_uid(client), client.Title())]) # If the current user is a client contact, do not display other clients client = api.get_current_client() if client: return DisplayList([(api.get_uid(client), client.Title())]) # Search for clients query = dict(portal_type='Client', inactive_state='active', sort_order='ascending', sort_on='title') brains = api.search(query, 'portal_catalog') clients = map(lambda brain: [api.get_uid(brain), brain.Title], brains) clients.insert(0, ['', '']) return DisplayList(clients)
def get_clients_vocabulary(self): """ Vocabulary list with clients :return: A DisplayList object """ if self.getBatches() or self.getAnalysisRequests(): # Allow to change the client if there are no ARs associated client = self.getPrimaryReferrer() if not client: # Maybe all Batches and ARs assigned to this Doctor belong to # the same Client.. If so, just assign this client by default client_uids = map(lambda ar: ar.getClientUID, self.getAnalysisRequests()) client_uids = list(set(client_uids)) if len(client_uids) > 1: # More than one client assigned! return DisplayList([('', '')]) clients = map(lambda batch: batch.getClient(), self.getBatches(full_objects=True)) client_uids += map(lambda client: api.get_uid(client), clients) client_uids = list(set(client_uids)) if len(client_uids) > 1: # More than one client assigned! return DisplayList([('', '')]) client = api.get_object_by_uid(client_uids[0]) return DisplayList([(api.get_uid(client), client.Title())]) # If the current user is a client contact, do not display other clients client = api.get_current_client() if client: return DisplayList([(api.get_uid(client), client.Title())]) # Search for clients query = dict(portal_type='Client', is_active=True, sort_order='ascending', sort_on='title') brains = api.search(query, 'portal_catalog') clients = map(lambda brain: [api.get_uid(brain), brain.Title], brains) clients.insert(0, ['', '']) return DisplayList(clients)
def is_client_contact(self): """Returns whether the current user is a client contact """ return api.get_current_client() is not None
def is_client_user(self): """Returns whether the current user belongs to an internal client """ if self._is_client_user is None: self._is_client_user = api.get_current_client() and True or False return self._is_client_user
def is_client_context(self): """Returns whether the batch listing is displayed in IClient context or if the current user is a client contact """ return api.get_current_client() or IClient.providedBy(self.context)
def get_user_client(self): """Returns the client from current user, if any """ return api.get_current_client()
def logged_in_client(context, member=None): return api.get_current_client()
def isVisible(self, field, mode="view", default="visible"): """Returns whether the field is visible in a given mode """ return api.get_current_client() and "invisible" or default