docs and make available without a pk (bug 846020)
This commit is contained in:
Родитель
f79eb26386
Коммит
d80796b870
|
@ -4,24 +4,41 @@
|
|||
Miscellaneous API
|
||||
======================
|
||||
|
||||
These APIs are not directly about updating Apps.
|
||||
Account
|
||||
=======
|
||||
|
||||
.. note:: Requires authentication.
|
||||
|
||||
To get data on the currently logged in user::
|
||||
|
||||
GET /api/account/mine/
|
||||
|
||||
Returns account information::
|
||||
|
||||
{"resource_uri": "/api/apps/account/1/",
|
||||
"display_name": "Nice person",
|
||||
"installed': [
|
||||
"/api/apps/3/",
|
||||
]}
|
||||
|
||||
The same information is also accessible at the canoncial `resource_uri`::
|
||||
|
||||
GET /api/account/1/
|
||||
|
||||
The `/api/account/mine/` URL is provided as a convenience for users who don't
|
||||
know their full URL ahead of time.
|
||||
|
||||
Categories
|
||||
==========
|
||||
|
||||
To find a list of categories available on the marketplace::
|
||||
|
||||
GET /api/apps/category/
|
||||
GET /api/apps/category/
|
||||
|
||||
Returns the list of categories::
|
||||
|
||||
{"meta":
|
||||
{"limit": 20, "next": null, "offset": 0,
|
||||
"previous": null, "total_count": 1},
|
||||
"objects":
|
||||
[{"id": 1, "name": "Webapp",
|
||||
"resource_uri": "/api/apps/category/1/",
|
||||
"slug": "webapp"}]
|
||||
}
|
||||
{"meta": {"limit": 20, "next": null...},
|
||||
"objects": [{"id": 1, "name": "App"...]}
|
||||
}
|
||||
|
||||
Use the `id` of the category in your app updating.
|
||||
|
|
|
@ -22,6 +22,10 @@ class AccountResource(MarketplaceResource):
|
|||
resource_name = 'account'
|
||||
|
||||
def obj_get(self, request=None, **kwargs):
|
||||
if kwargs.get('pk') == 'mine':
|
||||
kwargs['pk'] = request.amo_user.pk
|
||||
|
||||
# TODO: put in acl checks for admins to get other users information.
|
||||
obj = super(AccountResource, self).obj_get(request=request, **kwargs)
|
||||
if not OwnerAuthorization().is_authorized(request, object=obj):
|
||||
raise ImmediateHttpResponse(response=http.HttpForbidden())
|
||||
|
|
|
@ -56,3 +56,9 @@ class TestAccount(BaseOAuth):
|
|||
|
||||
def test_other(self):
|
||||
eq_(self.client.get(get_url('account', '10482')).status_code, 403)
|
||||
|
||||
def test_own(self):
|
||||
res = self.client.get(get_url('account', 'mine'))
|
||||
eq_(res.status_code, 200)
|
||||
data = json.loads(res.content)
|
||||
eq_(data['display_name'], self.user.display_name)
|
||||
|
|
Загрузка…
Ссылка в новой задаче