Skip to content

Commit 72bfc37

Browse files
authored
Merge pull request #1 from zhangchunlin/master
同步代码
2 parents 7b7ff6a + ef703f3 commit 72bfc37

File tree

7 files changed

+132
-205
lines changed

7 files changed

+132
-205
lines changed

demo/apps/apijson_demo/dbinit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
Moment = models.moment
1111

1212
user_list = [
13+
{
14+
"username": "admin",
15+
"nickname": "Administrator",
16+
"email": "admin@localhost",
17+
},
1318
{
1419
"username": "usera",
1520
"nickname": "User A",
@@ -101,7 +106,10 @@
101106
print("create user '%s'"%(d["username"]))
102107
u = User(**d)
103108
u.set_password("123")
109+
if d["username"]=="admin":
110+
u.is_superuser = True
104111
u.save()
112+
105113
for d in privacy_list:
106114
user = User.get(User.c.username==d["username"])
107115
if user:

demo/apps/apijson_demo/views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
@expose('/')
66
def index():
77
if request.user:
8-
user_info = "login as user '%s'"%(request.user)
8+
user_info = "login as user '%s(%s)'"%(request.user.username,request.user)
99
else:
10-
user_info = "not login, you can login with username 'usera/userb/userc', and password '123'"
10+
user_info = "not login, you can login with username 'admin/usera/userb/userc', and password '123'"
1111
request_get = [
1212
{
13-
"label":"Single record query: with id as parameter",
13+
"label":"Single record query: no parameter",
1414
"value":'''{
1515
"user":{
16-
"id":1
1716
}
1817
}''',
1918
},
2019
{
21-
"label":"Single record query: no parameter",
20+
"label":"Single record query: with id as parameter",
2221
"value":'''{
2322
"user":{
23+
"id":1
2424
}
2525
}''',
2626
},

demo/apps/settings.ini

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ INSTALLED_APPS = [
1313
'uliweb.contrib.auth',
1414
'uliweb.contrib.i18n',
1515
'uliweb.contrib.flashmessage',
16+
'uliweb.contrib.rbac',
1617
'uliweb_apps.site',
1718
'uliweb_apps.login',
1819
'uliweb_comui',
@@ -27,14 +28,9 @@ MAINMENU = {
2728
]
2829
}
2930

30-
[APIJSON_MODEL]
31-
#overwrite user table to public for test
32-
user = {
33-
"user_id_field" : "id",
34-
"secret_fields" : ["password"],
35-
"default_filter_by_self" : True
36-
}
37-
3831
[LAYOUT]
3932
logo_lg = "Uliweb"
4033
logo_mini = "U"
34+
35+
[SESSION]
36+
timeout = 36000

demo/doc/imgs/demo_screenshot.png

21.3 KB
Loading

uliweb_apijson/apijson/README.md

Lines changed: 10 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -7,176 +7,26 @@ uliweb-apijson is a subset and slightly different variation of [apijson](https:/
77
## example
88

99
```
10-
[APIJSON_MODEL_CONFIG]
10+
[APIJSON_MODELS]
1111
user = {
12-
"public" : False,
1312
"user_id_field" : "id",
1413
"secret_fields" : ["password"],
15-
"default_filter_by_self" : True
14+
"rbac_get" : {
15+
"roles" : ["ADMIN","OWNER"]
16+
}
1617
}
1718
```
1819

1920
## document
2021

2122
settings.APIJSON_MODEL_CONFIG.[MODEL_NAME]
2223

23-
| Field | Doc |
24-
| ---------------------- | ------------------------------------------------------------ |
25-
| public | Default to be "False".<br />If not public, should be **login user** and only can see **user own data**. |
26-
| user_id_field | Field name of user id, related to query user own data. |
27-
| secret_fields | Secret fields won't be exposed. |
28-
| default_filter_by_self | If True, when no filter parameter, will filter by self user id |
24+
| Field | Doc |
25+
| ------------- | ---------------------------------------------------------- |
26+
| user_id_field | Field name of user id, related to query user own data. |
27+
| secret_fields | Secret fields won't be exposed. |
28+
| rbac_get | Configure of roles or permissions for apijson 'get' method |
2929

3030
# Supported API Examples
3131

32-
### Single record query: with id as parameter
33-
34-
URL: apijson/get
35-
36-
Method: POST
37-
38-
Request:
39-
40-
```
41-
{
42-
"user":{
43-
"id":1
44-
}
45-
}
46-
```
47-
48-
Response:
49-
50-
```
51-
{
52-
"code": 200,
53-
"msg": "success",
54-
"user": {
55-
"username": "usera",
56-
"nickname": "User A",
57-
"email": "usera@localhost",
58-
"is_superuser": false,
59-
"last_login": null,
60-
"date_join": "2018-12-05 15:44:26",
61-
"image": "",
62-
"active": false,
63-
"locked": false,
64-
"deleted": false,
65-
"auth_type": "default",
66-
"id": 1
67-
}
68-
}
69-
```
70-
71-
### Single record query: no parameter
72-
73-
URL: apijson/get
74-
75-
Method: POST
76-
77-
Request:
78-
79-
```
80-
{
81-
"user":{
82-
}
83-
}
84-
```
85-
86-
Response:
87-
88-
```
89-
{
90-
"code": 200,
91-
"msg": "success",
92-
"user": {
93-
"username": "usera",
94-
"nickname": "User A",
95-
"email": "usera@localhost",
96-
"is_superuser": false,
97-
"last_login": null,
98-
"date_join": "2018-12-05 15:44:26",
99-
"image": "",
100-
"active": false,
101-
"locked": false,
102-
"deleted": false,
103-
"auth_type": "default",
104-
"id": 1
105-
}
106-
}
107-
```
108-
109-
### Single record query: @column
110-
111-
URL: apijson/get
112-
113-
Method: POST
114-
115-
Request:
116-
117-
```
118-
{
119-
"user":{
120-
"@column": "id,username,email"
121-
}
122-
}
123-
```
124-
125-
Response:
126-
127-
```
128-
{
129-
"code": 200,
130-
"msg": "success",
131-
"user": {
132-
"username": "usera",
133-
"email": "usera@localhost",
134-
"id": 1
135-
}
136-
}
137-
```
138-
139-
### Array query
140-
141-
URL: apijson/get
142-
143-
Method: POST
144-
145-
Request:
146-
147-
```
148-
{
149-
"[]":{
150-
"@count":2,
151-
"@page":0,
152-
"user":{
153-
"@column":"id,username,nickname,email",
154-
"@order":"id-"
155-
}
156-
}
157-
}
158-
```
159-
160-
Response:
161-
162-
```
163-
{
164-
"code": 200,
165-
"msg": "success",
166-
"[]": [
167-
{
168-
"username": "userc",
169-
"nickname": "User C",
170-
"email": "userc@localhost",
171-
"id": 3
172-
},
173-
{
174-
"username": "userb",
175-
"nickname": "User B",
176-
"email": "userb@localhost",
177-
"id": 2
178-
}
179-
]
180-
}
181-
```
182-
32+
Please run [demo](../../demo/README.md) project and try it.
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
[APIJSON_MODEL_CONFIG]
1+
#apijson style role names
2+
[ROLES]
3+
ADMIN = _('APIJSON ADMIN'), 'uliweb.contrib.rbac.superuser', True
4+
UNKNOWN = _('APIJSON UNKNOWN'), 'uliweb.contrib.rbac.anonymous', True
5+
LOGIN = _('APIJSON LOGIN'), 'uliweb.contrib.rbac.trusted', True
6+
#will do more when query in the database
7+
OWNER = _('APIJSON OWNER'), 'uliweb.contrib.rbac.trusted', True
8+
9+
[APIJSON_MODELS]
210
user = {
3-
"public" : False,
411
"user_id_field" : "id",
512
"secret_fields" : ["password"],
6-
"default_filter_by_self" : True
13+
"rbac_get" : {
14+
"roles" : ["ADMIN","OWNER"]
15+
}
716
}

0 commit comments

Comments
 (0)