From: Eevee Date: Sun, 8 Aug 2010 18:12:25 +0000 (-0700) Subject: Added soapbox and archive forum access levels. #313 X-Git-Tag: veekun-promotions/2010080801^0 X-Git-Url: http://git.veekun.com/zzz-spline-forum.git/commitdiff_plain/0bdf4461e31fce365e9fbc2e0784e634d2431a0e Added soapbox and archive forum access levels. #313 --- diff --git a/migration/versions/003_Added_some_forum_access_levels.py b/migration/versions/003_Added_some_forum_access_levels.py new file mode 100644 index 0000000..591fb8f --- /dev/null +++ b/migration/versions/003_Added_some_forum_access_levels.py @@ -0,0 +1,27 @@ +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) diff --git a/splinext/forum/controllers/forum.py b/splinext/forum/controllers/forum.py index b5bacab..342e8e6 100644 --- a/splinext/forum/controllers/forum.py +++ b/splinext/forum/controllers/forum.py @@ -54,7 +54,7 @@ class ForumController(BaseController): 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: @@ -99,7 +99,7 @@ class ForumController(BaseController): 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: diff --git a/splinext/forum/model/__init__.py b/splinext/forum/model/__init__.py index a137866..f312b4d 100644 --- a/splinext/forum/model/__init__.py +++ b/splinext/forum/model/__init__.py @@ -2,7 +2,7 @@ from datetime import datetime 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 @@ -14,6 +14,24 @@ 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, 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' @@ -35,6 +53,18 @@ class Thread(TableBase): 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) diff --git a/splinext/forum/templates/forum/lib.mako b/splinext/forum/templates/forum/lib.mako index 5be6251..8a1893d 100644 --- a/splinext/forum/templates/forum/lib.mako +++ b/splinext/forum/templates/forum/lib.mako @@ -26,7 +26,7 @@ <%def name="write_thread_form(forum)"> -% if c.user.can('create_forum_thread'): +% if forum.can_create_thread(c.user):

Create new thread

${h.form(url(controller='forum', action='write_thread', forum_id=forum.id))}
@@ -40,7 +40,7 @@ ${h.end_form()} <%def name="write_post_form(thread)"> -% if c.user.can('create_forum_post'): +% if thread.can_create_post(c.user):

Reply

${h.form(url(controller='forum', action='write', forum_id=thread.forum.id, thread_id=thread.id))}