# -*- coding: utf-8 # $Id$ # # Copyright 2001, 2002 by IVA Team and contributors # # This file is part of IVA. # # IVA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # IVA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Contains class WebtopLink, which represents a URL stored in a user's webtop.""" __version__ = "$Revision$"[11:-2] from common import intersect_bool from WebtopItem import WebtopItem from Cruft import Cruft # for find_URL_of_fle_root() from AccessControl import ClassSecurityInfo from AccessControl.PermissionRole import rolesForPermissionOn import OFS #from Globals import Persistent, HTMLFile import Globals from common import perm_view, perm_edit, perm_manage, perm_add_lo, \ get_roles, course_level_roles class WebtopLink( WebtopItem,OFS.SimpleItem.Item, Globals.Persistent, Cruft): """A link in a Webtop.""" meta_type = "WebtopLink" security = ClassSecurityInfo() def __init__(self, parent, name, url_or_obj, internal=0): """Construct the webtop link object, either to a URL or to another ZObject.""" WebtopItem.__init__(self,parent,name) self.__is_internal=internal if internal: if type(url_or_obj)!=type(''): #url_or_obj = self.get_object_of_url(url_or_obj,parent) url_or_obj = self.get_url_to_object(url_or_obj) #url_or_obj = self.restrictedTraverse(url_or_obj) #path = url.split('/') #path.pop() # drop last entry (usually 'index_html') #if path[0]=='http:': # remove protocol # url='/'+'/'.join(path[3:])+'/' #self.__internal_link=url_or_obj self.set_icon('images/type_link.gif') else: self.set_icon('images/type_external.gif') self.set_icon('images/link_gif.gif') self.__url=url_or_obj security.declarePrivate('manage_afterAdd') def manage_afterAdd(self,item,container): """Clean up creation - create the TempObjectManager and set permissions.""" #TempObjectManager.manage_afterAdd(self, item, container) WebtopItem.manage_afterAdd(self, item, container) security.declarePrivate('get_obj') def get_obj_ref(self): if not self.__is_internal: return None #return self.__internal_link return self.get_object_of_url(self.__url, self) ## path=self.__url.split('/') ## path.pop() # remove last entry ## path.reverse() ## path.pop() # remove first (root) entry ## obj = self.getPhysicalRoot() ## while path: ## oname=path.pop() ## obj=getattr(obj,oname).__of__(obj) ## return obj def index_html(self, REQUEST): """ index html """ self.viewedObject(REQUEST, self.getRelativeURL(self)) return REQUEST.RESPONSE.redirect(self.__url) security.declareProtected(perm_view, 'get_url') def get_url(self): """Returns the url contained in the link.""" return self.__url ## if self.__is_internal: ## return self.get_url_to_object(self.__internal_link) ## else: ## return self.__url # for ZCatalog security.declarePrivate('get_content') def get_content(self): """Return content (url)of the link.""" return self.get_url() security.declareProtected(perm_view, 'is_internal_link') def is_internal_link(self, REQUEST=None): """Return whether URL points inside FLE""" return self.__is_internal security.declareProtected(perm_view, 'may_follow_link') def may_follow_link(self, REQUEST): """Return whether current user has view access to place pointed by link.""" if not self.is_internal_link(): return 1 object = self.get_obj_ref() if not object: return 0 # Figure out which roles user has on a course person = str(REQUEST.AUTHENTICATED_USER) actual_roles = get_roles(object,person) valid_roles = course_level_roles return intersect_bool(actual_roles, valid_roles) security.declareProtected(perm_view, 'get_size') def get_size(self): """Return size of the object.""" return len(self.__url) Globals.InitializeClass(WebtopLink) # EOF