Пример #1
0
    def deny_handler(self, targets, fields=None):
        assert len(targets) == 1
        proj_id = targets[0]

        if not self._apply_transition_to(proj_id, 'reject_by_owner'):
            return {}

        id_ = self.viewed_member_info['id']

        # there must be a better way to get the last wf transition which was an invite... right?
        wftool = self.get_tool("portal_workflow")
        team = self.get_tool("portal_teams").getTeamById(proj_id)
        mship = team.getMembershipByMemberId(id_)
        wf_id = wftool.getChainFor(mship)[0]
        wf_history = mship.workflow_history.get(wf_id)
        spurned_admin = [i for i in wf_history if i['review_state'] == 'pending'][-1]['actor']
        
        transient_msgs = ITransientMessage(self.portal)

        member_url = u'%s/%s' % (getToolByName(self.context, 'portal_url')(),
                                 member_path(id_))
        project_url = self.project_url(proj_id)
        msg = _(u'tmsg_decline_invite',
                u'<a href="${member_url}">${id}</a> has declined your invitation to join <a href="${project_url}">${proj_id}</a>',
                mapping={u'id':id_, u'project_url':project_url, u'proj_id':proj_id, u'member_url':member_url})
        transient_msgs.store(spurned_admin, "membership", msg)

        elt_id = '%s_invitation' % proj_id
        return ajax_update(elt_id, self.nupdates())
Пример #2
0
 def infomsgs(self):
     """info messages re project admission/rejection
     
        tuples are returned in the form of (idx, msg)
        so that they can be popped by the user"""
     # XXX explicit context shouldn't be req'd, but lookup fails
     # in the tests w/o it  :(
     tm = ITransientMessage(self.portal)
     mem_id = self.viewed_member_info['id']
     msgs = tm.get_msgs(mem_id, self.msg_category)
     return msgs
Пример #3
0
 def close_msg_handler(self, targets, fields=None):
     assert len(targets) == 1
     idx = targets[0]
     idx = int(idx)
     # XXX explicit context shouldn't be req'd, but lookup fails
     # in the tests w/o it  :(
     tm = ITransientMessage(self.portal)
     mem_id = self.viewed_member_info['id']
     try:
         tm.pop(mem_id, self.msg_category, idx)
     except KeyError:
         return {}
     else:
         elt_id = 'close_info_message_%s' % idx
         return ajax_update(elt_id, self.nupdates())
Пример #4
0
    def user_message_count(self):
        """
        returns the number of transient messages currently stored
        for the logged in member
        """
        mem_id = self.loggedinmember.getId()
        tm = ITransientMessage(self.portal)
        t_msgs = tm.get_all_msgs(mem_id)
        msg_count = sum([len(value) for key,value in t_msgs.iteritems() if not key == 'Trackback'])

        query = dict(portal_type='OpenMembership',
                     getId=mem_id,
                     )
        mship_brains = self.catalog(**query)
        proj_invites = [brain for brain in mship_brains if brain.review_state == 'pending' and brain.lastWorkflowActor != mem_id]
        
        return msg_count + len(proj_invites)
Пример #5
0
    def accept_handler(self, targets, fields=None):
        assert len(targets) == 1
        proj_id = targets[0]

        if not self._apply_transition_to(proj_id, 'approve_public'):
            return {}

        # security reindex (async to the catalog queue)
        team = self.get_tool('portal_teams').getTeamById(proj_id)
        team.reindexTeamSpaceSecurity()

        admin_ids = team.get_admin_ids()
        transient_msgs = ITransientMessage(self.portal)
        id_ = self.viewed_member_info['id']
        member_url = u'%s/%s' % (getToolByName(self.context, 'portal_url')(),
                                 member_path(id_))
        project_url = self.project_url(proj_id)
        msg = _(u'tmsg_joined_project',
                u'<a href="${member_url}">${id}</a> has joined <a href="${project_url}">${proj_id}</a>',
                mapping={u'id':id_, u'project_url':project_url, u'proj_id':proj_id, u'member_url':member_url})
        for mem_id in admin_ids:
            transient_msgs.store(mem_id, "membership", msg)
        
        projinfos = self.projects_for_user
        if len(projinfos) > 1:
            projinfo = self._get_projinfo_for_id(proj_id)
            new_proj_row = self.project_row(proj_id=proj_id, projinfo=projinfo)
            command = {'projinfos_for_user': {'action': 'append',
                                              'effects': 'highlight',
                                              'html': new_proj_row
                                              }}
        else:
            new_proj_table = self.project_table()
            command = {'project_table': {'action': 'replace',
                                         'html': new_proj_table
                                         }}

        elt_id = '%s_invitation' % proj_id
        
        command.update(ajax_update(elt_id, self.nupdates()))

        mship = team._getOb(id_)
        notify(JoinedProjectEvent(mship))

        return command
