Add possibility to delete messages from non-bestuur
This commit is contained in:
parent
450bcf2040
commit
16f495ffde
3 changed files with 28 additions and 0 deletions
20
app/app.py
20
app/app.py
|
@ -8,6 +8,7 @@ import config
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import pdb
|
import pdb
|
||||||
|
from mattermostdriver import Driver
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -21,6 +22,14 @@ response_setting = "in_channel"
|
||||||
|
|
||||||
from app import models
|
from app import models
|
||||||
|
|
||||||
|
driver = Driver({
|
||||||
|
'scheme': 'http',
|
||||||
|
'url': config.server_url,
|
||||||
|
'token': config.personal_auth_token
|
||||||
|
})
|
||||||
|
|
||||||
|
driver.login()
|
||||||
|
|
||||||
def check_regular(username):
|
def check_regular(username):
|
||||||
'''Check if a user has the permissions of a regular user.'''
|
'''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
|
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})
|
'username': username, 'token': config.slotmachien_token, 'text': command})
|
||||||
return r.text
|
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'])
|
@app.route('/door', methods=['POST'])
|
||||||
@requires_token('door')
|
@requires_token('door')
|
||||||
|
|
|
@ -8,3 +8,9 @@ tokens = {
|
||||||
}
|
}
|
||||||
slotmachien_url = 'https://kelder.zeus.ugent.be/slotmachien/slack/'
|
slotmachien_url = 'https://kelder.zeus.ugent.be/slotmachien/slack/'
|
||||||
slotmachien_token = '123'
|
slotmachien_token = '123'
|
||||||
|
personal_auth_token='zeusbot-auth-token'
|
||||||
|
server_url='mattermost.myserver.com'
|
||||||
|
bestuur = [
|
||||||
|
"user1",
|
||||||
|
"user2"
|
||||||
|
]
|
||||||
|
|
|
@ -10,6 +10,7 @@ itsdangerous==0.24
|
||||||
Jinja2==2.10
|
Jinja2==2.10
|
||||||
Mako==1.0.7
|
Mako==1.0.7
|
||||||
MarkupSafe==1.0
|
MarkupSafe==1.0
|
||||||
|
mattermostdriver==6.1.3
|
||||||
PyBug==1.2.1
|
PyBug==1.2.1
|
||||||
python-dateutil==2.8.0
|
python-dateutil==2.8.0
|
||||||
python-editor==1.0.4
|
python-editor==1.0.4
|
||||||
|
@ -17,4 +18,5 @@ requests==2.19.1
|
||||||
six==1.12.0
|
six==1.12.0
|
||||||
SQLAlchemy==1.2.12
|
SQLAlchemy==1.2.12
|
||||||
urllib3==1.23
|
urllib3==1.23
|
||||||
|
websockets==7.0
|
||||||
Werkzeug==0.14.1
|
Werkzeug==0.14.1
|
||||||
|
|
Loading…
Reference in a new issue