Revision 207b70d5 api/networks.py

b/api/networks.py
41 41

  
42 42

  
43 43
def network_to_dict(network, detail=True):
44
    d = {'id': network.id, 'name': network.name}
44
    network_id = str(network.id) if not network.public else 'public'
45
    d = {'id': network_id, 'name': network.name}
45 46
    if detail:
46 47
        d['updated'] = isoformat(network.updated)
47 48
        d['created'] = isoformat(network.created)
......
145 146
        raise BadRequest('Malformed request.')
146 147

  
147 148
    net = get_network(network_id, request.user)
149
    if net.public:
150
        raise Unauthorized('Can not rename the public network.')
148 151
    net.name = name
149 152
    net.save()
150 153
    return HttpResponse(status=204)
......
159 162
    #                       unauthorized (401),
160 163
    #                       overLimit (413)
161 164
    
162
    if network_id in ('1', 'public'):
163
        raise Unauthorized('Can not delete the public network.')
164 165
    net = get_network(network_id, request.user)
166
    if net.public:
167
        raise Unauthorized('Can not delete the public network.')
165 168
    backend.delete_network(net)
166 169
    return HttpResponse(status=204)
167 170

  
168 171
@api_method('POST')
169 172
def network_action(request, network_id):
170 173
    net = get_network(network_id, request.user)
174
    if net.public:
175
        raise Unauthorized('Can not modify the public network.')
176
    
171 177
    req = get_request_dict(request)
172 178
    if len(req) != 1:
173 179
        raise BadRequest('Malformed request.')

Also available in: Unified diff