Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gotlium committed May 29, 2016
1 parent 505aee9 commit a3730c9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
63 changes: 63 additions & 0 deletions docs/decorators.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. _decorators:

Builtin decorators
==================


Allowed users::

from mattermost_bot.utils import allowed_users
from mattermost_bot.bot import respond_to


@respond_to('^is-allowed$')
@allowed_users('admin', 'root')
def access_allowed(message):
message.reply('Access is allowed')



Direct messages::

from mattermost_bot.utils import allow_only_direct_message
from mattermost_bot.bot import respond_to


@respond_to('^direct-msg$')
@allow_only_direct_message()
def direct_msg(message):
message.reply('Message is direct')



Real case
---------

For example we have some users on our chat. We want allow some functionality
to some users. We can create constants with allowed users on bot settings::

ADMIN_USERS = ['admin', 'root']
SUPPORT_USERS = ['mike', 'nick']


So now we can close access to some functions on plugins::

from mattermost_bot.utils import allow_only_direct_message
from mattermost_bot.utils import allowed_users
from mattermost_bot.bot import respond_to
from mattermost_bot import settings


@respond_to('^selfupdate')
@allow_only_direct_message()
@allowed_users(*settings.ADMIN_USERS)
def self_update(message):
# some code
message.reply('Update was done')


@respond_to('^smsto (.*)')
@allowed_users(*settings.SUPPORT_USERS)
def sms_to(message, name):
# some code
message.reply('Sms was sent to %s' % name)
2 changes: 1 addition & 1 deletion docs/demo_installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Install stable package from PyPi::
Create settings file `mattermost_bot_settings.py` with the following lines::

DEBUG = True
BOT_URL = 'http://mm.example.com:8065/api/v1'
BOT_URL = 'http://mm.example.com:8065/api/v3'
BOT_LOGIN = '<BOT_EMAIL>'
BOT_PASSWORD = '<BOT_PASSWORD>'
BOT_TEAM = '<TEAM>'
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Contents
plugins
deploy
use_cases
decorators
demo_installation
dev_install
contributing
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Installation
Compatibility
-------------
* Python: 2.6, 3.4+
* Mattermost: 1.4+
* Mattermost: 3.x+


Recommended way to install is via pip::

pip install mattermost_bot
pip install -U mattermost_bot


Check `mattermost_bot` version::
Expand Down
4 changes: 3 additions & 1 deletion mattermost_bot/plugins/access.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- encoding: utf-8 -*-

from mattermost_bot.utils import allow_only_direct_message
from mattermost_bot.utils import allowed_users
from mattermost_bot.bot import respond_to


@respond_to('^admin$')
@allow_only_direct_message()
@allowed_users('admin', 'root')
def hello_react(message):
def users_access(message):
message.reply('Access allowed!')

0 comments on commit a3730c9

Please sign in to comment.