Skip to content

Commit

Permalink
Issue 18: Provide a basic admin tool for viewing and disabling accounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
logan committed Jul 6, 2008
1 parent 891959b commit 05dfdaa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
21 changes: 21 additions & 0 deletions iq/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions iq/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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),
Expand Down
24 changes: 24 additions & 0 deletions iq/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions iq/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ <h2>Admin Menu</h2>
<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>
Expand Down

0 comments on commit 05dfdaa

Please sign in to comment.