allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [8/14] git commit: [#4637] ticket:168 URL shortener Allura App improvements
Date Tue, 25 Sep 2012 02:13:10 GMT
[#4637] ticket:168 URL shortener Allura App improvements


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

Branch: refs/heads/master
Commit: d44aa45e64f49cc3c81689bbda316b0cd36a2eb0
Parents: 22c09c5
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Sep 17 10:38:52 2012 +0400
Committer: Cory Johns <johnsca@geek.net>
Committed: Fri Sep 21 20:06:16 2012 +0000

----------------------------------------------------------------------
 ForgeShortUrl/forgeshorturl/main.py                |   29 +++++++++------
 ForgeShortUrl/forgeshorturl/model/shorturl.py      |   16 +++++----
 .../forgeshorturl/tests/functional/test.py         |   11 ++----
 3 files changed, 29 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d44aa45e/ForgeShortUrl/forgeshorturl/main.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/main.py b/ForgeShortUrl/forgeshorturl/main.py
index 982d418..89c7026 100644
--- a/ForgeShortUrl/forgeshorturl/main.py
+++ b/ForgeShortUrl/forgeshorturl/main.py
@@ -1,19 +1,23 @@
 from tg import expose, validate, redirect, flash, request
+
 from allura.app import Application, SitemapEntry, DefaultAdminController
 from allura import model as M
 from allura.lib.security import require_access, has_access
 from allura.lib import helpers as h
 from allura.controllers import BaseController
 from allura.lib.widgets import form_fields as ffw
+
 from webob import exc
+import pylons
 from pylons import c, g
+from datetime import datetime
 from formencode import validators
 from formencode.compound import All
-import logging
+
 from forgeshorturl.model.shorturl import ShortUrl
-from datetime import datetime
 from forgeshorturl.widgets.short_url import CreateShortUrlWidget
-import pylons
+
+import logging
 
 
 log = logging.getLogger(__name__)
@@ -36,7 +40,6 @@ class ForgeShortUrlApp(Application):
     sitemap = []
     ordinal = 14
     installable = False
-    hidden = True
     icons = {
         24: 'images/ext_24.png',
         32: 'images/ext_32.png',
@@ -48,6 +51,10 @@ class ForgeShortUrlApp(Application):
         self.root = RootController()
         self.admin = ShortURLAdminController(self)
 
+    def is_visible_to(self, user):
+        '''Whether the user can view the app.'''
+        return has_access(c.project, 'create')(user=user)
+
     @property
     @h.exceptionless([], log)
     def sitemap(self):
@@ -88,16 +95,15 @@ class ForgeShortUrlApp(Application):
         super(ForgeShortUrlApp, self).install(project)
         # Setup permissions
         role_admin = M.ProjectRole.by_name('Admin')._id
-        role_anon = M.ProjectRole.anonymous()._id
         self.config.acl = [
             M.ACE.allow(role_admin, 'create'),
             M.ACE.allow(role_admin, 'update'),
             M.ACE.allow(role_admin, 'view_private'),
-            M.ACE.allow(role_anon, 'read'),
             M.ACE.allow(role_admin, 'configure'), ]
 
     def uninstall(self, project):
         "Remove all the tool's artifacts from the database"
+        ShortUrl.query.remove(dict(app_config_id=c.app.config._id))
         super(ForgeShortUrlApp, self).uninstall(project)
 
 
@@ -115,7 +121,7 @@ class RootController(BaseController):
         c.page_list = W.page_list
         c.page_size = W.page_size
         limit, pagenum, start = g.handle_paging(limit, page, default=100)
-        p = {'project_id': c.project._id}
+        p = {'app_config_id': c.app.config._id}
         if not has_access(c.app, 'view_private'):
             p['private'] = False
         short_urls = (ShortUrl.query.find(p))
@@ -133,11 +139,10 @@ class RootController(BaseController):
     @expose()
     def _lookup(self, pname, *remainder):
         if request.method == 'GET':
-            short_url = ShortUrl.query.find({'project_id': c.project._id,
+            short_url = ShortUrl.query.find({'app_config_id': c.app.config._id,
                                              'short_name': pname}).first()
             if short_url:
-                u = validators.URL(add_http=True)
-                redirect(u.to_python(short_url.url))
+                redirect(short_url.url)
 
         flash("We're sorry but we weren't able "
               "to process this request.", "error")
@@ -153,7 +158,7 @@ class ShortURLAdminController(DefaultAdminController):
         redirect(c.project.url() + 'admin/tools')
 
     @expose('jinja:forgeshorturl:templates/add.html')
-    @validate(dict(full_url=All(validators.URL(),
+    @validate(dict(full_url=All(validators.URL(add_http=True),
                                 validators.NotEmpty()),
                    short_url=validators.NotEmpty()))
     def add(self, short_url="",
@@ -188,7 +193,7 @@ class ShortURLAdminController(DefaultAdminController):
                 shorturl.short_name = short_url
                 shorturl.description = description
                 shorturl.create_user = c.user._id
-                shorturl.project_id = c.project._id
+                shorturl.app_config_id = self.app.config._id
                 if private == "on":
                     shorturl.private = True
                 else:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d44aa45e/ForgeShortUrl/forgeshorturl/model/shorturl.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/model/shorturl.py b/ForgeShortUrl/forgeshorturl/model/shorturl.py
index d20987c..b7585ce 100644
--- a/ForgeShortUrl/forgeshorturl/model/shorturl.py
+++ b/ForgeShortUrl/forgeshorturl/model/shorturl.py
@@ -1,22 +1,18 @@
 import pymongo
-from ming.orm.declarative import MappedClass
 from allura.model import project_orm_session
 from ming.orm import FieldProperty, ForeignIdProperty, session
 from datetime import datetime
-from ming import schema
 from allura.model.auth import User
-from allura.model import Project
-from allura.model.timeline import ActivityNode, ActivityObject
+from allura import model as M
 
 
-class ShortUrl(MappedClass, ActivityNode, ActivityObject):
+class ShortUrl(M.Artifact):
 
     class __mongometa__:
         name = 'short_urls'
         session = project_orm_session
         unique_indexes = ['short_name']
 
-    _id = FieldProperty(schema.ObjectId)
     url = FieldProperty(str)
     short_name = FieldProperty(str)
     description = FieldProperty(str)
@@ -24,7 +20,6 @@ class ShortUrl(MappedClass, ActivityNode, ActivityObject):
     create_user = ForeignIdProperty(User)
     created = FieldProperty(datetime, if_missing=datetime.utcnow)
     last_updated = FieldProperty(datetime, if_missing=datetime.utcnow)
-    project_id = ForeignIdProperty(Project)
 
     @property
     def user(self):
@@ -42,3 +37,10 @@ class ShortUrl(MappedClass, ActivityNode, ActivityObject):
             session(u).expunge(u)
             u = cls.query.get(short_name=shortname)
         return u
+
+    def index(self):
+        result = M.Artifact.index(self)
+        result.update(
+            url=self.url,
+            short_name=self.short_name)
+        return result

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d44aa45e/ForgeShortUrl/forgeshorturl/tests/functional/test.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/tests/functional/test.py b/ForgeShortUrl/forgeshorturl/tests/functional/test.py
index 466845f..5551d2b 100644
--- a/ForgeShortUrl/forgeshorturl/tests/functional/test.py
+++ b/ForgeShortUrl/forgeshorturl/tests/functional/test.py
@@ -34,14 +34,9 @@ class TestRootController(TestController):
                            full_url='http://www.amazone.com/',
                            private='on',
                            description="description1"))
-
-        self.app.post('/admin/url/add',
-                      dict(short_url='test',
-                           full_url='http://www.google.com/',
-                           description="description2"))
-        r = self.app.get('/url/', extra_environ=dict(username='*anonymous'))
-        assert 'http://www.google.com/' in r
-        assert 'http://www.amazone.com/' not in r
+        r = self.app.get('/url/')
+        assert 'http://www.amazone.com/' in r
+        assert '<td><small>yes</small></td>' in r
 
     def test_shorturl_errors(self):
         d = dict(short_url='http://www.amazone.com/',


Mime
View raw message