Show More
@@ -1,706 +1,708 | |||
|
1 | 1 | """ |
|
2 | 2 | Routes configuration |
|
3 | 3 | |
|
4 | 4 | The more specific and detailed routes should be defined first so they |
|
5 | 5 | may take precedent over the more generic routes. For more information |
|
6 | 6 | refer to the routes manual at http://routes.groovie.org/docs/ |
|
7 | 7 | """ |
|
8 | 8 | from __future__ import with_statement |
|
9 | 9 | from routes import Mapper |
|
10 | 10 | |
|
11 | 11 | # prefix for non repository related links needs to be prefixed with `/` |
|
12 | 12 | ADMIN_PREFIX = '/_admin' |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | def make_map(config): |
|
16 | 16 | """Create, configure and return the routes Mapper""" |
|
17 | 17 | rmap = Mapper(directory=config['pylons.paths']['controllers'], |
|
18 | 18 | always_scan=config['debug']) |
|
19 | 19 | rmap.minimization = False |
|
20 | 20 | rmap.explicit = False |
|
21 | 21 | |
|
22 | 22 | from rhodecode.lib.utils import is_valid_repo |
|
23 | 23 | from rhodecode.lib.utils import is_valid_repos_group |
|
24 | 24 | |
|
25 | 25 | def check_repo(environ, match_dict): |
|
26 | 26 | """ |
|
27 | 27 | check for valid repository for proper 404 handling |
|
28 | 28 | |
|
29 | 29 | :param environ: |
|
30 | 30 | :param match_dict: |
|
31 | 31 | """ |
|
32 | 32 | from rhodecode.model.db import Repository |
|
33 | 33 | repo_name = match_dict.get('repo_name') |
|
34 | 34 | |
|
35 | 35 | if match_dict.get('f_path'): |
|
36 | 36 | #fix for multiple initial slashes that causes errors |
|
37 | 37 | match_dict['f_path'] = match_dict['f_path'].lstrip('/') |
|
38 | 38 | |
|
39 | 39 | try: |
|
40 | 40 | by_id = repo_name.split('_') |
|
41 | 41 | if len(by_id) == 2 and by_id[1].isdigit() and by_id[0] == '': |
|
42 | 42 | repo_name = Repository.get(by_id[1]).repo_name |
|
43 | 43 | match_dict['repo_name'] = repo_name |
|
44 | 44 | except Exception: |
|
45 | 45 | pass |
|
46 | 46 | |
|
47 | 47 | return is_valid_repo(repo_name, config['base_path']) |
|
48 | 48 | |
|
49 | 49 | def check_group(environ, match_dict): |
|
50 | 50 | """ |
|
51 | 51 | check for valid repository group for proper 404 handling |
|
52 | 52 | |
|
53 | 53 | :param environ: |
|
54 | 54 | :param match_dict: |
|
55 | 55 | """ |
|
56 | 56 | repos_group_name = match_dict.get('group_name') |
|
57 | 57 | return is_valid_repos_group(repos_group_name, config['base_path']) |
|
58 | 58 | |
|
59 | 59 | def check_group_skip_path(environ, match_dict): |
|
60 | 60 | """ |
|
61 | 61 | check for valid repository group for proper 404 handling, but skips |
|
62 | 62 | verification of existing path |
|
63 | 63 | |
|
64 | 64 | :param environ: |
|
65 | 65 | :param match_dict: |
|
66 | 66 | """ |
|
67 | 67 | repos_group_name = match_dict.get('group_name') |
|
68 | 68 | return is_valid_repos_group(repos_group_name, config['base_path'], |
|
69 | 69 | skip_path_check=True) |
|
70 | 70 | |
|
71 | 71 | def check_user_group(environ, match_dict): |
|
72 | 72 | """ |
|
73 | 73 | check for valid user group for proper 404 handling |
|
74 | 74 | |
|
75 | 75 | :param environ: |
|
76 | 76 | :param match_dict: |
|
77 | 77 | """ |
|
78 | 78 | return True |
|
79 | 79 | |
|
80 | 80 | def check_int(environ, match_dict): |
|
81 | 81 | return match_dict.get('id').isdigit() |
|
82 | 82 | |
|
83 | 83 | # The ErrorController route (handles 404/500 error pages); it should |
|
84 | 84 | # likely stay at the top, ensuring it can always be resolved |
|
85 | 85 | rmap.connect('/error/{action}', controller='error') |
|
86 | 86 | rmap.connect('/error/{action}/{id}', controller='error') |
|
87 | 87 | |
|
88 | 88 | #========================================================================== |
|
89 | 89 | # CUSTOM ROUTES HERE |
|
90 | 90 | #========================================================================== |
|
91 | 91 | |
|
92 | 92 | #MAIN PAGE |
|
93 | 93 | rmap.connect('home', '/', controller='home', action='index') |
|
94 | 94 | rmap.connect('repo_switcher', '/repos', controller='home', |
|
95 | 95 | action='repo_switcher') |
|
96 | 96 | rmap.connect('branch_tag_switcher', '/branches-tags/{repo_name:.*?}', |
|
97 | 97 | controller='home', action='branch_tag_switcher') |
|
98 | 98 | rmap.connect('bugtracker', |
|
99 | 99 | "http://bitbucket.org/marcinkuzminski/rhodecode/issues", |
|
100 | 100 | _static=True) |
|
101 | 101 | rmap.connect('rst_help', |
|
102 | 102 | "http://docutils.sourceforge.net/docs/user/rst/quickref.html", |
|
103 | 103 | _static=True) |
|
104 | 104 | rmap.connect('rhodecode_official', "http://rhodecode.org", _static=True) |
|
105 | 105 | |
|
106 | 106 | #ADMIN REPOSITORY REST ROUTES |
|
107 | 107 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
108 | 108 | controller='admin/repos') as m: |
|
109 | 109 | m.connect("repos", "/repos", |
|
110 | 110 | action="create", conditions=dict(method=["POST"])) |
|
111 | 111 | m.connect("repos", "/repos", |
|
112 | 112 | action="index", conditions=dict(method=["GET"])) |
|
113 | 113 | m.connect("formatted_repos", "/repos.{format}", |
|
114 | 114 | action="index", |
|
115 | 115 | conditions=dict(method=["GET"])) |
|
116 | 116 | m.connect("new_repo", "/create_repository", |
|
117 | 117 | action="create_repository", conditions=dict(method=["GET"])) |
|
118 | 118 | m.connect("/repos/{repo_name:.*?}", |
|
119 | 119 | action="update", conditions=dict(method=["PUT"], |
|
120 | 120 | function=check_repo)) |
|
121 | 121 | m.connect("/repos/{repo_name:.*?}", |
|
122 | 122 | action="delete", conditions=dict(method=["DELETE"], |
|
123 | 123 | function=check_repo)) |
|
124 | 124 | m.connect("formatted_edit_repo", "/repos/{repo_name:.*?}.{format}/edit", |
|
125 | 125 | action="edit", conditions=dict(method=["GET"], |
|
126 | 126 | function=check_repo)) |
|
127 | 127 | m.connect("repo", "/repos/{repo_name:.*?}", |
|
128 | 128 | action="show", conditions=dict(method=["GET"], |
|
129 | 129 | function=check_repo)) |
|
130 | 130 | m.connect("formatted_repo", "/repos/{repo_name:.*?}.{format}", |
|
131 | 131 | action="show", conditions=dict(method=["GET"], |
|
132 | 132 | function=check_repo)) |
|
133 | 133 | #add repo perm member |
|
134 | 134 | m.connect('set_repo_perm_member', |
|
135 | 135 | "/repos/{repo_name:.*?}/grant_perm", |
|
136 | 136 | action="set_repo_perm_member", |
|
137 | 137 | conditions=dict(method=["POST"], function=check_repo)) |
|
138 | 138 | |
|
139 | 139 | #ajax delete repo perm user |
|
140 | 140 | m.connect('delete_repo_perm_member', |
|
141 | 141 | "/repos/{repo_name:.*?}/revoke_perm", |
|
142 | 142 | action="delete_repo_perm_member", |
|
143 | 143 | conditions=dict(method=["DELETE"], function=check_repo)) |
|
144 | 144 | |
|
145 | 145 | #settings actions |
|
146 | 146 | m.connect('repo_stats', "/repos_stats/{repo_name:.*?}", |
|
147 | 147 | action="repo_stats", conditions=dict(method=["DELETE"], |
|
148 | 148 | function=check_repo)) |
|
149 | 149 | m.connect('repo_cache', "/repos_cache/{repo_name:.*?}", |
|
150 | 150 | action="repo_cache", conditions=dict(method=["DELETE"], |
|
151 | 151 | function=check_repo)) |
|
152 | 152 | m.connect('repo_public_journal', "/repos_public_journal/{repo_name:.*?}", |
|
153 | 153 | action="repo_public_journal", conditions=dict(method=["PUT"], |
|
154 | 154 | function=check_repo)) |
|
155 | 155 | m.connect('repo_pull', "/repo_pull/{repo_name:.*?}", |
|
156 | 156 | action="repo_pull", conditions=dict(method=["PUT"], |
|
157 | 157 | function=check_repo)) |
|
158 | 158 | m.connect('repo_as_fork', "/repo_as_fork/{repo_name:.*?}", |
|
159 | 159 | action="repo_as_fork", conditions=dict(method=["PUT"], |
|
160 | 160 | function=check_repo)) |
|
161 | 161 | m.connect('repo_locking', "/repo_locking/{repo_name:.*?}", |
|
162 | 162 | action="repo_locking", conditions=dict(method=["PUT"], |
|
163 | 163 | function=check_repo)) |
|
164 | 164 | m.connect('toggle_locking', "/locking_toggle/{repo_name:.*?}", |
|
165 | 165 | action="toggle_locking", conditions=dict(method=["GET"], |
|
166 | 166 | function=check_repo)) |
|
167 | 167 | |
|
168 | 168 | #repo fields |
|
169 | 169 | m.connect('create_repo_fields', "/repo_fields/{repo_name:.*?}/new", |
|
170 | 170 | action="create_repo_field", conditions=dict(method=["PUT"], |
|
171 | 171 | function=check_repo)) |
|
172 | 172 | |
|
173 | 173 | m.connect('delete_repo_fields', "/repo_fields/{repo_name:.*?}/{field_id}", |
|
174 | 174 | action="delete_repo_field", conditions=dict(method=["DELETE"], |
|
175 | 175 | function=check_repo)) |
|
176 | 176 | |
|
177 | 177 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
178 | 178 | controller='admin/repos_groups') as m: |
|
179 | 179 | m.connect("repos_groups", "/repos_groups", |
|
180 | 180 | action="create", conditions=dict(method=["POST"])) |
|
181 | 181 | m.connect("repos_groups", "/repos_groups", |
|
182 | 182 | action="index", conditions=dict(method=["GET"])) |
|
183 | 183 | m.connect("formatted_repos_groups", "/repos_groups.{format}", |
|
184 | 184 | action="index", conditions=dict(method=["GET"])) |
|
185 | 185 | m.connect("new_repos_group", "/repos_groups/new", |
|
186 | 186 | action="new", conditions=dict(method=["GET"])) |
|
187 | 187 | m.connect("formatted_new_repos_group", "/repos_groups/new.{format}", |
|
188 | 188 | action="new", conditions=dict(method=["GET"])) |
|
189 | 189 | m.connect("update_repos_group", "/repos_groups/{group_name:.*?}", |
|
190 | 190 | action="update", conditions=dict(method=["PUT"], |
|
191 | 191 | function=check_group)) |
|
192 | 192 | #add repo group perm member |
|
193 | 193 | m.connect('set_repo_group_perm_member', |
|
194 | 194 | "/repos_groups/{group_name:.*?}/grant_perm", |
|
195 | 195 | action="set_repo_group_perm_member", |
|
196 | 196 | conditions=dict(method=["POST"], function=check_group)) |
|
197 | 197 | |
|
198 | 198 | #ajax delete repo group perm |
|
199 | 199 | m.connect('delete_repo_group_perm_member', |
|
200 | 200 | "/repos_groups/{group_name:.*?}/revoke_perm", |
|
201 | 201 | action="delete_repo_group_perm_member", |
|
202 | 202 | conditions=dict(method=["DELETE"], function=check_group)) |
|
203 | 203 | |
|
204 | 204 | m.connect("delete_repos_group", "/repos_groups/{group_name:.*?}", |
|
205 | 205 | action="delete", conditions=dict(method=["DELETE"], |
|
206 | 206 | function=check_group_skip_path)) |
|
207 | 207 | m.connect("edit_repos_group", "/repos_groups/{group_name:.*?}/edit", |
|
208 | 208 | action="edit", conditions=dict(method=["GET"], |
|
209 | 209 | function=check_group)) |
|
210 | 210 | m.connect("formatted_edit_repos_group", |
|
211 | 211 | "/repos_groups/{group_name:.*?}.{format}/edit", |
|
212 | 212 | action="edit", conditions=dict(method=["GET"], |
|
213 | 213 | function=check_group)) |
|
214 | 214 | m.connect("repos_group", "/repos_groups/{group_name:.*?}", |
|
215 | 215 | action="show", conditions=dict(method=["GET"], |
|
216 | 216 | function=check_group)) |
|
217 | 217 | m.connect("formatted_repos_group", "/repos_groups/{group_name:.*?}.{format}", |
|
218 | 218 | action="show", conditions=dict(method=["GET"], |
|
219 | 219 | function=check_group)) |
|
220 | 220 | |
|
221 | 221 | #ADMIN USER REST ROUTES |
|
222 | 222 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
223 | 223 | controller='admin/users') as m: |
|
224 | 224 | m.connect("users", "/users", |
|
225 | 225 | action="create", conditions=dict(method=["POST"])) |
|
226 | 226 | m.connect("users", "/users", |
|
227 | 227 | action="index", conditions=dict(method=["GET"])) |
|
228 | 228 | m.connect("formatted_users", "/users.{format}", |
|
229 | 229 | action="index", conditions=dict(method=["GET"])) |
|
230 | 230 | m.connect("new_user", "/users/new", |
|
231 | 231 | action="new", conditions=dict(method=["GET"])) |
|
232 | 232 | m.connect("formatted_new_user", "/users/new.{format}", |
|
233 | 233 | action="new", conditions=dict(method=["GET"])) |
|
234 | 234 | m.connect("update_user", "/users/{id}", |
|
235 | 235 | action="update", conditions=dict(method=["PUT"])) |
|
236 | 236 | m.connect("delete_user", "/users/{id}", |
|
237 | 237 | action="delete", conditions=dict(method=["DELETE"])) |
|
238 | 238 | m.connect("edit_user", "/users/{id}/edit", |
|
239 | 239 | action="edit", conditions=dict(method=["GET"])) |
|
240 | 240 | m.connect("formatted_edit_user", |
|
241 | 241 | "/users/{id}.{format}/edit", |
|
242 | 242 | action="edit", conditions=dict(method=["GET"])) |
|
243 | 243 | m.connect("user", "/users/{id}", |
|
244 | 244 | action="show", conditions=dict(method=["GET"])) |
|
245 | 245 | m.connect("formatted_user", "/users/{id}.{format}", |
|
246 | 246 | action="show", conditions=dict(method=["GET"])) |
|
247 | 247 | |
|
248 | 248 | #EXTRAS USER ROUTES |
|
249 | 249 | m.connect("user_perm", "/users_perm/{id}", |
|
250 | 250 | action="update_perm", conditions=dict(method=["PUT"])) |
|
251 | 251 | m.connect("user_emails", "/users_emails/{id}", |
|
252 | 252 | action="add_email", conditions=dict(method=["PUT"])) |
|
253 | 253 | m.connect("user_emails_delete", "/users_emails/{id}", |
|
254 | 254 | action="delete_email", conditions=dict(method=["DELETE"])) |
|
255 | 255 | m.connect("user_ips", "/users_ips/{id}", |
|
256 | 256 | action="add_ip", conditions=dict(method=["PUT"])) |
|
257 | 257 | m.connect("user_ips_delete", "/users_ips/{id}", |
|
258 | 258 | action="delete_ip", conditions=dict(method=["DELETE"])) |
|
259 | 259 | |
|
260 | 260 | #ADMIN USER GROUPS REST ROUTES |
|
261 | 261 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
262 | 262 | controller='admin/users_groups') as m: |
|
263 | 263 | m.connect("users_groups", "/users_groups", |
|
264 | 264 | action="create", conditions=dict(method=["POST"])) |
|
265 | 265 | m.connect("users_groups", "/users_groups", |
|
266 | 266 | action="index", conditions=dict(method=["GET"])) |
|
267 | 267 | m.connect("formatted_users_groups", "/users_groups.{format}", |
|
268 | 268 | action="index", conditions=dict(method=["GET"])) |
|
269 | 269 | m.connect("new_users_group", "/users_groups/new", |
|
270 | 270 | action="new", conditions=dict(method=["GET"])) |
|
271 | 271 | m.connect("formatted_new_users_group", "/users_groups/new.{format}", |
|
272 | 272 | action="new", conditions=dict(method=["GET"])) |
|
273 | 273 | m.connect("update_users_group", "/users_groups/{id}", |
|
274 | 274 | action="update", conditions=dict(method=["PUT"])) |
|
275 | 275 | m.connect("delete_users_group", "/users_groups/{id}", |
|
276 | 276 | action="delete", conditions=dict(method=["DELETE"])) |
|
277 | 277 | m.connect("edit_users_group", "/users_groups/{id}/edit", |
|
278 | 278 | action="edit", conditions=dict(method=["GET"]), |
|
279 | 279 | function=check_user_group) |
|
280 | 280 | m.connect("formatted_edit_users_group", |
|
281 | 281 | "/users_groups/{id}.{format}/edit", |
|
282 | 282 | action="edit", conditions=dict(method=["GET"])) |
|
283 | 283 | m.connect("users_group", "/users_groups/{id}", |
|
284 | 284 | action="show", conditions=dict(method=["GET"])) |
|
285 | 285 | m.connect("formatted_users_group", "/users_groups/{id}.{format}", |
|
286 | 286 | action="show", conditions=dict(method=["GET"])) |
|
287 | 287 | |
|
288 | 288 | #EXTRAS USER ROUTES |
|
289 | 289 | # update |
|
290 | 290 | m.connect("users_group_perm", "/users_groups/{id}/update_global_perm", |
|
291 | 291 | action="update_perm", conditions=dict(method=["PUT"])) |
|
292 | 292 | |
|
293 | 293 | #add user group perm member |
|
294 | 294 | m.connect('set_user_group_perm_member', "/users_groups/{id}/grant_perm", |
|
295 | 295 | action="set_user_group_perm_member", |
|
296 | 296 | conditions=dict(method=["POST"])) |
|
297 | 297 | |
|
298 | 298 | #ajax delete user group perm |
|
299 | 299 | m.connect('delete_user_group_perm_member', "/users_groups/{id}/revoke_perm", |
|
300 | 300 | action="delete_user_group_perm_member", |
|
301 | 301 | conditions=dict(method=["DELETE"])) |
|
302 | 302 | |
|
303 | 303 | #ADMIN GROUP REST ROUTES |
|
304 | 304 | rmap.resource('group', 'groups', |
|
305 | 305 | controller='admin/groups', path_prefix=ADMIN_PREFIX) |
|
306 | 306 | |
|
307 | 307 | #ADMIN PERMISSIONS REST ROUTES |
|
308 | 308 | rmap.resource('permission', 'permissions', |
|
309 | 309 | controller='admin/permissions', path_prefix=ADMIN_PREFIX) |
|
310 | 310 | |
|
311 | 311 | #ADMIN DEFAULTS REST ROUTES |
|
312 | 312 | rmap.resource('default', 'defaults', |
|
313 | 313 | controller='admin/defaults', path_prefix=ADMIN_PREFIX) |
|
314 | 314 | |
|
315 | 315 | ##ADMIN LDAP SETTINGS |
|
316 | 316 | rmap.connect('ldap_settings', '%s/ldap' % ADMIN_PREFIX, |
|
317 | 317 | controller='admin/ldap_settings', action='ldap_settings', |
|
318 | 318 | conditions=dict(method=["POST"])) |
|
319 | 319 | |
|
320 | 320 | rmap.connect('ldap_home', '%s/ldap' % ADMIN_PREFIX, |
|
321 | 321 | controller='admin/ldap_settings') |
|
322 | 322 | |
|
323 | 323 | #ADMIN SETTINGS REST ROUTES |
|
324 | 324 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
325 | 325 | controller='admin/settings') as m: |
|
326 | 326 | m.connect("admin_settings", "/settings", |
|
327 | 327 | action="create", conditions=dict(method=["POST"])) |
|
328 | 328 | m.connect("admin_settings", "/settings", |
|
329 | 329 | action="index", conditions=dict(method=["GET"])) |
|
330 | 330 | m.connect("formatted_admin_settings", "/settings.{format}", |
|
331 | 331 | action="index", conditions=dict(method=["GET"])) |
|
332 | 332 | m.connect("admin_new_setting", "/settings/new", |
|
333 | 333 | action="new", conditions=dict(method=["GET"])) |
|
334 | 334 | m.connect("formatted_admin_new_setting", "/settings/new.{format}", |
|
335 | 335 | action="new", conditions=dict(method=["GET"])) |
|
336 | 336 | m.connect("/settings/{setting_id}", |
|
337 | 337 | action="update", conditions=dict(method=["PUT"])) |
|
338 | 338 | m.connect("/settings/{setting_id}", |
|
339 | 339 | action="delete", conditions=dict(method=["DELETE"])) |
|
340 | 340 | m.connect("admin_edit_setting", "/settings/{setting_id}/edit", |
|
341 | 341 | action="edit", conditions=dict(method=["GET"])) |
|
342 | 342 | m.connect("formatted_admin_edit_setting", |
|
343 | 343 | "/settings/{setting_id}.{format}/edit", |
|
344 | 344 | action="edit", conditions=dict(method=["GET"])) |
|
345 | 345 | m.connect("admin_setting", "/settings/{setting_id}", |
|
346 | 346 | action="show", conditions=dict(method=["GET"])) |
|
347 | 347 | m.connect("formatted_admin_setting", "/settings/{setting_id}.{format}", |
|
348 | 348 | action="show", conditions=dict(method=["GET"])) |
|
349 | 349 | m.connect("admin_settings_my_account", "/my_account", |
|
350 | 350 | action="my_account", conditions=dict(method=["GET"])) |
|
351 | 351 | m.connect("admin_settings_my_account_update", "/my_account_update", |
|
352 | 352 | action="my_account_update", conditions=dict(method=["PUT"])) |
|
353 | 353 | m.connect("admin_settings_my_repos", "/my_account/repos", |
|
354 | 354 | action="my_account_my_repos", conditions=dict(method=["GET"])) |
|
355 | 355 | m.connect("admin_settings_my_pullrequests", "/my_account/pull_requests", |
|
356 | 356 | action="my_account_my_pullrequests", conditions=dict(method=["GET"])) |
|
357 | 357 | |
|
358 | 358 | #NOTIFICATION REST ROUTES |
|
359 | 359 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
360 | 360 | controller='admin/notifications') as m: |
|
361 | 361 | m.connect("notifications", "/notifications", |
|
362 | 362 | action="create", conditions=dict(method=["POST"])) |
|
363 | 363 | m.connect("notifications", "/notifications", |
|
364 | 364 | action="index", conditions=dict(method=["GET"])) |
|
365 | 365 | m.connect("notifications_mark_all_read", "/notifications/mark_all_read", |
|
366 | 366 | action="mark_all_read", conditions=dict(method=["GET"])) |
|
367 | 367 | m.connect("formatted_notifications", "/notifications.{format}", |
|
368 | 368 | action="index", conditions=dict(method=["GET"])) |
|
369 | 369 | m.connect("new_notification", "/notifications/new", |
|
370 | 370 | action="new", conditions=dict(method=["GET"])) |
|
371 | 371 | m.connect("formatted_new_notification", "/notifications/new.{format}", |
|
372 | 372 | action="new", conditions=dict(method=["GET"])) |
|
373 | 373 | m.connect("/notification/{notification_id}", |
|
374 | 374 | action="update", conditions=dict(method=["PUT"])) |
|
375 | 375 | m.connect("/notification/{notification_id}", |
|
376 | 376 | action="delete", conditions=dict(method=["DELETE"])) |
|
377 | 377 | m.connect("edit_notification", "/notification/{notification_id}/edit", |
|
378 | 378 | action="edit", conditions=dict(method=["GET"])) |
|
379 | 379 | m.connect("formatted_edit_notification", |
|
380 | 380 | "/notification/{notification_id}.{format}/edit", |
|
381 | 381 | action="edit", conditions=dict(method=["GET"])) |
|
382 | 382 | m.connect("notification", "/notification/{notification_id}", |
|
383 | 383 | action="show", conditions=dict(method=["GET"])) |
|
384 |
m.connect("formatted_notification", "/notification |
|
|
384 | m.connect("formatted_notification", "/notification/{notification_id}.{format}", | |
|
385 | 385 | action="show", conditions=dict(method=["GET"])) |
|
386 | 386 | |
|
387 | 387 | #ADMIN GIST |
|
388 | 388 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
389 | 389 | controller='admin/gists') as m: |
|
390 | 390 | m.connect("gists", "/gists", |
|
391 | 391 | action="create", conditions=dict(method=["POST"])) |
|
392 | 392 | m.connect("gists", "/gists", |
|
393 | 393 | action="index", conditions=dict(method=["GET"])) |
|
394 |
m.connect("formatted_gists", "/gists |
|
|
394 | m.connect("formatted_gists", "/gists/{format}", | |
|
395 | 395 | action="index", conditions=dict(method=["GET"])) |
|
396 | 396 | m.connect("new_gist", "/gists/new", |
|
397 | 397 | action="new", conditions=dict(method=["GET"])) |
|
398 |
m.connect("formatted_new_gist", "/gists/new |
|
|
398 | m.connect("formatted_new_gist", "/gists/new/{format}", | |
|
399 | 399 | action="new", conditions=dict(method=["GET"])) |
|
400 | 400 | m.connect("/gist/{gist_id}", |
|
401 | 401 | action="update", conditions=dict(method=["PUT"])) |
|
402 | 402 | m.connect("/gist/{gist_id}", |
|
403 | 403 | action="delete", conditions=dict(method=["DELETE"])) |
|
404 | 404 | m.connect("edit_gist", "/gist/{gist_id}/edit", |
|
405 | 405 | action="edit", conditions=dict(method=["GET"])) |
|
406 | 406 | m.connect("formatted_edit_gist", |
|
407 |
"/gist/{gist_id} |
|
|
407 | "/gist/{gist_id}/{format}/edit", | |
|
408 | 408 | action="edit", conditions=dict(method=["GET"])) |
|
409 | 409 | m.connect("gist", "/gist/{gist_id}", |
|
410 | 410 | action="show", conditions=dict(method=["GET"])) |
|
411 |
m.connect("formatted_gist", "/gist |
|
|
411 | m.connect("formatted_gist", "/gist/{gist_id}/{format}", | |
|
412 | action="show", conditions=dict(method=["GET"])) | |
|
413 | m.connect("formatted_gist_file", "/gist/{gist_id}/{format}/{revision}/{f_path:.*}", | |
|
412 | 414 | action="show", conditions=dict(method=["GET"])) |
|
413 | 415 | |
|
414 | 416 | #ADMIN MAIN PAGES |
|
415 | 417 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
416 | 418 | controller='admin/admin') as m: |
|
417 | 419 | m.connect('admin_home', '', action='index') |
|
418 | 420 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
|
419 | 421 | action='add_repo') |
|
420 | 422 | #========================================================================== |
|
421 | 423 | # API V2 |
|
422 | 424 | #========================================================================== |
|
423 | 425 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
424 | 426 | controller='api/api') as m: |
|
425 | 427 | m.connect('api', '/api') |
|
426 | 428 | |
|
427 | 429 | #USER JOURNAL |
|
428 | 430 | rmap.connect('journal', '%s/journal' % ADMIN_PREFIX, |
|
429 | 431 | controller='journal', action='index') |
|
430 | 432 | rmap.connect('journal_rss', '%s/journal/rss' % ADMIN_PREFIX, |
|
431 | 433 | controller='journal', action='journal_rss') |
|
432 | 434 | rmap.connect('journal_atom', '%s/journal/atom' % ADMIN_PREFIX, |
|
433 | 435 | controller='journal', action='journal_atom') |
|
434 | 436 | |
|
435 | 437 | rmap.connect('public_journal', '%s/public_journal' % ADMIN_PREFIX, |
|
436 | 438 | controller='journal', action="public_journal") |
|
437 | 439 | |
|
438 | 440 | rmap.connect('public_journal_rss', '%s/public_journal/rss' % ADMIN_PREFIX, |
|
439 | 441 | controller='journal', action="public_journal_rss") |
|
440 | 442 | |
|
441 | 443 | rmap.connect('public_journal_rss_old', '%s/public_journal_rss' % ADMIN_PREFIX, |
|
442 | 444 | controller='journal', action="public_journal_rss") |
|
443 | 445 | |
|
444 | 446 | rmap.connect('public_journal_atom', |
|
445 | 447 | '%s/public_journal/atom' % ADMIN_PREFIX, controller='journal', |
|
446 | 448 | action="public_journal_atom") |
|
447 | 449 | |
|
448 | 450 | rmap.connect('public_journal_atom_old', |
|
449 | 451 | '%s/public_journal_atom' % ADMIN_PREFIX, controller='journal', |
|
450 | 452 | action="public_journal_atom") |
|
451 | 453 | |
|
452 | 454 | rmap.connect('toggle_following', '%s/toggle_following' % ADMIN_PREFIX, |
|
453 | 455 | controller='journal', action='toggle_following', |
|
454 | 456 | conditions=dict(method=["POST"])) |
|
455 | 457 | |
|
456 | 458 | #SEARCH |
|
457 | 459 | rmap.connect('search', '%s/search' % ADMIN_PREFIX, controller='search',) |
|
458 | 460 | rmap.connect('search_repo_admin', '%s/search/{repo_name:.*}' % ADMIN_PREFIX, |
|
459 | 461 | controller='search', |
|
460 | 462 | conditions=dict(function=check_repo)) |
|
461 | 463 | rmap.connect('search_repo', '/{repo_name:.*?}/search', |
|
462 | 464 | controller='search', |
|
463 | 465 | conditions=dict(function=check_repo), |
|
464 | 466 | ) |
|
465 | 467 | |
|
466 | 468 | #LOGIN/LOGOUT/REGISTER/SIGN IN |
|
467 | 469 | rmap.connect('login_home', '%s/login' % ADMIN_PREFIX, controller='login') |
|
468 | 470 | rmap.connect('logout_home', '%s/logout' % ADMIN_PREFIX, controller='login', |
|
469 | 471 | action='logout') |
|
470 | 472 | |
|
471 | 473 | rmap.connect('register', '%s/register' % ADMIN_PREFIX, controller='login', |
|
472 | 474 | action='register') |
|
473 | 475 | |
|
474 | 476 | rmap.connect('reset_password', '%s/password_reset' % ADMIN_PREFIX, |
|
475 | 477 | controller='login', action='password_reset') |
|
476 | 478 | |
|
477 | 479 | rmap.connect('reset_password_confirmation', |
|
478 | 480 | '%s/password_reset_confirmation' % ADMIN_PREFIX, |
|
479 | 481 | controller='login', action='password_reset_confirmation') |
|
480 | 482 | |
|
481 | 483 | #FEEDS |
|
482 | 484 | rmap.connect('rss_feed_home', '/{repo_name:.*?}/feed/rss', |
|
483 | 485 | controller='feed', action='rss', |
|
484 | 486 | conditions=dict(function=check_repo)) |
|
485 | 487 | |
|
486 | 488 | rmap.connect('atom_feed_home', '/{repo_name:.*?}/feed/atom', |
|
487 | 489 | controller='feed', action='atom', |
|
488 | 490 | conditions=dict(function=check_repo)) |
|
489 | 491 | |
|
490 | 492 | #========================================================================== |
|
491 | 493 | # REPOSITORY ROUTES |
|
492 | 494 | #========================================================================== |
|
493 | 495 | rmap.connect('summary_home', '/{repo_name:.*?}', |
|
494 | 496 | controller='summary', |
|
495 | 497 | conditions=dict(function=check_repo)) |
|
496 | 498 | |
|
497 | 499 | rmap.connect('repo_size', '/{repo_name:.*?}/repo_size', |
|
498 | 500 | controller='summary', action='repo_size', |
|
499 | 501 | conditions=dict(function=check_repo)) |
|
500 | 502 | |
|
501 | 503 | rmap.connect('repos_group_home', '/{group_name:.*}', |
|
502 | 504 | controller='admin/repos_groups', action="show_by_name", |
|
503 | 505 | conditions=dict(function=check_group)) |
|
504 | 506 | |
|
505 | 507 | rmap.connect('changeset_home', '/{repo_name:.*?}/changeset/{revision}', |
|
506 | 508 | controller='changeset', revision='tip', |
|
507 | 509 | conditions=dict(function=check_repo)) |
|
508 | 510 | |
|
509 | 511 | # no longer user, but kept for routes to work |
|
510 | 512 | rmap.connect("_edit_repo", "/{repo_name:.*?}/edit", |
|
511 | 513 | controller='admin/repos', action="edit", |
|
512 | 514 | conditions=dict(method=["GET"], function=check_repo) |
|
513 | 515 | ) |
|
514 | 516 | |
|
515 | 517 | rmap.connect("edit_repo", "/{repo_name:.*?}/settings", |
|
516 | 518 | controller='admin/repos', action="edit", |
|
517 | 519 | conditions=dict(method=["GET"], function=check_repo) |
|
518 | 520 | ) |
|
519 | 521 | |
|
520 | 522 | #still working url for backward compat. |
|
521 | 523 | rmap.connect('raw_changeset_home_depraced', |
|
522 | 524 | '/{repo_name:.*?}/raw-changeset/{revision}', |
|
523 | 525 | controller='changeset', action='changeset_raw', |
|
524 | 526 | revision='tip', conditions=dict(function=check_repo)) |
|
525 | 527 | |
|
526 | 528 | ## new URLs |
|
527 | 529 | rmap.connect('changeset_raw_home', |
|
528 | 530 | '/{repo_name:.*?}/changeset-diff/{revision}', |
|
529 | 531 | controller='changeset', action='changeset_raw', |
|
530 | 532 | revision='tip', conditions=dict(function=check_repo)) |
|
531 | 533 | |
|
532 | 534 | rmap.connect('changeset_patch_home', |
|
533 | 535 | '/{repo_name:.*?}/changeset-patch/{revision}', |
|
534 | 536 | controller='changeset', action='changeset_patch', |
|
535 | 537 | revision='tip', conditions=dict(function=check_repo)) |
|
536 | 538 | |
|
537 | 539 | rmap.connect('changeset_download_home', |
|
538 | 540 | '/{repo_name:.*?}/changeset-download/{revision}', |
|
539 | 541 | controller='changeset', action='changeset_download', |
|
540 | 542 | revision='tip', conditions=dict(function=check_repo)) |
|
541 | 543 | |
|
542 | 544 | rmap.connect('changeset_comment', |
|
543 | 545 | '/{repo_name:.*?}/changeset/{revision}/comment', |
|
544 | 546 | controller='changeset', revision='tip', action='comment', |
|
545 | 547 | conditions=dict(function=check_repo)) |
|
546 | 548 | |
|
547 | 549 | rmap.connect('changeset_comment_preview', |
|
548 | 550 | '/{repo_name:.*?}/changeset/comment/preview', |
|
549 | 551 | controller='changeset', action='preview_comment', |
|
550 | 552 | conditions=dict(function=check_repo, method=["POST"])) |
|
551 | 553 | |
|
552 | 554 | rmap.connect('changeset_comment_delete', |
|
553 | 555 | '/{repo_name:.*?}/changeset/comment/{comment_id}/delete', |
|
554 | 556 | controller='changeset', action='delete_comment', |
|
555 | 557 | conditions=dict(function=check_repo, method=["DELETE"])) |
|
556 | 558 | |
|
557 | 559 | rmap.connect('changeset_info', '/changeset_info/{repo_name:.*?}/{revision}', |
|
558 | 560 | controller='changeset', action='changeset_info') |
|
559 | 561 | |
|
560 | 562 | rmap.connect('compare_url', |
|
561 | 563 | '/{repo_name:.*?}/compare/{org_ref_type}@{org_ref:.*?}...{other_ref_type}@{other_ref:.*?}', |
|
562 | 564 | controller='compare', action='index', |
|
563 | 565 | conditions=dict(function=check_repo), |
|
564 | 566 | requirements=dict( |
|
565 | 567 | org_ref_type='(branch|book|tag|rev|__other_ref_type__)', |
|
566 | 568 | other_ref_type='(branch|book|tag|rev|__org_ref_type__)') |
|
567 | 569 | ) |
|
568 | 570 | |
|
569 | 571 | rmap.connect('pullrequest_home', |
|
570 | 572 | '/{repo_name:.*?}/pull-request/new', controller='pullrequests', |
|
571 | 573 | action='index', conditions=dict(function=check_repo, |
|
572 | 574 | method=["GET"])) |
|
573 | 575 | |
|
574 | 576 | rmap.connect('pullrequest', |
|
575 | 577 | '/{repo_name:.*?}/pull-request/new', controller='pullrequests', |
|
576 | 578 | action='create', conditions=dict(function=check_repo, |
|
577 | 579 | method=["POST"])) |
|
578 | 580 | |
|
579 | 581 | rmap.connect('pullrequest_show', |
|
580 | 582 | '/{repo_name:.*?}/pull-request/{pull_request_id}', |
|
581 | 583 | controller='pullrequests', |
|
582 | 584 | action='show', conditions=dict(function=check_repo, |
|
583 | 585 | method=["GET"])) |
|
584 | 586 | rmap.connect('pullrequest_update', |
|
585 | 587 | '/{repo_name:.*?}/pull-request/{pull_request_id}', |
|
586 | 588 | controller='pullrequests', |
|
587 | 589 | action='update', conditions=dict(function=check_repo, |
|
588 | 590 | method=["PUT"])) |
|
589 | 591 | rmap.connect('pullrequest_delete', |
|
590 | 592 | '/{repo_name:.*?}/pull-request/{pull_request_id}', |
|
591 | 593 | controller='pullrequests', |
|
592 | 594 | action='delete', conditions=dict(function=check_repo, |
|
593 | 595 | method=["DELETE"])) |
|
594 | 596 | |
|
595 | 597 | rmap.connect('pullrequest_show_all', |
|
596 | 598 | '/{repo_name:.*?}/pull-request', |
|
597 | 599 | controller='pullrequests', |
|
598 | 600 | action='show_all', conditions=dict(function=check_repo, |
|
599 | 601 | method=["GET"])) |
|
600 | 602 | |
|
601 | 603 | rmap.connect('pullrequest_comment', |
|
602 | 604 | '/{repo_name:.*?}/pull-request-comment/{pull_request_id}', |
|
603 | 605 | controller='pullrequests', |
|
604 | 606 | action='comment', conditions=dict(function=check_repo, |
|
605 | 607 | method=["POST"])) |
|
606 | 608 | |
|
607 | 609 | rmap.connect('pullrequest_comment_delete', |
|
608 | 610 | '/{repo_name:.*?}/pull-request-comment/{comment_id}/delete', |
|
609 | 611 | controller='pullrequests', action='delete_comment', |
|
610 | 612 | conditions=dict(function=check_repo, method=["DELETE"])) |
|
611 | 613 | |
|
612 | 614 | rmap.connect('summary_home_summary', '/{repo_name:.*?}/summary', |
|
613 | 615 | controller='summary', conditions=dict(function=check_repo)) |
|
614 | 616 | |
|
615 | 617 | rmap.connect('branches_home', '/{repo_name:.*?}/branches', |
|
616 | 618 | controller='branches', conditions=dict(function=check_repo)) |
|
617 | 619 | |
|
618 | 620 | rmap.connect('tags_home', '/{repo_name:.*?}/tags', |
|
619 | 621 | controller='tags', conditions=dict(function=check_repo)) |
|
620 | 622 | |
|
621 | 623 | rmap.connect('bookmarks_home', '/{repo_name:.*?}/bookmarks', |
|
622 | 624 | controller='bookmarks', conditions=dict(function=check_repo)) |
|
623 | 625 | |
|
624 | 626 | rmap.connect('changelog_home', '/{repo_name:.*?}/changelog', |
|
625 | 627 | controller='changelog', conditions=dict(function=check_repo)) |
|
626 | 628 | |
|
627 | 629 | rmap.connect('changelog_summary_home', '/{repo_name:.*?}/changelog_summary', |
|
628 | 630 | controller='changelog', action='changelog_summary', |
|
629 | 631 | conditions=dict(function=check_repo)) |
|
630 | 632 | |
|
631 | 633 | rmap.connect('changelog_file_home', '/{repo_name:.*?}/changelog/{revision}/{f_path:.*}', |
|
632 | 634 | controller='changelog', f_path=None, |
|
633 | 635 | conditions=dict(function=check_repo)) |
|
634 | 636 | |
|
635 | 637 | rmap.connect('changelog_details', '/{repo_name:.*?}/changelog_details/{cs}', |
|
636 | 638 | controller='changelog', action='changelog_details', |
|
637 | 639 | conditions=dict(function=check_repo)) |
|
638 | 640 | |
|
639 | 641 | rmap.connect('files_home', '/{repo_name:.*?}/files/{revision}/{f_path:.*}', |
|
640 | 642 | controller='files', revision='tip', f_path='', |
|
641 | 643 | conditions=dict(function=check_repo)) |
|
642 | 644 | |
|
643 | 645 | rmap.connect('files_home_nopath', '/{repo_name:.*?}/files/{revision}', |
|
644 | 646 | controller='files', revision='tip', f_path='', |
|
645 | 647 | conditions=dict(function=check_repo)) |
|
646 | 648 | |
|
647 | 649 | rmap.connect('files_history_home', |
|
648 | 650 | '/{repo_name:.*?}/history/{revision}/{f_path:.*}', |
|
649 | 651 | controller='files', action='history', revision='tip', f_path='', |
|
650 | 652 | conditions=dict(function=check_repo)) |
|
651 | 653 | |
|
652 | 654 | rmap.connect('files_diff_home', '/{repo_name:.*?}/diff/{f_path:.*}', |
|
653 | 655 | controller='files', action='diff', revision='tip', f_path='', |
|
654 | 656 | conditions=dict(function=check_repo)) |
|
655 | 657 | |
|
656 | 658 | rmap.connect('files_rawfile_home', |
|
657 | 659 | '/{repo_name:.*?}/rawfile/{revision}/{f_path:.*}', |
|
658 | 660 | controller='files', action='rawfile', revision='tip', |
|
659 | 661 | f_path='', conditions=dict(function=check_repo)) |
|
660 | 662 | |
|
661 | 663 | rmap.connect('files_raw_home', |
|
662 | 664 | '/{repo_name:.*?}/raw/{revision}/{f_path:.*}', |
|
663 | 665 | controller='files', action='raw', revision='tip', f_path='', |
|
664 | 666 | conditions=dict(function=check_repo)) |
|
665 | 667 | |
|
666 | 668 | rmap.connect('files_annotate_home', |
|
667 | 669 | '/{repo_name:.*?}/annotate/{revision}/{f_path:.*}', |
|
668 | 670 | controller='files', action='index', revision='tip', |
|
669 | 671 | f_path='', annotate=True, conditions=dict(function=check_repo)) |
|
670 | 672 | |
|
671 | 673 | rmap.connect('files_edit_home', |
|
672 | 674 | '/{repo_name:.*?}/edit/{revision}/{f_path:.*}', |
|
673 | 675 | controller='files', action='edit', revision='tip', |
|
674 | 676 | f_path='', conditions=dict(function=check_repo)) |
|
675 | 677 | |
|
676 | 678 | rmap.connect('files_add_home', |
|
677 | 679 | '/{repo_name:.*?}/add/{revision}/{f_path:.*}', |
|
678 | 680 | controller='files', action='add', revision='tip', |
|
679 | 681 | f_path='', conditions=dict(function=check_repo)) |
|
680 | 682 | |
|
681 | 683 | rmap.connect('files_archive_home', '/{repo_name:.*?}/archive/{fname}', |
|
682 | 684 | controller='files', action='archivefile', |
|
683 | 685 | conditions=dict(function=check_repo)) |
|
684 | 686 | |
|
685 | 687 | rmap.connect('files_nodelist_home', |
|
686 | 688 | '/{repo_name:.*?}/nodelist/{revision}/{f_path:.*}', |
|
687 | 689 | controller='files', action='nodelist', |
|
688 | 690 | conditions=dict(function=check_repo)) |
|
689 | 691 | |
|
690 | 692 | rmap.connect('repo_fork_create_home', '/{repo_name:.*?}/fork', |
|
691 | 693 | controller='forks', action='fork_create', |
|
692 | 694 | conditions=dict(function=check_repo, method=["POST"])) |
|
693 | 695 | |
|
694 | 696 | rmap.connect('repo_fork_home', '/{repo_name:.*?}/fork', |
|
695 | 697 | controller='forks', action='fork', |
|
696 | 698 | conditions=dict(function=check_repo)) |
|
697 | 699 | |
|
698 | 700 | rmap.connect('repo_forks_home', '/{repo_name:.*?}/forks', |
|
699 | 701 | controller='forks', action='forks', |
|
700 | 702 | conditions=dict(function=check_repo)) |
|
701 | 703 | |
|
702 | 704 | rmap.connect('repo_followers_home', '/{repo_name:.*?}/followers', |
|
703 | 705 | controller='followers', action='followers', |
|
704 | 706 | conditions=dict(function=check_repo)) |
|
705 | 707 | |
|
706 | 708 | return rmap |
@@ -1,195 +1,198 | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | rhodecode.controllers.admin.gist |
|
4 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 | 5 | |
|
6 | 6 | gist controller for RhodeCode |
|
7 | 7 | |
|
8 | 8 | :created_on: May 9, 2013 |
|
9 | 9 | :author: marcink |
|
10 | 10 | :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com> |
|
11 | 11 | :license: GPLv3, see COPYING for more details. |
|
12 | 12 | """ |
|
13 | 13 | # This program is free software: you can redistribute it and/or modify |
|
14 | 14 | # it under the terms of the GNU General Public License as published by |
|
15 | 15 | # the Free Software Foundation, either version 3 of the License, or |
|
16 | 16 | # (at your option) any later version. |
|
17 | 17 | # |
|
18 | 18 | # This program is distributed in the hope that it will be useful, |
|
19 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 | 21 | # GNU General Public License for more details. |
|
22 | 22 | # |
|
23 | 23 | # You should have received a copy of the GNU General Public License |
|
24 | 24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25 | 25 | import time |
|
26 | 26 | import logging |
|
27 | 27 | import traceback |
|
28 | 28 | import formencode |
|
29 | 29 | from formencode import htmlfill |
|
30 | 30 | |
|
31 | from pylons import request, tmpl_context as c, url | |
|
31 | from pylons import request, response, tmpl_context as c, url | |
|
32 | 32 | from pylons.controllers.util import abort, redirect |
|
33 | 33 | from pylons.i18n.translation import _ |
|
34 | 34 | |
|
35 | 35 | from rhodecode.model.forms import GistForm |
|
36 | 36 | from rhodecode.model.gist import GistModel |
|
37 | 37 | from rhodecode.model.meta import Session |
|
38 | 38 | from rhodecode.model.db import Gist |
|
39 | 39 | from rhodecode.lib import helpers as h |
|
40 | 40 | from rhodecode.lib.base import BaseController, render |
|
41 | 41 | from rhodecode.lib.auth import LoginRequired, NotAnonymous |
|
42 | 42 | from rhodecode.lib.utils2 import safe_str, safe_int, time_to_datetime |
|
43 | 43 | from rhodecode.lib.helpers import Page |
|
44 | 44 | from webob.exc import HTTPNotFound, HTTPForbidden |
|
45 | 45 | from sqlalchemy.sql.expression import or_ |
|
46 | 46 | from rhodecode.lib.vcs.exceptions import VCSError |
|
47 | 47 | |
|
48 | 48 | log = logging.getLogger(__name__) |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | class GistsController(BaseController): |
|
52 | 52 | """REST Controller styled on the Atom Publishing Protocol""" |
|
53 | 53 | |
|
54 | 54 | def __load_defaults(self): |
|
55 | 55 | c.lifetime_values = [ |
|
56 | 56 | (str(-1), _('forever')), |
|
57 | 57 | (str(5), _('5 minutes')), |
|
58 | 58 | (str(60), _('1 hour')), |
|
59 | 59 | (str(60 * 24), _('1 day')), |
|
60 | 60 | (str(60 * 24 * 30), _('1 month')), |
|
61 | 61 | ] |
|
62 | 62 | c.lifetime_options = [(c.lifetime_values, _("Lifetime"))] |
|
63 | 63 | |
|
64 | 64 | @LoginRequired() |
|
65 | 65 | def index(self, format='html'): |
|
66 | 66 | """GET /admin/gists: All items in the collection""" |
|
67 | 67 | # url('gists') |
|
68 | 68 | c.show_private = request.GET.get('private') and c.rhodecode_user.username != 'default' |
|
69 | 69 | c.show_public = request.GET.get('public') and c.rhodecode_user.username != 'default' |
|
70 | 70 | |
|
71 | 71 | gists = Gist().query()\ |
|
72 | 72 | .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\ |
|
73 | 73 | .order_by(Gist.created_on.desc()) |
|
74 | 74 | if c.show_private: |
|
75 | 75 | c.gists = gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\ |
|
76 | 76 | .filter(Gist.gist_owner == c.rhodecode_user.user_id) |
|
77 | 77 | elif c.show_public: |
|
78 | 78 | c.gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\ |
|
79 | 79 | .filter(Gist.gist_owner == c.rhodecode_user.user_id) |
|
80 | 80 | |
|
81 | 81 | else: |
|
82 | 82 | c.gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC) |
|
83 | 83 | p = safe_int(request.GET.get('page', 1), 1) |
|
84 | 84 | c.gists_pager = Page(c.gists, page=p, items_per_page=10) |
|
85 | 85 | return render('admin/gists/index.html') |
|
86 | 86 | |
|
87 | 87 | @LoginRequired() |
|
88 | 88 | @NotAnonymous() |
|
89 | 89 | def create(self): |
|
90 | 90 | """POST /admin/gists: Create a new item""" |
|
91 | 91 | # url('gists') |
|
92 | 92 | self.__load_defaults() |
|
93 | 93 | gist_form = GistForm([x[0] for x in c.lifetime_values])() |
|
94 | 94 | try: |
|
95 | 95 | form_result = gist_form.to_python(dict(request.POST)) |
|
96 | 96 | #TODO: multiple files support, from the form |
|
97 | 97 | nodes = { |
|
98 | 98 | form_result['filename'] or 'gistfile1.txt': { |
|
99 | 99 | 'content': form_result['content'], |
|
100 | 100 | 'lexer': None # autodetect |
|
101 | 101 | } |
|
102 | 102 | } |
|
103 | 103 | _public = form_result['public'] |
|
104 | 104 | gist_type = Gist.GIST_PUBLIC if _public else Gist.GIST_PRIVATE |
|
105 | 105 | gist = GistModel().create( |
|
106 | 106 | description=form_result['description'], |
|
107 | 107 | owner=c.rhodecode_user, |
|
108 | 108 | gist_mapping=nodes, |
|
109 | 109 | gist_type=gist_type, |
|
110 | 110 | lifetime=form_result['lifetime'] |
|
111 | 111 | ) |
|
112 | 112 | Session().commit() |
|
113 | 113 | new_gist_id = gist.gist_access_id |
|
114 | 114 | except formencode.Invalid, errors: |
|
115 | 115 | defaults = errors.value |
|
116 | 116 | |
|
117 | 117 | return formencode.htmlfill.render( |
|
118 | 118 | render('admin/gists/new.html'), |
|
119 | 119 | defaults=defaults, |
|
120 | 120 | errors=errors.error_dict or {}, |
|
121 | 121 | prefix_error=False, |
|
122 | 122 | encoding="UTF-8" |
|
123 | 123 | ) |
|
124 | 124 | |
|
125 | 125 | except Exception, e: |
|
126 | 126 | log.error(traceback.format_exc()) |
|
127 | 127 | h.flash(_('Error occurred during gist creation'), category='error') |
|
128 | 128 | return redirect(url('new_gist')) |
|
129 | 129 | return redirect(url('gist', gist_id=new_gist_id)) |
|
130 | 130 | |
|
131 | 131 | @LoginRequired() |
|
132 | 132 | @NotAnonymous() |
|
133 | 133 | def new(self, format='html'): |
|
134 | 134 | """GET /admin/gists/new: Form to create a new item""" |
|
135 | 135 | # url('new_gist') |
|
136 | 136 | self.__load_defaults() |
|
137 | 137 | return render('admin/gists/new.html') |
|
138 | 138 | |
|
139 | 139 | @LoginRequired() |
|
140 | 140 | @NotAnonymous() |
|
141 | 141 | def update(self, gist_id): |
|
142 | 142 | """PUT /admin/gists/gist_id: Update an existing item""" |
|
143 | 143 | # Forms posted to this method should contain a hidden field: |
|
144 | 144 | # <input type="hidden" name="_method" value="PUT" /> |
|
145 | 145 | # Or using helpers: |
|
146 | 146 | # h.form(url('gist', gist_id=ID), |
|
147 | 147 | # method='put') |
|
148 | 148 | # url('gist', gist_id=ID) |
|
149 | 149 | |
|
150 | 150 | @LoginRequired() |
|
151 | 151 | @NotAnonymous() |
|
152 | 152 | def delete(self, gist_id): |
|
153 | 153 | """DELETE /admin/gists/gist_id: Delete an existing item""" |
|
154 | 154 | # Forms posted to this method should contain a hidden field: |
|
155 | 155 | # <input type="hidden" name="_method" value="DELETE" /> |
|
156 | 156 | # Or using helpers: |
|
157 | 157 | # h.form(url('gist', gist_id=ID), |
|
158 | 158 | # method='delete') |
|
159 | 159 | # url('gist', gist_id=ID) |
|
160 | 160 | gist = GistModel().get_gist(gist_id) |
|
161 | 161 | owner = gist.gist_owner == c.rhodecode_user.user_id |
|
162 | 162 | if h.HasPermissionAny('hg.admin')() or owner: |
|
163 | 163 | GistModel().delete(gist) |
|
164 | 164 | Session().commit() |
|
165 | 165 | h.flash(_('Deleted gist %s') % gist.gist_access_id, category='success') |
|
166 | 166 | else: |
|
167 | 167 | raise HTTPForbidden() |
|
168 | 168 | |
|
169 | 169 | return redirect(url('gists')) |
|
170 | 170 | |
|
171 | 171 | @LoginRequired() |
|
172 | def show(self, gist_id, format='html'): | |
|
172 | def show(self, gist_id, format='html', revision='tip', f_path=None): | |
|
173 | 173 | """GET /admin/gists/gist_id: Show a specific item""" |
|
174 | 174 | # url('gist', gist_id=ID) |
|
175 | 175 | c.gist = Gist.get_or_404(gist_id) |
|
176 | 176 | |
|
177 | 177 | #check if this gist is not expired |
|
178 | 178 | if c.gist.gist_expires != -1: |
|
179 | 179 | if time.time() > c.gist.gist_expires: |
|
180 | 180 | log.error('Gist expired at %s' % |
|
181 | 181 | (time_to_datetime(c.gist.gist_expires))) |
|
182 | 182 | raise HTTPNotFound() |
|
183 | 183 | try: |
|
184 | 184 | c.file_changeset, c.files = GistModel().get_gist_files(gist_id) |
|
185 | 185 | except VCSError: |
|
186 | 186 | log.error(traceback.format_exc()) |
|
187 | 187 | raise HTTPNotFound() |
|
188 | ||
|
188 | if format == 'raw': | |
|
189 | content = '\n\n'.join([f.content for f in c.files if (f_path is None or f.path == f_path)]) | |
|
190 | response.content_type = 'text/plain' | |
|
191 | return content | |
|
189 | 192 | return render('admin/gists/show.html') |
|
190 | 193 | |
|
191 | 194 | @LoginRequired() |
|
192 | 195 | @NotAnonymous() |
|
193 | 196 | def edit(self, gist_id, format='html'): |
|
194 | 197 | """GET /admin/gists/gist_id/edit: Form to edit an existing item""" |
|
195 | 198 | # url('edit_gist', gist_id=ID) |
@@ -1,92 +1,97 | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | <%inherit file="/base/base.html"/> |
|
3 | 3 | |
|
4 | 4 | <%def name="title()"> |
|
5 | 5 | ${_('gist')}:${c.gist.gist_access_id} · ${c.rhodecode_name} |
|
6 | 6 | </%def> |
|
7 | 7 | |
|
8 | 8 | <%def name="breadcrumbs_links()"> |
|
9 | 9 | ${_('Gist')} · gist:${c.gist.gist_access_id} |
|
10 | 10 | </%def> |
|
11 | 11 | |
|
12 | 12 | <%def name="page_nav()"> |
|
13 | 13 | ${self.menu('gists')} |
|
14 | 14 | </%def> |
|
15 | 15 | |
|
16 | 16 | <%def name="main()"> |
|
17 | 17 | <div class="box"> |
|
18 | 18 | <!-- box / title --> |
|
19 | 19 | <div class="title"> |
|
20 | 20 | ${self.breadcrumbs()} |
|
21 | 21 | %if c.rhodecode_user.username != 'default': |
|
22 | 22 | <ul class="links"> |
|
23 | 23 | <li> |
|
24 | 24 | <span>${h.link_to(_(u'Create new gist'), h.url('new_gist'))}</span> |
|
25 | 25 | </li> |
|
26 | 26 | </ul> |
|
27 | 27 | %endif |
|
28 | 28 | </div> |
|
29 | 29 | <div class="table"> |
|
30 | 30 | <div id="files_data"> |
|
31 | 31 | <div id="body" class="codeblock"> |
|
32 | 32 | <div class="code-header"> |
|
33 | 33 | <div class="stats"> |
|
34 | 34 | <div class="left" style="margin: -4px 0px 0px 0px"> |
|
35 | 35 | %if c.gist.gist_type == 'public': |
|
36 | 36 | <div class="ui-btn green badge">${_('Public gist')}</div> |
|
37 | 37 | %else: |
|
38 | 38 | <div class="ui-btn yellow badge">${_('Private gist')}</div> |
|
39 | 39 | %endif |
|
40 | 40 | </div> |
|
41 | 41 | <div class="left item ${'' if c.gist.gist_description else 'last'}" style="color: #AAA"> |
|
42 | 42 | %if c.gist.gist_expires == -1: |
|
43 | 43 | ${_('Expires')}: ${_('never')} |
|
44 | 44 | %else: |
|
45 | 45 | ${_('Expires')}: ${h.age(h.time_to_datetime(c.gist.gist_expires))} |
|
46 | 46 | %endif |
|
47 | 47 | </div> |
|
48 | 48 | <div class="left item last"> |
|
49 | 49 | ${c.gist.gist_description} |
|
50 | 50 | </div> |
|
51 | <div class="buttons"> | |
|
52 | ## only owner should see that | |
|
53 | 51 |
|
|
54 | ##${h.link_to(_('Edit'),h.url(''),class_="ui-btn")} | |
|
52 | <div style="float:right;margin:-4px 0px 0px 0px"> | |
|
55 | 53 | ${h.form(url('gist', gist_id=c.gist.gist_id),method='delete')} |
|
56 | 54 | ${h.submit('remove_gist', _('Delete'),class_="ui-btn red",onclick="return confirm('"+_('Confirm to delete this gist')+"');")} |
|
57 | 55 | ${h.end_form()} |
|
56 | </div> | |
|
58 | 57 |
|
|
58 | <div class="buttons"> | |
|
59 | ## only owner should see that | |
|
60 | ##%if h.HasPermissionAny('hg.admin')() or c.gist.gist_owner == c.rhodecode_user.user_id: | |
|
61 | ##${h.link_to(_('Edit'),h.url(''),class_="ui-btn")} | |
|
62 | ##%endif | |
|
63 | ${h.link_to(_('Show as raw'),h.url('formatted_gist', gist_id=c.gist.gist_id, format='raw'),class_="ui-btn")} | |
|
59 | 64 | </div> |
|
60 | 65 | </div> |
|
61 | 66 | |
|
62 | 67 | <div class="author"> |
|
63 | 68 | <div class="gravatar"> |
|
64 | 69 | <img alt="gravatar" src="${h.gravatar_url(h.email_or_none(c.file_changeset.author),16)}"/> |
|
65 | 70 | </div> |
|
66 | 71 | <div title="${c.file_changeset.author}" class="user">${h.person(c.file_changeset.author)} - ${_('created')} ${h.age(c.file_changeset.date)}</div> |
|
67 | 72 | </div> |
|
68 | 73 | <div class="commit">${h.urlify_commit(c.file_changeset.message,c.repo_name)}</div> |
|
69 | 74 | </div> |
|
70 | 75 | </div> |
|
71 | 76 | |
|
72 | 77 | ## iterate over the files |
|
73 | 78 | % for file in c.files: |
|
74 | 79 | <div style="border: 1px solid #EEE;margin-top:20px"> |
|
75 | 80 | <div id="${h.FID('G', file.path)}" class="stats" style="border-bottom: 1px solid #DDD;padding: 8px 14px;"> |
|
76 | 81 | <a href="${c.gist.gist_url()}">¶</a> |
|
77 | 82 | <b style="margin:0px 0px 0px 4px">${file.path}</b> |
|
78 |
|
|
|
79 | ## ${h.link_to(_('Show as raw'),h.url(''),class_="ui-btn")} | |
|
80 |
|
|
|
83 | <div style="float:right"> | |
|
84 | ${h.link_to(_('Show as raw'),h.url('formatted_gist_file', gist_id=c.gist.gist_id, format='raw', revision=file.changeset.raw_id, f_path=file.path),class_="ui-btn")} | |
|
85 | </div> | |
|
81 | 86 | </div> |
|
82 | 87 | <div class="code-body"> |
|
83 | 88 | ${h.pygmentize(file,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")} |
|
84 | 89 | </div> |
|
85 | 90 | </div> |
|
86 | 91 | %endfor |
|
87 | 92 | </div> |
|
88 | 93 | </div> |
|
89 | 94 | |
|
90 | 95 | |
|
91 | 96 | </div> |
|
92 | 97 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now