diff --git a/CHANGES b/CHANGES index dbe75ac..0fb6e6b 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,14 @@ Flask-Security Changelog Here you can see the full list of changes between each Flask-Security release. +Version 1.2.1 +------------- + +Released March 28th, 2012 + +- Added optional user model mixin parameter for datastores +- Added CreateRoleCommand to available Flask-Script commands + Version 1.2.0 ------------- diff --git a/docs/index.rst b/docs/index.rst index a7df7f5..e4607d4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -28,6 +28,7 @@ Contents * :ref:`overview` * :ref:`installation` * :ref:`getting-started` +* :ref:`additional-user-fields` * :ref:`flask-script-commands` * :ref:`api` * :doc:`Changelog ` @@ -153,6 +154,22 @@ specific role:: {$ endif %} +.. _additional-user-fields: + +Additional User Fields +---------------------- +If you'd like to add additional fields to the user model you can use a mixin +class that specifies your additional fields. The following is an example of +how you might do this:: + + db = SQLAlchemy(app) + + class UserAccountMixin(): + first_name = db.Column(db.String(120)) + last_name = db.Column(db.String(120)) + + Security(app, SQLAlchemyUserDatastore(db, UserAccountMixin)) + .. _flask-script-commands: Flask-Script Commands @@ -160,6 +177,7 @@ Flask-Script Commands Flask-Security comes packed with a few Flask-Script commands. They are: * :class:`flask.ext.security.script.CreateUserCommand` +* :class:`flask.ext.security.script.CreateRoleCommand` * :class:`flask.ext.security.script.AddRoleCommand` * :class:`flask.ext.security.script.RemoveRoleCommand` * :class:`flask.ext.security.script.DeactivateUserCommand` @@ -236,9 +254,11 @@ Datastores .. autoclass:: flask_security.datastore.sqlalchemy.SQLAlchemyUserDatastore :members: + :inherited-members: .. autoclass:: flask_security.datastore.mongoengine.MongoEngineUserDatastore :members: + :inherited-members: Models diff --git a/flask_security/datastore/__init__.py b/flask_security/datastore/__init__.py index ef02910..9210448 100644 --- a/flask_security/datastore/__init__.py +++ b/flask_security/datastore/__init__.py @@ -19,8 +19,10 @@ class UserDatastore(object): :attr:`_do_find_user`, and :attr:`_do_find_role` methods. :param db: An instance of a configured databse manager from a Flask - extension such as Flask-SQLAlchemy or Flask-MongoEngine""" - + extension such as Flask-SQLAlchemy or Flask-MongoEngine + :param user_account_mixin: An optional mixin class that specifies additional + fields to be added to the user model + """ def __init__(self, db, user_account_mixin=None): self.db = db self.user_account_mixin = user_account_mixin or object diff --git a/flask_security/script.py b/flask_security/script.py index c7f71df..a320766 100644 --- a/flask_security/script.py +++ b/flask_security/script.py @@ -46,6 +46,19 @@ class CreateUserCommand(Command): pprint(kwargs) +class CreateRoleCommand(Command): + """Create a role""" + + option_list = ( + Option('-n', '--name', dest='name', default=None), + Option('-d', '--desc', dest='description', default=None), + ) + + def run(self, **kwargs): + role = user_datastore.create_role(**kwargs) + print 'Role "%(name)s" created successfully.' % kwargs + + class _RoleCommand(Command): option_list = ( Option('-u', '--user', dest='user_identifier'),