def create_tree(userid): pm = api.portal.get_tool(name='portal_membership') root = pm.getHomeFolder(userid) if root is None: pm.createMemberarea(member_id=userid) root = pm.getHomeFolder(userid) if root is None:return id = 'workspace' try: wk = root[id] except: wk = None if wk != None:return # bypass permission check old_sm = getSecurityManager() portal = api.portal.get() tmp_user = UnrestrictedUser(old_sm.getUser().getId(),'', ['Manager'],'') tmp_user = tmp_user.__of__(portal.acl_users) newSecurityManager(None, tmp_user) title = u'个人工作区'.encode("utf-8") item = api.content.create(type='emc.memberArea.workspace',id=id,title=title,container=root) chown(item,userid) root = root['workspace'] # id = 'myfolder' # title = u'个人网盘'.encode("utf-8") # item = api.content.create(type='emc.memberArea.myfolder',id=id,title=title,container=root) # chown(item,userid) id = 'todo' title = u'代办事宜'.encode("utf-8") item = api.content.create(type='emc.memberArea.todo',id=id,title=title,container=root) chown(item,userid) id = 'favorite' title = u'我的收藏'.encode("utf-8") item = api.content.create(type='emc.memberArea.favorite',id=id,title=title,container=root) chown(item,userid) id = 'messagebox' title = u'个人信箱'.encode("utf-8") item = api.content.create(type='emc.memberArea.messagebox',id=id,title=title,container=root) chown(item,userid) root = root['messagebox'] id = "inputbox" title = u'收件箱'.encode("utf-8") item = api.content.create(type='emc.memberArea.inputbox',id=id,title=title,container=root) chown(item,userid) id = "outputbox" title = u'发件箱'.encode("utf-8") item = api.content.create(type='emc.memberArea.outputbox',id=id,title=title,container=root) chown(item,userid) # recover old sm setSecurityManager(old_sm) return
def create_messagebox(obj,event): """创建个人信箱""" pm = getToolByName(obj,'portal_membership') root = pm.getHomeFolder(pm.getAuthenticatedMember().getId()) if root is None: return # bypass permission check old_sm = getSecurityManager() portal = api.portal.get() tmp_user = UnrestrictedUser(old_sm.getUser().getId(),'', ['Manager'],'') tmp_user = tmp_user.__of__(portal.acl_users) newSecurityManager(None, tmp_user) id = 'workspace' fd = createContentInContainer(root,"emc.memberArea.workspace",checkConstraints=False,id=id) fd.title = u'个人工作区'.encode("utf-8") id = 'mentionmefolder' item = createContentInContainer(fd,"emc.kb.mentionmefolder",checkConstraints=False,id=id) item.title = '和我相关' item.reindexObject() id = 'feedsfolder' item = createContentInContainer(fd,"emc.kb.feedsfolder",checkConstraints=False,id=id) item.title = '系统通知' item.reindexObject() id = 'messagebox' item = createContentInContainer(fd,"emc.memberArea.messagebox",checkConstraints=False,id=id) item.title = u'个人信箱'.encode("utf-8") item.reindexObject() inputbox = createContentInContainer(item,"emc.memberArea.inputbox",checkConstraints=False,id="inputbox") # inputbox.id = "inputbox" inputbox.title = u'收件箱'.encode("utf-8") inputbox.reindexObject() outputbox = createContentInContainer(item,"emc.memberArea.outputbox",checkConstraints=False,id="outputbox") # outputbox.id = "outputbox" outputbox.title = u'发件箱'.encode("utf-8") outputbox.reindexObject() id = 'myfolder' item = createContentInContainer(fd,"emc.memberArea.myfolder",checkConstraints=False,id=id) item.title = u'个人网盘'.encode("utf-8") item.reindexObject() id = 'todo' item = createContentInContainer(fd,"emc.memberArea.todo",checkConstraints=False,id=id) item.title = u'代办事宜'.encode("utf-8") item.reindexObject() id = 'favorite' item = createContentInContainer(fd,"emc.memberArea.favorite",checkConstraints=False,id=id) item.title = u'我的收藏'.encode("utf-8") item.reindexObject() # recover old sm setSecurityManager(old_sm)
def create_messagebox(obj,event): """创建个人信箱""" pm = getToolByName(obj,'portal_membership') root = pm.getHomeFolder(pm.getAuthenticatedMember().getId()) if root is None: return # bypass permission check old_sm = getSecurityManager() portal = api.portal.get() tmp_user = UnrestrictedUser(old_sm.getUser().getId(),'', ['Manager'],'') tmp_user = tmp_user.__of__(portal.acl_users) newSecurityManager(None, tmp_user) id = 'workspace' fd = createContentInContainer(root,"emc.memberArea.workspace",checkConstraints=False,id=id) fd.title = u'个人工作区'.encode("utf-8") id = 'messagebox' item = createContentInContainer(fd,"emc.memberArea.messagebox",checkConstraints=False,id=id) item.title = u'个人信箱'.encode("utf-8") item.reindexObject() inputbox = createContentInContainer(item,"emc.memberArea.inputbox",checkConstraints=False,id="inputbox") # inputbox.id = "inputbox" inputbox.title = u'收件箱'.encode("utf-8") inputbox.reindexObject() outputbox = createContentInContainer(item,"emc.memberArea.outputbox",checkConstraints=False,id="outputbox") # outputbox.id = "outputbox" outputbox.title = u'发件箱'.encode("utf-8") outputbox.reindexObject() id = 'myfolder' item = createContentInContainer(fd,"emc.memberArea.myfolder",checkConstraints=False,id=id) item.title = u'个人网盘'.encode("utf-8") item.reindexObject() id = 'todo' item = createContentInContainer(fd,"emc.memberArea.todo",checkConstraints=False,id=id) item.title = u'代办事宜'.encode("utf-8") item.reindexObject() id = 'favorite' item = createContentInContainer(fd,"emc.memberArea.favorite",checkConstraints=False,id=id) item.title = u'我的收藏'.encode("utf-8") item.reindexObject() # recover old sm setSecurityManager(old_sm)
def dispatch_message(obj,event): """This handler will deliver message to incoming box of receivers""" receivers = obj.sendto # bypass permission check old_sm = getSecurityManager() tmp_user = UnrestrictedUser(old_sm.getUser().getId(),'', ['Manager'],'') portal = api.portal.get() tmp_user = tmp_user.__of__(portal.acl_users) newSecurityManager(None, tmp_user) for i in receivers: inputbox = get_personal_inputbox_byid(obj,i) api.content.copy(source=obj, target=inputbox) id = obj.id # message init state is unreaded status # api.content.transition(obj=inputbox[id], transition='undo') inputbox[id].reindexObject() # recover old sm setSecurityManager(old_sm)
def create_todoitem(event): """创建个人代办事项""" # fetch parameters of the event instance title = event.title userid = event.userid sender = event.sender sender = api.user.get(userid=sender).fullname or sender description = u"消息来自于:".encode("utf-8") description = "%s%s" % (description, sender) text = event.text # import pdb # pdb.set_trace() todofolder = get_personal_todo_container_byid(userid) if todofolder is None: return # bypass permission check old_sm = getSecurityManager() portal = api.portal.get() tmp_user = UnrestrictedUser(old_sm.getUser().getId(), '', ['Manager'], '') tmp_user = tmp_user.__of__(portal.acl_users) newSecurityManager(None, tmp_user) # todoitem will be created in "${homefolder}/workspace/todo" container #todoitem's id rules:fetch parent object's total,turn into string total = str(int(getattr(todofolder, 'todoitems', '0')) + 1) id = '%s' % total todofolder.todoitems = id # import pdb # pdb.set_trace() todoitem = api.content.create(type="emc.memberArea.todoitem", title=title, description=description, id=id, container=todofolder) todoitem.text = RichTextValue(text, 'text/html', 'text/html') chown(todoitem, userid) # recover old sm setSecurityManager(old_sm)