def new(self): "Displays a generic form for creating a new object" context = HttpContext.current() sCC = context.request.queryString['cc'][0] oNewItem = misc.getCallableByName(sCC)() params = { 'CC': sCC, 'URI': context.request.getRootUrl() + '/' + self.id, 'ICON': oNewItem.__image__, 'PROPERTIES_TAB': '', 'EXTRA_TABS': '', 'SECURITY_TAB': baseitem._getSecurity(self, context.user, True) } # inspect item properties sProperties = '' for attr_name in oNewItem.__props__: attr = getattr(oNewItem, attr_name) if isinstance(attr, datatypes.DataType): control, tab = baseitem._getControlFromAttribute(oNewItem, attr_name, attr, False, True) sProperties += control params['EXTRA_TABS'] += tab params['PROPERTIES'] = sProperties return params
def update(self, data): "Updates an object based on values contained inside the data dictionary" context = HttpContext.current() # get user role iUserRole = objectAccess.getAccess(self, context.user) if data.has_key('__rolesinherited') and iUserRole == objectAccess.COORDINATOR: self.inheritRoles = data.pop('__rolesinherited') if not self.inheritRoles: acl = data.pop('__acl') if acl: security = {} for descriptor in acl: security[descriptor['id']] = int(descriptor['role']) self.security = security for prop in data: oAttr = getattr(self, prop) if isinstance(oAttr, datatypes.File): # see if the user has uploaded a new file if data[prop]['tempfile']: oAttr.filename = data[prop]['filename'] sPath = context.server.temp_folder + '/' + data[prop]['tempfile'] oAttr.loadFromFile(sPath) elif isinstance(oAttr, datatypes.Date): oAttr.value = data[prop].value elif isinstance(oAttr, datatypes.Integer): oAttr.value = int(data[prop]) else: oAttr.value = data[prop] txn = db.getTransaction() self.update(txn) return True
def selectobjects(self): "Displays the select objects dialog" context = HttpContext.current() sCC = context.request.queryString['cc'][0] params = { 'ID': self.id or '/', 'IMG': self.__image__, 'DN': self.displayName.value, 'HAS_SUBFOLDERS': str(self.hasSubfolders()).lower(), 'MULTIPLE': context.request.queryString['multiple'][0], 'CC': sCC } oCmd = OqlCommand() sOql = "select * from '%s'" % self.id if sCC != '*': ccs = sCC.split('|') ccs = ["contentclass='%s'" % x for x in ccs] sConditions = " or ".join(ccs) sOql += " where %s" % sConditions oRes = oCmd.execute(sOql) sOptions = '' for obj in oRes: sOptions += '<option img="%s" value="%s" caption="%s"/>' % \ (obj.__image__, obj.id, obj.displayName.value) params['OPTIONS'] = sOptions return params
def applySettings(self, data): "Saves user's preferences" context = HttpContext.current() activeUser = context.original_user for key in data: activeUser.settings.value[key] = data[key] txn = db.get_transaction() activeUser.update(txn) return True
def rename(self): "Displays the rename dialog" context = HttpContext.current() context.response.setHeader('cache-control', 'no-cache') return { 'TITLE': self.displayName.value, 'ID': self.id, 'DN': self.displayName.value, }
def login(self, username, password): "Remote method for authenticating users" http_context = HttpContext.current() users_container = db.getItem("users") user = users_container.getChildByName(username) if user and hasattr(user, "authenticate"): if user.authenticate(password): http_context.session.user = user return True return False
def login(self, username, password): "Remote method for authenticating users" http_context = HttpContext.current() users_container = db.get_item('users') user = users_container.get_child_by_name(username) if user and hasattr(user, 'authenticate'): if user.authenticate(password): http_context.session.userid = user.id return True return False
def new(self): "Displays the form for creating a new application" context = HttpContext.current() oApp = common.Application() return { 'CC': oApp.contentclass, 'URI': self.id, 'ICON': oApp.__image__, 'SECURITY_TAB': baseitem._getSecurity(self, context.user, True) }
def new(self): context = HttpContext.current() oGroup = security.Group() return { 'CC' : oGroup.contentclass, 'URI' : self.id, 'REL_CC' : '|'.join(oGroup.members.relCc), 'ICON' : oGroup.__image__, 'SELECT_FROM_POLICIES' : 'policies', 'POLICIES_REL_CC' : '|'.join(oGroup.policies.relCc), 'SECURITY_TAB' : baseitem._getSecurity(self, context.user, True) }
def properties(self): "Displays the deleted item's properties form" context = HttpContext.current() sLang = context.request.getLang() modified = date.Date(self.modified) return { "ICON": self.__image__, "NAME": xml.xml_encode(self.originalName), "LOC": xml.xml_encode(self.originalLocation), "MODIFIED": modified.format(baseitem.DATES_FORMAT, sLang), "MODIFIED_BY": xml.xml_encode(self.modifiedBy), "CONTENTCLASS": self.get_deleted_item().contentclass, }
def properties(self): "Displays the deleted item's properties form" context = HttpContext.current() sLang = context.request.getLang() modified = date.Date(self.modified) return { 'ICON': self.__image__, 'NAME': self.originalName, 'LOC': self.originalLocation, 'MODIFIED': modified.format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY': self.modifiedBy, 'CONTENTCLASS': self.getDeletedItem().contentclass }
def upload(self, chunk, fname): context = HttpContext.current() chunk = base64.decodestring(chunk) if not fname: fileno, fname = context.session.getTempFile() os.write(fileno, chunk) os.close(fileno) fname = os.path.basename(fname) else: tmpfile = file(context.server.temp_folder + '/' + fname, 'ab+') tmpfile.write(chunk) tmpfile.close() return fname
def new(self): "Displays the form for creating a new user" context = HttpContext.current() oUser = security.User() return { 'CC' : oUser.contentclass, 'URI' : self.id, 'REL_CC' : '|'.join(oUser.memberof.relCc), 'ICON' : oUser.__image__, 'SELECT_FROM_POLICIES' : 'policies', 'POLICIES_REL_CC' : '|'.join(oUser.policies.relCc), 'SECURITY_TAB' : baseitem._getSecurity(self, context.user, True) }
def user_settings(self): "Displays the user settings dialog" context = HttpContext.current() context.response.setHeader("cache-control", "no-cache") settings = context.session.user.settings taskbar_pos = settings.value.setdefault("TASK_BAR_POS", "bottom") params = {"TASK_BAR_POS": taskbar_pos} if taskbar_pos == "bottom": params["CHECKED_TOP"] = "false" params["CHECKED_BOTTOM"] = "true" else: params["CHECKED_TOP"] = "true" params["CHECKED_BOTTOM"] = "false" autoRun = settings.value.setdefault("AUTO_RUN", "") if settings.value.setdefault("RUN_MAXIMIZED", False) == True: params["RUN_MAXIMIZED_VALUE"] = "true" else: params["RUN_MAXIMIZED_VALUE"] = "false" # get applications oCmd = OqlCommand() sOql = "select displayName,launchUrl,icon from 'apps' " + "order by displayName asc" apps = oCmd.execute(sOql) sSelected = "" if autoRun == "": sSelected = "true" sApps = '<option caption="@@NONE_APP@@" selected="%s" value=""/>' % sSelected if len(apps) > 0: for app in apps: if autoRun == app["launchUrl"]: sSelected = "true" else: sSelected = "false" sApps += '<option img="%s" caption="%s" value="%s" selected="%s"/>' % ( app["icon"], app["displayName"], app["launchUrl"], sSelected, ) params["APPS"] = sApps return params
def selectcontainer(self): "Displays a dialog for selecting the destination container" context = HttpContext.current() rootFolder = db.getItem('') params = { 'ROOT_ID': '/', 'ROOT_IMG': rootFolder.__image__, 'ROOT_DN': rootFolder.displayName.value, 'ID': self.id, } sAction = context.request.queryString['action'][0] params['TITLE'] = '@@%s@@' % sAction.upper() if sAction != 'select_folder': params['TITLE'] += ' "%s"' % self.displayName.value return params
def user_settings(self): "Displays the user settings dialog" context = HttpContext.current() context.response.setHeader('cache-control', 'no-cache') settings = context.user.settings taskbar_pos = settings.value.setdefault('TASK_BAR_POS', 'bottom') params = {'TASK_BAR_POS' : taskbar_pos} if taskbar_pos == 'bottom': params['CHECKED_TOP'] = 'false' params['CHECKED_BOTTOM'] = 'true' else: params['CHECKED_TOP'] = 'true' params['CHECKED_BOTTOM'] = 'false' autoRun = settings.value.setdefault('AUTO_RUN', '') if settings.value.setdefault('RUN_MAXIMIZED', False) == True: params['RUN_MAXIMIZED_VALUE'] = 'true' else: params['RUN_MAXIMIZED_VALUE'] = 'false' # get applications oCmd = OqlCommand() sOql = "select displayName,launchUrl,icon from 'apps' " + \ "order by displayName asc" apps = oCmd.execute(sOql) sSelected = '' if autoRun == '': sSelected = 'true' sApps = '<option caption="@@NONE_APP@@" selected="%s" value=""/>' \ % sSelected if len(apps) > 0: for app in apps: if autoRun == app['launchUrl']: sSelected = 'true' else: sSelected = 'false' sApps += \ '<option img="%s" caption="%s" value="%s" selected="%s"/>' % \ (app['icon'], app['displayName'], app['launchUrl'], sSelected) params['APPS'] = sApps return params
def properties(self): "Displays the group's properties form" context = HttpContext.current() context.response.setHeader('cache-control', 'no-cache') sLang = context.request.getLang() user = context.user iUserRole = objectAccess.getAccess(self, user) readonly = (iUserRole==1) params = { 'ID' : self.id, 'ICON' : self.__image__, 'SELECT_FROM_POLICIES' : 'policies', 'POLICIES_REL_CC' : '|'.join(self.policies.relCc), 'NAME' : xml.xml_encode(self.displayName.value), 'DESCRIPTION' : xml.xml_encode(self.description.value), 'MODIFIED' : date.Date(self.modified).format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY' : xml.xml_encode(self.modifiedBy), 'CONTENTCLASS' : self.contentclass, 'SELECT_FROM' : self.parentid, 'REL_CC' : '|'.join(self.members.relCc), 'READONLY' : str(readonly).lower() } members_options = [] members = self.members.getItems() for user in members: members_options += [xml.xml_encode(user.__image__), user.id, xml.xml_encode(user.displayName.value)] params['MEMBERS'] = ';'.join(members_options) policies_options = [] policies = self.policies.getItems() for policy in policies: policies_options += [xml.xml_encode(policy.__image__), policy.id, xml.xml_encode(policy.displayName.value)] params['POLICIES'] = ';'.join(policies_options) params['SECURITY_TAB'] = baseitem._getSecurity(self, user) return params
def properties(self): "Displays the application's properties form" context = HttpContext.current() sLang = context.request.getLang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = (iUserRole == 1) modified = date.Date(self.modified) return { 'ID' : self.id, 'IMG' : self.__image__, 'NAME' : xml.xml_encode(self.displayName.value), 'DESCRIPTION' : xml.xml_encode(self.description.value), 'ICON' : self.icon.value, 'LAUNCH_URL' : xml.xml_encode(self.launchUrl.value), 'MODIFIED' : modified.format(baseitem.DATES_FORMAT, sLang), 'MODIFIED_BY' : xml.xml_encode(self.modifiedBy), 'CONTENTCLASS' : self.contentclass, 'SECURITY_TAB' : baseitem._getSecurity(self, context.user), 'READONLY' : str(readonly).lower() }
def properties(self): "Displays the group's properties form" context = HttpContext.current() sLang = context.request.getLang() user = context.user iUserRole = permsresolver.get_access(self, user) readonly = iUserRole == 1 params = { "ID": self.id, "ICON": self.__image__, "SELECT_FROM_POLICIES": "policies", "POLICIES_REL_CC": "|".join(self.policies.relCc), "NAME": xml.xml_encode(self.displayName.value), "DESCRIPTION": xml.xml_encode(self.description.value), "MODIFIED": date.Date(self.modified).format(baseitem.DATES_FORMAT, sLang), "MODIFIED_BY": xml.xml_encode(self.modifiedBy), "CONTENTCLASS": self.contentclass, "SELECT_FROM": self.parentid, "REL_CC": "|".join(self.members.relCc), "READONLY": str(readonly).lower(), } members_options = [] members = self.members.get_items() for user in members: members_options += [xml.xml_encode(user.__image__), user.id, xml.xml_encode(user.displayName.value)] params["MEMBERS"] = ";".join(members_options) policies_options = [] policies = self.policies.get_items() for policy in policies: policies_options += [xml.xml_encode(policy.__image__), policy.id, xml.xml_encode(policy.displayName.value)] params["POLICIES"] = ";".join(policies_options) params["SECURITY_TAB"] = baseitem._getSecurity(self, user) return params
def properties(self): "Displays a generic edit form based on the object's schema" context = HttpContext.current() context.response.setHeader('Cache-Control', 'no-cache') sLang = context.request.getLang() user = context.user iUserRole = objectAccess.getAccess(self, user) readonly = (iUserRole==1) modified = date.Date(self.modified) params = { 'ID': self.id, 'ICON': self.__image__, 'NAME': xml.xml_encode(self.displayName.value), 'MODIFIED': modified.format(DATES_FORMAT, sLang), 'MODIFIED_BY': xml.xml_encode(self.modifiedBy), 'CONTENTCLASS': self.contentclass, 'PROPERTIES_TAB': '', 'EXTRA_TABS': '', 'SECURITY_TAB': _getSecurity(self, context.user), 'UPDATE_DISABLED': str(readonly).lower() } # inspect item properties sProperties = '' for attr_name in self.__props__: attr = getattr(self, attr_name) if isinstance(attr, datatypes.DataType): control, tab = \ _getControlFromAttribute(self, attr_name, attr, readonly) sProperties += control params['EXTRA_TABS'] += tab params['PROPERTIES'] = sProperties return params
def create(self, data): "Creates a new item" context = HttpContext.current() oNewItem = misc.getCallableByName(data.pop('CC'))() # get user role iUserRole = objectAccess.getAccess(self, context.session.user) if data.has_key('__rolesinherited') and iUserRole == objectAccess.COORDINATOR: oNewItem.inheritRoles = data.pop('__rolesinherited') if not oNewItem.inheritRoles: acl = data.pop('__acl') if acl: security = {} for descriptor in acl: security[descriptor['id']] = int(descriptor['role']) oNewItem.security = security # set props for prop in data: oAttr = getattr(oNewItem, prop) if isinstance(oAttr, datatypes.File): if data[prop]['tempfile']: oAttr.filename = data[prop]['filename'] sPath = context.server.temp_folder + '/' + data[prop]['tempfile'] oAttr.loadFromFile(sPath) os.remove(sPath) elif isinstance(oAttr, datatypes.Date): oAttr.value = data[prop].value elif isinstance(oAttr, datatypes.Integer): oAttr.value = int(data[prop]) else: oAttr.value = data[prop] txn = db.getTransaction() oNewItem.appendTo(self, txn) txn.commit() return oNewItem.id
def getInfo(self): "Retutns info about the container's contents" context = HttpContext.current() sLang = context.request.getLang() lstChildren = [] children = self.getChildren() for child in children: obj = { 'id' : child.id, 'cc' : child.contentclass, 'image': child.__image__, 'displayName' : child.displayName.value, 'isCollection': child.isCollection, 'modified': date.Date(child.modified) } if hasattr(child, 'size'): obj['size'] = child.size lstChildren.append(obj) containment = [] for contained in self.containment: image = misc.getCallableByName(contained).__image__ if not type(image) == str: image = '' localestring = resources.getResource(contained, sLang) containment.append( [localestring, contained, image] ) return { 'displayName' : self.displayName.value, 'path' : misc.getFullPath(self), 'parentid' : self.parentid, 'iscollection' : self.isCollection, 'containment' : containment, 'user_role' : objectAccess.getAccess(self, context.user), 'contents' : lstChildren }
def about(self): "Displays the about dialog" context = HttpContext.current() return {'VERSION': context.server.version}
def login(self): "Displays the login page" return { 'URI': HttpContext.current().request.SCRIPT_NAME or '.' }
def loginas(self): "Displays the login as dialog" return { 'URI': HttpContext.current().request.SCRIPT_NAME + '/?cmd=login' }
def list(self): "Displays the recycle bin's window" context = HttpContext.current() context.response.setExpiration(1200) return {'ID' : self.id}
def properties(self): "Displays a generic edit form based on the object's schema" context = HttpContext.current() rootUrl = context.request.getRootUrl() context.response.redirect('%s/%s?cmd=properties' % (rootUrl, self.target.value))
def logoff(self): context = HttpContext.current() context.session.terminate() return True
def __blank__(self): "Displays the browser not supported HTML page" return { 'USER_AGENT' : HttpContext.current().request.HTTP_USER_AGENT }
def __blank__(self): "Displays the desktop" context = HttpContext.current() oUser = context.user params = { 'USER' : oUser.displayName.value, 'AUTO_RUN' : '', 'RUN_MAXIMIZED' : 0, 'SETTINGS_DISABLED' : '', 'LOGOFF_DISABLED' : '' } if hasattr(oUser, 'authenticate'): settings = oUser.settings params['AUTO_RUN'] = \ settings.value.setdefault('AUTO_RUN', '') params['RUN_MAXIMIZED'] = \ int(settings.value.setdefault('RUN_MAXIMIZED', False)) taskbar_position = \ settings.value.setdefault('TASK_BAR_POS', 'bottom') else: taskbar_position = 'bottom' params['SETTINGS_DISABLED'] = 'true' params['LOGOFF_DISABLED'] = 'true' params['REPOSITORY_DISABLED'] = 'true' params['PERSONAL_FOLDER'] = '' if hasattr(oUser, 'personalFolder'): params['REPOSITORY_DISABLED'] = 'false' params['PERSONAL_FOLDER'] = oUser.personalFolder.value # has the user access to recycle bin? rb_icon = '' rb = db.get_item('rb') if rb: rb_icon = ''' <icon top="80" left="10" width="80" height="80" imgalign="top" ondblclick="generic.openContainer" img="desktop/images/trashcan_full.gif" color="white" caption="%s"> <prop name="folderID" value="rb"></prop> </icon> ''' % rb.displayName.value desktop_pane = DESKSTOP_PANE % (self.displayName.value, rb_icon) if taskbar_position == 'bottom': params['TOP'] = desktop_pane params['BOTTOM'] = '' else: params['TOP'] = '' params['BOTTOM'] = desktop_pane # get applications oCmd = OqlCommand() sOql = "select launchUrl,displayName,icon from 'apps' " + \ "order by displayName asc" apps = oCmd.execute(sOql) sApps = '' if len(apps) > 0: for app in apps: sApps += '''<menuoption img="%s" caption="%s" onclick="generic.runApp"> <prop name="url" value="%s"></prop> </menuoption>''' % \ (app['icon'], app['displayName'], app['launchUrl']) params['APPS'] = sApps else: params['APPS'] = '<menuoption caption="@@EMPTY@@"' + \ ' disabled="true"></menuoption>' return params