allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [2/2] git commit: [#4987] ticket:631 Remove ambiguity in shortlinks when possible
Date Thu, 21 Aug 2014 10:37:53 GMT
[#4987] ticket:631 Remove ambiguity in shortlinks when possible


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/5c0f3b09
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/5c0f3b09
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/5c0f3b09

Branch: refs/heads/je/42cc_4987
Commit: 5c0f3b09dce2c122d68e437420850f506601f970
Parents: 4c5d051
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Aug 20 11:29:40 2014 +0300
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Wed Aug 20 12:01:16 2014 +0300

----------------------------------------------------------------------
 Allura/allura/model/index.py | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/5c0f3b09/Allura/allura/model/index.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/index.py b/Allura/allura/model/index.py
index 573414b..61a036a 100644
--- a/Allura/allura/model/index.py
+++ b/Allura/allura/model/index.py
@@ -183,20 +183,37 @@ class Shortlink(object):
                     matches = (
                         m for m in matches
                         if m.app_config.options.mount_point == d['app'])
-                matches = list(matches)
-                if matches:
-                    result[link] = matches[0]
-                else:
-                    result[link] = None
-                if len(matches) > 1:
-                    log.warn('Ambiguous link to %s', link)
-                    for m in matches:
-                        log.warn('... %r', m)
+                result[link] = cls._get_correct_match(link, list(matches))
             return result
         else:
             return {}
 
     @classmethod
+    def _get_correct_match(cls, link, matches):
+        result = None
+        if len(matches) == 1:
+            result = matches[0]
+        elif len(matches) > 1 and getattr(c, 'app', None):
+            # use current app's link
+            for m in matches:
+                if m.app_config_id == c.app.config._id:
+                    result = m
+                    break
+            if not result:
+                cls.log_ambiguous_link('Can not remove ambiguity for link %s with c.app %s',
matches, link, c.app)
+                result = matches[0]
+        elif len(matches) > 1 and not getattr(c, 'app', None):
+            cls.log_ambiguous_link('Ambiguous link to %s and c.app is not present to remove
ambiguity', matches, link)
+            result = matches[0]
+        return result
+
+    @classmethod
+    def log_ambiguous_link(cls, msg, matches, *args):
+        log.warn(msg, *args)
+        for m in matches:
+            log.warn('... %r', m)
+
+    @classmethod
     def _parse_link(cls, s):
         '''Parse a shortlink into its nbhd/project/app/artifact parts'''
         s = s.strip()


Mime
View raw message