Added soapbox and archive forum access levels. #313 veekun-promotions/2010080801 veekun-promotions/2010080802
authorEevee <git@veekun.com>
Sun, 8 Aug 2010 18:12:25 +0000 (11:12 -0700)
committerEevee <git@veekun.com>
Sun, 8 Aug 2010 18:12:25 +0000 (11:12 -0700)
migration/versions/003_Added_some_forum_access_levels.py [new file with mode: 0644]
splinext/forum/controllers/forum.py
splinext/forum/model/__init__.py
splinext/forum/templates/forum/lib.mako

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 (file)
index 0000000..591fb8f
--- /dev/null
@@ -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)
index b5bacab..342e8e6 100644 (file)
@@ -54,7 +54,7 @@ class ForumController(BaseController):
 
     def write_thread(self, forum_id):
         """Provides a form for posting a new thread."""
 
     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:
             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."""
 
     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:
             abort(403)
 
         try:
index a137866..f312b4d 100644 (file)
@@ -2,7 +2,7 @@ from datetime import datetime
 
 from sqlalchemy import and_, Column, ForeignKey, Index
 from sqlalchemy.orm import relation
 
 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
 
 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)
     __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'
 
 class Thread(TableBase):
     __tablename__ = 'threads'
@@ -35,6 +53,18 @@ class Thread(TableBase):
 
         return self.posts.filter_by(position=position).one()
 
 
         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)
 class Post(TableBase):
     __tablename__ = 'posts'
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
index 5be6251..8a1893d 100644 (file)
@@ -26,7 +26,7 @@
 </%def>
 
 <%def name="write_thread_form(forum)">
 </%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">
 <h1>Create new thread</h1>
 ${h.form(url(controller='forum', action='write_thread', forum_id=forum.id))}
 <dl class="standard-form">
@@ -40,7 +40,7 @@ ${h.end_form()}
 </%def>
 
 <%def name="write_post_form(thread)">
 </%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">
 <h1>Reply</h1>
 ${h.form(url(controller='forum', action='write', forum_id=thread.forum.id, thread_id=thread.id))}
 <dl class="standard-form">