Mercurial > wikked
annotate wikked/webimpl/edit.py @ 451:6cd51ea6dfcf
auth: Rewrite permission system and improve support for it.
- More proper ACL model for permissions.
- Page-level ACL is only specified locally, not inherited anymore.
- Protect more API and UI routes with permission checks.
- Improve error handling and error pages.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 07 Jan 2018 11:11:04 -0800 |
parents | 8ca8c2713c92 |
children | faa4c8467291 |
rev | line source |
---|---|
437
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
1 import os.path |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import logging |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import urllib.parse |
437
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
4 from werkzeug.utils import secure_filename |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 from wikked.page import Page, PageData |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 from wikked.formatter import PageFormatter, FormattingContext |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 from wikked.resolver import PageResolver |
425
e28f2c76691c
web: Add "broken links" and "wanted pages" lists.
Ludovic Chabant <ludovic@chabant.com>
parents:
389
diff
changeset
|
8 from wikked.utils import PageNotFoundError |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 from wikked.webimpl import ( |
425
e28f2c76691c
web: Add "broken links" and "wanted pages" lists.
Ludovic Chabant <ludovic@chabant.com>
parents:
389
diff
changeset
|
10 get_page_or_raise, get_page_meta, make_page_title) |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 logger = logging.getLogger(__name__) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 class DummyPage(Page): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 """ A dummy page for previewing in-progress editing. |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 """ |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 def __init__(self, wiki, url, text): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 data = self._loadData(wiki, url, text) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 super(DummyPage, self).__init__(wiki, data) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 def _loadData(self, wiki, url, text): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 data = PageData() |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 extension = wiki.fs.default_extension |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 data.url = url |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 data.path = '__preview__.' + extension |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 data.raw_text = text |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 ctx = FormattingContext(url) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 f = PageFormatter() |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 data.formatted_text = f.formatText(ctx, data.raw_text) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 data.local_meta = ctx.meta |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 data.local_links = ctx.out_links |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 data.title = (data.local_meta.get('title') or |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 make_page_title(url)) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 if isinstance(data.title, list): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 data.title = data.title[0] |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 return data |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 def get_edit_page(wiki, user, url, author=None, custom_data=None): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 page = None |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 try: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 page = get_page_or_raise(wiki, url, |
451
6cd51ea6dfcf
auth: Rewrite permission system and improve support for it.
Ludovic Chabant <ludovic@chabant.com>
parents:
447
diff
changeset
|
48 check_perms=(user, 'edit')) |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 except PageNotFoundError: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 # Only catch errors about the page not existing. Permission |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 # errors still go through. |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 page = None |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 if page is None: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 result = { |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 'meta': { |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 'url': urllib.parse.quote(url.encode('utf-8')), |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 'title': make_page_title(url) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 }, |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 'text': '' |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 } |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 else: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 result = { |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 'meta': get_page_meta(page, True), |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 'text': page.raw_text |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 } |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 result['commit_meta'] = { |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 'author': author, |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 'desc': 'Editing ' + result['meta']['title'] |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 } |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
72 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 if custom_data: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 result.update(custom_data) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 return result |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
79 def do_edit_page(wiki, user, url, text, author=None, message=None): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
80 try: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
81 get_page_or_raise(wiki, url, |
451
6cd51ea6dfcf
auth: Rewrite permission system and improve support for it.
Ludovic Chabant <ludovic@chabant.com>
parents:
447
diff
changeset
|
82 check_perms=(user, 'edit')) |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 except PageNotFoundError: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 # Only catch errors about the page not existing. Permission |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
85 # errors still go through. |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 pass |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 author = author or user |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 if author is None: |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 raise Exception("No author or user was specified.") |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 message = message or 'Edited ' + url |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 page_fields = { |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 'text': text, |
389
08b831d894c8
web: Actually pass the correct author to the SCM backend.
Ludovic Chabant <ludovic@chabant.com>
parents:
342
diff
changeset
|
95 'author': author, |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 'message': message |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 } |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 wiki.setPage(url, page_fields) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 def preview_edited_page(wiki, url, raw_text): |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 dummy = DummyPage(wiki, url, raw_text) |
447
8ca8c2713c92
web: Optimize the page resolver.
Ludovic Chabant <ludovic@chabant.com>
parents:
437
diff
changeset
|
103 # We can pass `can_use_resolved_meta` since we know we have the only |
8ca8c2713c92
web: Optimize the page resolver.
Ludovic Chabant <ludovic@chabant.com>
parents:
437
diff
changeset
|
104 # resolver running right now... this will speed things up dramatically. |
8ca8c2713c92
web: Optimize the page resolver.
Ludovic Chabant <ludovic@chabant.com>
parents:
437
diff
changeset
|
105 resolver = PageResolver(dummy, can_use_resolved_meta=True) |
341
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
106 dummy._setExtendedData(resolver.run()) |
37f426e067c4
Big refactor to get rid of this whole single page app crap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
107 return dummy.text |
437
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
108 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
109 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
110 def do_upload_file(wiki, user, reqfile, for_url=None, submit=True): |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
111 if not reqfile: |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
112 raise Exception("No file was specified.") |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
113 if not reqfile.filename: |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
114 raise Exception("No file name was specified.") |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
115 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
116 # TODO: check permissions for the user. |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
117 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
118 filename = secure_filename(reqfile.filename) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
119 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
120 files_dir = os.path.join(wiki.root, '_files') |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
121 upload_dir = files_dir |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
122 if for_url: |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
123 upload_dir = os.path.join(wiki.root, for_url) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
124 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
125 path = os.path.join(upload_dir, filename) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
126 path = os.path.normpath(path) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
127 if not path.startswith(wiki.root): |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
128 raise Exception("Don't try anything weird, please.") |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
129 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
130 # Save to disk. |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
131 os.makedirs(os.path.dirname(path), exist_ok=True) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
132 reqfile.save(path) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
133 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
134 # Commit the file to the source-control. |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
135 if submit: |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
136 commit_meta = { |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
137 'author': user, |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
138 'message': "Uploaded '%s'." % filename} |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
139 wiki.scm.commit([path], commit_meta) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
140 |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
141 if for_url: |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
142 example = './%s' % filename |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
143 else: |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
144 example = os.path.relpath(path, files_dir) |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
145 result = { |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
146 'example': example |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
147 } |
3985b3d72353
web: Add basic ability to upload files.
Ludovic Chabant <ludovic@chabant.com>
parents:
425
diff
changeset
|
148 return result |