Changeset - 1fdec7e3aeb2
[Not reviewed]
beta
0 6 0
Marcin Kuzminski - 12 years ago 2013-05-18 23:41:37
marcin@python-works.com
refactored url.resource to full definition of routes

- id -> gist_id
6 files changed with 53 insertions and 31 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -384,16 +384,39 @@ def make_map(config):
 
        m.connect("formatted_notification", "/notifications/{notification_id}.{format}",
 
                  action="show", conditions=dict(method=["GET"]))
 

	
 
    #ADMIN GIST
 
    with rmap.submapper(path_prefix=ADMIN_PREFIX,
 
                        controller='admin/gists') as m:
 
        m.connect("gists", "/gists",
 
                  action="create", conditions=dict(method=["POST"]))
 
        m.connect("gists", "/gists",
 
                  action="index", conditions=dict(method=["GET"]))
 
        m.connect("formatted_gists", "/gists.{format}",
 
                  action="index", conditions=dict(method=["GET"]))
 
        m.connect("new_gist", "/gists/new",
 
                  action="new", conditions=dict(method=["GET"]))
 
        m.connect("formatted_new_gist", "/gists/new.{format}",
 
                  action="new", conditions=dict(method=["GET"]))
 
        m.connect("/gist/{gist_id}",
 
                  action="update", conditions=dict(method=["PUT"]))
 
        m.connect("/gist/{gist_id}",
 
                  action="delete", conditions=dict(method=["DELETE"]))
 
        m.connect("edit_gist", "/gist/{gist_id}/edit",
 
                  action="edit", conditions=dict(method=["GET"]))
 
        m.connect("formatted_edit_gist",
 
                  "/gist/{gist_id}.{format}/edit",
 
                  action="edit", conditions=dict(method=["GET"]))
 
        m.connect("gist", "/gist/{gist_id}",
 
                  action="show", conditions=dict(method=["GET"]))
 
        m.connect("formatted_gist", "/gists/{gist_id}.{format}",
 
                  action="show", conditions=dict(method=["GET"]))
 

	
 
    #ADMIN MAIN PAGES
 
    with rmap.submapper(path_prefix=ADMIN_PREFIX,
 
                        controller='admin/admin') as m:
 
        m.connect('admin_home', '', action='index')
 
        m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
 
                  action='add_repo')
 

	
 
    #ADMIN GIST
 
    rmap.resource('gist', 'gists', controller='admin/gists',
 
        path_prefix=ADMIN_PREFIX)
 
    #==========================================================================
 
    # API V2
 
    #==========================================================================
rhodecode/controllers/admin/gists.py
Show inline comments
 
@@ -126,7 +126,7 @@ class GistsController(BaseController):
 
            log.error(traceback.format_exc())
 
            h.flash(_('Error occurred during gist creation'), category='error')
 
            return redirect(url('new_gist'))
 
        return redirect(url('gist', id=new_gist_id))
 
        return redirect(url('gist', gist_id=new_gist_id))
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
@@ -138,26 +138,26 @@ class GistsController(BaseController):
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
    def update(self, id):
 
        """PUT /admin/gists/id: Update an existing item"""
 
    def update(self, gist_id):
 
        """PUT /admin/gists/gist_id: Update an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="PUT" />
 
        # Or using helpers:
 
        #    h.form(url('gist', id=ID),
 
        #    h.form(url('gist', gist_id=ID),
 
        #           method='put')
 
        # url('gist', id=ID)
 
        # url('gist', gist_id=ID)
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
    def delete(self, id):
 
        """DELETE /admin/gists/id: Delete an existing item"""
 
    def delete(self, gist_id):
 
        """DELETE /admin/gists/gist_id: Delete an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
 
        #    h.form(url('gist', id=ID),
 
        #    h.form(url('gist', gist_id=ID),
 
        #           method='delete')
 
        # url('gist', id=ID)
 
        gist = GistModel().get_gist(id)
 
        # url('gist', gist_id=ID)
 
        gist = GistModel().get_gist(gist_id)
 
        owner = gist.gist_owner == c.rhodecode_user.user_id
 
        if h.HasPermissionAny('hg.admin')() or owner:
 
            GistModel().delete(gist)
 
@@ -169,10 +169,9 @@ class GistsController(BaseController):
 
        return redirect(url('gists'))
 

	
 
    @LoginRequired()
 
    def show(self, id, format='html'):
 
        """GET /admin/gists/id: Show a specific item"""
 
        # url('gist', id=ID)
 
        gist_id = id
 
    def show(self, gist_id, format='html'):
 
        """GET /admin/gists/gist_id: Show a specific item"""
 
        # url('gist', gist_id=ID)
 
        c.gist = Gist.get_or_404(gist_id)
 

	
 
        #check if this gist is not expired
 
