diff --git a/app/app.py b/app/app.py index 31311d5..4979c1d 100644 --- a/app/app.py +++ b/app/app.py @@ -8,6 +8,7 @@ import config import random import re import pdb +from mattermostdriver import Driver app = Flask(__name__) @@ -21,6 +22,14 @@ response_setting = "in_channel" from app import models +driver = Driver({ + 'scheme': 'http', + 'url': config.server_url, + 'token': config.personal_auth_token +}) + +driver.login() + def check_regular(username): '''Check if a user has the permissions of a regular user.''' return models.User.query.filter_by(username=username, authorized=True).first() is not None @@ -117,6 +126,17 @@ def slotmachien_request(username, command): 'username': username, 'token': config.slotmachien_token, 'text': command}) return r.text +def is_bestuur(username): + return username in config.bestuur + +@app.route('/new_message', methods=['POST']) +def new_message(): + if not is_bestuur(request.values.get("user_name")): + delete_message(request.values.get("post_id")) + return "" + +def delete_message(message_id): + driver.posts.delete_post(message_id) @app.route('/door', methods=['POST']) @requires_token('door') diff --git a/config.py.example b/config.py.example index cd41db5..8723a8b 100644 --- a/config.py.example +++ b/config.py.example @@ -8,3 +8,9 @@ tokens = { } slotmachien_url = 'https://kelder.zeus.ugent.be/slotmachien/slack/' slotmachien_token = '123' +personal_auth_token='zeusbot-auth-token' +server_url='mattermost.myserver.com' +bestuur = [ + "user1", + "user2" +] diff --git a/requirements.txt b/requirements.txt index e0b813c..5578327 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ itsdangerous==0.24 Jinja2==2.10 Mako==1.0.7 MarkupSafe==1.0 +mattermostdriver==6.1.3 PyBug==1.2.1 python-dateutil==2.8.0 python-editor==1.0.4 @@ -17,4 +18,5 @@ requests==2.19.1 six==1.12.0 SQLAlchemy==1.2.12 urllib3==1.23 +websockets==7.0 Werkzeug==0.14.1