| 1 |
from trac.core import * |
|---|
| 2 |
from trac.web.chrome import add_stylesheet |
|---|
| 3 |
from trac.wiki import wiki_to_html, wiki_to_oneliner |
|---|
| 4 |
from trac.perm import PermissionError |
|---|
| 5 |
from trac.util import format_datetime, pretty_timedelta, escape, unescape, \ |
|---|
| 6 |
Markup |
|---|
| 7 |
import time |
|---|
| 8 |
|
|---|
| 9 |
class DiscussionApi(object): |
|---|
| 10 |
def __init__(self, component, req): |
|---|
| 11 |
self.env = component.env |
|---|
| 12 |
self.log = component.log |
|---|
| 13 |
|
|---|
| 14 |
# Main request processing function |
|---|
| 15 |
|
|---|
| 16 |
def render_discussion(self, req, cursor): |
|---|
| 17 |
# Get request mode |
|---|
| 18 |
group, forum, topic, message = self._get_items(req, cursor) |
|---|
| 19 |
modes = self._get_modes(req, group, forum, topic, message) |
|---|
| 20 |
self.log.debug('modes: %s' % modes) |
|---|
| 21 |
|
|---|
| 22 |
# Determine moderator rights. |
|---|
| 23 |
if forum: |
|---|
| 24 |
is_moderator = (req.authname in forum['moderators']) or \ |
|---|
| 25 |
req.perm.has_permission('DISCUSSION_ADMIN') |
|---|
| 26 |
else: |
|---|
| 27 |
is_moderator = req.perm.has_permission('DISCUSSION_ADMIN') |
|---|
| 28 |
|
|---|
| 29 |
# Perform mode actions |
|---|
| 30 |
self._do_action(req, cursor, modes, group, forum, topic, message, |
|---|
| 31 |
is_moderator) |
|---|
| 32 |
|
|---|
| 33 |
# Add CSS styles |
|---|
| 34 |
add_stylesheet(req, 'common/css/wiki.css') |
|---|
| 35 |
add_stylesheet(req, 'discussion/css/discussion.css') |
|---|
| 36 |
add_stylesheet(req, 'discussion/css/admin.css') |
|---|
| 37 |
|
|---|
| 38 |
# Fill up HDF structure and return template |
|---|
| 39 |
req.hdf['discussion.authname'] = req.authname |
|---|
| 40 |
req.hdf['discussion.is_moderator'] = is_moderator |
|---|
| 41 |
if group: |
|---|
| 42 |
group['name'] = wiki_to_oneliner(group['name'], self.env) |
|---|
| 43 |
group['description'] = wiki_to_oneliner(group['description'], |
|---|
| 44 |
self.env) |
|---|
| 45 |
req.hdf['discussion.group'] = group |
|---|
| 46 |
if forum: |
|---|
| 47 |
forum['name'] = wiki_to_oneliner(forum['name'], self.env) |
|---|
| 48 |
forum['description'] = wiki_to_oneliner(forum['description'], |
|---|
| 49 |
self.env) |
|---|
| 50 |
forum['subject'] = wiki_to_oneliner(forum['subject'], self.env) |
|---|
| 51 |
forum['time'] = format_datetime(forum['time']) |
|---|
| 52 |
req.hdf['discussion.forum'] = forum |
|---|
| 53 |
if topic: |
|---|
| 54 |
topic['subject'] = wiki_to_oneliner(topic['subject'], self.env) |
|---|
| 55 |
topic['author'] = wiki_to_oneliner(topic['author'], self.env) |
|---|
| 56 |
topic['body'] = wiki_to_html(topic['body'], self.env, req) |
|---|
| 57 |
topic['time'] = format_datetime(topic['time']) |
|---|
| 58 |
req.hdf['discussion.topic'] = topic |
|---|
| 59 |
if message: |
|---|
| 60 |
message['author'] = wiki_to_oneliner(message['author'], self.env) |
|---|
| 61 |
message['body'] = wiki_to_html(message['body'], self.env, req) |
|---|
| 62 |
message['time'] = format_datetime(message['time']) |
|---|
| 63 |
req.hdf['discussion.message'] = message |
|---|
| 64 |
req.hdf['discussion.mode'] = modes[-1] |
|---|
| 65 |
req.hdf['discussion.time'] = format_datetime(time.time()) |
|---|
| 66 |
return modes[-1] + '.cs', None |
|---|
| 67 |
|
|---|
| 68 |
def _get_items(self, req, cursor): |
|---|
| 69 |
group, forum, topic, message = None, None, None, None |
|---|
| 70 |
|
|---|
| 71 |
# Populate active group |
|---|
| 72 |
if req.args.has_key('group'): |
|---|
| 73 |
group_id = req.args.get('group') |
|---|
| 74 |
group = self.get_group(cursor, group_id) |
|---|
| 75 |
|
|---|
| 76 |
# Populate active forum |
|---|
| 77 |
if req.args.has_key('forum'): |
|---|
| 78 |
forum_id = req.args.get('forum') |
|---|
| 79 |
forum = self.get_forum(cursor, forum_id) |
|---|
| 80 |
|
|---|
| 81 |
# Populate active topic |
|---|
| 82 |
if req.args.has_key('topic'): |
|---|
| 83 |
topic_id = req.args.get('topic') |
|---|
| 84 |
topic = self.get_topic(cursor, topic_id) |
|---|
| 85 |
|
|---|
| 86 |
# Populate active topic |
|---|
| 87 |
if req.args.has_key('message'): |
|---|
| 88 |
message_id = req.args.get('message') |
|---|
| 89 |
message = self.get_message(cursor, message_id) |
|---|
| 90 |
|
|---|
| 91 |
self.log.debug('message: %s' % message) |
|---|
| 92 |
self.log.debug('topic: %s' % topic) |
|---|
| 93 |
self.log.debug('forum: %s' % forum) |
|---|
| 94 |
self.log.debug('group: %s' % group) |
|---|
| 95 |
return group, forum, topic, message |
|---|
| 96 |
|
|---|
| 97 |
def _get_modes(self, req, group, forum, topic, message): |
|---|
| 98 |
# Get action |
|---|
| 99 |
component = req.args.get('component') |
|---|
| 100 |
action = req.args.get('discussion_action') |
|---|
| 101 |
preview = req.args.has_key('preview'); |
|---|
| 102 |
submit = req.args.has_key('submit'); |
|---|
| 103 |
self.log.debug('component: %s' % component) |
|---|
| 104 |
self.log.debug('action: %s' % action) |
|---|
| 105 |
|
|---|
| 106 |
if component == 'admin': |
|---|
| 107 |
req.hdf['discussion.href'] = self.env.href.admin('discussion') |
|---|
| 108 |
elif component == 'wiki': |
|---|
| 109 |
req.hdf['discussion.href'] = self.env.href(req.path_info) |
|---|
| 110 |
else: |
|---|
| 111 |
req.hdf['discussion.href'] = self.env.href.discussion() |
|---|
| 112 |
req.hdf['discussion.component'] = component |
|---|
| 113 |
|
|---|
| 114 |
# Determine mode |
|---|
| 115 |
if message: |
|---|
| 116 |
if component == 'admin': |
|---|
| 117 |
pass |
|---|
| 118 |
elif component == 'wiki': |
|---|
| 119 |
if action == 'add': |
|---|
| 120 |
return ['message-list'] |
|---|
| 121 |
elif action == 'quote': |
|---|
| 122 |
return ['message-quote', 'message-list'] |
|---|
| 123 |
elif action == 'post-add': |
|---|
| 124 |
if preview: |
|---|
| 125 |
return ['message-list'] |
|---|
| 126 |
else: |
|---|
| 127 |
return ['message-post-add', 'message-list'] |
|---|
| 128 |
elif action == 'edit': |
|---|
| 129 |
return ['message-edit', 'message-list'] |
|---|
| 130 |
elif action == 'post-edit': |
|---|
| 131 |
if preview: |
|---|
| 132 |
return ['message-list'] |
|---|
| 133 |
else: |
|---|
| 134 |
return ['message-post-edit', 'message-list'] |
|---|
| 135 |
elif action == 'delete': |
|---|
| 136 |
return ['message-delete', 'message-list'] |
|---|
| 137 |
elif action == 'set-display': |
|---|
| 138 |
return ['message-set-display', 'message-list'] |
|---|
| 139 |
else: |
|---|
| 140 |
return ['message-list'] |
|---|
| 141 |
else: |
|---|
| 142 |
if action == 'add': |
|---|
| 143 |
return ['message-list'] |
|---|
| 144 |
elif action == 'quote': |
|---|
| 145 |
return ['message-quote', 'message-list'] |
|---|
| 146 |
elif action == 'post-add': |
|---|
| 147 |
if preview: |
|---|
| 148 |
return ['message-list'] |
|---|
| 149 |
else: |
|---|
| 150 |
return ['message-post-add', 'message-list'] |
|---|
| 151 |
elif action == 'edit': |
|---|
| 152 |
return ['message-edit', 'message-list'] |
|---|
| 153 |
elif action == 'post-edit': |
|---|
| 154 |
if preview: |
|---|
| 155 |
return ['message-list'] |
|---|
| 156 |
else: |
|---|
| 157 |
return ['message-post-edit', 'message-list'] |
|---|
| 158 |
elif action == 'delete': |
|---|
| 159 |
return ['message-delete', 'message-list'] |
|---|
| 160 |
elif action == 'set-display': |
|---|
| 161 |
return ['message-set-display', 'message-list'] |
|---|
| 162 |
else: |
|---|
| 163 |
return ['message-list'] |
|---|
| 164 |
if topic: |
|---|
| 165 |
if component == 'admin': |
|---|
| 166 |
pass |
|---|
| 167 |
elif component == 'wiki': |
|---|
| 168 |
if action == 'add': |
|---|
| 169 |
return ['message-list'] |
|---|
| 170 |
elif action == 'quote': |
|---|
| 171 |
return ['topic-quote', 'message-list'] |
|---|
| 172 |
elif action == 'post-add': |
|---|
| 173 |
if preview: |
|---|
| 174 |
return ['message-list'] |
|---|
| 175 |
else: |
|---|
| 176 |
return ['message-post-add', 'message-list'] |
|---|
| 177 |
elif action == 'edit': |
|---|
| 178 |
return ['topic-edit', 'message-list'] |
|---|
| 179 |
elif action == 'post-edit': |
|---|
| 180 |
if preview: |
|---|
| 181 |
return ['message-list'] |
|---|
| 182 |
else: |
|---|
| 183 |
return ['topic-post-edit', 'message-list'] |
|---|
| 184 |
elif action == 'delete': |
|---|
| 185 |
req.hdf['discussion.no_display'] = True |
|---|
| 186 |
return ['topic-delete', 'message-list'] |
|---|
| 187 |
elif action == 'set-display': |
|---|
| 188 |
return ['message-set-display', 'message-list'] |
|---|
| 189 |
else: |
|---|
| 190 |
return ['message-list'] |
|---|
| 191 |
else: |
|---|
| 192 |
if action == 'add': |
|---|
| 193 |
return ['message-list'] |
|---|
| 194 |
elif action == 'quote': |
|---|
| 195 |
return ['topic-quote', 'message-list'] |
|---|
| 196 |
elif action == 'post-add': |
|---|
| 197 |
if preview: |
|---|
| 198 |
return ['message-list'] |
|---|
| 199 |
else: |
|---|
| 200 |
return ['message-post-add', 'message-list'] |
|---|
| 201 |
elif action == 'edit': |
|---|
| 202 |
return ['topic-edit', 'message-list'] |
|---|
| 203 |
elif action == 'post-edit': |
|---|
| 204 |
if preview: |
|---|
| 205 |
return ['message-list'] |
|---|
| 206 |
else: |
|---|
| 207 |
return ['topic-post-edit', 'message-list'] |
|---|
| 208 |
elif action == 'delete': |
|---|
| 209 |
return ['topic-delete', 'topic-list'] |
|---|
| 210 |
elif action == 'move': |
|---|
| 211 |
return ['topic-move'] |
|---|
| 212 |
elif action == 'post-move': |
|---|
| 213 |
return ['topic-post-move', 'topic-list'] |
|---|
| 214 |
elif action == 'set-display': |
|---|
| 215 |
return ['message-set-display', 'message-list'] |
|---|
| 216 |
else: |
|---|
| 217 |
return ['message-list'] |
|---|
| 218 |
elif forum: |
|---|
| 219 |
if component == 'admin': |
|---|
| 220 |
if action == 'post-edit': |
|---|
| 221 |
return ['forum-post-edit', 'admin-forum-list'] |
|---|
| 222 |
else: |
|---|
| 223 |
return ['admin-forum-list'] |
|---|
| 224 |
elif component == 'wiki': |
|---|
| 225 |
pass |
|---|
| 226 |
else: |
|---|
| 227 |
if action == 'add': |
|---|
| 228 |
return ['topic-add'] |
|---|
| 229 |
elif action == 'post-add': |
|---|
| 230 |
if preview: |
|---|
| 231 |
return ['topic-add'] |
|---|
| 232 |
else: |
|---|
| 233 |
return ['topic-post-add', 'topic-list'] |
|---|
| 234 |
elif action == 'delete': |
|---|
| 235 |
return ['forum-delete', 'forum-list'] |
|---|
| 236 |
else: |
|---|
| 237 |
return ['topic-list'] |
|---|
| 238 |
elif group: |
|---|
| 239 |
if component == 'admin': |
|---|
| 240 |
if action == 'post-add': |
|---|
| 241 |
return ['forum-post-add', 'admin-forum-list'] |
|---|
| 242 |
elif action == 'post-edit': |
|---|
| 243 |
return ['group-post-edit', 'admin-group-list'] |
|---|
| 244 |
elif action == 'delete': |
|---|
| 245 |
return ['forums-delete', 'admin-forum-list'] |
|---|
| 246 |
else: |
|---|
| 247 |
if group['id']: |
|---|
| 248 |
return ['admin-group-list'] |
|---|
| 249 |
else: |
|---|
| 250 |
return ['admin-forum-list'] |
|---|
| 251 |
elif component == 'wiki': |
|---|
| 252 |
pass |
|---|
| 253 |
else: |
|---|
| 254 |
if action == 'post-add': |
|---|
| 255 |
return ['forum-post-add', 'forum-list'] |
|---|
| 256 |
else: |
|---|
| 257 |
return ['forum-list'] |
|---|
| 258 |
else: |
|---|
| 259 |
if component == 'admin': |
|---|
| 260 |
if action == 'post-add': |
|---|
| 261 |
return ['group-post-add', 'admin-group-list'] |
|---|
| 262 |
elif action == 'delete': |
|---|
| 263 |
return ['groups-delete', 'admin-group-list'] |
|---|
| 264 |
else: |
|---|
| 265 |
return ['admin-group-list'] |
|---|
| 266 |
elif component == 'wiki': |
|---|
| 267 |
pass |
|---|
| 268 |
else: |
|---|
| 269 |
if action == 'add': |
|---|
| 270 |
return ['forum-add'] |
|---|
| 271 |
elif action == 'post-add': |
|---|
| 272 |
return ['forum-post-add', 'forum-list'] |
|---|
| 273 |
else: |
|---|
| 274 |
return ['forum-list'] |
|---|
| 275 |
|
|---|
| 276 |
def _do_action(self, req, cursor, modes, group, forum, topic, message, |
|---|
| 277 |
is_moderator): |
|---|
| 278 |
for mode in modes: |
|---|
| 279 |
self.log.debug('doing %s mode action' % (mode,)) |
|---|
| 280 |
if mode == 'group-list': |
|---|
| 281 |
req.perm.assert_permission('DISCUSSION_VIEW') |
|---|
| 282 |
|
|---|
| 283 |
# Display groups. |
|---|
| 284 |
req.hdf['discussion.groups'] = self.get_groups(req, cursor) |
|---|
| 285 |
|
|---|
| 286 |
elif mode == 'admin-group-list': |
|---|
| 287 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 288 |
|
|---|
| 289 |
# Get form values |
|---|
| 290 |
order = req.args.get('order') or 'id' |
|---|
| 291 |
desc = req.args.get('desc') |
|---|
| 292 |
|
|---|
| 293 |
# Prepare ORDER BY statement |
|---|
| 294 |
order_by = 'ORDER BY ' + order |
|---|
| 295 |
if desc: |
|---|
| 296 |
order_by = order_by + ' DESC' |
|---|
| 297 |
else: |
|---|
| 298 |
order_by = order_by + ' ASC' |
|---|
| 299 |
|
|---|
| 300 |
# Display groups. |
|---|
| 301 |
req.hdf['discussion.order'] = order |
|---|
| 302 |
req.hdf['discussion.desc'] = desc |
|---|
| 303 |
if group: |
|---|
| 304 |
req.hdf['discussion.name'] = group['name'] |
|---|
| 305 |
req.hdf['discussion.description'] = \ |
|---|
| 306 |
group['description'] |
|---|
| 307 |
req.hdf['discussion.groups'] = self.get_groups(req, cursor, order_by) |
|---|
| 308 |
|
|---|
| 309 |
elif mode == 'group-add': |
|---|
| 310 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 311 |
|
|---|
| 312 |
elif mode == 'group-post-add': |
|---|
| 313 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 314 |
|
|---|
| 315 |
# Get form values. |
|---|
| 316 |
new_name = Markup(req.args.get('name')) |
|---|
| 317 |
new_description = Markup(req.args.get('description')) |
|---|
| 318 |
|
|---|
| 319 |
# Add new group. |
|---|
| 320 |
self.add_group(cursor, new_name, new_description) |
|---|
| 321 |
|
|---|
| 322 |
elif mode == 'group-post-edit': |
|---|
| 323 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 324 |
|
|---|
| 325 |
# Get form values. |
|---|
| 326 |
new_group = req.args.get('group') |
|---|
| 327 |
new_name = Markup(req.args.get('name')) |
|---|
| 328 |
new_description = Markup(req.args.get('description')) |
|---|
| 329 |
|
|---|
| 330 |
# Edit group. |
|---|
| 331 |
self.edit_group(cursor, new_group, new_name, new_description) |
|---|
| 332 |
|
|---|
| 333 |
elif mode == 'group-delete': |
|---|
| 334 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 335 |
|
|---|
| 336 |
elif mode == 'groups-delete': |
|---|
| 337 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 338 |
|
|---|
| 339 |
# Get selected groups. |
|---|
| 340 |
selection = req.args.get('selection') |
|---|
| 341 |
if isinstance(selection, (str, unicode)): |
|---|
| 342 |
selection = [selection] |
|---|
| 343 |
|
|---|
| 344 |
# Delete selected groups. |
|---|
| 345 |
if selection: |
|---|
| 346 |
for group_id in selection: |
|---|
| 347 |
self.delete_group(cursor, group_id) |
|---|
| 348 |
|
|---|
| 349 |
elif mode == 'forum-list': |
|---|
| 350 |
req.perm.assert_permission('DISCUSSION_VIEW') |
|---|
| 351 |
|
|---|
| 352 |
# Get form values |
|---|
| 353 |
order = req.args.get('order') or 'id' |
|---|
| 354 |
desc = req.args.get('desc') |
|---|
| 355 |
|
|---|
| 356 |
# Prepare ORDER BY statement |
|---|
| 357 |
order_by = 'ORDER BY ' + order |
|---|
| 358 |
if desc: |
|---|
| 359 |
order_by = order_by + ' DESC' |
|---|
| 360 |
else: |
|---|
| 361 |
order_by = order_by + ' ASC' |
|---|
| 362 |
|
|---|
| 363 |
# Display forums. |
|---|
| 364 |
req.hdf['discussion.order'] = order |
|---|
| 365 |
req.hdf['discussion.desc'] = desc |
|---|
| 366 |
req.hdf['discussion.groups'] = self.get_groups(req, cursor) |
|---|
| 367 |
req.hdf['discussion.forums'] = self.get_forums(req, cursor, |
|---|
| 368 |
order_by) |
|---|
| 369 |
|
|---|
| 370 |
elif mode == 'admin-forum-list': |
|---|
| 371 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 372 |
|
|---|
| 373 |
# Get form values |
|---|
| 374 |
order = req.args.get('order') or 'id' |
|---|
| 375 |
desc = req.args.get('desc') |
|---|
| 376 |
|
|---|
| 377 |
# Prepare ORDER BY statement |
|---|
| 378 |
order_by = 'ORDER BY ' + order |
|---|
| 379 |
if desc: |
|---|
| 380 |
order_by = order_by + ' DESC' |
|---|
| 381 |
else: |
|---|
| 382 |
order_by = order_by + ' ASC' |
|---|
| 383 |
|
|---|
| 384 |
# Display forums. |
|---|
| 385 |
req.hdf['discussion.order'] = order |
|---|
| 386 |
req.hdf['discussion.desc'] = desc |
|---|
| 387 |
self.log.debug(forum) |
|---|
| 388 |
if forum: |
|---|
| 389 |
req.hdf['discussion.name'] = forum['name'] |
|---|
| 390 |
req.hdf['discussion.subject'] = forum['subject'] |
|---|
| 391 |
req.hdf['discussion.description'] = \ |
|---|
| 392 |
forum['description'] |
|---|
| 393 |
req.hdf['discussion.moderators'] = forum['moderators'] |
|---|
| 394 |
req.hdf['discussion.group'] = forum['group'] |
|---|
| 395 |
req.hdf['discussion.users'] = self.get_users() |
|---|
| 396 |
req.hdf['discussion.groups'] = self.get_groups(req, cursor) |
|---|
| 397 |
req.hdf['discussion.forums'] = self.get_forums(req, cursor, order_by) |
|---|
| 398 |
|
|---|
| 399 |
elif mode == 'forum-add': |
|---|
| 400 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 401 |
|
|---|
| 402 |
# Display Add Forum form. |
|---|
| 403 |
req.hdf['discussion.users'] = self.get_users() |
|---|
| 404 |
req.hdf['discussion.groups'] = self.get_groups(req, cursor) |
|---|
| 405 |
|
|---|
| 406 |
elif mode == 'forum-post-add': |
|---|
| 407 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 408 |
|
|---|
| 409 |
# Get form values |
|---|
| 410 |
new_name = Markup(req.args.get('name')) |
|---|
| 411 |
new_author = req.authname |
|---|
| 412 |
new_subject = Markup(req.args.get('subject')) |
|---|
| 413 |
new_description = Markup(req.args.get('description')) |
|---|
| 414 |
new_moderators = req.args.get('moderators') |
|---|
| 415 |
new_group = req.args.get('group') |
|---|
| 416 |
if not new_moderators: |
|---|
| 417 |
new_moderators = [] |
|---|
| 418 |
if not isinstance(new_moderators, list): |
|---|
| 419 |
new_moderators = [new_moderators] |
|---|
| 420 |
|
|---|
| 421 |
# Perform new forum add. |
|---|
| 422 |
self.add_forum(cursor, new_name, new_author, new_subject, |
|---|
| 423 |
new_description, new_moderators, new_group) |
|---|
| 424 |
|
|---|
| 425 |
elif mode == 'forum-post-edit': |
|---|
| 426 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 427 |
|
|---|
| 428 |
# Get form values. |
|---|
| 429 |
new_forum = req.args.get('forum') |
|---|
| 430 |
new_name = Markup(req.args.get('name')) |
|---|
| 431 |
new_subject = Markup(req.args.get('subject')) |
|---|
| 432 |
new_description = Markup(req.args.get('description')) |
|---|
| 433 |
new_moderators = req.args.get('moderators') |
|---|
| 434 |
new_group = req.args.get('group') |
|---|
| 435 |
if not new_moderators: |
|---|
| 436 |
new_moderators = [] |
|---|
| 437 |
if not isinstance(new_moderators, list): |
|---|
| 438 |
new_moderators = [new_moderators] |
|---|
| 439 |
|
|---|
| 440 |
# Perform forum edit. |
|---|
| 441 |
self.edit_forum(cursor, new_forum, new_name, new_subject, |
|---|
| 442 |
new_description, new_moderators, new_group) |
|---|
| 443 |
|
|---|
| 444 |
elif mode == 'forum-delete': |
|---|
| 445 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 446 |
|
|---|
| 447 |
# Delete forum |
|---|
| 448 |
self.delete_forum(cursor, forum['id']) |
|---|
| 449 |
|
|---|
| 450 |
elif mode == 'forums-delete': |
|---|
| 451 |
req.perm.assert_permission('DISCUSSION_ADMIN') |
|---|
| 452 |
|
|---|
| 453 |
# Get selected forums. |
|---|
| 454 |
selection = req.args.get('selection') |
|---|
| 455 |
if isinstance(selection, (str, unicode)): |
|---|
| 456 |
selection = [selection] |
|---|
| 457 |
|
|---|
| 458 |
# Delete selected forums. |
|---|
| 459 |
if selection: |
|---|
| 460 |
for forum_id in selection: |
|---|
| 461 |
self.delete_forum(cursor, forum_id) |
|---|
| 462 |
|
|---|
| 463 |
elif mode == 'topic-list': |
|---|
| 464 |
req.perm.assert_permission('DISCUSSION_VIEW') |
|---|
| 465 |
|
|---|
| 466 |
# Get form values |
|---|
| 467 |
order = req.args.get('order') or 'id' |
|---|
| 468 |
desc = req.args.get('desc') |
|---|
| 469 |
|
|---|
| 470 |
# Prepare ORDER BY statement |
|---|
| 471 |
|
|---|