##// END OF EJS Templates
refactored url.resource to full definition of routes...
marcink -
r3866:1fdec7e3 beta
parent child Browse files
Show More
@@ -384,16 +384,39 b' def make_map(config):'
384 m.connect("formatted_notification", "/notifications/{notification_id}.{format}",
384 m.connect("formatted_notification", "/notifications/{notification_id}.{format}",
385 action="show", conditions=dict(method=["GET"]))
385 action="show", conditions=dict(method=["GET"]))
386
386
387 #ADMIN GIST
388 with rmap.submapper(path_prefix=ADMIN_PREFIX,
389 controller='admin/gists') as m:
390 m.connect("gists", "/gists",
391 action="create", conditions=dict(method=["POST"]))
392 m.connect("gists", "/gists",
393 action="index", conditions=dict(method=["GET"]))
394 m.connect("formatted_gists", "/gists.{format}",
395 action="index", conditions=dict(method=["GET"]))
396 m.connect("new_gist", "/gists/new",
397 action="new", conditions=dict(method=["GET"]))
398 m.connect("formatted_new_gist", "/gists/new.{format}",
399 action="new", conditions=dict(method=["GET"]))
400 m.connect("/gist/{gist_id}",
401 action="update", conditions=dict(method=["PUT"]))
402 m.connect("/gist/{gist_id}",
403 action="delete", conditions=dict(method=["DELETE"]))
404 m.connect("edit_gist", "/gist/{gist_id}/edit",
405 action="edit", conditions=dict(method=["GET"]))
406 m.connect("formatted_edit_gist",
407 "/gist/{gist_id}.{format}/edit",
408 action="edit", conditions=dict(method=["GET"]))
409 m.connect("gist", "/gist/{gist_id}",
410 action="show", conditions=dict(method=["GET"]))
411 m.connect("formatted_gist", "/gists/{gist_id}.{format}",
412 action="show", conditions=dict(method=["GET"]))
413
387 #ADMIN MAIN PAGES
414 #ADMIN MAIN PAGES
388 with rmap.submapper(path_prefix=ADMIN_PREFIX,
415 with rmap.submapper(path_prefix=ADMIN_PREFIX,
389 controller='admin/admin') as m:
416 controller='admin/admin') as m:
390 m.connect('admin_home', '', action='index')
417 m.connect('admin_home', '', action='index')
391 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
418 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
392 action='add_repo')
419 action='add_repo')
393
394 #ADMIN GIST
395 rmap.resource('gist', 'gists', controller='admin/gists',
396 path_prefix=ADMIN_PREFIX)
397 #==========================================================================
420 #==========================================================================
398 # API V2
421 # API V2
399 #==========================================================================
422 #==========================================================================
@@ -126,7 +126,7 b' class GistsController(BaseController):'
126 log.error(traceback.format_exc())
126 log.error(traceback.format_exc())
127 h.flash(_('Error occurred during gist creation'), category='error')
127 h.flash(_('Error occurred during gist creation'), category='error')
128 return redirect(url('new_gist'))
128 return redirect(url('new_gist'))
129 return redirect(url('gist', id=new_gist_id))
129 return redirect(url('gist', gist_id=new_gist_id))
130
130
131 @LoginRequired()
131 @LoginRequired()
132 @NotAnonymous()
132 @NotAnonymous()
@@ -138,26 +138,26 b' class GistsController(BaseController):'
138
138
139 @LoginRequired()
139 @LoginRequired()
140 @NotAnonymous()
140 @NotAnonymous()
141 def update(self, id):
141 def update(self, gist_id):
142 """PUT /admin/gists/id: Update an existing item"""
142 """PUT /admin/gists/gist_id: Update an existing item"""
143 # Forms posted to this method should contain a hidden field:
143 # Forms posted to this method should contain a hidden field:
144 # <input type="hidden" name="_method" value="PUT" />
144 # <input type="hidden" name="_method" value="PUT" />
145 # Or using helpers:
145 # Or using helpers:
146 # h.form(url('gist', id=ID),
146 # h.form(url('gist', gist_id=ID),
147 # method='put')
147 # method='put')
148 # url('gist', id=ID)
148 # url('gist', gist_id=ID)
149
149
150 @LoginRequired()
150 @LoginRequired()
151 @NotAnonymous()
151 @NotAnonymous()
152 def delete(self, id):
152 def delete(self, gist_id):
153 """DELETE /admin/gists/id: Delete an existing item"""
153 """DELETE /admin/gists/gist_id: Delete an existing item"""
154 # Forms posted to this method should contain a hidden field:
154 # Forms posted to this method should contain a hidden field:
155 # <input type="hidden" name="_method" value="DELETE" />
155 # <input type="hidden" name="_method" value="DELETE" />
156 # Or using helpers:
156 # Or using helpers:
157 # h.form(url('gist', id=ID),
157 # h.form(url('gist', gist_id=ID),
158 # method='delete')
158 # method='delete')
159 # url('gist', id=ID)
159 # url('gist', gist_id=ID)
160 gist = GistModel().get_gist(id)
160 gist = GistModel().get_gist(gist_id)
161 owner = gist.gist_owner == c.rhodecode_user.user_id
161 owner = gist.gist_owner == c.rhodecode_user.user_id
162 if h.HasPermissionAny('hg.admin')() or owner:
162 if h.HasPermissionAny('hg.admin')() or owner:
163 GistModel().delete(gist)
163 GistModel().delete(gist)
@@ -169,10 +169,9 b' class GistsController(BaseController):'
169 return redirect(url('gists'))
169 return redirect(url('gists'))
170
170
171 @LoginRequired()
171 @LoginRequired()
172 def show(self, id, format='html'):
172 def show(self, gist_id, format='html'):
173 """GET /admin/gists/id: Show a specific item"""
173 """GET /admin/gists/gist_id: Show a specific item"""
174 # url('gist', id=ID)
174 # url('gist', gist_id=ID)
175 gist_id = id
176 c.gist = Gist.get_or_404(gist_id)
175 c.gist = Gist.get_or_404(gist_id)
177
176
178 #check if this gist is not expired
177 #check if this gist is not expired
@@ -191,6 +190,6 b' class GistsController(BaseController):'
191
190
192 @LoginRequired()
191 @LoginRequired()
193 @NotAnonymous()
192 @NotAnonymous()
194 def edit(self, id, format='html'):
193 def edit(self, gist_id, format='html'):
195 """GET /admin/gists/id/edit: Form to edit an existing item"""
194 """GET /admin/gists/gist_id/edit: Form to edit an existing item"""
196 # url('edit_gist', id=ID)
195 # url('edit_gist', gist_id=ID)
@@ -2161,7 +2161,7 b' class Gist(Base, BaseModel):'
2161 return alias_url.replace('{gistid}', self.gist_access_id)
2161 return alias_url.replace('{gistid}', self.gist_access_id)
2162
2162
2163 from pylons import url
2163 from pylons import url
2164 return url('gist', id=self.gist_access_id, qualified=True)
2164 return url('gist', gist_id=self.gist_access_id, qualified=True)
2165
2165
2166 @classmethod
2166 @classmethod
2167 def base_path(cls):
2167 def base_path(cls):
@@ -42,7 +42,7 b''
42 </div>
42 </div>
43 <div title="${gist.owner.full_contact}" class="user" style="font-size: 16px">
43 <div title="${gist.owner.full_contact}" class="user" style="font-size: 16px">
44 <b>${h.person(gist.owner.full_contact)}</b> /
44 <b>${h.person(gist.owner.full_contact)}</b> /
45 <b><a href="${h.url('gist',id=gist.gist_access_id)}">gist:${gist.gist_access_id}</a></b>
45 <b><a href="${h.url('gist',gist_id=gist.gist_access_id)}">gist:${gist.gist_access_id}</a></b>
46 </div>
46 </div>
47 <div style="padding: 4px 0px 0px 0px">
47 <div style="padding: 4px 0px 0px 0px">
48 ${_('Created')} ${h.age(gist.created_on)} /
48 ${_('Created')} ${h.age(gist.created_on)} /
@@ -52,7 +52,7 b''
52 ## only owner should see that
52 ## only owner should see that
53 %if h.HasPermissionAny('hg.admin')() or c.gist.gist_owner == c.rhodecode_user.user_id:
53 %if h.HasPermissionAny('hg.admin')() or c.gist.gist_owner == c.rhodecode_user.user_id:
54 ##${h.link_to(_('Edit'),h.url(''),class_="ui-btn")}
54 ##${h.link_to(_('Edit'),h.url(''),class_="ui-btn")}
55 ${h.form(url('gist', id=c.gist.gist_id),method='delete')}
55 ${h.form(url('gist', gist_id=c.gist.gist_id),method='delete')}
56 ${h.submit('remove_gist', _('Delete'),class_="ui-btn red",onclick="return confirm('"+_('Confirm to delete this gist')+"');")}
56 ${h.submit('remove_gist', _('Delete'),class_="ui-btn red",onclick="return confirm('"+_('Confirm to delete this gist')+"');")}
57 ${h.end_form()}
57 ${h.end_form()}
58 %endif
58 %endif
@@ -92,7 +92,7 b' class TestGistsController(TestController'
92 Session().add(gist)
92 Session().add(gist)
93 Session().commit()
93 Session().commit()
94
94
95 response = self.app.get(url('gist', id=gist.gist_access_id), status=404)
95 response = self.app.get(url('gist', gist_id=gist.gist_access_id), status=404)
96
96
97 def test_create_private(self):
97 def test_create_private(self):
98 self.log_user()
98 self.log_user()
@@ -128,28 +128,28 b' class TestGistsController(TestController'
128
128
129 def test_update(self):
129 def test_update(self):
130 self.skipTest('not implemented')
130 self.skipTest('not implemented')
131 response = self.app.put(url('gist', id=1))
131 response = self.app.put(url('gist', gist_id=1))
132
132
133 def test_delete(self):
133 def test_delete(self):
134 self.log_user()
134 self.log_user()
135 gist = _create_gist('delete-me')
135 gist = _create_gist('delete-me')
136 response = self.app.delete(url('gist', id=gist.gist_id))
136 response = self.app.delete(url('gist', gist_id=gist.gist_id))
137 self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
137 self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
138
138
139 def test_delete_normal_user_his_gist(self):
139 def test_delete_normal_user_his_gist(self):
140 self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
140 self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
141 gist = _create_gist('delete-me', owner=TEST_USER_REGULAR_LOGIN)
141 gist = _create_gist('delete-me', owner=TEST_USER_REGULAR_LOGIN)
142 response = self.app.delete(url('gist', id=gist.gist_id))
142 response = self.app.delete(url('gist', gist_id=gist.gist_id))
143 self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
143 self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
144
144
145 def test_delete_normal_user_not_his_own_gist(self):
145 def test_delete_normal_user_not_his_own_gist(self):
146 self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
146 self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
147 gist = _create_gist('delete-me')
147 gist = _create_gist('delete-me')
148 response = self.app.delete(url('gist', id=gist.gist_id), status=403)
148 response = self.app.delete(url('gist', gist_id=gist.gist_id), status=403)
149
149
150 def test_show(self):
150 def test_show(self):
151 gist = _create_gist('gist-show-me')
151 gist = _create_gist('gist-show-me')
152 response = self.app.get(url('gist', id=gist.gist_access_id))
152 response = self.app.get(url('gist', gist_id=gist.gist_access_id))
153 response.mustcontain('added file: gist-show-me<')
153 response.mustcontain('added file: gist-show-me<')
154 response.mustcontain('test_admin (RhodeCode Admin) - created')
154 response.mustcontain('test_admin (RhodeCode Admin) - created')
155 response.mustcontain('gist-desc')
155 response.mustcontain('gist-desc')
@@ -157,4 +157,4 b' class TestGistsController(TestController'
157
157
158 def test_edit(self):
158 def test_edit(self):
159 self.skipTest('not implemented')
159 self.skipTest('not implemented')
160 response = self.app.get(url('edit_gist', id=1))
160 response = self.app.get(url('edit_gist', gist_id=1))
General Comments 0
You need to be logged in to leave comments. Login now