def canView(self): # Permissions to view ORGANS DE GOVERN # Bypass if manager roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True organType = self.context.organType # If Obert if organType == 'open_organ': return True # if restricted_to_members_organ elif organType == 'restricted_to_members_organ': if utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True else: raise Unauthorized # if restricted_to_affected_organ elif organType == 'restricted_to_affected_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True else: raise Unauthorized else: raise Unauthorized
def canView(self): # Permissions to view acords based on ODT definition file # TODO: add if is obert /restricted to ... estatSessio = utils.session_wf_state(self) roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True elif estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'realitzada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'tancada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'en_correccio' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True else: raise Unauthorized
def _brains(self): catalog = api.portal.get_tool(name='portal_catalog') items = catalog(path={ 'query': '/'.join(self.context.getPhysicalPath()), 'depth': 1 }) filtered_items = [] for item in items: if item.portal_type in [ 'genweb.organs.acord', 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.document', 'genweb.organs.file', 'genweb.organs.organgovern', 'genweb.organs.organsfolder', 'genweb.organs.punt', 'genweb.organs.sessio', 'genweb.organs.subpunt', ]: add = False tipus = item.portal_type organ_tipus = item.organType if tipus == 'genweb.organs.organsfolder': add = True elif tipus == 'genweb.organs.sessio' or tipus == 'genweb.organs.organgovern': roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if organ_tipus == 'open_organ': add = True elif organ_tipus == 'restricted_to_members_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): add = True elif organ_tipus == 'restricted_to_affected_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): add = True else: add = False else: # Els elements tipics de Plone/Genweb es mostren al RSS add = True if add: filtered_items.append(item) installed = packages_installed() if 'genweb.organs' in installed: return sorted(filtered_items, key=itemgetter('start'), reverse=True) else: return sorted(filtered_items, key=itemgetter('Date'), reverse=True)
def OrgansInside(self): """ Retorna els organs de govern depenent del rol i l'estat de l'Organ. Per això fa 3 cerques """ portal_catalog = api.portal.get_tool(name='portal_catalog') folder_path = '/'.join(self.context.getPhysicalPath()) values = portal_catalog.searchResults( portal_type='genweb.organs.organgovern', sort_on='getObjPositionInParent', path={'query': folder_path, 'depth': 1}) results = [] if api.user.is_anonymous(): username = None else: username = api.user.get_current().id for obj in values: value = obj.getObject() organType = value.organType if username: roles = api.user.get_roles(obj=value, username=username) else: roles = [] # If Manager or open bypass and list all if 'Manager' in roles or (organType == 'open_organ'): results.append(dict(title=value.title, absolute_url=value.absolute_url(), acronim=value.acronim, organType=value.organType, review_state=obj.review_state)) # if restricted_to_members_organ elif organType == 'restricted_to_members_organ': if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): results.append(dict(title=value.title, absolute_url=value.absolute_url(), acronim=value.acronim, organType=value.organType, review_state=obj.review_state)) # if restricted_to_affected_organ elif organType == 'restricted_to_affected_organ': if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): results.append(dict(title=value.title, absolute_url=value.absolute_url(), acronim=value.acronim, organType=value.organType, review_state=obj.review_state)) return results
def canViewVotacionsInside(self): roles = utils.getUserRoles(self, self.context, api.user.get_current().id) estatSessio = utils.session_wf_state(self) if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio in [ 'convocada', 'realitzada', 'tancada', 'en_correccio' ] and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre'], roles): return True else: return False
def canView(self): # Permissions per veure l'estat dels organs a la taula principal roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if utils.checkhasRol(['Manager', 'OG1-Secretari', 'OG2-Editor'], roles): return True else: return False
def viewOrdena(self): roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if utils.checkhasRol(['Manager', 'OG1-Secretari', 'OG2-Editor'], roles): value = True return False
def viewPrintButon(self): roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return True else: return False
def viewExportAcords(self): # Només els Secretaris i Editors poden veure les excuses roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if utils.checkhasRol(['Manager', 'OG1-Secretari'], roles): return True else: return False
def changeEstat(self): if api.user.is_anonymous(): return False else: username = api.user.get_current().id if username is None: return False else: roles = api.user.get_roles(username=username, obj=self.context) if utils.checkhasRol( ['Manager', 'OG1-Secretari', 'OG2-Editor'], roles): if self.wf_state() in [ 'planificada', 'convocada', 'realitzada' ]: return True if utils.checkhasRol(['Manager', 'OG1-Secretari'], roles): if self.wf_state() == 'en_correccio': return True else: return False
def canView(self): # Permissions to view VOTACIOACORD # If manager Show all roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True estatSessio = utils.session_wf_state(self) if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio in [ 'convocada', 'realitzada', 'tancada', 'en_correccio' ] and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre'], roles): return True else: raise Unauthorized
def viewActes(self): """ Si es Manager/Secretari/Editor/Membre show actas Affectat i altres NO veuen MAI les ACTES """ roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False
def getUserRole(self): # Només els rols Reponsable, Editor i Manager poden veure aquesta vista role = self.request.form.get('id', '') username = api.user.get_current().id if username: roles = api.user.get_roles(username=username, obj=self.context) if utils.checkhasRol(['Manager', 'OG1-Secretari', 'OG2-Editor'], roles): return role else: return False else: return False
def update(self): """ Disable the view if username has no roles. Send Message if user is Editor / Secretari / Manager """ if api.user.is_anonymous() is True: raise Unauthorized else: username = api.user.get_current().id roles = api.user.get_roles(username=username, obj=self.context) if utils.checkhasRol(['Manager', 'OG1-Secretari', 'OG2-Editor'], roles): self.request.set('disable_border', True) super(Message, self).update() else: raise Unauthorized
def update(self): if api.user.is_anonymous() is True: raise Unauthorized else: username = api.user.get_current().id roles = api.user.get_roles(username=username, obj=self.context) if utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): self.request.set('disable_border', True) super(Message, self).update() else: raise Unauthorized
def hasPermission(self): if api.user.is_anonymous(): return False else: username = api.user.get_current().id if username is None: return False else: roles = api.user.get_roles(username=username, obj=self.context) if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False return False
def getOwnOrgans(self): if not api.user.is_anonymous(): results = [] portal_catalog = api.portal.get_tool(name='portal_catalog') root_path = '/'.join(api.portal.get().getPhysicalPath()) # /998/govern lt = getToolByName(self, 'portal_languages') lang = lt.getPreferredLanguage() values = portal_catalog.searchResults( portal_type=['genweb.organs.organgovern'], path=root_path + '/' + lang) username = api.user.get_current().id for obj in values: organ = obj.getObject() all_roles = api.user.get_roles(username=username, obj=organ) roles = [o for o in all_roles if o in ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat']] if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): results.append(dict( url=obj.getObject().absolute_url(), title=obj.Title, color=organ.eventsColor, role=roles)) return results
def canView(self): # Permissions to view audio roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True estatSessio = utils.session_wf_state(self) organ_tipus = self.context.organType if estatSessio == 'planificada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'realitzada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif organ_tipus == 'open_organ' and estatSessio == 'tancada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): return True elif organ_tipus != 'open_organ' and estatSessio == 'tancada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'en_correccio' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True else: raise Unauthorized
def getFileOrgans(self): if not self.fieldname: info = IPrimaryFieldInfo(self.context, None) if info is None: # Ensure that we have at least a filedname raise NotFound(self, '', self.request) self.fieldname = info.fieldname file = info.value else: context = getattr(self.context, 'aq_explicit', self.context) file = guarded_getattr(context, self.fieldname, None) if file is None: raise NotFound(self, self.fieldname, self.request) # GENWEB ORGANS CODE ADDED # Antes de retornar el fichero comprobamos los estados de la sesion # para ver si lo debemos mostrar o no # Check if genweb.organs installed... from Products.CMFCore.utils import getToolByName qi = getToolByName(self.context, 'portal_quickinstaller') prods = qi.listInstalledProducts() installed = False if 'genweb.organs' in [prod['id'] for prod in prods]: installed = True if not installed: # Standard functionallity. return file elif self.context.portal_type == 'File': # If package is installed but thit is not an organ type # then only is an standeard file, we have to show it. return file else: # # WARNING: Organs functionallity # from plone import api from genweb.organs import utils roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return file if self.context.aq_parent.aq_parent.portal_type == 'genweb.organs.sessio': # first level estatSessio = api.content.get_state( obj=self.context.aq_parent.aq_parent) elif self.context.portal_type == 'genweb.organs.acta': estatSessio = api.content.get_state(obj=self.context.aq_parent) else: # second level estatSessio = api.content.get_state( obj=self.context.aq_parent.aq_parent.aq_parent) # Get Organ Type here organ_tipus = self.context.organType if organ_tipus == 'open_organ': if estatSessio == 'planificada': if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file else: raise Unauthorized if estatSessio == 'convocada': if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol( ['OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file else: if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'visiblefile': return file else: raise Unauthorized elif (self.context.hiddenfile): raise Unauthorized elif (self.context.visiblefile): return file else: raise Unauthorized if estatSessio == 'realitzada': if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol( ['OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file else: if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'visiblefile': return file else: raise Unauthorized elif (self.context.hiddenfile): raise Unauthorized elif (self.context.visiblefile): return file else: raise Unauthorized if estatSessio == 'tancada': if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol( ['OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file else: if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'visiblefile': return file else: raise Unauthorized elif (self.context.hiddenfile): raise Unauthorized elif (self.context.visiblefile): return file else: raise Unauthorized if estatSessio == 'en_correccio': if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol( ['OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file else: if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'visiblefile': return file else: raise Unauthorized elif (self.context.hiddenfile): raise Unauthorized elif (self.context.visiblefile): return file else: raise Unauthorized elif organ_tipus == 'restricted_to_members_organ': if estatSessio == 'planificada': if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file else: raise Unauthorized if estatSessio == 'convocada': if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol(['OG3-Membre', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file else: raise Unauthorized if (estatSessio == 'realitzada' or estatSessio == 'tancada' or estatSessio == 'en_correccio'): if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol(['OG3-Membre', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file elif 'OG4-Afectat' in roles: raise Unauthorized else: raise Unauthorized elif organ_tipus == 'restricted_to_affected_organ': if estatSessio == 'planificada': if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file else: raise Unauthorized if estatSessio == 'convocada': if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol(['OG3-Membre', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file else: raise Unauthorized if (estatSessio == 'realitzada' or estatSessio == 'tancada' or estatSessio == 'en_correccio'): if self.context.portal_type in [ 'genweb.organs.acta', 'genweb.organs.audio', 'genweb.organs.annex' ]: if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return file else: raise Unauthorized else: if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return file elif utils.checkhasRol(['OG3-Membre', 'OG5-Convidat'], roles): if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'hiddenfile': return file else: raise Unauthorized else: return file elif 'OG4-Afectat' in roles: if (self.context.visiblefile and self.context.hiddenfile): if self.fieldname == 'visiblefile': return file else: raise Unauthorized if (self.context.hiddenfile): raise Unauthorized if (self.context.visiblefile): return file else: raise Unauthorized
def canViewPunt(self, item): # Permissions to view PUNTS self.context = item roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True estatSessio = utils.session_wf_state(self) organ_tipus = self.context.organType if organ_tipus == 'open_organ': if estatSessio == 'planificada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada': return True elif estatSessio == 'realitzada': return True elif estatSessio == 'tancada': return True elif estatSessio == 'en_correccio': return True else: return False if organ_tipus == 'restricted_to_members_organ': if estatSessio == 'planificada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'realitzada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'tancada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'en_correccio' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True else: return False if organ_tipus == 'restricted_to_affected_organ': if estatSessio == 'planificada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'realitzada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): return True elif estatSessio == 'tancada' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): return True elif estatSessio == 'en_correccio' and utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): return True else: return False
def canView(self): # Permissions to view ACORDS. Poden estar a 1 i 2 nivells # If manager Show all roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True estatSessio = utils.session_wf_state(self) organ_tipus = self.context.organType if organ_tipus == 'open_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada': return True elif estatSessio == 'realitzada': return True elif estatSessio == 'tancada': return True elif estatSessio == 'en_correccio': return True else: raise Unauthorized if organ_tipus == 'restricted_to_members_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'realitzada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'tancada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'en_correccio' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True else: raise Unauthorized if organ_tipus == 'restricted_to_affected_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): return True elif estatSessio == 'convocada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): return True elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True elif estatSessio == 'tancada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True elif estatSessio == 'en_correccio' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True else: raise Unauthorized
def viewReserved(self): """ Cuando se muestra la parte privada del FICHERO """ roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True organ_tipus = self.context.organType if self.context.visiblefile and self.context.hiddenfile: if organ_tipus == 'open_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_members_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_affected_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif self.context.hiddenfile: if organ_tipus == 'open_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_members_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_affected_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif self.context.visiblefile: if organ_tipus == 'open_organ': return True else: if not self.context.visiblefile and not self.context.hiddenfile: return None else: raise Unauthorized
def viewDocumentPublic(self): """ Cuando se muestra la parte pública del documento """ roles = utils.getUserRoles(self, self.context, api.user.get_current().id) if 'Manager' in roles: return True organ_tipus = self.context.organType if self.context.defaultContent and self.context.alternateContent: if organ_tipus == 'open_organ': if utils.checkhasRol( ['OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): return False else: return True elif organ_tipus == 'restricted_to_members_organ': if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor'], roles): return True else: return False elif organ_tipus == 'restricted_to_affected_organ': if utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor', 'OG4-Afectat'], roles): return True else: return False elif self.context.alternateContent: if organ_tipus == 'open_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_members_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_affected_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif self.context.defaultContent: if organ_tipus == 'open_organ': return True elif organ_tipus == 'restricted_to_members_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): return True else: return False elif organ_tipus == 'restricted_to_affected_organ': if utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): return True else: return False else: raise Unauthorized
def customBuildFolderTree(context, obj=None, query={}, strategy=NavtreeStrategyBase()): """ """ from plone import api from genweb.organs import utils as utilsOrgans portal_url = getToolByName(context, 'portal_url') portal_catalog = api.portal.get_tool(name='portal_catalog') showAllParents = strategy.showAllParents rootPath = strategy.rootPath request = getattr(context, 'REQUEST', {}) # Find the object's path. Use parent folder if context is a default-page objPath = None objPhysicalPath = None if obj is not None: objPhysicalPath = obj.getPhysicalPath() if utils.isDefaultPage(obj, request): objPhysicalPath = objPhysicalPath[:-1] objPath = '/'.join(objPhysicalPath) portalPath = portal_url.getPortalPath() portalObject = portal_url.getPortalObject() # Calculate rootPath from the path query if not set. if 'path' not in query: if rootPath is None: rootPath = portalPath query['path'] = rootPath elif rootPath is None: pathQuery = query['path'] if type(pathQuery) == StringType: rootPath = pathQuery else: # Adjust for the fact that in a 'navtree' query, the actual path # is the path of the current context if pathQuery.get('navtree', False): navtreeLevel = pathQuery.get('navtree_start', 1) if navtreeLevel > 1: navtreeContextPath = pathQuery['query'] navtreeContextPathElements = navtreeContextPath[len(portalPath) + 1:].split('/') # Short-circuit if we won't be able to find this path if len(navtreeContextPathElements) < (navtreeLevel - 1): return {'children': []} rootPath = portalPath + '/' + '/'.join(navtreeContextPathElements[:navtreeLevel - 1]) else: rootPath = portalPath else: rootPath = pathQuery['query'] rootDepth = len(rootPath.split('/')) # Determine if we need to prune the root (but still force the path to) # the parent if necessary pruneRoot = False if strategy is not None: rootObject = portalObject.unrestrictedTraverse(rootPath, None) if rootObject is not None: pruneRoot = not strategy.showChildrenOf(rootObject) # Allow the strategy to suppliment the query for keys not already # present in the query such as sorting and omitting default pages for key, value in strategy.supplimentQuery.iteritems(): if key not in query: query[key] = value results2 = portal_catalog.searchResults(query) results = [] from plone import api if api.user.is_anonymous(): username = None else: username = api.user.get_current().id for value in results2: if value.portal_type == 'genweb.organs.organgovern': organ = value.getObject() if username: roles = api.user.get_roles(obj=organ, username=username) else: roles = [] organType = organ.organType if 'Manager' in roles or (organType == 'open_organ'): results.append(value) elif organType == 'restricted_to_members_organ': if utilsOrgans.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat'], roles): results.append(value) elif organType == 'restricted_to_affected_organ': if utilsOrgans.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): results.append(value) else: # remove element continue else: results.append(value) # We keep track of a dict of item path -> node, so that we can easily # find parents and attach children. If a child appears before its # parent, we stub the parent node. # This is necessary because whilst the sort_on parameter will ensure # that the objects in a folder are returned in the right order relative # to each other, we don't know the relative order of objects from # different folders. So, if /foo comes before /bar, and /foo/a comes # before /foo/b, we may get a list like (/bar/x, /foo/a, /foo/b, /foo, # /bar,). itemPaths = {} # Add an (initially empty) node for the root itemPaths[rootPath] = {'children': []} # If we need to "prune" the parent (but still allow showAllParent to # force some children), do so now if pruneRoot: itemPaths[rootPath]['_pruneSubtree'] = True def insertElement(itemPaths, item, forceInsert=False): """Insert the given 'item' brain into the tree, which is kept in 'itemPaths'. If 'forceInsert' is True, ignore node- and subtree- filters, otherwise any node- or subtree-filter set will be allowed to block the insertion of a node. """ itemPath = item.getPath() itemInserted = (itemPaths.get(itemPath, {}).get('item', None) is not None) # Short-circuit if we already added this item. Don't short-circuit # if we're forcing the insert, because we may have inserted but # later pruned off the node if not forceInsert and itemInserted: return itemPhysicalPath = itemPath.split('/') parentPath = '/'.join(itemPhysicalPath[:-1]) parentPruned = (itemPaths.get(parentPath, {}).get('_pruneSubtree', False)) # Short-circuit if we know we're pruning this item's parent # XXX: We could do this recursively, in case of parent of the # parent was being pruned, but this may not be a great trade-off # There is scope for more efficiency improvement here: If we knew we # were going to prune the subtree, we would short-circuit here each time. # In order to know that, we'd have to make sure we inserted each parent # before its children, by sorting the catalog result set (probably # manually) to get a breadth-first search. if not forceInsert and parentPruned: return isCurrent = isCurrentParent = False if objPath is not None: if objPath == itemPath: isCurrent = True elif objPath.startswith(itemPath + '/') and len(objPhysicalPath) > len(itemPhysicalPath): isCurrentParent = True relativeDepth = len(itemPhysicalPath) - rootDepth newNode = {'item': item, 'depth': relativeDepth, 'currentItem': isCurrent, 'currentParent': isCurrentParent, } insert = True if not forceInsert and strategy is not None: insert = strategy.nodeFilter(newNode) if insert: if strategy is not None: newNode = strategy.decoratorFactory(newNode) # Tell parent about this item, unless an earlier subtree filter # told us not to. If we're forcing the insert, ignore the # pruning, but avoid inserting the node twice if parentPath in itemPaths: itemParent = itemPaths[parentPath] if forceInsert: nodeAlreadyInserted = False for i in itemParent['children']: if i['item'].getPath() == itemPath: nodeAlreadyInserted = True break if not nodeAlreadyInserted: itemParent['children'].append(newNode) elif not itemParent.get('_pruneSubtree', False): itemParent['children'].append(newNode) else: itemPaths[parentPath] = {'children': [newNode]} # Ask the subtree filter (if any), if we should be expanding this node if strategy.showAllParents and isCurrentParent: # If we will be expanding this later, we can't prune off children now expand = True else: expand = getattr(item, 'is_folderish', True) if expand and (not forceInsert and strategy is not None): expand = strategy.subtreeFilter(newNode) children = newNode.setdefault('children', []) if expand: # If we had some orphaned children for this node, attach # them if itemPath in itemPaths: children.extend(itemPaths[itemPath]['children']) else: newNode['_pruneSubtree'] = True itemPaths[itemPath] = newNode # Add the results of running the query for r in results: insertElement(itemPaths, r) # If needed, inject additional nodes for the direct parents of the # context. Note that we use an unrestricted query: things we don't normally # have permission to see will be included in the tree. if strategy.showAllParents and objPath is not None: objSubPathElements = objPath[len(rootPath) + 1:].split('/') parentPaths = [] haveNode = (itemPaths.get(rootPath, {}).get('item', None) is None) if not haveNode: parentPaths.append(rootPath) parentPath = rootPath for i in range(len(objSubPathElements)): nodePath = rootPath + '/' + '/'.join(objSubPathElements[:i + 1]) node = itemPaths.get(nodePath, None) # If we don't have this node, we'll have to get it, if we have it # but it wasn't connected, re-connect it if node is None or 'item' not in node: parentPaths.append(nodePath) else: nodeParent = itemPaths.get(parentPath, None) if nodeParent is not None: nodeAlreadyInserted = False for i in nodeParent['children']: if i['item'].getPath() == nodePath: nodeAlreadyInserted = True break if not nodeAlreadyInserted: nodeParent['children'].append(node) parentPath = nodePath # If we were outright missing some nodes, find them again if len(parentPaths) > 0: query = {'path': {'query': parentPaths, 'depth': 0}} results = portal_catalog.unrestrictedSearchResults(query) for r in results: insertElement(itemPaths, r, forceInsert=True) # Return the tree starting at rootPath as the root node. return itemPaths[rootPath]
def allAcords(self): results = api.content.find(portal_type='genweb.organs.acord') results2 = [] results3 = [] if api.user.is_anonymous(): username = None else: username = api.user.get_current().id for value in results: element = value.getObject() if element.aq_parent.aq_parent.portal_type == 'genweb.organs.organgovern': if username: roles = api.user.get_roles(obj=element.aq_parent.aq_parent, username=username) else: roles = [] organ_tipus = element.organType estatSessio = api.content.get_state(obj=element.aq_parent) if organ_tipus == 'open_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): results2.append(value) elif estatSessio == 'convocada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'tancada': results2.append(value) elif estatSessio == 'en_correccio': results2.append(value) else: continue if organ_tipus == 'restricted_to_members_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): results2.append(value) elif estatSessio == 'convocada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'tancada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'en_correccio' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) else: continue if organ_tipus == 'restricted_to_affected_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): results2.append(value) elif estatSessio == 'convocada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'tancada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'en_correccio' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) else: continue else: # remove element continue elif element.aq_parent.aq_parent.aq_parent.portal_type == 'genweb.organs.organgovern': if username: roles = api.user.get_roles( obj=element.aq_parent.aq_parent.aq_parent, username=username) else: roles = [] organ_tipus = element.organType estatSessio = api.content.get_state( obj=element.aq_parent.aq_parent) if organ_tipus == 'open_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): results2.append(value) elif estatSessio == 'convocada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'tancada': results2.append(value) elif estatSessio == 'en_correccio': results2.append(value) else: continue if organ_tipus == 'restricted_to_members_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): results2.append(value) elif estatSessio == 'convocada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'tancada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'en_correccio' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) else: continue if organ_tipus == 'restricted_to_affected_organ': if estatSessio == 'planificada' and utils.checkhasRol( ['OG1-Secretari', 'OG2-Editor'], roles): results2.append(value) elif estatSessio == 'convocada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'realitzada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'tancada' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) elif estatSessio == 'en_correccio' and utils.checkhasRol([ 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat' ], roles): results2.append(value) else: continue else: # remove element continue else: continue for value in results2: item = value.getObject() results3.append( dict( id=item.agreement, path=item.absolute_url(), estatsLlista=item.estatsLlista, color=self.getColor(item), title=item.Title(), )) return sorted(results3, key=itemgetter('id'), reverse=True)
def filesinside(self, item): portal_catalog = api.portal.get_tool(name='portal_catalog') session_path = '/'.join( self.context.getPhysicalPath()) + '/' + item['id'] values = portal_catalog.searchResults( portal_type=['genweb.organs.file', 'genweb.organs.document'], sort_on='getObjPositionInParent', path={ 'query': session_path, 'depth': 1 }) results = [] for obj in values: visibleUrl = '' hiddenUrl = '' hasPublic = hasPrivate = isGODocument = isGOFile = file = raw_content = listFile = False visibleUrl = obj.getObject().absolute_url() anonymous = api.user.is_anonymous() file = obj.getObject() if anonymous: if obj.portal_type == 'genweb.organs.file': classCSS = 'fa fa-file-pdf-o' abs_path = file.absolute_url_path() isGOFile = True if file.visiblefile and file.hiddenfile: hasPublic = True hasPrivate = False visibleUrl = file.absolute_url( ) + '/@@display-file/visiblefile/' + file.visiblefile.filename hiddenUrl = '' listFile = True elif file.visiblefile: hasPublic = True hasPrivate = False visibleUrl = file.absolute_url( ) + '/@@display-file/visiblefile/' + file.visiblefile.filename listFile = True hiddenUrl = '' if obj.portal_type == 'genweb.organs.document': classCSS = 'fa fa-file-text-o' abs_path = None isGODocument = True if file.alternateContent and file.defaultContent: hasPublic = True hasPrivate = False listFile = True raw_content = file.defaultContent elif file.defaultContent: hasPublic = True hasPrivate = False listFile = True raw_content = file.defaultContent if listFile: results.append( dict(title=obj.Title, path=abs_path, absolute_url=obj.getURL(), hasPublic=hasPublic, hasPrivate=hasPrivate, classCSS=classCSS, publicURL=visibleUrl, reservedURL=hiddenUrl, isGOFile=isGOFile, isGODocument=isGODocument, raw_content=raw_content, id=obj.id)) else: # user is validated username = api.user.get_current().id if obj.portal_type == 'genweb.organs.file': # Tractem els files i fiquem colors... isGOFile = True raw_content = None abs_path = file.absolute_url_path() roles = api.user.get_roles(username=username, obj=self.context) classCSS = 'fa fa-file-pdf-o' if file.visiblefile and file.hiddenfile: if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): hasPublic = False hasPrivate = True visibleUrl = '' hiddenUrl = file.absolute_url( ) + '/@@display-file/hiddenfile/' + file.hiddenfile.filename classCSS = 'fa fa-file-pdf-o text-success double-icon' elif 'OG4-Afectat' in roles: hasPublic = True hasPrivate = False visibleUrl = file.absolute_url( ) + '/@@display-file/visiblefile/' + file.visiblefile.filename hiddenUrl = '' classCSS = 'fa fa-file-pdf-o text-success' elif file.hiddenfile: if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): hasPublic = False hasPrivate = True visibleUrl = '' hiddenUrl = file.absolute_url( ) + '/@@display-file/hiddenfile/' + file.hiddenfile.filename classCSS = 'fa fa-file-pdf-o text-error' elif file.visiblefile: hasPublic = True hasPrivate = False visibleUrl = file.absolute_url( ) + '/@@display-file/visiblefile/' + file.visiblefile.filename hiddenUrl = '' classCSS = 'fa fa-file-pdf-o text-success' if obj.portal_type == 'genweb.organs.document': isGODocument = True abs_path = None roles = api.user.get_roles(username=username, obj=self.context) classCSS = 'fa fa-file-text-o' if file.alternateContent and file.defaultContent: if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): hasPublic = False hasPrivate = True raw_content = file.alternateContent classCSS = 'fa fa-file-text-o text-success double-icon' elif 'OG4-Afectat' in roles: hasPublic = True hasPrivate = False raw_content = file.defaultContent classCSS = 'fa fa-file-text-o text-success' elif file.defaultContent: if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): hasPublic = False hasPrivate = True raw_content = file.defaultContent classCSS = 'fa fa-file-text-o text-success' elif file.alternateContent: if utils.checkhasRol([ 'Manager', 'OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG5-Convidat' ], roles): hasPublic = False hasPrivate = True raw_content = file.alternateContent classCSS = 'fa fa-file-text-o text-error' results.append( dict(title=obj.Title, path=abs_path, absolute_url=obj.getURL(), hasPublic=hasPublic, hasPrivate=hasPrivate, classCSS=classCSS, publicURL=visibleUrl, reservedURL=hiddenUrl, isGOFile=isGOFile, isGODocument=isGODocument, raw_content=raw_content, id=obj.id)) return results
def results(self, query=None, batch=True, b_size=100, b_start=0, old=False): """ Get properly wrapped search results from the catalog. Everything in Plone that performs searches should go through this view. 'query' should be a dictionary of catalog parameters. """ if batch: query['b_start'] = b_start = int(b_start) query['b_size'] = b_size query = self.filter_query(query) if query['path'] == '/empty_path/': return {} query['sort_order'] = 'reverse' newresults = [] new_path = [] root_path = '/'.join(api.portal.get().getPhysicalPath()) # /998/govern lt = getToolByName(self, 'portal_languages') lang = lt.getPreferredLanguage() query_paths = [ root_path + '/' + lang + '/consell-de-govern/consell-de-govern/', root_path + '/' + lang + '/cs/ple-del-consell-social/', root_path + '/' + lang + '/claustre-universitari/claustre-universitari/'] username = api.user.get_current().id if root_path + '/not_anon_my_organs/' in query['path']: # Si no es anonim i ha enviat el check de "organs relacionats amb mi" # fem una cerca especial, amb un string que després eliminem if not api.user.is_anonymous(): results = [] values = api.content.find( portal_type=['genweb.organs.organgovern'], path=root_path + '/' + lang) for obj in values: organ = obj.getObject() all_roles = api.user.get_roles(username=username, obj=organ) roles = [o for o in all_roles if o in ['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat']] sessionpath = obj.getPath() if utils.checkhasRol(['OG1-Secretari', 'OG2-Editor', 'OG3-Membre', 'OG4-Afectat', 'OG5-Convidat'], roles): if type(query['path']) == str: query['path'] = sessionpath.split() else: query['path'].append(sessionpath) elif type(query['path']) == str: if query['path'] not in query_paths: return None else: for value in query['path']: if value not in query_paths: return None if query['latest_session']: if isinstance(query['path'], list): for organ in query['path']: session_path = api.content.find( path=organ, portal_type='genweb.organs.sessio', sort_on='created', sort_order='reverse') if session_path: new_path.append(session_path[0].getPath()) if isinstance(query['path'], str): session_path = api.content.find( path=query['path'], portal_type='genweb.organs.sessio', sort_on='created', sort_order='reverse') if session_path: new_path.append(session_path[0].getPath()) query['path'] = new_path # Make default view return 0 results if 'SearchableText' not in query: # La primera vez, sin seleccionar nada, están marcados todos los elementos # Hacemos el check con el Folder if 'Folder' in query['portal_type']: return None if 'genweb.organs.punt' in query['portal_type']: query['portal_type'].append('genweb.organs.subpunt') if query is None: return None else: catalog = api.portal.get_tool(name='portal_catalog') try: # for all acords or punts results = catalog(**query) all_results = [] for res in results: all_results.append(res) # for subjects aux_subject_res = catalog.searchResults(portal_type=query['portal_type'], Subject=query['SearchableText'].replace('*', '')) for res in aux_subject_res: if res not in all_results: all_results.append(res) # for documents ptype = query['portal_type'] query_docs = query query_docs['portal_type'] = "genweb.organs.document" aux_doc_res = catalog(**query_docs) for res in aux_doc_res: obj = res.getObject() parent = obj.getParentNode() if parent.portal_type in ptype: if parent not in all_results: p_brain = catalog.searchResults(portal_type=ptype, id=parent.id)[0] all_results.append(p_brain) for res in all_results: item = res.getObject() if item.portal_type == "genweb.organs.document": item = item.getParentNode() if item.portal_type == 'genweb.organs.punt': if permissions.canViewPunt(self, item): newresults.append(res) if item.portal_type == 'genweb.organs.subpunt': if permissions.canViewSubpunt(self, item): newresults.append(res) if item.portal_type == 'genweb.organs.acord': if permissions.canViewAcord(self, item): newresults.append(res) except ParseError: return [] # Old documents if old: genweborgansegg = pkg_resources.get_distribution('genweb.organs') docs_1315 = open('{}/genweb/organs/2013-2015.json'.format(genweborgansegg.location)) docs_9613 = open('{}/genweb/organs/1996-2013.json'.format(genweborgansegg.location)) data = json.loads(docs_1315.read()) data2 = json.loads(docs_9613.read()) old_results = [] for d in data: if query['SearchableText'].replace('*', '') in d['title']: if isinstance(query['path'], str): if str(d['unitat']).lower().replace(' ', '-') in query['path']: old_results.append(d) else: for path in query['path']: if str(d['unitat']).lower().replace(' ', '-') in path: old_results.append(d) for d in data2: if query['SearchableText'].replace('*', '') in str(d['text']): old_results.append(d) if batch: old_results = Batch(old_results, b_size, b_start) if 'created' not in query: return old_results else: return [] results = IContentListing(newresults) if batch: results = Batch(results, b_size, b_start) return results