@@ -191,6 +190,6 @@ class GistsController(BaseController):
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
    def edit(self, id, format='html'):
 
        """GET /admin/gists/id/edit: Form to edit an existing item"""
 
        # url('edit_gist', id=ID)
 
    def edit(self, gist_id, format='html'):
 
        """GET /admin/gists/gist_id/edit: Form to edit an existing item"""
 
        # url('edit_gist', gist_id=ID)
rhodecode/model/db.py
Show inline comments
 
@@ -2161,7 +2161,7 @@ class Gist(Base, BaseModel):
 
            return alias_url.replace('{gistid}', self.gist_access_id)
 

	
 
        from pylons import url
 
        return url('gist', id=self.gist_access_id, qualified=True)
 
        return url('gist', gist_id=self.gist_access_id, qualified=True)
 

	
 
    @classmethod
 
    def base_path(cls):
rhodecode/templates/admin/gists/index.html
Show inline comments
 
@@ -42,7 +42,7 @@
 
            </div>
 
            <div title="${gist.owner.full_contact}" class="user" style="font-size: 16px">
 
                <b>${h.person(gist.owner.full_contact)}</b> /
 
                <b><a href="${h.url('gist',id=gist.gist_access_id)}">gist:${gist.gist_access_id}</a></b>
 
                <b><a href="${h.url('gist',gist_id=gist.gist_access_id)}">gist:${gist.gist_access_id}</a></b>
 
            </div>
 
            <div style="padding: 4px 0px 0px 0px">
 
                ${_('Created')} ${h.age(gist.created_on)} /
rhodecode/templates/admin/gists/show.html
Show inline comments
 
@@ -52,7 +52,7 @@
 
                          ## only owner should see that
 
                          %if h.HasPermissionAny('hg.admin')() or c.gist.gist_owner == c.rhodecode_user.user_id:
 
                            ##${h.link_to(_('Edit'),h.url(''),class_="ui-btn")}
 
                            ${h.form(url('gist', id=c.gist.gist_id),method='delete')}
 
                            ${h.form(url('gist', gist_id=c.gist.gist_id),method='delete')}
 
                                ${h.submit('remove_gist', _('Delete'),class_="ui-btn red",onclick="return confirm('"+_('Confirm to delete this gist')+"');")}
 
                            ${h.end_form()}
 
                          %endif
rhodecode/tests/functional/test_admin_gists.py
Show inline comments
 
@@ -92,7 +92,7 @@ class TestGistsController(TestController
 
        Session().add(gist)
 
        Session().commit()
 

	
 
        response = self.app.get(url('gist', id=gist.gist_access_id), status=404)
 
        response = self.app.get(url('gist', gist_id=gist.gist_access_id), status=404)
 

	
 
    def test_create_private(self):
 
        self.log_user()
 
@@ -128,28 +128,28 @@ class TestGistsController(TestController
 

	
 
    def test_update(self):
 
        self.skipTest('not implemented')
 
        response = self.app.put(url('gist', id=1))
 
        response = self.app.put(url('gist', gist_id=1))
 

	
 
    def test_delete(self):
 
        self.log_user()
 
        gist = _create_gist('delete-me')
 
        response = self.app.delete(url('gist', id=gist.gist_id))
 
        response = self.app.delete(url('gist', gist_id=gist.gist_id))
 
        self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
 

	
 
    def test_delete_normal_user_his_gist(self):
 
        self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
 
        gist = _create_gist('delete-me', owner=TEST_USER_REGULAR_LOGIN)
 
        response = self.app.delete(url('gist', id=gist.gist_id))
 
        response = self.app.delete(url('gist', gist_id=gist.gist_id))
 
        self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
 

	
 
    def test_delete_normal_user_not_his_own_gist(self):
 
        self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
 
        gist = _create_gist('delete-me')
 
        response = self.app.delete(url('gist', id=gist.gist_id), status=403)
 
        response = self.app.delete(url('gist', gist_id=gist.gist_id), status=403)
 

	
 
    def test_show(self):
 
        gist = _create_gist('gist-show-me')
 
        response = self.app.get(url('gist', id=gist.gist_access_id))
 
        response = self.app.get(url('gist', gist_id=gist.gist_access_id))
 
        response.mustcontain('added file: gist-show-me<')
 
        response.mustcontain('test_admin (RhodeCode Admin) - created')
 
        response.mustcontain('gist-desc')
 
@@ -157,4 +157,4 @@ class TestGistsController(TestController
 

	
 
    def test_edit(self):
 
        self.skipTest('not implemented')
 
        response = self.app.get(url('edit_gist', id=1))
 
        response = self.app.get(url('edit_gist', gist_id=1))
0 comments (0 inline, 0 general)