--- /dev/null
+from sqlalchemy import *
+from migrate import *
+import migrate.changeset
+
+from sqlalchemy.ext.declarative import declarative_base
+TableBase = declarative_base()
+
+
+class Forum(TableBase):
+ __tablename__ = 'forums'
+ id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
+ name = Column(Unicode(133), nullable=False)
+ access_level = Column(Enum(u'normal', u'soapbox', u'archive', name='forums_access_level'), nullable=False, server_default=u'normal')
+
+
+def upgrade(migrate_engine):
+ TableBase.metadata.bind = migrate_engine
+
+ Forum.__table__.c.access_level.type.create(bind=migrate_engine)
+ Forum.__table__.c.access_level.create()
+
+def downgrade(migrate_engine):
+ TableBase.metadata.bind = migrate_engine
+ access_level_type = Forum.__table__.c.access_level.type
+
+ Forum.__table__.c.access_level.drop()
+ access_level_type.drop(bind=migrate_engine)
def write_thread(self, forum_id):
"""Provides a form for posting a new thread."""
- if not c.user.can('create_forum_thread'):
+ if not c.user.can('forum:create-thread'):
abort(403)
try:
def write(self, forum_id, thread_id):
"""Provides a form for posting to a thread."""
- if not c.user.can('create_forum_post'):
+ if not c.user.can('forum:create-post'):
abort(403)
try:
from sqlalchemy import and_, Column, ForeignKey, Index
from sqlalchemy.orm import relation
-from sqlalchemy.types import DateTime, Integer, Unicode
+from sqlalchemy.types import DateTime, Enum, Integer, Unicode
from spline.model.meta import TableBase
from splinext.users import model as users_model
__tablename__ = 'forums'
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
name = Column(Unicode(133), nullable=False)
+ access_level = Column(Enum(u'normal', u'soapbox', u'archive', name='forums_access_level'), nullable=False, default=u'normal', server_default=u'normal')
+
+ def can_create_thread(self, user):
+ """Returns True ifff the named user can make a new thread in this
+ forum.
+ """
+ if not user.can('forum:create-thread'):
+ return False
+
+ if self.access_level == u'soapbox' and \
+ not user.can('forum:override-soapbox'):
+ return False
+
+ if self.access_level == u'archive' and \
+ not user.can('forum:override-archive'):
+ return False
+
+ return True
class Thread(TableBase):
__tablename__ = 'threads'
return self.posts.filter_by(position=position).one()
+ def can_create_post(self, user):
+ """Returns True ifff the named user can make a new post in this thread.
+ """
+ if not user.can('forum:create-post'):
+ return False
+
+ if self.forum.access_level == u'archive' and \
+ not user.can('forum:override-archive'):
+ return False
+
+ return True
+
class Post(TableBase):
__tablename__ = 'posts'
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
</%def>
<%def name="write_thread_form(forum)">
-% if c.user.can('create_forum_thread'):
+% if forum.can_create_thread(c.user):
<h1>Create new thread</h1>
${h.form(url(controller='forum', action='write_thread', forum_id=forum.id))}
<dl class="standard-form">
</%def>
<%def name="write_post_form(thread)">
-% if c.user.can('create_forum_post'):
+% if thread.can_create_post(c.user):
<h1>Reply</h1>
${h.form(url(controller='forum', action='write', forum_id=thread.forum.id, thread_id=thread.id))}
<dl class="standard-form">