X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=httpserver.py;h=9e835c3a2cd6a34e7b278969a588bd4ad9415309;hb=df24c745ecf5d0f6c129479c6037a59fe061637b;hp=ecf878c592cf226c817293f7c0c5f12fd7d93bd5;hpb=e7bedebdf51c347e44e0b709e8d3086f491b7967;p=osm%2Fopenvim.git diff --git a/httpserver.py b/httpserver.py index ecf878c..9e835c3 100644 --- a/httpserver.py +++ b/httpserver.py @@ -1042,10 +1042,11 @@ def http_get_images(tenant_id): ('id','name','description','path','public') ) if tenant_id=='any': from_ ='images' + where_or_ = None else: - from_ ='tenants_images inner join images on tenants_images.image_id=images.uuid' - where_['tenant_id'] = tenant_id - result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, LIMIT=limit_) + from_ ='tenants_images right join images on tenants_images.image_id=images.uuid' + where_or_ = {'tenant_id': tenant_id, 'public': 'yes'} + result, content = my.db.get_table(SELECT=select_, DISTINCT=True, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) if result < 0: print "http_get_images Error", content bottle.abort(-result, content) @@ -1067,11 +1068,12 @@ def http_get_image_id(tenant_id, image_id): ('id','name','description','progress', 'status','path', 'created', 'updated','public') ) if tenant_id=='any': from_ ='images' + where_or_ = None else: - from_ ='tenants_images as ti inner join images as i on ti.image_id=i.uuid' - where_['tenant_id'] = tenant_id + from_ ='tenants_images as ti right join images as i on ti.image_id=i.uuid' + where_or_ = {'tenant_id': tenant_id, 'public': "yes"} where_['uuid'] = image_id - result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, LIMIT=limit_) + result, content = my.db.get_table(SELECT=select_, DISTINCT=True, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) if result < 0: print "http_get_images error %d %s" % (result, content) @@ -1225,10 +1227,11 @@ def http_put_image_id(tenant_id, image_id): where_={'uuid': image_id} if tenant_id=='any': from_ ='images' + where_or_ = None else: - from_ ='tenants_images as ti inner join images as i on ti.image_id=i.uuid' - where_['tenant_id'] = tenant_id - result, content = my.db.get_table(SELECT=('public',), FROM=from_, WHERE=where_) + from_ ='tenants_images as ti right join images as i on ti.image_id=i.uuid' + where_or_ = {'tenant_id': tenant_id, 'public': 'yes'} + result, content = my.db.get_table(SELECT=('public',), DISTINCT=True, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND") if result==0: text_error="Image '%s' not found" % image_id if tenant_id!='any': @@ -1356,8 +1359,9 @@ def http_post_server_id(tenant_id): return server['flavor']=content[0] #check image valid and take info - result, content = my.db.get_table(FROM='tenants_images as ti join images as i on ti.image_id=i.uuid', - SELECT=('path','metadata'), WHERE={'uuid':server['image_id'], 'tenant_id':tenant_id, "status":"ACTIVE"}) + result, content = my.db.get_table(FROM='tenants_images as ti right join images as i on ti.image_id=i.uuid', + SELECT=('path','metadata'), WHERE={'uuid':server['image_id'], "status":"ACTIVE"}, + WHERE_OR={'tenant_id':tenant_id, 'public': 'yes'}, WHERE_AND_OR="AND", DISTINCT=True) if result<=0: bottle.abort(HTTP_Not_Found, 'image_id %s not found or not ACTIVE' % server['image_id']) return @@ -1499,8 +1503,9 @@ def http_server_action(server_id, tenant_id, action): else: #result==1 image_id = content[0]['image_id'] - result, content = my.db.get_table(FROM='tenants_images as ti join images as i on ti.image_id=i.uuid', - SELECT=('path','metadata'), WHERE={'uuid':image_id, 'tenant_id':tenant_id, "status":"ACTIVE"}) + result, content = my.db.get_table(FROM='tenants_images as ti right join images as i on ti.image_id=i.uuid', + SELECT=('path','metadata'), WHERE={'uuid':image_id, "status":"ACTIVE"}, + WHERE_OR={'tenant_id':tenant_id, 'public': 'yes'}, WHERE_AND_OR="AND", DISTINCT=True) if result<=0: bottle.abort(HTTP_Not_Found, 'image_id %s not found or not ACTIVE' % image_id) return