[ckan-changes] commit/ckan: John Glover: [merge] default

Bitbucket commits-noreply at bitbucket.org
Tue Oct 4 16:47:08 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/35f6ace6009f/
changeset:   35f6ace6009f
branch:      feature-1363-add-task-status
user:        John Glover
date:        2011-10-04 18:46:49
summary:     [merge] default
affected #:  5 files (-1 bytes)

--- a/ckan/config/routing.py	Tue Oct 04 10:53:06 2011 +0100
+++ b/ckan/config/routing.py	Tue Oct 04 17:46:49 2011 +0100
@@ -104,8 +104,6 @@
 
     map.connect('/api/search/{register}', controller='api', action='search')
     map.connect('/api/tag_counts', controller='api', action='tag_counts')
-
-    map.connect('/api/markdown', controller='api', action='markdown')
     
     map.connect('/api/rest', controller='api', action='index')
 
@@ -167,6 +165,8 @@
     map.connect('/api/2/util/authorizationgroup/autocomplete', controller='api',
         action='authorizationgroup_autocomplete')
 
+    map.connect('/api/util/markdown', controller='api', action='markdown')
+
     ###########
     ## /END API
     ###########


--- a/ckan/logic/action/update.py	Tue Oct 04 10:53:06 2011 +0100
+++ b/ckan/logic/action/update.py	Tue Oct 04 17:46:49 2011 +0100
@@ -148,7 +148,7 @@
     model = context['model']
     session = context['session']
     user = context['user']
-    id = context["id"]
+    id = data_dict["id"]
     schema = context.get('schema') or default_update_resource_schema()
     model.Session.remove()
 
@@ -157,8 +157,8 @@
 
     if not resource:
         raise NotFound(_('Resource was not found.'))
-    context["id"] = resource.id
 
+    # check authentication against the resource package
     # TODO: can check_access be used against a resource?
     query = session.query(model.Package
     ).join(model.ResourceGroup
@@ -167,8 +167,7 @@
     pkg = query.first()
     if not pkg:
         raise NotFound(_('No package found for this resource, cannot check auth.'))
-
-    check_access('package_update', context, data_dict)
+    check_access('package_update', context, package_dictize(pkg, context))
 
     data, errors = validate(data_dict, schema, context)
 


--- a/ckan/misc.py	Tue Oct 04 10:53:06 2011 +0100
+++ b/ckan/misc.py	Tue Oct 04 17:46:49 2011 +0100
@@ -13,7 +13,7 @@
 
 
 class MarkdownFormat(TextFormat):
-    internal_link = re.compile('(package|tag|group):([a-z0-9\-_]+)')
+    internal_link = re.compile('(dataset|package|tag|group):([a-z0-9\-_]+)')
     normal_link = re.compile('<(http:[^>]+)>')
 
     html_whitelist = 'b center li ol p table td tr ul'.split(' ')
@@ -24,6 +24,7 @@
     any_link = re.compile(r'<a[^>]*?>', re.IGNORECASE)
     close_link = re.compile(r'<(\/a[^>]*)>', re.IGNORECASE)
     link_escp = re.compile(r'\\xfc\\xfd(\/?(%s)[^>]*?)\\xfd\\xfc' % "|".join(['a']), re.IGNORECASE)
+    web_address = re.compile(r'(\s|^)((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)', re.IGNORECASE)
     
     def to_html(self, text):
         if text is None:
@@ -31,6 +32,9 @@
         # Encode whitelist elements.
         text = self.whitelist_elem.sub(r'\\\\xfc\\\\xfd\1\\\\xfd\\\\xfc', text)
 
+        # Discover external addresses and make them links
+        text = self.web_address.sub(r'\1<\2>', text)
+        
         # Encode links only in an acceptable format (guard against spammers)
         text = self.normal_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc', text)
         text = self.abbrev_link.sub(r'\\\\xfc\\\\xfda href="\1" target="_blank" rel="nofollow"\\\\xfd\\\\xfc\1</a>', text)


--- a/ckan/public/scripts/application.js	Tue Oct 04 10:53:06 2011 +0100
+++ b/ckan/public/scripts/application.js	Tue Oct 04 17:46:49 2011 +0100
@@ -226,7 +226,7 @@
       if (action=='preview') {
         raw_markdown=textarea.val();
         preview.html("<em>"+CKAN.Strings.loading+"<em>");
-        $.post("/api/markdown", { q: raw_markdown },
+        $.post("/api/util/markdown", { q: raw_markdown },
           function(data) { preview.html(data); }
         );
         preview.width(textarea.width())


--- a/ckan/tests/misc/test_format_text.py	Tue Oct 04 10:53:06 2011 +0100
+++ b/ckan/tests/misc/test_format_text.py	Tue Oct 04 17:46:49 2011 +0100
@@ -46,6 +46,20 @@
         out = format.to_html(instr)
         assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
 
+    def test_auto_link(self):
+        instr = 'http://somelink.com'
+        exp = '<a href="http://somelink.com" target="_blank" rel="nofollow">http://somelink.com</a>'
+        format = MarkdownFormat()
+        out = format.to_html(instr)
+        assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+
+    def test_auto_link_after_whitespace(self):
+        instr = 'go to http://somelink.com'
+        exp = 'go to <a href="http://somelink.com" target="_blank" rel="nofollow">http://somelink.com</a>'
+        format = MarkdownFormat()
+        out = format.to_html(instr)
+        assert exp in out, '\nGot: %s\nWanted: %s' % (out, exp)
+
     def test_malformed_link_1(self):
         instr = u'<a href=\u201dsomelink\u201d>somelink</a>'
         exp = '<a href="TAG MALFORMED" target="_blank" rel="nofollow">somelink</a>'

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list