forked from slackhappy/fs-slack
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config_page.py
46 lines (40 loc) · 1.13 KB
/
config_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import config
import context
import webapp2
import logging
from google.appengine.api import users
CONFIG_KEYS = ['team_domain', 'incoming_webhook_token', 'api_token']
class ConfigPage(webapp2.RequestHandler):
def ensure_admin(self):
user = users.get_current_user()
if user:
if users.is_current_user_admin():
return True
else:
self.error(500)
return False
else:
self.redirect(users.create_login_url(self.request.uri))
def get(self):
if self.ensure_admin():
self.render()
def post(self):
if self.ensure_admin():
settings = {}
for key in CONFIG_KEYS:
settings[key] = self.request.get(key)
if not settings[key]:
settings[key] = ''
logging.info(settings)
config.set_config(**settings)
self.render()
def render(self):
conf = config.get_config()
settings = {}
for key in CONFIG_KEYS:
if hasattr(conf, key):
settings[key] = getattr(conf, key)
else:
settings[key] = ''
template = context.jinja_environment.get_template('config.html')
self.response.out.write(template.render(settings))