Skip to content
Snippets Groups Projects
Commit 2db68603 authored by jan.bednarik's avatar jan.bednarik
Browse files

Report type has revisions

parent 7061085b
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,8 @@ class Report(graphene.ObjectType):
is_draft = graphene.Boolean()
extra = JSONString()
edited = graphene.String()
has_revisions = graphene.Boolean()
revisions = graphene.List(lambda: Report)
class Meta:
interfaces = (relay.Node,)
......@@ -36,7 +38,7 @@ class Report(graphene.ObjectType):
@classmethod
def from_es(cls, report, author=None):
return cls(
id=report.meta.id,
id=int(report.meta.id),
author=author,
date=report.date,
published=report.published,
......@@ -86,6 +88,15 @@ class Report(graphene.ObjectType):
author = author_type.get_node(info, report.author_id)
return cls.from_es(report, author)
def resolve_has_revisions(self, info, **kwargs):
return models.Report.objects.filter(superseded_by_id=self.id).count() > 0
def resolve_revisions(self, info, **kwargs):
revisions = models.Report.objects.filter(superseded_by_id=self.id).order_by(
"-edited"
)
return [Report.from_db(r) for r in revisions]
class ReportConnection(relay.Connection):
total_count = graphene.Int()
......
......@@ -98,13 +98,12 @@ reports = [
"date": arrow.get(2018, 1, 3).datetime,
"published": arrow.get(2018, 1, 4).datetime,
"edited": arrow.get(2018, 2, 1).datetime,
"title": "The Two Towers",
"body": "Another long story in progress.",
"received_benefit": "Mithrill Jacket",
"provided_benefit": "The Ring",
"our_participants": "Frodo, Gimli, Legolas",
"other_participants": "Saruman, Sauron",
"extra": {"rings": 2},
"title": "Oldest story",
"body": "Nothing yet.",
"received_benefit": "old bread",
"provided_benefit": "",
"our_participants": "",
"other_participants": "",
},
{
"id": 7,
......
......@@ -102,6 +102,7 @@ snapshots['test_update_draft_with_draft 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 05:50:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': True,
'otherParticipants': 'grandchilds',
......@@ -109,6 +110,8 @@ snapshots['test_update_draft_with_draft 1'] = {
'providedBenefit': 'water',
'published': '2018-01-02 05:50:00+00:00',
'receivedBenefit': 'cake',
'revisions': [
],
'title': 'New title'
}
}
......@@ -130,6 +133,7 @@ snapshots['test_update_draft_with_published 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 05:50:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': False,
'otherParticipants': 'grandchilds',
......@@ -137,6 +141,8 @@ snapshots['test_update_draft_with_published 1'] = {
'providedBenefit': 'water',
'published': '2018-01-02 05:50:00+00:00',
'receivedBenefit': 'cake',
'revisions': [
],
'title': 'New title'
}
}
......@@ -158,6 +164,7 @@ snapshots['test_update_published_with_published 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 05:50:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': False,
'otherParticipants': 'grandchilds',
......@@ -165,6 +172,8 @@ snapshots['test_update_published_with_published 1'] = {
'providedBenefit': 'water',
'published': '2018-01-02 00:00:00+00:00',
'receivedBenefit': 'cake',
'revisions': [
],
'title': 'New title'
}
}
......@@ -186,6 +195,7 @@ snapshots['test_input_sanitization 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 05:50:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': False,
'otherParticipants': 'you!',
......@@ -193,6 +203,8 @@ snapshots['test_input_sanitization 1'] = {
'providedBenefit': 'tea',
'published': '2018-01-02 00:00:00+00:00',
'receivedBenefit': 'coffee',
'revisions': [
],
'title': 'No tags'
}
}
......@@ -214,6 +226,7 @@ snapshots['test_update_draft_with_draft__late_edit 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 06:10:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': True,
'otherParticipants': 'grandchilds',
......@@ -221,6 +234,8 @@ snapshots['test_update_draft_with_draft__late_edit 1'] = {
'providedBenefit': 'water',
'published': '2018-01-02 06:10:00+00:00',
'receivedBenefit': 'cake',
'revisions': [
],
'title': 'New title'
}
}
......@@ -242,6 +257,7 @@ snapshots['test_update_draft_with_published__late_edit 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 06:10:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': False,
'otherParticipants': 'grandchilds',
......@@ -249,6 +265,8 @@ snapshots['test_update_draft_with_published__late_edit 1'] = {
'providedBenefit': 'water',
'published': '2018-01-02 06:10:00+00:00',
'receivedBenefit': 'cake',
'revisions': [
],
'title': 'New title'
}
}
......@@ -365,6 +383,7 @@ snapshots['test_update_published_with_published__late_edit 1'] = {
'date': '2018-03-03 00:00:00+00:00',
'edited': '2018-01-02 06:10:00+00:00',
'extra': None,
'hasRevisions': True,
'id': 'UmVwb3J0OjY2Ng==',
'isDraft': False,
'otherParticipants': 'grandchilds',
......@@ -372,6 +391,22 @@ snapshots['test_update_published_with_published__late_edit 1'] = {
'providedBenefit': 'water',
'published': '2018-01-02 00:00:00+00:00',
'receivedBenefit': 'cake',
'revisions': [
{
'body': 'Previous body.',
'date': '2018-01-01 00:00:00+00:00',
'edited': '2018-01-02 05:00:00+00:00',
'extra': None,
'id': '__STRIPPED__',
'isDraft': False,
'otherParticipants': 'grandma',
'ourParticipants': 'grandpa',
'providedBenefit': 'old tea',
'published': '2018-01-02 00:00:00+00:00',
'receivedBenefit': 'old coffee',
'title': 'Original'
}
],
'title': 'New title'
}
}
......
......@@ -27,6 +27,21 @@ mutation updateReport ($input: UpdateReportInput!) {
isDraft
extra
edited
hasRevisions
revisions {
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
isDraft
extra
edited
}
author {
id
firstName
......@@ -171,6 +186,7 @@ def test_update_published_with_published__late_edit(
with patch("openlobby.core.api.mutations.arrow.utcnow", return_value=late_edited):
response = call_api(query, input, original_report.author)
strip_value(response, "data", "updateReport", "report", "revisions", "id")
snapshot.assert_match(response)
assert Report.objects.count() == 2
updated = Report.objects.filter(id=original_report.id).values()[0]
......
......@@ -109,3 +109,65 @@ snapshots['test_report__is_draft 1'] = {
}
}
}
snapshots['test_report__without_revisions 1'] = {
'data': {
'node': {
'hasRevisions': False,
'id': 'UmVwb3J0OjM=',
'revisions': [
],
'title': 'The Return of the King'
}
}
}
snapshots['test_report__with_revisions 1'] = {
'data': {
'node': {
'body': 'Another long story.',
'date': '2018-01-03 00:00:00+00:00',
'edited': '2018-01-04 05:00:00+00:00',
'extra': '{"rings": 1}',
'hasRevisions': True,
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
'ourParticipants': 'Frodo, Gimli, Legolas',
'providedBenefit': '',
'published': '2018-01-04 00:00:00+00:00',
'receivedBenefit': 'Mithrill Jacket',
'revisions': [
{
'body': 'What am I doing?',
'date': '2018-01-03 00:00:00+00:00',
'edited': '2018-02-05 00:00:00+00:00',
'extra': '{"rings": 1}',
'id': 'UmVwb3J0Ojc=',
'isDraft': False,
'otherParticipants': '',
'ourParticipants': 'Ringo Starr',
'providedBenefit': 'The Ringo',
'published': '2018-01-04 00:00:00+00:00',
'receivedBenefit': 'Jacket',
'title': 'The Towels'
},
{
'body': 'Nothing yet.',
'date': '2018-01-03 00:00:00+00:00',
'edited': '2018-02-01 00:00:00+00:00',
'extra': None,
'id': 'UmVwb3J0OjY=',
'isDraft': False,
'otherParticipants': '',
'ourParticipants': '',
'providedBenefit': '',
'published': '2018-01-04 00:00:00+00:00',
'receivedBenefit': 'old bread',
'title': 'Oldest story'
}
],
'title': 'The Two Towers'
}
}
}
......@@ -26,6 +26,7 @@ snapshots['test_all 1'] = {
'date': '2018-01-05 00:00:00+00:00',
'edited': '2018-01-06 07:00:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjM=',
'isDraft': False,
'otherParticipants': 'Sauron',
......@@ -51,6 +52,7 @@ snapshots['test_all 1'] = {
'date': '2018-01-03 00:00:00+00:00',
'edited': '2018-01-04 05:00:00+00:00',
'extra': '{"rings": 1}',
'hasRevisions': True,
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
......@@ -76,6 +78,7 @@ snapshots['test_all 1'] = {
'date': '2018-01-01 00:00:00+00:00',
'edited': '2018-01-02 03:00:00+00:00',
'extra': None,
'hasRevisions': True,
'id': 'UmVwb3J0OjE=',
'isDraft': False,
'otherParticipants': 'Saruman',
......@@ -117,6 +120,7 @@ snapshots['test_query 1'] = {
'date': '2018-01-03 00:00:00+00:00',
'edited': '2018-01-04 05:00:00+00:00',
'extra': '{"rings": 1}',
'hasRevisions': True,
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
......@@ -152,6 +156,7 @@ snapshots['test_highlight 1'] = {
'date': '2018-01-05 00:00:00+00:00',
'edited': '2018-01-06 07:00:00+00:00',
'extra': None,
'hasRevisions': False,
'id': 'UmVwb3J0OjM=',
'isDraft': False,
'otherParticipants': 'Sauron',
......@@ -177,6 +182,7 @@ snapshots['test_highlight 1'] = {
'date': '2018-01-01 00:00:00+00:00',
'edited': '2018-01-02 03:00:00+00:00',
'extra': None,
'hasRevisions': True,
'id': 'UmVwb3J0OjE=',
'isDraft': False,
'otherParticipants': 'Saruman',
......
......@@ -160,6 +160,71 @@ def test_report__is_draft__viewer_is_not_author(client, snapshot):
snapshot.assert_match(response)
def test_report__without_revisions(client, snapshot):
prepare_reports()
query = """
query {{
node (id:"{id}") {{
... on Report {{
id
title
hasRevisions
revisions {{
id
}}
}}
}}
}}
""".format(
id=to_global_id("Report", 3)
)
response = call_api(client, query)
snapshot.assert_match(response)
def test_report__with_revisions(client, snapshot):
prepare_reports()
query = """
query {{
node (id:"{id}") {{
... on Report {{
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
isDraft
extra
edited
hasRevisions
revisions {{
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
isDraft
extra
edited
}}
}}
}}
}}
""".format(
id=to_global_id("Report", 2)
)
response = call_api(client, query)
snapshot.assert_match(response)
def test_user__unauthorized(client, snapshot):
User.objects.create(
id=8,
......
......@@ -28,6 +28,7 @@ def test_all(client, snapshot):
isDraft
extra
edited
hasRevisions
author {
id
firstName
......@@ -72,6 +73,7 @@ def test_query(client, snapshot):
isDraft
extra
edited
hasRevisions
author {
id
firstName
......@@ -110,6 +112,7 @@ def test_highlight(client, snapshot):
isDraft
extra
edited
hasRevisions
author {
id
firstName
......
......@@ -26,7 +26,12 @@ def strip_value(data, *path):
data[element] = "__STRIPPED__"
return value
else:
if isinstance(value, dict):
return strip_value(value, *path[1:])
elif isinstance(value, list):
return [strip_value(item, *path[1:]) for item in value]
else:
raise NotImplementedError()
def dates_to_iso(data):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment