Просмотр исходного кода

Begin integration of Flask-Allows

Alec Nikolas Reiter 9 лет назад
Родитель
Сommit
e55b229612
3 измененных файлов с 30 добавлено и 1 удалено
  1. 5 1
      flaskbb/app.py
  2. 19 0
      flaskbb/exceptions.py
  3. 6 0
      flaskbb/extensions.py

+ 5 - 1
flaskbb/app.py

@@ -35,7 +35,7 @@ from flaskbb.forum.views import forum
 from flaskbb.forum.models import Post, Topic, Category, Forum
 from flaskbb.forum.models import Post, Topic, Category, Forum
 # extensions
 # extensions
 from flaskbb.extensions import db, login_manager, mail, cache, redis_store, \
 from flaskbb.extensions import db, login_manager, mail, cache, redis_store, \
-    debugtoolbar, migrate, themes, plugin_manager, babel, csrf
+    debugtoolbar, migrate, themes, plugin_manager, babel, csrf, allows
 # various helpers
 # various helpers
 from flaskbb.utils.helpers import format_date, time_since, crop_title, \
 from flaskbb.utils.helpers import format_date, time_since, crop_title, \
     is_online, render_markup, mark_online, forum_is_unread, topic_is_unread, \
     is_online, render_markup, mark_online, forum_is_unread, topic_is_unread, \
@@ -157,6 +157,10 @@ def configure_extensions(app):
         # otherwise we will just fallback to the default language
         # otherwise we will just fallback to the default language
         return flaskbb_config["DEFAULT_LANGUAGE"]
         return flaskbb_config["DEFAULT_LANGUAGE"]
 
 
+    # Flask-Allows
+    allows.init_app(app)
+    allows.identity_loader(lambda: current_user)
+
 
 
 def configure_template_filters(app):
 def configure_template_filters(app):
     """Configures the template filters."""
     """Configures the template filters."""

+ 19 - 0
flaskbb/exceptions.py

@@ -0,0 +1,19 @@
+"""
+    flaskbb.exceptions
+    ~~~~~~~~~~~~~~~~~~
+
+    Exceptions implemented by FlaskBB.
+
+    :copyright: (c) 2015 by the FlaskBBB Team.
+    :license: BSD, see LICENSE for more details
+"""
+from werkzeug.exceptions import HTTPException, Forbidden
+
+
+class FlaskBBError(HTTPException):
+    "Root exception for FlaskBB"
+    description = "An internal error has occured"
+
+
+class AuthorizationRequired(FlaskBBError, Forbidden):
+    description = "Authorization is required to access this area."

+ 6 - 0
flaskbb/extensions.py

@@ -8,6 +8,7 @@
     :copyright: (c) 2014 by the FlaskBB Team.
     :copyright: (c) 2014 by the FlaskBB Team.
     :license: BSD, see LICENSE for more details.
     :license: BSD, see LICENSE for more details.
 """
 """
+from flask_allows import Allows
 from flask_sqlalchemy import SQLAlchemy
 from flask_sqlalchemy import SQLAlchemy
 from flask_login import LoginManager
 from flask_login import LoginManager
 from flask_mail import Mail
 from flask_mail import Mail
@@ -20,6 +21,11 @@ from flask_plugins import PluginManager
 from flask_babelex import Babel
 from flask_babelex import Babel
 from flask_wtf.csrf import CsrfProtect
 from flask_wtf.csrf import CsrfProtect
 
 
+from flaskbb.exceptions import AuthorizationRequired
+
+
+# Permissions Manager
+allows = Allows(throws=AuthorizationRequired)
 
 
 # Database
 # Database
 db = SQLAlchemy()
 db = SQLAlchemy()