Skip to content

Commit

Permalink
Merge pull request #1721 from ianco/fix/issue-1707
Browse files Browse the repository at this point in the history
Duplicate checking for schema and cred def
  • Loading branch information
swcurran authored Apr 7, 2022
2 parents df73b64 + f523a67 commit 5077299
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aries_cloudagent/messaging/credential_definitions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq
tag = body.get("tag")
rev_reg_size = body.get("revocation_registry_size")

tag_query = {"schema_id": schema_id}
async with profile.session() as session:
storage = session.inject(BaseStorage)
found = await storage.find_all_records(
type_filter=CRED_DEF_SENT_RECORD_TYPE,
tag_query=tag_query,
)
if 0 < len(found):
# need to check the 'tag' value
for record in found:
cred_def_id = record.value
cred_def_id_parts = cred_def_id.split(":")
if tag == cred_def_id_parts[4]:
raise web.HTTPBadRequest(
reason=f"Cred def for {schema_id} {tag} already exists"
)

# check if we need to endorse
if is_author_role(context.profile):
# authors cannot write to the ledger
Expand Down
12 changes: 12 additions & 0 deletions aries_cloudagent/messaging/schemas/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ async def schemas_send_schema(request: web.BaseRequest):
schema_version = body.get("schema_version")
attributes = body.get("attributes")

tag_query = {"schema_name": schema_name, "schema_version": schema_version}
async with profile.session() as session:
storage = session.inject(BaseStorage)
found = await storage.find_all_records(
type_filter=SCHEMA_SENT_RECORD_TYPE,
tag_query=tag_query,
)
if 0 < len(found):
raise web.HTTPBadRequest(
reason=f"Schema {schema_name} {schema_version} already exists"
)

# check if we need to endorse
if is_author_role(context.profile):
# authors cannot write to the ledger
Expand Down

0 comments on commit 5077299

Please sign in to comment.