Fixes handling of duplicate share access rule creation

Closes: bug 1274163
Change-Id: Id6d649dcf03c5be9ce6fd7204dfa725d59582412
This commit is contained in:
Andrei V. Ostapenko 2014-01-29 17:49:49 +02:00
parent 7eca7e3d7d
commit b103503d07
2 changed files with 7 additions and 4 deletions

View File

@ -116,8 +116,11 @@ class ShareActionsController(wsgi.Controller):
else:
exc_str = "Only 'ip' or 'sid' access types are supported"
raise webob.exc.HTTPBadRequest(explanation=exc_str)
access = self.share_api.allow_access(
context, share, access_type, access_to)
try:
access = self.share_api.allow_access(
context, share, access_type, access_to)
except exception.ShareAccessExists as e:
raise webob.exc.HTTPBadRequest(explanation=e.msg)
return {'access': access}
@wsgi.action('os-deny_access')

View File

@ -360,8 +360,8 @@ class API(base.Base):
values = {'share_id': share['id'],
'access_type': access_type,
'access_to': access_to}
access = self.db.share_access_get_all_by_type_and_access(
ctx, share['id'], access_type, access_to)
access = [a for a in self.db.share_access_get_all_by_type_and_access(
ctx, share['id'], access_type, access_to) if a['state'] != 'error']
if access:
raise exception.ShareAccessExists(access_type=access_type,
access=access_to)