Changeset 2818
- Timestamp:
- 11/23/07 21:47:33 (1 year ago)
- Files:
-
- addcommentmacro/0.11/addcomment/macro.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
addcommentmacro/0.11/addcomment/macro.py
r2797 r2818 48 48 page_url = req.href.wiki(resource.id) 49 49 wikipreview = req.args.get("preview", "") 50 51 # Can this user add a comment to this page? 50 52 appendonly = ('appendonly' in args) 51 # Can this user add a comment to this page? 52 cancomment = not page.readonly 53 # Is this an "append-only" comment or are we an administrator? 54 if 'WIKI_ADMIN' in req.perm(resource) or appendonly: 53 cancomment = False 54 if page.readonly: 55 if 'WIKI_ADMIN' in req.perm(resource): 56 cancomment = True 57 elif 'WIKI_MODIFY' in req.perm(resource): 55 58 cancomment = True 56 if not cancomment: 59 elif appendonly and 'WIKI_VIEW' in req.perm(resource): 60 cancomment = True 61 else: 57 62 raise TracError('Error: Insufficient privileges to AddComment') 58 disabled = False59 63 60 64 # Get the data from the POST … … 71 75 72 76 the_preview = the_message = the_form = tag() 73 74 if wikipreview or not ('WIKI_MODIFY' in req.perm(resource) or appendonly): 75 disabled = True 76 77 77 78 # If we are submitting or previewing, inject comment as it should look 78 79 if cancomment and comment and (preview or submit): … … 85 86 class_="wikipage", id="preview") 86 87 88 # Check the form_token 89 form_ok = True 90 if submit and req.args.get('__FORM_TOKEN','') != req.form_token: 91 form_ok = False 92 the_message = tag.div(tag.strong("ERROR: "), 93 "AddComment received incorrect form token. " 94 "Do you have cookies enabled?", 95 class_="system-message") 96 87 97 # When submitting, inject comment before macro 88 if comment and submit :98 if comment and submit and cancomment and form_ok: 89 99 submitted = False 90 100 newtext = "" … … 118 128 name="addcomment", 119 129 cols=80, rows=5, 120 disabled=(disabledand "disabled" or None)),130 disabled=(not cancomment and "disabled" or None)), 121 131 class_="field" 122 132 ), … … 127 137 size=30, value=authname) 128 138 ) or None), 139 tag.input(type="hidden", name="__FORM_TOKEN", 140 value=req.form_token), 129 141 tag.div( 130 142 tag.input(value="Add comment", type="submit", 131 143 name="submitaddcomment", size=30, 132 disabled=( disabledand "disabled" or None)),144 disabled=(not cancomment and "disabled" or None)), 133 145 tag.input(value="Preview comment", type="submit", 134 146 name="previewaddcomment", 135 disabled=( disabledand "disabled" or None)),147 disabled=(not cancomment and "disabled" or None)), 136 148 tag.input(value="Cancel", type="submit", 137 149 name="canceladdcomment", 138 disabled=( disabledand "disabled" or None)),150 disabled=(not cancomment and "disabled" or None)), 139 151 class_="buttons" 140 152 ), … … 145 157 146 158 add_script(req, 'common/js/wikitoolbar.js') 147 159 148 160 return tag.div(the_preview, the_message, the_form, id="commenting") 149 161
