Merge ~jsseidel/maas:jsseidel-users-api-annotations into maas:master

Proposed by Spencer Seidel
Status: Merged
Approved by: Newell Jensen
Approved revision: 94cfac375f0c19b673254a501851a8241243b56f
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-users-api-annotations
Merge into: maas:master
Diff against target: 152 lines (+97/-14)
2 files modified
src/maasserver/api/examples/users.json (+39/-0)
src/maasserver/api/users.py (+58/-14)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
MAAS Lander Approve
Review via email: mp+359129@code.launchpad.net

Commit message

Added API annotations to users and collected examples.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b jsseidel-users-api-annotations lp:~jsseidel/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 94cfac375f0c19b673254a501851a8241243b56f

review: Approve
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Looks good. One inline comment but not going to block on this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/examples/users.json b/src/maasserver/api/examples/users.json
2new file mode 100644
3index 0000000..5c46062
4--- /dev/null
5+++ b/src/maasserver/api/examples/users.json
6@@ -0,0 +1,39 @@
7+{
8+ "create": {
9+ "is_superuser": false,
10+ "username": "foobar",
11+ "email": "foo@foobar.com",
12+ "is_local": true,
13+ "resource_uri": "/MAAS/api/2.0/users/foobar/"
14+ },
15+ "read": {
16+ "is_superuser": false,
17+ "username": "foobar",
18+ "email": "foo@foobar.com",
19+ "is_local": true,
20+ "resource_uri": "/MAAS/api/2.0/users/foobar/"
21+ },
22+ "whoami": {
23+ "is_superuser": true,
24+ "username": "admin",
25+ "email": "NN7ER2rH6x@example.com",
26+ "is_local": true,
27+ "resource_uri": "/MAAS/api/2.0/users/admin/"
28+ },
29+ "list": [
30+ {
31+ "is_superuser": false,
32+ "username": "ZZaqFHnASE",
33+ "email": "th851JAwIa@example.com",
34+ "is_local": true,
35+ "resource_uri": "/MAAS/api/2.0/users/ZZaqFHnASE/"
36+ },
37+ {
38+ "is_superuser": false,
39+ "username": "zZrMZtK.kq",
40+ "email": "lmcdDnyn5H@example.com",
41+ "is_local": true,
42+ "resource_uri": "/MAAS/api/2.0/users/zZrMZtK.kq/"
43+ }
44+ ]
45+}
46diff --git a/src/maasserver/api/users.py b/src/maasserver/api/users.py
47index 10dfdf0..d2bd795 100644
48--- a/src/maasserver/api/users.py
49+++ b/src/maasserver/api/users.py
50@@ -50,32 +50,56 @@ class UsersHandler(OperationsHandler):
51 return ('users_handler', [])
52
53 def read(self, request):
54- """List users."""
55+ """@description-title List users
56+ @description List users
57+
58+ @success (http-status-code) "200" 200
59+ @success (json) "success-json" A JSON object containing a list of
60+ users.
61+ @success-example "success-json" [exkey=list] placeholder text
62+ """
63 return User.objects.all().order_by('username')
64
65 @operation(idempotent=True)
66 def whoami(self, request):
67- """Returns the currently logged in user."""
68+ """@description-title Retrieve logged-in user
69+ @description Returns the currently logged-in user.
70+
71+ @success (http-status-code) "200" 200
72+ @success (json) "success-json" A JSON object containing information
73+ about the currently logged-in user.
74+ @success-example "success-json" [exkey=whoami] placeholder text
75+ """
76 return request.user
77
78 @admin_method
79 def create(self, request):
80- """Create a MAAS user account.
81+ """@description-title Create a MAAS user account
82+ @description Creates a MAAS user account.
83
84 This is not safe: the password is sent in plaintext. Avoid it for
85 production, unless you are confident that you can prevent eavesdroppers
86 from observing the request.
87
88- :param username: Identifier-style username for the new user.
89- :type username: unicode
90- :param email: Email address for the new user.
91- :type email: unicode
92- :param password: Password for the new user.
93- :type password: unicode
94- :param is_superuser: Whether the new user is to be an administrator.
95- :type is_superuser: bool ('0' for False, '1' for True)
96+ @param (string) "username" [required=true] Identifier-style username
97+ for the new user.
98+
99+ @param (string) "email" [required=true] Email address for the new user.
100+
101+ @param (string) "password" [required=true] Password for the new user.
102+
103+ @param (boolean) "is_superuser" [required=true] Whether the new user is
104+ to be an administrator. ('0' == False, '1' == True)
105+
106+ @success (http-status-code) "200" 200
107+ @success (json) "success-json" A JSON object containing information
108+ about the new user.
109+ @success-example "success-json" [exkey=create] placeholder text
110
111- Returns 400 if any mandatory parameters are missing.
112+ @error (http-status-code) "400" 400
113+ @error (content) "error-content" Mandatory parameters are missing.
114+ @error-example "error-content"
115+ No provided username!
116 """
117 username = get_mandatory_param(request.data, 'username')
118 email = get_mandatory_param(request.data, 'email')
119@@ -117,12 +141,32 @@ class UserHandler(OperationsHandler):
120 )
121
122 def read(self, request, username):
123- """Return user details."""
124+ """@description-title Retrieve user details
125+ @description Retrieve a user's details.
126+
127+ @param (string) "{username}" [required=true] A username.
128+
129+ @success (http-status-code) "200" 200
130+ @success (json) "success-json" A JSON object containing user
131+ information.
132+ @success-example "success-json" [exkey=read] placeholder text
133+
134+ @error (http-status-code) "404" 404
135+ @error (content) "not-found" The given user was not found.
136+ @error-example "not-found"
137+ Not Found
138+ """
139 return get_object_or_404(User, username=username)
140
141 @admin_method
142 def delete(self, request, username):
143- """Deletes a user"""
144+ """@description-title Delete a user
145+ @description Deletes a given username.
146+
147+ @param (string) "{username}" [required=true] The username to delete.
148+
149+ @success (http-status-code) "204" 204
150+ """
151 if request.user.username == username:
152 raise ValidationError("An administrator cannot self-delete.")
153

Subscribers

People subscribed via source and target branches