File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 9
9
10
10
from ircb .config import settings
11
11
from ircb .web .user import SigninView , SignoutView
12
- from ircb .web .network import NetworkListView , NetworkView
12
+ from ircb .web .network import (NetworkListView , NetworkView ,
13
+ NetworkConnectionView )
13
14
14
15
logging .config .dictConfig (settings .LOGGING_CONF )
15
16
@@ -39,6 +40,9 @@ def init(loop):
39
40
name = 'networks' )
40
41
app .router .add_route ('*' , '/api/v1/network/{id}' , NetworkView ,
41
42
name = 'network' )
43
+ app .router .add_route ('PUT' , '/api/v1/network/{id}/{action}' ,
44
+ NetworkConnectionView ,
45
+ name = 'network_connection' )
42
46
srv = yield from loop .create_server (
43
47
app .make_handler (), '0.0.0.0' , 10001 )
44
48
return srv
Original file line number Diff line number Diff line change @@ -96,3 +96,30 @@ def put(self):
96
96
raise web .HTTPNotFound ()
97
97
resp = yield from self ._create_or_update (data , username , networks [0 ])
98
98
return resp
99
+
100
+
101
+ class NetworkConnectionView (View ):
102
+ store = NetworkStore
103
+
104
+ @auth_required
105
+ @asyncio .coroutine
106
+ def put (self ):
107
+ network_id = self .request .match_info ['id' ]
108
+ action = self .request .match_info ['action' ]
109
+ if action not in ('connect' , 'disconnect' ):
110
+ raise web .HTTPNotFound ()
111
+ username = yield from get_auth (self .request )
112
+ user = yield from UserStore .get (
113
+ dict (query = ('username' , username )))
114
+ networks = yield from NetworkStore .get (
115
+ dict (query = {'user_id' : user .id , 'id' : network_id })
116
+ )
117
+ if not networks :
118
+ raise web .HTTPNotFound ()
119
+ network = networks [0 ]
120
+ network = yield from NetworkStore .update (
121
+ dict (filter = ('id' , network .id ),
122
+ update = {'status' : '0' if action == 'connect' else '2' })
123
+ )
124
+ return web .Response (body = self .serialize (network ).encode (),
125
+ content_type = 'application/json' )
You can’t perform that action at this time.
0 commit comments