Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue 18: Provide a basic admin tool for viewing and disabling accounts.

  • Loading branch information...
commit 05dfdaa5dd100d7dcb5afa71188fd9ba32646dfc 1 parent 891959b
logan authored
View
21 iq/admin.py
@@ -69,10 +69,31 @@ def get(self):
pass
+class AccountPage(service.Service):
+ @admin('accounts.html')
+ def get(self):
+ # TODO: Support >1000 accounts
+ order = self.request.get('order', '-active')
+ query = accounts.Account.all()
+ query.order(order)
+ self.template.accounts = query.fetch(offset=0, limit=1000)
+
+
+class EditAccountPage(service.Service):
+ @admin('edit-account.html')
+ def get(self):
+ account = accounts.Account.getById(self.request.get('id'))
+ if not account:
+ self.template.error = 'Invalid ID'
+ self.template.account = account
+
+
def main():
pages = [
('/admin', AdminPage),
+ ('/admin/accounts', AccountPage),
('/admin/api', ApiPage),
+ ('/admin/edit-account', EditAccountPage),
('/admin/env', EnvironmentPage),
('/admin/rebuild', RebuildPage),
('/admin/wipe', WipePage),
View
7 iq/json.py
@@ -62,6 +62,12 @@ def get(self):
self.maybeCreateAccount()
+class EditAccountPage(service.EditAccountService):
+ @json(require_admin=True)
+ def get(self):
+ self.editAccount()
+
+
class LoginPage(service.LoginService):
@json()
def get(self):
@@ -196,6 +202,7 @@ def post(self):
def main():
pages = [
('/json/create-account', CreateAccountPage),
+ ('/json/edit-account', EditAccountPage),
('/json/login', LoginPage),
('/json/logout', LogoutPage),
('/json/migrate-account', MigrateAccountPage),
View
24 iq/service.py
@@ -263,6 +263,30 @@ def maybeCreateAccount(self):
return account
+class EditAccountService(Service):
+ def editAccount(self):
+ account = accounts.Account.getById(self.request.get('id'))
+ if not account:
+ self.template.edited = False
+ return
+
+ def toggle(field):
+ value = self.request.get(field, '')
+ logging.info("field = %r, value = %r", field, value)
+ if value == 'true':
+ logging.info(' account.%s = True', field)
+ setattr(account, field, True)
+ elif value == 'false':
+ logging.info(' account.%s = False', field)
+ setattr(account, field, False)
+
+ toggle('trusted')
+ toggle('admin')
+
+ account.put()
+ self.template.edited = True
+
+
class ActivationService(Service):
def activate(self):
self.template.activated = False
View
1  iq/templates/admin/index.html
@@ -4,6 +4,7 @@
<ul>
<li><a href="#setup">Setup</a>
<li><a href="#api">API Access</a>
+ <li><a href="/admin/accounts">Accounts</a>
</ul>
<hr>
<h2><a name="setup" href="#setup">Setup</a></h2>

0 comments on commit 05dfdaa

Please sign in to comment.
Something went wrong with that request. Please try again.