def get_dashboard(self): write = False with api.env.adopt_roles(['Manager']): if 'dashboards' not in self.context.objectIds(): write = True api.content.create(type='Folder', title='Dashboards', id='dashboards', container=self.context, exclude_from_nav=True) dashboards = self.context['dashboards'] if not IHideFromBreadcrumbs.providedBy(dashboards): alsoProvides(dashboards, IHideFromBreadcrumbs) if api.content.get_state( obj=dashboards, default='Unknown') not in ('published', 'publish_internally'): write = True publish_content(dashboards) member = api.user.get_current() user_id = member.getId() if user_id not in dashboards.objectIds(): with api.env.adopt_roles(['Manager']): write = True # first make sure it is in allowed types... pts = api.portal.get_tool('portal_types') Folder = pts['Folder'] if 'Dashboard' not in Folder.allowed_content_types: allowed = list(Folder.allowed_content_types) allowed.append('Dashboard') Folder.allowed_content_types = tuple(allowed) aspect = ISelectableConstrainTypes(dashboards) if (aspect.getConstrainTypesMode() != 1 or ['Dashboard'] != aspect.getImmediatelyAddableTypes()): aspect.setConstrainTypesMode(1) aspect.setImmediatelyAddableTypes(['Dashboard']) api.content.create(type='Dashboard', title='Dashboard', id=user_id, container=dashboards, exclude_from_nav=True) dashboard = dashboards[user_id] if dashboard.getOwner().getId() != user_id: with api.env.adopt_roles(['Manager']): write = True dashboard.changeOwnership(member.getUser(), recursive=False) dashboard.reindexObjectSecurity() if write: alsoProvides(self.request, IDisableCSRFProtection) return dashboard
def handle_auto_folder_creation(self, folder, type_): # we only auto publish built-in repositories, otherwise, leave it be try: if api.content.get_state(obj=folder) not in ('published', 'publish_internally'): publish_content(folder) except WorkflowException: pass aspect = ISelectableConstrainTypes(folder, None) if (aspect and ( aspect.getConstrainTypesMode() != 1 or [type_] != aspect.getImmediatelyAddableTypes())): aspect.setConstrainTypesMode(1) try: aspect.setImmediatelyAddableTypes([type_]) except Exception: pass if not getattr(folder, 'exclude_from_nav', False): # if auto generated path, exclude from nav folder.exclude_from_nav = True folder.reindexObject()