-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
records: added verified field to record.
- Loading branch information
1 parent
15a164c
commit ff1434d
Showing
17 changed files
with
248 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,9 @@ | |
} | ||
} | ||
}, | ||
"is_verified": { | ||
"type": "boolean" | ||
}, | ||
"review": { | ||
"type": "object", | ||
"properties": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,9 @@ | |
} | ||
} | ||
}, | ||
"is_verified": { | ||
"type": "boolean" | ||
}, | ||
"review": { | ||
"type": "object", | ||
"properties": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,9 @@ | |
} | ||
} | ||
}, | ||
"is_verified": { | ||
"type": "boolean" | ||
}, | ||
"communities": { | ||
"properties": { | ||
"ids": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,9 @@ | |
} | ||
} | ||
}, | ||
"is_verified": { | ||
"type": "boolean" | ||
}, | ||
"communities": { | ||
"properties": { | ||
"ids": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,9 @@ | |
} | ||
} | ||
}, | ||
"is_verified": { | ||
"type": "boolean" | ||
}, | ||
"communities": { | ||
"properties": { | ||
"ids": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Record 'verified' system field.""" | ||
|
||
from invenio_records_resources.records.systemfields.calculated import CalculatedField | ||
|
||
|
||
class IsVerifiedField(CalculatedField): | ||
"""Systemfield for calculating whether or not the request is expired.""" | ||
|
||
def __init__(self, key=None): | ||
"""Constructor.""" | ||
super().__init__(key=key, use_cache=False) | ||
|
||
def calculate(self, record): | ||
"""Calculate the ``is_expired`` property of the request.""" | ||
owner = record.access.owner | ||
if not owner: | ||
return False | ||
is_verified = ( | ||
owner.resolve().verified_at is not None | ||
) # TODO property is_verified in user | ||
return is_verified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# # -*- coding: utf-8 -*- | ||
# # | ||
# # Copyright (C) 2023 CERN. | ||
# # | ||
# # Invenio-RDM is free software; you can redistribute it and/or modify | ||
# # it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Test user moderation actions.""" | ||
|
||
from invenio_access.permissions import system_identity | ||
from invenio_requests.proxies import current_requests_service | ||
|
||
from invenio_rdm_records.proxies import current_rdm_records_service as records_service | ||
|
||
|
||
def fetch_user_records(user_id, allversions=False): | ||
"""Fetches records from a given user.""" | ||
user_records_q = f"parent.access.owned_by.user:{user_id}" | ||
return records_service.search( | ||
system_identity, params={"q": user_records_q, "allversions": allversions} | ||
) | ||
|
||
|
||
def test_user_moderation_approve( | ||
running_app, | ||
mod_request_create, | ||
mod_identity, | ||
uploader, | ||
test_user, | ||
es_clear, | ||
minimal_record, | ||
): | ||
"""Tests moderation action after user approval. | ||
The user records, and all its versions, should have a "is_verified" field set to "True". | ||
""" | ||
# Create a record | ||
draft = records_service.create(uploader.identity, minimal_record) | ||
record = records_service.publish(id_=draft.id, identity=uploader.identity) | ||
|
||
# Create a new version of the record | ||
new_version = records_service.new_version(uploader.identity, id_=record.id) | ||
records_service.update_draft(uploader.identity, new_version.id, minimal_record) | ||
new_record = records_service.publish(identity=uploader.identity, id_=new_version.id) | ||
|
||
pre_approval_records = fetch_user_records(uploader.id, allversions=True) | ||
assert pre_approval_records.total == 2 | ||
hits = pre_approval_records.to_dict()["hits"]["hits"] | ||
is_verified = all([hit["parent"]["is_verified"] for hit in hits]) | ||
|
||
assert is_verified == False | ||
|
||
moderation_request = mod_request_create(uploader.id) | ||
|
||
# Approve user, records are verified from now on | ||
current_requests_service.execute_action( | ||
mod_identity, id_=moderation_request.id, action="accept" | ||
) | ||
|
||
post_approval_records = fetch_user_records(uploader.id, allversions=True) | ||
assert post_approval_records.total == 2 | ||
hits = post_approval_records.to_dict()["hits"]["hits"] | ||
is_verified = all([hit["parent"]["is_verified"] for hit in hits]) | ||
assert is_verified == True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters