Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Specify what change was made to a document in event message #438

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion creator/files/schema/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,34 @@ def mutate(self, info, kf_id, **kwargs):
):
raise GraphQLError("Not allowed")

update_fields = []

try:
if kwargs.get("name"):
if file.name != kwargs.get("name"):
update_fields.append("name")
file.name = kwargs.get("name")
if kwargs.get("description"):
if file.description != kwargs.get("description"):
update_fields.append("description")
file.description = kwargs.get("description")
if kwargs.get("file_type"):
if file.file_type != kwargs.get("file_type"):
update_fields.append("file type")
file.file_type = kwargs.get("file_type")
if "tags" in kwargs:
if file.tags != kwargs.get("tags"):
update_fields.append("tags")
file.tags = kwargs.get("tags")
file.save()
except ClientError:
raise GraphQLError("Failed to save file mutation.")

# Make an update event
message = f"{user.username} updated file {file.kf_id}"
message = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is ok to leave an event even though none of the mutable fields are modified. The updated field is still modified so I would say it's ok, though we may consider not updating at all or making an event if nothing changed.

f"{user.username} updated {', '.join(update_fields)} "
f"{'of ' if len(update_fields)>0 else ''} file {file.kf_id}"
)
event = Event(
file=file,
study=file.study,
Expand Down