def main(app, zipfile, username):
    user = app.acl_users.getUser('admin')
    print "Changing stuff as user", user
    newSecurityManager(None, user)
    app = makerequest(app)

    member = app.openplans.people[username]

    zipfile = ZipFile(zipfile)

    import tempfile
    tempdir = tempfile.mkdtemp(prefix="--opencore-wiki-import-")

    wiki_filename_map = {}
    import simplejson

    for path in zipfile.namelist():
        parts = path.split("/")
        if parts[-1] == "notifications.json":
            f = zipfile.read(path)
            notifications = simplejson.loads(f)
            msgs = ITransientMessage(app.openplans)
            for category in notifications:
                for msg in notifications[category]:
                    msgs.store(username, category, msg)

        if parts[-1] == "wiki_history_filenames.json":
            f = zipfile.read(path)
            wiki_filename_map = simplejson.loads(f)
            from pprint import pprint
            pprint(wiki_filename_map)
            continue

        if len(parts) < 3:
            continue
        if parts[2] == "wiki_history":
            if path.endswith("/"):
                try:
                    os.makedirs(os.path.join(tempdir, *parts[3:]))
                except:
                    pass
                continue
            else:
                try:
                    os.makedirs(os.path.join(tempdir, *parts[3:-1]))
                except:
                    pass
            f = zipfile.read(path)
            fp = open(os.path.join(tempdir, *parts[3:]), 'w')
            try:
                fp.write(f)
            finally:
                fp.close()

    from sven.bzr import BzrAccess
    bzr = BzrAccess(tempdir)

    from DateTime import DateTime
    repo = getToolByName(member, 'portal_repository')
    archivist = getToolByName(member, 'portal_archivist')
    
    PAGES = set()
    i = 0
    for revision in reversed(bzr.log("/")):
        i += 1
        fs_path = revision['href']

        path = wiki_filename_map.get(fs_path, {}).get('filename', fs_path)

        timestamp = revision['fields']['timestamp']
        mod_date = DateTime(timestamp)
        user_id = revision['fields']['author']
        commit_message = revision['fields']['message']
        if isinstance(commit_message, unicode):
            commit_message = commit_message.encode("utf8")
        content = bzr.read(path, rev=revision['fields']['version'])

        print "Saving %s, revision %s" % (path, revision['fields']['version'])
        try:
            page_ctx = member[path]
        except KeyError:
            title = wiki_filename_map.get(fs_path, {}).get('title', fs_path)
            member.invokeFactory("Document", id=path, title=title)
            page_ctx = member[path]
        PAGES.add(path)

        page_ctx.getField("modification_date").set(page_ctx, mod_date)
        from lxml.html import fromstring, tostring
        try:
            content = tostring(fromstring(content.decode("utf8")))
        except:
            content = ''
        page_ctx.setText(content)

        ## if all goes well this will set lastModifiedAuthor
        from opencore.project.browser.metadata import _update_last_modified_author
        _update_last_modified_author(page_ctx, user_id)
        
        sys_metadata = repo._prepareSysMetadata(commit_message)
        sys_metadata['timestamp'] = mod_date.timeTime()
        prep = archivist.prepare(page_ctx, {}, sys_metadata)
        prep.metadata['sys_metadata']['principal'] = user_id
        archivist.save(prep, autoregister=repo.autoapply)
        prep.copyVersionIdFromClone()

        if i % 500 == 0:
            transaction.get().commit(True)

    attachment_metadata = json.loads(zipfile.read("people/%s/attachments.json" % username))

    from StringIO import StringIO
    plone_utils = getToolByName(member, 'plone_utils')

    for path in zipfile.namelist():
        parts = path.split("/")
        if len(parts) < 2:
            continue
        if parts[2] == "pages":
            if len(parts) < 5 or parts[4] == '':
                continue

            metadata = attachment_metadata[path]

            page = parts[3]
            filename = parts[4]
            file = StringIO(zipfile.read(path))
            fileId = filename
            context = member[page]
            context.invokeFactory(id=fileId, type_name="FileAttachment")

            object = context._getOb(fileId, None)
            object.setTitle(metadata['title'] or fileId)
            object.setFile(file)
            
            creation_date = DateTime(metadata['creation_date'])

            object.Schema()['creators'].set(object, (metadata['creator'],))

            object.getField("creation_date").set(object, creation_date)
            object.getField("modification_date").set(object, creation_date) # @@TODO this is getting overwritten with the current date :-(
            object.setModificationDate(creation_date)

            object.reindexObject()

    from opencore.nui.wiki.utils import cache_history
    for page in PAGES:
        cache_history(member[page], repo)

    import shutil
    shutil.rmtree(tempdir)