update api docs

This commit is contained in:
rolux 2014-12-18 18:43:35 +00:00
parent 3024c0225b
commit ec508dd6b7

View file

@ -46,20 +46,21 @@ def get_group_or_404(data):
def signin(request, data): def signin(request, data):
''' '''
takes { Sign in
username: string, takes {
password: string username: string,
password: string
}
returns {
errors: {
username: 'Unknown Username',
password: 'Incorrect Password'
} }
user: {
returns { ...
errors: {
username: 'Unknown Username',
password: 'Incorrect Password'
}
user: {
...
}
} }
}
see: signout, signup
''' '''
if 'assertion' in data: if 'assertion' in data:
response = persona.signin(request) response = persona.signin(request)
@ -108,13 +109,15 @@ actions.register(signin, cache=False)
def signout(request, data): def signout(request, data):
''' '''
takes {} Sign out
takes {}
returns { returns {
user: { user: { // default user
default user key: value, // user data
} ... // more user daa
} }
}
see: signin, signup
''' '''
response = json_response(text='ok') response = json_response(text='ok')
if request.user.is_authenticated(): if request.user.is_authenticated():
@ -132,21 +135,23 @@ actions.register(signout, cache=False)
def signup(request, data): def signup(request, data):
''' '''
takes { Sign up
username: string, takes {
password: string, username: string,
email: string password: string,
} email: string
}
returns { returns {
errors: { errors: {
username: 'Unknown Username', username: 'Unknown Username',
password: 'Incorrect Password' password: 'Incorrect Password'
}
user: {
...
}
} }
user: {
...
}
}
see: signin, signout
''' '''
if 'username' in data and 'password' in data: if 'username' in data and 'password' in data:
data['username'] = data['username'].strip() data['username'] = data['username'].strip()
@ -216,19 +221,20 @@ actions.register(signup, cache=False)
def resetPassword(request, data): def resetPassword(request, data):
''' '''
takes { Resets password for a given user
username: string, takes {
password: string, username: string,
code: string password: string,
code: string
}
returns {
errors: {
code: 'Incorrect Code'
} }
user {
returns {
errors: {
code: 'Incorrect Code'
}
user {
}
} }
}
see: ...
''' '''
if 'code' in data and 'password' in data: if 'code' in data and 'password' in data:
if not data['password']: if not data['password']:
@ -268,18 +274,18 @@ actions.register(resetPassword, cache=False)
def requestToken(request, data): def requestToken(request, data):
''' '''
takes { Requests a password reset token
username: string, takes {
email: string username: string,
} email: string
}
returns { returns {
errors: { errors: {
username: 'Unknown Username' username: 'Unknown Username'
email: 'Unknown Email' email: 'Unknown Email'
}
username: user
} }
username: user
}
''' '''
user = None user = None
if 'username' in data: if 'username' in data:
@ -333,14 +339,14 @@ actions.register(requestToken, cache=False)
@capability_required_json('canManageUsers') @capability_required_json('canManageUsers')
def editUser(request, data): def editUser(request, data):
''' '''
takes { Edits a user
key: value takes {
} key: value
required key: id }
optional keys: username, email, level, notes required key: id
optional keys: username, email, level, notes
returns { returns {
} }
''' '''
response = json_response() response = json_response()
user = get_object_or_404_json(User, pk=ox.fromAZ(data['id'])) user = get_object_or_404_json(User, pk=ox.fromAZ(data['id']))
@ -389,10 +395,10 @@ actions.register(editUser, cache=False)
@capability_required_json('canManageUsers') @capability_required_json('canManageUsers')
def removeUser(request, data): def removeUser(request, data):
''' '''
takes { takes {
username: username username: username
} }
returns {} returns {}
''' '''
response = json_response() response = json_response()
u = get_user_or_404(data) u = get_user_or_404(data)
@ -404,16 +410,17 @@ actions.register(removeUser, cache=False)
def findUser(request, data): def findUser(request, data):
''' '''
takes { takes {
key: string, //username, email key: string, //username, email
value: string, value: string,
operator: "==" // "==", "=" operator: "==" // "==", "="
keys: [string] keys: [string]
} }
returns { returns {
users: [object] users: [object]
} }
see: editUser
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
#keys = data.get('keys') #keys = data.get('keys')
@ -539,6 +546,7 @@ Positions
query: query object, more on query syntax at query: query object, more on query syntax at
https://wiki.0x2620.org/wiki/pandora/QuerySyntax https://wiki.0x2620.org/wiki/pandora/QuerySyntax
positions: ids of places for which positions are required positions: ids of places for which positions are required
see: editUser
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
query = parse_query(data, request.user) query = parse_query(data, request.user)
@ -653,14 +661,14 @@ actions.register(mail, cache=False)
def contact(request, data): def contact(request, data):
''' '''
takes { Sends a message to the contact address
email: string, takes {
subject: string, email: string,
message: string subject: string,
} message: string
}
returns { returns {
} }
''' '''
name = data.get('name', '') name = data.get('name', '')
email = data.get('email', '') email = data.get('email', '')
@ -725,11 +733,12 @@ def getPositionById(list, key):
@login_required_json @login_required_json
def editPreferences(request, data): def editPreferences(request, data):
''' '''
takes { Edits the current user's preferences
key: value takes {
} key: value
keys: email, password }
returns {} keys: email, password
returns {}
''' '''
errors = {} errors = {}
change = False change = False
@ -768,12 +777,10 @@ def reset_ui(request):
def resetUI(request, data): def resetUI(request, data):
''' '''
reset user ui settings to defaults Resets the user's UI settings to the default state
takes { takes {}
} returns {}
see: setUI
returns {
}
''' '''
response = json_response() response = json_response()
if request.user.is_authenticated(): if request.user.is_authenticated():
@ -788,14 +795,14 @@ actions.register(resetUI, cache=False)
def setUI(request, data): def setUI(request, data):
''' '''
takes { Sets one or more UI settings for the current user
key.subkey: value takes {
} key: value, // property and new value
you can set nested keys ... // more key/value pairs
api.setUI({"lists|my|ListView": "icons"}) }
returns {}
returns { notes: To set nested keys, use {'foo.bar.baz': value}
} see: resetUI
''' '''
if request.user.is_authenticated(): if request.user.is_authenticated():
profile = request.user.get_profile() profile = request.user.get_profile()
@ -840,10 +847,11 @@ actions.register(setUI, cache=False)
@capability_required_json('canManageUsers') @capability_required_json('canManageUsers')
def statistics(request, data): def statistics(request, data):
''' '''
takes {} Gets usage statistics
returns { takes {}
... returns {
} ... // undocumented
}
''' '''
response = json_response() response = json_response()
from app.models import Settings from app.models import Settings
@ -869,13 +877,14 @@ def group_json(g):
@login_required_json @login_required_json
def getGroups(request, data): def getGroups(request, data):
''' '''
takes {} Gets user groups
returns { takes {}
groups: [ returns {
{id: string, name: string, users: int, items: int} groups: [
] {id: string, name: string, users: int, items: int}
} ]
}
see: addGroup, editGroup, getGroups, removeGroup
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
response['data']['groups'] = [] response['data']['groups'] = []
@ -888,18 +897,19 @@ actions.register(getGroups)
@login_required_json @login_required_json
def getGroup(request, data): def getGroup(request, data):
''' '''
takes { Gets user group
id: string takes {
or id: string
name: string or
} name: string
returns { }
id: string, returns {
name: string id: string,
users: int name: string
items: int users: int
} items: int
}
see: addGroup, editGroup, getGroups, removeGroup
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
g = get_group_or_404(data) g = get_group_or_404(data)
@ -911,16 +921,17 @@ actions.register(getGroup, cache=False)
@capability_required_json('canManageUsers') @capability_required_json('canManageUsers')
def addGroup(request, data): def addGroup(request, data):
''' '''
takes { Adds user group
name: string takes {
} name: string
returns { }
id: string, returns {
name: string id: string,
users: int name: string
items: int users: int
} items: int
}
see: editGroup, getGroup, getGroups, removeGroup
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
created = False created = False
@ -940,16 +951,17 @@ actions.register(addGroup, cache=False)
@capability_required_json('canManageUsers') @capability_required_json('canManageUsers')
def editGroup(request, data): def editGroup(request, data):
''' '''
takes { Edits user group
id: string, takes {
name: string id: string,
name: string
}
returns {
name: string
users: int
}
}
returns {
name: string
users: int
}
see: addGroup, getGroup, getGroups, removeGroup
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
g = Group.objects.get(id=ox.fromAZ(data['id'])) g = Group.objects.get(id=ox.fromAZ(data['id']))
@ -964,12 +976,13 @@ actions.register(editGroup, cache=False)
@capability_required_json('canManageUsers') @capability_required_json('canManageUsers')
def removeGroup(request, data): def removeGroup(request, data):
''' '''
takes { Removes user group
id: string takes {
} id: string
returns { }
} returns {
}
see: addGroup, editGroup, getGroup, getGroups
''' '''
response = json_response(status=200, text='ok') response = json_response(status=200, text='ok')
g = get_group_or_404(data) g = get_group_or_404(data)