commit bff10194b88c4384ffa63c3b3c01002e2e48c307
Author: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date:   Fri Apr 1 17:06:27 2016 +0200

    remove FileWithPreviewAndStrongboxWidget (#10515)
    
    MSP and strongbox support is removed, fargo support is moved in w.c.s.

diff --git a/extra/auquotidien.py b/extra/auquotidien.py
index 2e4b9b9..5722008 100644
--- a/extra/auquotidien.py
+++ b/extra/auquotidien.py
@@ -14,7 +14,6 @@ import modules.strongbox_ui
 import modules.formpage
 import modules.template
 import modules.root
-import modules.form
 import modules.payments
 import modules.connectors
 import modules.abelium_domino_ui
@@ -50,9 +49,6 @@ rdb.register_menu_item('strongbox/', _('Strongbox'))
 rdb.register_directory('settings', modules.admin.SettingsDirectory())
 rdb.register_directory('categories', modules.categories_admin.CategoriesDirectory())
 
-import wcs.fields
-wcs.fields.FileField.widget_class = modules.form.FileWithPreviewAndStrongboxWidget
-
 import wcs.admin.settings
 wcs.admin.settings.SettingsDirectory.domino = modules.abelium_domino_ui.AbeliumDominoDirectory()
 wcs.admin.settings.SettingsDirectory._q_exports.append('domino')
diff --git a/extra/modules/fargo_ui.py b/extra/modules/fargo_ui.py
deleted file mode 100644
index 9754171..0000000
--- a/extra/modules/fargo_ui.py
+++ /dev/null
@@ -1,60 +0,0 @@
-import urllib
-import urlparse
-import json
-
-from quixote import get_publisher, get_request, redirect, get_response, get_session
-from quixote.directory import Directory
-from quixote.html import TemplateIO, htmltext
-
-import qommon.form
-
-
-class FargoDirectory(Directory):
-    _q_exports = ['pick']
-
-    @property
-    def fargo_url(self):
-        return get_publisher().get_site_option('fargo_url')
-
-    def pick (self):
-        request = get_request()
-        if 'cancel' in request.form:
-            get_response().add_javascript(['jquery.js'])
-            get_response().page_template_key = 'iframe'
-            r = TemplateIO(html=True)
-            r += htmltext('<html><body>')
-            r += htmltext('<script>window.top.document.fargo_close_dialog();</script>')
-            r += htmltext('</body></html>')
-            return r.getvalue()
-        elif 'url' in request.form:
-            # Download file
-            # FIXME: handle error cases
-            url = request.form['url']
-            document = urllib.urlopen(request.form['url']).read()
-            scheme, netloc, path, qs, frag = urlparse.urlsplit(url)
-            path = map(None, path.split('/'))
-            name = urllib.unquote(path[-1])
-            download = qommon.form.PicklableUpload(name,
-                    content_type='application/pdf')
-            download.__setstate__({
-                'data': document,
-            })
-            token = get_session().add_tempfile(download)
-            return self.set_token(token, name)
-        else:
-            # Display file picker
-            frontoffice_url = get_publisher().get_frontoffice_url()
-            self_url = frontoffice_url
-            self_url += '/fargo/pick'
-            return redirect('%spick?pick=%s' % (self.fargo_url,
-                urllib.quote(self_url)))
-
-    def set_token(self, token, title):
-        get_response().add_javascript(['jquery.js'])
-        get_response().page_template_key = 'iframe'
-        r = TemplateIO(html=True)
-        r += htmltext('<html><body>')
-        r += htmltext('<script>window.top.document.fargo_set_token(%s, %s);</script>' % (
-            json.dumps(token), json.dumps(title)))
-        r += htmltext('</body></html>')
-        return r.getvalue()
diff --git a/extra/modules/form.py b/extra/modules/form.py
deleted file mode 100644
index ed3375e..0000000
--- a/extra/modules/form.py
+++ /dev/null
@@ -1,36 +0,0 @@
-from qommon.form import *
-
-
-class FileWithPreviewAndStrongboxWidget(FileWithPreviewWidget):
-    def render_hint(self, hint):
-        t = CompositeWidget.render_hint(self, hint)
-        if not self.allow_portfolio_picking:
-            return t
-        root_url = get_publisher().get_root_url()
-        if get_publisher().has_site_option('strongbox') and get_request().user and not self.preview:
-            get_response().add_javascript(['../../aq/js/strongbox.js'])
-            t += htmltext('''<p class="use-file-from-strongbox"><span
-                               data-url="%smyspace/strongbox/pick"
-                               rel="popup">%s</span></p>''') % (
-                                root_url, _('Use file from strongbox'))
-        if get_publisher().get_site_option('msp') is not None and not self.preview:
-            get_response().add_javascript(['../../aq/js/msp.js'])
-            t += htmltext('''<p class="use-file-from-msp"><span
-                               data-src="%smsp/pick"
-                               data-width="500"
-                               data-height="400"
-                               data-title="%s"
-                               rel="popup">%s</span></p>''') % (
-                                root_url, _('Pick a file on mon.Service-Public.fr'),
-                                _('Use file from mon.Service-Public.fr'))
-        if get_publisher().get_site_option('fargo_url') is not None and not self.preview:
-            get_response().add_javascript(['fargo.js'])
-            t += htmltext('''<p class="use-file-from-fargo"><span
-                               data-src="%sfargo/pick"
-                               data-width="500"
-                               data-height="400"
-                               data-title="%s"
-                               rel="popup">%s</span></p>''') % (
-                                root_url, _('Pick a file from your dropbox'),
-                                _('Use file from my dropbox'))
-        return t
diff --git a/extra/modules/msp_ui.py b/extra/modules/msp_ui.py
deleted file mode 100644
index ccbdd62..0000000
--- a/extra/modules/msp_ui.py
+++ /dev/null
@@ -1,183 +0,0 @@
-import urllib
-import urllib2
-import urlparse
-import json
-import base64
-import datetime
-
-from quixote import get_publisher, get_request, redirect, get_response, get_session_manager, get_session
-from quixote.directory import AccessControlled, Directory
-from quixote.html import TemplateIO, htmltext
-
-import qommon.form
-from qommon.misc import http_post_request, http_get_page
-
-
-class MSPDirectory(Directory):
-    _q_exports = ['', 'pick', 'download']
-
-    @property
-    def msp_gateway_base_url(self):
-        return get_publisher().get_site_option('msp')
-
-    @property
-    def authorize_url(self):
-        return urlparse.urljoin(self.msp_gateway_base_url, 'authorize/')
-
-    @property
-    def access_token_url(self):
-        return urlparse.urljoin(self.msp_gateway_base_url, 'access_token/')
-
-    @property
-    def documents_url(self):
-        return urlparse.urljoin(self.msp_gateway_base_url, 'documents/')
-
-    @property
-    def document_url(self):
-        return urlparse.urljoin(self.msp_gateway_base_url, 'documents/%s/')
-
-    @property
-    def client_id(self):
-        return get_publisher().get_site_option('msp_client_id')
-
-    @property
-    def client_secret(self):
-        return get_publisher().get_site_option('msp_client_secret')
-
-    def fix_document(self, document):
-        site_charset = get_publisher().site_charset
-        for key, value in document.iteritems():
-            # date are returned as millisecond POSIX timestamp,
-            # it should be ISO-8601 instead
-            if key.endswith('Date') and value is not None:
-                document[key] = unicode(datetime.date.fromtimestamp(value // 1000))
-                value = document[key] = document[key].replace(u'-', u'\u2011')
-            if isinstance(value, unicode) and key != 'content':
-                document[key] = value.encode(site_charset)
-
-    def get_documents(self, access_token):
-        response, status, content, auth_header = http_get_page(self.documents_url, {
-            'Authorization': 'Bearer %s' % access_token,
-        });
-        documents = json.loads(content)
-        for document in documents:
-            self.fix_document(document)
-        return documents
-
-    def get_document(self, doc_id, access_token):
-        response, status, content, auth_header = http_get_page(
-                self.document_url % doc_id, 
-                { 'Authorization': 'Bearer %s' % access_token, }
-        );
-        document = json.loads(content)
-        self.fix_document(document)
-        return document
-
-    def authorize(self, self_url, scope):
-        params = {
-                'redirect_uri': self_url,
-                'response_type': 'code',
-                'scope': scope,
-        }
-        return redirect('%s?%s' % (
-            self.authorize_url, urllib.urlencode(params)))
-
-    def access_token(self, self_url, code):
-        params = {
-                'code': code,
-                'client_id': self.client_id,
-                'client_secret': self.client_secret,
-                'grant_type': 'authorization_code',
-                'redirect_uri': self_url,
-        }
-        response, status, data, auth_header = http_post_request(self.access_token_url,
-                urllib.urlencode(params), { 'Content-Type': 'application/x-www-form-urlencoded' })
-        return json.loads(data)['access_token']
-
-    def pick (self):
-        request = get_request()
-        frontoffice_url = get_publisher().get_frontoffice_url()
-        self_url = frontoffice_url
-        self_url += '/msp/pick'
-        self_url = self_url.replace('://', '://iframe-')
-
-        if 'code' not in request.form and 'error' not in request.form:
-            return self.authorize(self_url, 'LIST_DOCS')
-        access_token = self.access_token(self_url, request.form['code'])
-        return self.pick_display(access_token)
-
-    def pick_display(self, access_token):
-        r = TemplateIO(html=True)
-
-        request = get_request()
-
-        get_response().add_javascript(['jquery.js',
-            'tablesorter/jquery.tablesorter.min.js'])
-        get_response().add_javascript_code(
-                 str('''$(function() { $("table.sortable").tablesorter(); });'''))
-        get_response().add_css_include('../js/tablesorter/themes/blue/style.css')
-
-        frontoffice_url = get_publisher().get_frontoffice_url()
-
-        r += htmltext('<h2>%s</h2>') % _('Pick a file')
-
-        if 'error' not in request.form:
-            documents = self.get_documents(access_token)
-            r += htmltext('<table id="msp-pick-file-table" class="sortable tablesorter">')
-            r += htmltext('<thead>')
-            r += htmltext('<tr>')
-            r += htmltext('<th>%s</th>') % _('Filename')
-            r += htmltext('<th>%s</th>') % _('Expiration date')
-            r += htmltext('</tr>')
-            r += htmltext('</thead>')
-            r += htmltext('<tbody>')
-            for document in documents:
-                r += htmltext('<tr>')
-                for key in ('name', 'expirationDate'):
-                    r += htmltext('<td class="msp-pick-file-table-%s">' % key)
-                    if key == 'name':
-                        r += htmltext('<a href="%s/msp/download?doc_id=%s">' % \
-                            (frontoffice_url, document['id']))
-                    r += '%s' % (document[key] or '')
-                    if key == 'name':
-                        r += htmltext('</a>')
-                    r += htmltext('</td>')
-                r += htmltext('</tr>')
-            r += htmltext('</tbody>')
-            r += htmltext('</table>')
-        else:
-            r += htmltext('<p>%s</p>') % _('Unable to access your mon.Service-Public.fr documents')
-        return r.getvalue()
-
-    def set_token(self, token, title):
-        get_response().add_javascript(['jquery.js'])
-        get_response().page_template_key = 'iframe'
-        r = TemplateIO(html=True)
-        r += htmltext('<html><body>')
-        r += htmltext('<pre>Token: %s</pre>') % token
-        r += htmltext('<script>window.top.document.set_token("%s", "%s");</script>' % (
-            token, title))
-        r += htmltext('</body></html>')
-        return r.getvalue()
-
-    def download(self):
-        request = get_request()
-        assert 'doc_id' in request.form
-        doc_id = request.form['doc_id']
-        frontoffice_url = get_publisher().get_frontoffice_url()
-        self_url = frontoffice_url
-        self_url += '/msp/download?%s' % urllib.urlencode({'doc_id': doc_id})
-        if 'code' not in request.form and 'error' not in request.form:
-            return self.authorize(self_url, 'GET_DOC')
-        if 'error' in request.form:
-            return self.set_token('', '')
-        else:
-            access_token = self.access_token(self_url, request.form['code'])
-            document = self.get_document(doc_id, access_token)
-            download = qommon.form.PicklableUpload(document['name'],
-                    content_type='application/pdf')
-            download.__setstate__({
-                'data': base64.b64decode(document['content']),
-            })
-            token = get_session().add_tempfile(download)
-            return self.set_token(token, document['name'])
diff --git a/extra/modules/myspace.py b/extra/modules/myspace.py
index 66045f4..a689006 100644
--- a/extra/modules/myspace.py
+++ b/extra/modules/myspace.py
@@ -28,7 +28,6 @@ import root
 from announces import AnnounceSubscription
 from strongbox import StrongboxItem, StrongboxType
 from payments import Invoice, Regie, is_payment_supported
-import msp_ui
 
 class MyInvoicesDirectory(Directory):
     _q_exports = ['']
@@ -422,9 +421,8 @@ class JsonDirectory(Directory):
 
 class MyspaceDirectory(wcs.myspace.MyspaceDirectory):
     _q_exports = ['', 'profile', 'new', 'password', 'remove', 'drafts', 'forms',
-            'announces', 'strongbox', 'invoices', 'json', 'msp']
+            'announces', 'strongbox', 'invoices', 'json']
 
-    msp = msp_ui.MSPDirectory()
     strongbox = StrongboxDirectory()
     invoices = MyInvoicesDirectory()
     json = JsonDirectory()
diff --git a/extra/modules/root.py b/extra/modules/root.py
index 548d1b5..a70ea26 100644
--- a/extra/modules/root.py
+++ b/extra/modules/root.py
@@ -55,8 +55,6 @@ OldRootDirectory = wcs.root.RootDirectory
 import qommon.ident.password
 import qommon.ident.idp
 
-import msp_ui
-import fargo_ui
 
 def category_get_homepage_position(self):
     if hasattr(self, 'homepage_position') and self.homepage_position:
@@ -771,7 +769,7 @@ class AlternateRootDirectory(OldRootDirectory):
             'myspace', 'services', 'agenda', 'categories', 'user',
             ('tmp-upload', 'tmp_upload'), 'json', '__version__',
             'themes', 'pages', 'payment', 'invoices', 'accesscode', 'roles',
-            'msp', 'api', 'code', 'fargo', 'tryauth', 'auth', 'preview',
+            'api', 'code', 'fargo', 'tryauth', 'auth', 'preview',
             ('reload-top', 'reload_top')]
 
     admin = admin.AdminRootDirectory()
@@ -784,8 +782,6 @@ class AlternateRootDirectory(OldRootDirectory):
     saml = Saml2Directory()
     payment = PublicPaymentDirectory()
     invoices = InvoicesDirectory()
-    msp = msp_ui.MSPDirectory()
-    fargo = fargo_ui.FargoDirectory()
     code = wcs.forms.root.TrackingCodesDirectory()
     preview = AlternatePreviewDirectory()
 
